Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / fileogg.h
blobc832897ec7e48058e6e03ca3a927852511bcb681
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 struct theoraframes_info_s
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;
75 typedef struct theoraframes_info_s theoraframes_info_t;
77 class FileOGG : public FileBase
79 friend class PackagingEngineOGG;
80 public:
81 FileOGG(Asset_GC asset, File *file);
82 ~FileOGG();
84 static void get_parameters(BC_WindowBase *parent_window,
85 Asset_GC asset,
86 BC_WindowBase* &format_window,
87 int audio_options,
88 int video_options);
90 int reset_parameters_derived();
91 int open_file(int rd, int wr);
92 static int check_sig(Asset_GC asset);
93 int close_file();
94 int close_file_derived();
95 int64_t get_video_position();
96 int64_t get_audio_position();
97 int set_video_position(int64_t x);
98 int set_audio_position(int64_t x);
99 int colormodel_supported(int colormodel);
100 int get_best_colormodel(Asset_GC asset, int driver);
101 int write_samples(double **buffer, int64_t len);
102 int write_frames(VFrame ***frames, int len);
103 int read_samples(double *buffer, int64_t len);
104 int read_frame(VFrame *frame);
106 private:
107 int write_samples_vorbis(double **buffer, int64_t len, int e_o_s);
108 int write_frames_theora(VFrame ***frames, int len, int e_o_s);
109 void flush_ogg(int e_o_s);
110 int write_audio_page();
111 int write_video_page();
113 FILE *stream;
114 off_t file_length;
116 theoraframes_info_t *tf;
117 VFrame *temp_frame;
118 Mutex *flush_lock;
120 off_t filedata_begin;
122 int ogg_get_last_page(sync_window_t *sw, long serialno, ogg_page *og);
123 int ogg_get_prev_page(sync_window_t *sw, long serialno, ogg_page *og);
124 int ogg_get_first_page(sync_window_t *sw, long serialno, ogg_page *og);
125 int ogg_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
126 int ogg_sync_and_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
128 int ogg_get_page_of_sample(sync_window_t *sw, long serialno, ogg_page *og, int64_t sample);
129 int ogg_seek_to_sample(sync_window_t *sw, long serialno, int64_t sample);
130 int ogg_decode_more_samples(sync_window_t *sw, long serialno);
132 int ogg_get_page_of_frame(sync_window_t *sw, long serialno, ogg_page *og, int64_t frame);
133 int ogg_seek_to_keyframe(sync_window_t *sw, long serialno, int64_t frame, int64_t *keyframe_number);
134 int ogg_seek_to_databegin(sync_window_t *sw, long serialno);
137 int64_t start_sample; // first and last sample inside this file
138 int64_t last_sample;
139 int64_t start_frame; // first and last frame inside this file
140 int64_t last_frame;
143 int64_t ogg_sample_position; // what will be the next sample taken from vorbis decoder
144 int64_t next_sample_position; // what is the next sample read_samples must deliver
146 int move_history(int from, int to, int len);
148 float **pcm_history;
149 #ifndef HISTORY_MAX
150 #define HISTORY_MAX 0x100000
151 #endif
152 int64_t history_start;
153 int64_t history_size;
155 int theora_cmodel;
156 int64_t ogg_frame_position; // LAST decoded frame position
157 int64_t next_frame_position; // what is the next sample read_frames must deliver
158 char theora_keyframe_granule_shift;
159 int final_write;
162 class OGGConfigAudio;
163 class OGGConfigVideo;
165 class OGGVorbisFixedBitrate : public BC_Radial
167 public:
168 OGGVorbisFixedBitrate(int x, int y, OGGConfigAudio *gui);
169 int handle_event();
170 OGGConfigAudio *gui;
173 class OGGVorbisVariableBitrate : public BC_Radial
175 public:
176 OGGVorbisVariableBitrate(int x, int y, OGGConfigAudio *gui);
177 int handle_event();
178 OGGConfigAudio *gui;
181 class OGGVorbisMinBitrate : public BC_TextBox
183 public:
184 OGGVorbisMinBitrate(int x,
185 int y,
186 OGGConfigAudio *gui,
187 char *text);
188 int handle_event();
189 OGGConfigAudio *gui;
192 class OGGVorbisMaxBitrate : public BC_TextBox
194 public:
195 OGGVorbisMaxBitrate(int x,
196 int y,
197 OGGConfigAudio *gui,
198 char *text);
199 int handle_event();
200 OGGConfigAudio *gui;
203 class OGGVorbisAvgBitrate : public BC_TextBox
205 public:
206 OGGVorbisAvgBitrate(int x,
207 int y,
208 OGGConfigAudio *gui,
209 char *text);
210 int handle_event();
211 OGGConfigAudio *gui;
215 class OGGConfigAudio: public BC_Window
217 public:
218 OGGConfigAudio(BC_WindowBase *parent_window, Asset_GC asset);
219 ~OGGConfigAudio();
221 int create_objects();
222 int close_event();
224 Asset_GC asset;
225 OGGVorbisFixedBitrate *fixed_bitrate;
226 OGGVorbisVariableBitrate *variable_bitrate;
227 private:
228 BC_WindowBase *parent_window;
229 char string[BCTEXTLEN];
233 class OGGTheoraBitrate : public BC_TextBox
235 public:
236 OGGTheoraBitrate(int x, int y, OGGConfigVideo *gui);
237 int handle_event();
238 OGGConfigVideo *gui;
241 class OGGTheoraKeyframeFrequency : public BC_TumbleTextBox
243 public:
244 OGGTheoraKeyframeFrequency(int x, int y, OGGConfigVideo *gui);
245 int handle_event();
246 OGGConfigVideo *gui;
249 class OGGTheoraKeyframeForceFrequency : public BC_TumbleTextBox
251 public:
252 OGGTheoraKeyframeForceFrequency(int x, int y, OGGConfigVideo *gui);
253 int handle_event();
254 OGGConfigVideo *gui;
257 class OGGTheoraSharpness : public BC_TumbleTextBox
259 public:
260 OGGTheoraSharpness(int x, int y, OGGConfigVideo *gui);
261 int handle_event();
262 OGGConfigVideo *gui;
265 class OGGTheoraFixedBitrate : public BC_Radial
267 public:
268 OGGTheoraFixedBitrate(int x, int y, OGGConfigVideo *gui);
269 int handle_event();
270 OGGConfigVideo *gui;
273 class OGGTheoraFixedQuality : public BC_Radial
275 public:
276 OGGTheoraFixedQuality(int x, int y, OGGConfigVideo *gui);
277 int handle_event();
278 OGGConfigVideo *gui;
283 class OGGConfigVideo: public BC_Window
285 public:
286 OGGConfigVideo(BC_WindowBase *parent_window, Asset_GC asset);
287 ~OGGConfigVideo();
289 int create_objects();
290 int close_event();
292 OGGTheoraFixedBitrate *fixed_bitrate;
293 OGGTheoraFixedQuality *fixed_quality;
294 Asset_GC asset;
295 private:
296 BC_WindowBase *parent_window;
299 class PackagingEngineOGG : public PackagingEngine
301 public:
302 PackagingEngineOGG();
303 ~PackagingEngineOGG();
304 int create_packages_single_farm(
305 EDL *edl,
306 Preferences *preferences,
307 Asset_GC default_asset,
308 double total_start,
309 double total_end);
310 RenderPackage* get_package_single_farm(double frames_per_second,
311 int client_number,
312 int use_local_rate);
313 int64_t get_progress_max();
314 void get_package_paths(ArrayList<char*> *path_list);
315 int packages_are_done();
317 private:
318 EDL *edl;
320 RenderPackage **packages;
321 int total_packages;
322 double video_package_len; // Target length of a single package
324 Asset_GC default_asset;
325 Preferences *preferences;
326 int current_package;
327 double total_start;
328 double total_end;
329 int64_t audio_position;
330 int64_t video_position;
331 int64_t audio_start;
332 int64_t video_start;
333 int64_t audio_end;
334 int64_t video_end;
339 #endif
341 // Local Variables:
342 // mode: C++
343 // c-file-style: "linux"
344 // End: