license header for review
[cinelerra_cv/ct.git] / cinelerra / fileogg.h
blob6afde9e6f8fadc6cbdc67271195be4620c306fad
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 audiopage;
30 ogg_page videopage;
32 double audiotime;
33 double videotime;
34 ogg_int64_t audio_bytesout;
35 ogg_int64_t video_bytesout;
37 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
38 ogg_packet op; /* one raw packet of data for decode */
40 theora_info ti;
41 theora_comment tc;
42 theora_state td;
44 vorbis_info vi; /* struct that stores all the static vorbis bitstream settings */
45 vorbis_comment vc; /* struct that stores all the user comments */
46 vorbis_dsp_state vd; /* central working state for the packet<->PCM encoder/decoder */
47 vorbis_block vb; /* local working space for packet<->PCM encode/decode */
49 /* used for muxing */
50 ogg_stream_state to; /* take physical pages, weld into a logical
51 * stream of packets */
52 ogg_stream_state vo; /* take physical pages, weld into a logical
53 * stream of packets */
55 int apage_valid;
56 int vpage_valid;
57 unsigned char *apage;
58 unsigned char *vpage;
59 int vpage_len;
60 int apage_len;
61 int vpage_buffer_length;
62 int apage_buffer_length;
65 // stuff needed for reading only
66 sync_window_t *audiosync;
67 sync_window_t *videosync;
69 //to do some manual page flusing
70 int v_pkg;
71 int a_pkg;
74 theoraframes_info_t;
76 class FileOGG : public FileBase
78 friend class PackagingEngineOGG;
79 public:
80 FileOGG(Asset_GC asset, File *file);
81 ~FileOGG();
83 static void get_parameters(BC_WindowBase *parent_window,
84 Asset_GC asset,
85 BC_WindowBase* &format_window,
86 int audio_options,
87 int video_options);
89 int reset_parameters_derived();
90 int open_file(int rd, int wr);
91 static int check_sig(Asset_GC asset);
92 int close_file();
93 int close_file_derived();
94 int64_t get_video_position();
95 int64_t get_audio_position();
96 int set_video_position(int64_t x);
97 int set_audio_position(int64_t x);
98 int colormodel_supported(int colormodel);
99 int get_best_colormodel(Asset_GC asset, int driver);
100 int write_samples(double **buffer, int64_t len);
101 int write_frames(VFrame ***frames, int len);
102 int read_samples(double *buffer, int64_t len);
103 int read_frame(VFrame *frame);
105 private:
106 int write_samples_vorbis(double **buffer, int64_t len, int e_o_s);
107 int write_frames_theora(VFrame ***frames, int len, int e_o_s);
108 void flush_ogg(int e_o_s);
109 int write_audio_page();
110 int write_video_page();
112 FILE *stream;
113 off_t file_length;
115 theoraframes_info_t *tf;
116 VFrame *temp_frame;
117 Mutex *flush_lock;
119 off_t filedata_begin;
121 int ogg_get_last_page(sync_window_t *sw, long serialno, ogg_page *og);
122 int ogg_get_prev_page(sync_window_t *sw, long serialno, ogg_page *og);
123 int ogg_get_first_page(sync_window_t *sw, long serialno, ogg_page *og);
124 int ogg_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
125 int ogg_sync_and_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
127 int ogg_get_page_of_sample(sync_window_t *sw, long serialno, ogg_page *og, int64_t sample);
128 int ogg_seek_to_sample(sync_window_t *sw, long serialno, int64_t sample);
129 int ogg_decode_more_samples(sync_window_t *sw, long serialno);
131 int ogg_get_page_of_frame(sync_window_t *sw, long serialno, ogg_page *og, int64_t frame);
132 int ogg_seek_to_keyframe(sync_window_t *sw, long serialno, int64_t frame, int64_t *keyframe_number);
133 int ogg_seek_to_databegin(sync_window_t *sw, long serialno);
136 int64_t start_sample; // first and last sample inside this file
137 int64_t last_sample;
138 int64_t start_frame; // first and last frame inside this file
139 int64_t last_frame;
142 int64_t ogg_sample_position; // what will be the next sample taken from vorbis decoder
143 int64_t next_sample_position; // what is the next sample read_samples must deliver
145 int move_history(int from, int to, int len);
147 float **pcm_history;
148 #ifndef HISTORY_MAX
149 #define HISTORY_MAX 0x100000
150 #endif
151 int64_t history_start;
152 int64_t history_size;
154 int theora_cmodel;
155 int64_t ogg_frame_position; // LAST decoded frame position
156 int64_t next_frame_position; // what is the next sample read_frames must deliver
157 char theora_keyframe_granule_shift;
158 int final_write;
161 class OGGConfigAudio;
162 class OGGConfigVideo;
164 class OGGVorbisFixedBitrate : public BC_Radial
166 public:
167 OGGVorbisFixedBitrate(int x, int y, OGGConfigAudio *gui);
168 int handle_event();
169 OGGConfigAudio *gui;
172 class OGGVorbisVariableBitrate : public BC_Radial
174 public:
175 OGGVorbisVariableBitrate(int x, int y, OGGConfigAudio *gui);
176 int handle_event();
177 OGGConfigAudio *gui;
180 class OGGVorbisMinBitrate : public BC_TextBox
182 public:
183 OGGVorbisMinBitrate(int x,
184 int y,
185 OGGConfigAudio *gui,
186 char *text);
187 int handle_event();
188 OGGConfigAudio *gui;
191 class OGGVorbisMaxBitrate : public BC_TextBox
193 public:
194 OGGVorbisMaxBitrate(int x,
195 int y,
196 OGGConfigAudio *gui,
197 char *text);
198 int handle_event();
199 OGGConfigAudio *gui;
202 class OGGVorbisAvgBitrate : public BC_TextBox
204 public:
205 OGGVorbisAvgBitrate(int x,
206 int y,
207 OGGConfigAudio *gui,
208 char *text);
209 int handle_event();
210 OGGConfigAudio *gui;
214 class OGGConfigAudio: public BC_Window
216 public:
217 OGGConfigAudio(BC_WindowBase *parent_window, Asset_GC asset);
218 ~OGGConfigAudio();
220 int create_objects();
221 int close_event();
223 Asset_GC asset;
224 OGGVorbisFixedBitrate *fixed_bitrate;
225 OGGVorbisVariableBitrate *variable_bitrate;
226 private:
227 BC_WindowBase *parent_window;
228 char string[BCTEXTLEN];
232 class OGGTheoraBitrate : public BC_TextBox
234 public:
235 OGGTheoraBitrate(int x, int y, OGGConfigVideo *gui);
236 int handle_event();
237 OGGConfigVideo *gui;
240 class OGGTheoraKeyframeFrequency : public BC_TumbleTextBox
242 public:
243 OGGTheoraKeyframeFrequency(int x, int y, OGGConfigVideo *gui);
244 int handle_event();
245 OGGConfigVideo *gui;
248 class OGGTheoraKeyframeForceFrequency : public BC_TumbleTextBox
250 public:
251 OGGTheoraKeyframeForceFrequency(int x, int y, OGGConfigVideo *gui);
252 int handle_event();
253 OGGConfigVideo *gui;
256 class OGGTheoraSharpness : public BC_TumbleTextBox
258 public:
259 OGGTheoraSharpness(int x, int y, OGGConfigVideo *gui);
260 int handle_event();
261 OGGConfigVideo *gui;
264 class OGGTheoraFixedBitrate : public BC_Radial
266 public:
267 OGGTheoraFixedBitrate(int x, int y, OGGConfigVideo *gui);
268 int handle_event();
269 OGGConfigVideo *gui;
272 class OGGTheoraFixedQuality : public BC_Radial
274 public:
275 OGGTheoraFixedQuality(int x, int y, OGGConfigVideo *gui);
276 int handle_event();
277 OGGConfigVideo *gui;
282 class OGGConfigVideo: public BC_Window
284 public:
285 OGGConfigVideo(BC_WindowBase *parent_window, Asset_GC asset);
286 ~OGGConfigVideo();
288 int create_objects();
289 int close_event();
291 OGGTheoraFixedBitrate *fixed_bitrate;
292 OGGTheoraFixedQuality *fixed_quality;
293 Asset_GC asset;
294 private:
295 BC_WindowBase *parent_window;
298 class PackagingEngineOGG : public PackagingEngine
300 public:
301 PackagingEngineOGG();
302 ~PackagingEngineOGG();
303 int create_packages_single_farm(
304 EDL *edl,
305 Preferences *preferences,
306 Asset_GC default_asset,
307 double total_start,
308 double total_end);
309 RenderPackage* get_package_single_farm(double frames_per_second,
310 int client_number,
311 int use_local_rate);
312 int64_t get_progress_max();
313 void get_package_paths(ArrayList<char*> *path_list);
314 int packages_are_done();
316 private:
317 EDL *edl;
319 RenderPackage **packages;
320 int total_packages;
321 double video_package_len; // Target length of a single package
323 Asset_GC default_asset;
324 Preferences *preferences;
325 int current_package;
326 double total_start;
327 double total_end;
328 int64_t audio_position;
329 int64_t video_position;
330 int64_t audio_start;
331 int64_t video_start;
332 int64_t audio_end;
333 int64_t video_end;
338 #endif
340 // Local Variables:
341 // mode: C++
342 // c-file-style: "linux"
343 // End: