r802: Remove renderframfsclient and renderfarmfsserver .h and .C from Makefile.am...
[cinelerra_cv/mob.git] / cinelerra / fileogg.h
blob051aab32779bc48de660726920d4c4c7299760d9
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;
73 theoraframes_info_t;
75 class FileOGG : public FileBase
77 public:
78 FileOGG(Asset *asset, File *file);
79 ~FileOGG();
81 static void get_parameters(BC_WindowBase *parent_window,
82 Asset *asset,
83 BC_WindowBase* &format_window,
84 int audio_options,
85 int video_options);
87 int reset_parameters_derived();
88 int open_file(int rd, int wr);
89 static int check_sig(Asset *asset);
90 int close_file();
91 int close_file_derived();
92 int64_t get_video_position();
93 int64_t get_audio_position();
94 int set_video_position(int64_t x);
95 int set_audio_position(int64_t x);
96 int colormodel_supported(int colormodel);
97 int get_best_colormodel(Asset *asset, int driver);
98 int write_samples(double **buffer, int64_t len);
99 int write_frames(VFrame ***frames, int len);
100 int read_samples(double *buffer, int64_t len);
101 int read_frame(VFrame *frame);
103 private:
104 int write_samples_vorbis(double **buffer, int64_t len, int e_o_s);
105 int write_frames_theora(VFrame ***frames, int len, int e_o_s);
106 void flush_ogg(int e_o_s);
107 int write_audio_page();
108 int write_video_page();
110 FILE *stream;
111 off_t file_length;
113 theoraframes_info_t *tf;
114 VFrame *temp_frame;
115 Mutex *flush_lock;
117 off_t filedata_begin;
119 int ogg_get_last_page(sync_window_t *sw, long serialno, ogg_page *og);
120 int ogg_get_prev_page(sync_window_t *sw, long serialno, ogg_page *og);
121 int ogg_get_first_page(sync_window_t *sw, long serialno, ogg_page *og);
122 int ogg_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
123 int ogg_sync_and_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
125 int ogg_get_page_of_sample(sync_window_t *sw, long serialno, ogg_page *og, int64_t sample);
126 int ogg_seek_to_sample(sync_window_t *sw, long serialno, int64_t sample);
127 int ogg_decode_more_samples(sync_window_t *sw, long serialno);
129 int ogg_get_page_of_frame(sync_window_t *sw, long serialno, ogg_page *og, int64_t frame);
130 int ogg_seek_to_keyframe(sync_window_t *sw, long serialno, int64_t frame, int64_t *keyframe_number);
133 int64_t start_sample; // first and last sample inside this file
134 int64_t last_sample;
135 int64_t start_frame; // first and last frame inside this file
136 int64_t last_frame;
139 int64_t ogg_sample_position; // what will be the next sample taken from vorbis decoder
140 int64_t next_sample_position; // what is the next sample read_samples must deliver
142 int move_history(int from, int to, int len);
144 float **pcm_history;
145 #ifndef HISTORY_MAX
146 #define HISTORY_MAX 0x100000
147 #endif
148 int64_t history_start;
149 int64_t history_size;
151 int theora_cmodel;
152 int64_t ogg_frame_position; // LAST decoded frame position
153 int64_t next_frame_position; // what is the next sample read_frames must deliver
154 char theora_keyframe_granule_shift;
157 class OGGConfigAudio;
158 class OGGConfigVideo;
160 class OGGVorbisFixedBitrate : public BC_Radial
162 public:
163 OGGVorbisFixedBitrate(int x, int y, OGGConfigAudio *gui);
164 int handle_event();
165 OGGConfigAudio *gui;
168 class OGGVorbisVariableBitrate : public BC_Radial
170 public:
171 OGGVorbisVariableBitrate(int x, int y, OGGConfigAudio *gui);
172 int handle_event();
173 OGGConfigAudio *gui;
176 class OGGVorbisMinBitrate : public BC_TextBox
178 public:
179 OGGVorbisMinBitrate(int x,
180 int y,
181 OGGConfigAudio *gui,
182 char *text);
183 int handle_event();
184 OGGConfigAudio *gui;
187 class OGGVorbisMaxBitrate : public BC_TextBox
189 public:
190 OGGVorbisMaxBitrate(int x,
191 int y,
192 OGGConfigAudio *gui,
193 char *text);
194 int handle_event();
195 OGGConfigAudio *gui;
198 class OGGVorbisAvgBitrate : public BC_TextBox
200 public:
201 OGGVorbisAvgBitrate(int x,
202 int y,
203 OGGConfigAudio *gui,
204 char *text);
205 int handle_event();
206 OGGConfigAudio *gui;
210 class OGGConfigAudio: public BC_Window
212 public:
213 OGGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
214 ~OGGConfigAudio();
216 int create_objects();
217 int close_event();
219 Asset *asset;
220 OGGVorbisFixedBitrate *fixed_bitrate;
221 OGGVorbisVariableBitrate *variable_bitrate;
222 private:
223 BC_WindowBase *parent_window;
224 char string[BCTEXTLEN];
228 class OGGTheoraBitrate : public BC_TextBox
230 public:
231 OGGTheoraBitrate(int x, int y, OGGConfigVideo *gui);
232 int handle_event();
233 OGGConfigVideo *gui;
236 class OGGTheoraKeyframeFrequency : public BC_TumbleTextBox
238 public:
239 OGGTheoraKeyframeFrequency(int x, int y, OGGConfigVideo *gui);
240 int handle_event();
241 OGGConfigVideo *gui;
244 class OGGTheoraKeyframeForceFrequency : public BC_TumbleTextBox
246 public:
247 OGGTheoraKeyframeForceFrequency(int x, int y, OGGConfigVideo *gui);
248 int handle_event();
249 OGGConfigVideo *gui;
252 class OGGTheoraSharpness : public BC_TumbleTextBox
254 public:
255 OGGTheoraSharpness(int x, int y, OGGConfigVideo *gui);
256 int handle_event();
257 OGGConfigVideo *gui;
260 class OGGTheoraFixedBitrate : public BC_Radial
262 public:
263 OGGTheoraFixedBitrate(int x, int y, OGGConfigVideo *gui);
264 int handle_event();
265 OGGConfigVideo *gui;
268 class OGGTheoraFixedQuality : public BC_Radial
270 public:
271 OGGTheoraFixedQuality(int x, int y, OGGConfigVideo *gui);
272 int handle_event();
273 OGGConfigVideo *gui;
278 class OGGConfigVideo: public BC_Window
280 public:
281 OGGConfigVideo(BC_WindowBase *parent_window, Asset *asset);
282 ~OGGConfigVideo();
284 int create_objects();
285 int close_event();
287 OGGTheoraFixedBitrate *fixed_bitrate;
288 OGGTheoraFixedQuality *fixed_quality;
289 Asset *asset;
290 private:
291 BC_WindowBase *parent_window;
295 #endif