r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / fileogg.h
blob9182301fe2593897aba1d7af2ab2eb72ef633131
1 #ifndef FILEOGG_H
2 #define FILEOGG_H
4 #include "../config.h"
5 #include "filebase.h"
6 #include "file.inc"
8 #include <theora/theora.h>
9 #include <vorbis/codec.h>
10 #include <vorbis/vorbisenc.h>
13 #include <libdv/dv.h>
15 /* This code was aspired by ffmpeg2theora */
16 /* Special thanks for help on this code goes out to j@v2v.cc */
18 typedef struct
20 ogg_sync_state sync;
21 off_t file_bufpos; // position of the start of the buffer inside the file
22 off_t file_pagepos; // position of the page that will be next read
23 off_t file_pagepos_found; // position of last page that was returned (in seeking operations)
24 int wlen;
25 } sync_window_t;
27 typedef struct
29 ogg_page videopage;
30 ogg_page audiopage;
31 int audioflag;
32 int videoflag;
33 double audiotime;
34 double videotime;
35 ogg_int64_t audio_bytesout;
36 ogg_int64_t video_bytesout;
38 ogg_stream_state to; /* take physical pages, weld into a logical
39 * stream of packets */
40 ogg_stream_state vo; /* take physical pages, weld into a logical
41 * stream of packets */
42 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
43 ogg_packet op; /* one raw packet of data for decode */
45 theora_info ti;
46 theora_comment tc;
47 theora_state td;
50 vorbis_info vi; /* struct that stores all the static vorbis bitstream settings */
51 vorbis_comment vc; /* struct that stores all the user comments */
52 vorbis_dsp_state vd; /* central working state for the packet<->PCM encoder/decoder */
53 vorbis_block vb; /* local working space for packet<->PCM encode/decode */
55 // stuff needed for reading only
56 sync_window_t *audiosync;
57 sync_window_t *videosync;
61 theoraframes_info_t;
63 class FileOGG : public FileBase
65 public:
66 FileOGG(Asset *asset, File *file);
67 ~FileOGG();
69 static void get_parameters(BC_WindowBase *parent_window,
70 Asset *asset,
71 BC_WindowBase* &format_window,
72 int audio_options,
73 int video_options);
75 int reset_parameters_derived();
76 int open_file(int rd, int wr);
77 static int check_sig(Asset *asset);
78 int close_file();
79 int close_file_derived();
80 int64_t get_video_position();
81 int64_t get_audio_position();
82 int set_video_position(int64_t x);
83 int set_audio_position(int64_t x);
84 int colormodel_supported(int colormodel);
85 int get_best_colormodel(Asset *asset, int driver);
86 int write_samples(double **buffer, int64_t len);
87 int write_frames(VFrame ***frames, int len);
88 int read_samples(double *buffer, int64_t len);
89 int read_frame(VFrame *frame);
91 private:
92 int write_samples_vorbis(double **buffer, int64_t len, int e_o_s);
93 int write_frames_theora(VFrame ***frames, int len, int e_o_s);
94 int flush_ogg(int e_o_s);
96 FILE *stream;
97 off_t file_length;
99 theoraframes_info_t *tf;
100 VFrame *temp_frame;
101 Mutex *flush_lock;
103 off_t filedata_begin;
105 int ogg_get_last_page(sync_window_t *sw, long serialno, ogg_page *og);
106 int ogg_get_prev_page(sync_window_t *sw, long serialno, ogg_page *og);
107 int ogg_get_first_page(sync_window_t *sw, long serialno, ogg_page *og);
108 int ogg_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
109 int ogg_sync_and_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
111 int ogg_get_page_of_sample(sync_window_t *sw, long serialno, ogg_page *og, int64_t sample);
112 int ogg_seek_to_sample(sync_window_t *sw, long serialno, int64_t sample);
113 int ogg_decode_more_samples(sync_window_t *sw, long serialno);
115 int ogg_get_page_of_frame(sync_window_t *sw, long serialno, ogg_page *og, int64_t frame);
116 int ogg_seek_to_keyframe(sync_window_t *sw, long serialno, int64_t frame, int64_t *keyframe_number);
119 int64_t start_sample; // first and last sample inside this file
120 int64_t last_sample;
121 int64_t start_frame; // first and last frame inside this file
122 int64_t last_frame;
125 int64_t ogg_sample_position; // what will be the next sample taken from vorbis decoder
126 int64_t next_sample_position; // what is the next sample read_samples must deliver
128 int move_history(int from, int to, int len);
130 float **pcm_history;
131 //#define HISTORY_MAX 0x100000
132 #define HISTORY_MAX 100000
133 int64_t history_start;
134 int64_t history_size;
136 int theora_cmodel;
137 int64_t ogg_frame_position; // LAST decoded frame position
138 int64_t next_frame_position; // what is the next sample read_frames must deliver
139 char theora_keyframe_granule_shift;
142 class OGGConfigAudio;
143 class OGGConfigVideo;
145 class OGGVorbisFixedBitrate : public BC_Radial
147 public:
148 OGGVorbisFixedBitrate(int x, int y, OGGConfigAudio *gui);
149 int handle_event();
150 OGGConfigAudio *gui;
153 class OGGVorbisVariableBitrate : public BC_Radial
155 public:
156 OGGVorbisVariableBitrate(int x, int y, OGGConfigAudio *gui);
157 int handle_event();
158 OGGConfigAudio *gui;
161 class OGGVorbisMinBitrate : public BC_TextBox
163 public:
164 OGGVorbisMinBitrate(int x,
165 int y,
166 OGGConfigAudio *gui,
167 char *text);
168 int handle_event();
169 OGGConfigAudio *gui;
172 class OGGVorbisMaxBitrate : public BC_TextBox
174 public:
175 OGGVorbisMaxBitrate(int x,
176 int y,
177 OGGConfigAudio *gui,
178 char *text);
179 int handle_event();
180 OGGConfigAudio *gui;
183 class OGGVorbisAvgBitrate : public BC_TextBox
185 public:
186 OGGVorbisAvgBitrate(int x,
187 int y,
188 OGGConfigAudio *gui,
189 char *text);
190 int handle_event();
191 OGGConfigAudio *gui;
195 class OGGConfigAudio: public BC_Window
197 public:
198 OGGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
199 ~OGGConfigAudio();
201 int create_objects();
202 int close_event();
204 Asset *asset;
205 OGGVorbisFixedBitrate *fixed_bitrate;
206 OGGVorbisVariableBitrate *variable_bitrate;
207 private:
208 BC_WindowBase *parent_window;
209 char string[BCTEXTLEN];
213 class OGGTheoraBitrate : public BC_TextBox
215 public:
216 OGGTheoraBitrate(int x, int y, OGGConfigVideo *gui);
217 int handle_event();
218 OGGConfigVideo *gui;
221 class OGGTheoraKeyframeFrequency : public BC_TumbleTextBox
223 public:
224 OGGTheoraKeyframeFrequency(int x, int y, OGGConfigVideo *gui);
225 int handle_event();
226 OGGConfigVideo *gui;
229 class OGGTheoraKeyframeForceFrequency : public BC_TumbleTextBox
231 public:
232 OGGTheoraKeyframeForceFrequency(int x, int y, OGGConfigVideo *gui);
233 int handle_event();
234 OGGConfigVideo *gui;
237 class OGGTheoraSharpness : public BC_TumbleTextBox
239 public:
240 OGGTheoraSharpness(int x, int y, OGGConfigVideo *gui);
241 int handle_event();
242 OGGConfigVideo *gui;
245 class OGGTheoraFixedBitrate : public BC_Radial
247 public:
248 OGGTheoraFixedBitrate(int x, int y, OGGConfigVideo *gui);
249 int handle_event();
250 OGGConfigVideo *gui;
253 class OGGTheoraFixedQuality : public BC_Radial
255 public:
256 OGGTheoraFixedQuality(int x, int y, OGGConfigVideo *gui);
257 int handle_event();
258 OGGConfigVideo *gui;
263 class OGGConfigVideo: public BC_Window
265 public:
266 OGGConfigVideo(BC_WindowBase *parent_window, Asset *asset);
267 ~OGGConfigVideo();
269 int create_objects();
270 int close_event();
272 OGGTheoraFixedBitrate *fixed_bitrate;
273 OGGTheoraFixedQuality *fixed_quality;
274 Asset *asset;
275 private:
276 BC_WindowBase *parent_window;
280 #endif