00001 #ifndef FILEOGG_H
00002 #define FILEOGG_H
00003
00004 #include "../config.h"
00005 #include "filebase.h"
00006 #include "file.inc"
00007
00008 #include <theora/theora.h>
00009 #include <vorbis/codec.h>
00010 #include <vorbis/vorbisenc.h>
00011
00012
00013 #include <libdv/dv.h>
00014
00015
00016
00017
00018 typedef struct
00019 {
00020 ogg_sync_state sync;
00021 off_t file_bufpos;
00022 off_t file_pagepos;
00023 off_t file_pagepos_found;
00024 int wlen;
00025 } sync_window_t;
00026
00027 typedef struct
00028 {
00029 ogg_page audiopage;
00030 ogg_page videopage;
00031
00032 double audiotime;
00033 double videotime;
00034 ogg_int64_t audio_bytesout;
00035 ogg_int64_t video_bytesout;
00036
00037 ogg_page og;
00038 ogg_packet op;
00039
00040 theora_info ti;
00041 theora_comment tc;
00042 theora_state td;
00043
00044 vorbis_info vi;
00045 vorbis_comment vc;
00046 vorbis_dsp_state vd;
00047 vorbis_block vb;
00048
00049
00050 ogg_stream_state to;
00051
00052 ogg_stream_state vo;
00053
00054
00055 int apage_valid;
00056 int vpage_valid;
00057 unsigned char *apage;
00058 unsigned char *vpage;
00059 int vpage_len;
00060 int apage_len;
00061 int vpage_buffer_length;
00062 int apage_buffer_length;
00063
00064
00065
00066 sync_window_t *audiosync;
00067 sync_window_t *videosync;
00068
00069
00070 int v_pkg;
00071 int a_pkg;
00072
00073 }
00074 theoraframes_info_t;
00075
00076 class FileOGG : public FileBase
00077 {
00078 friend class PackagingEngineOGG;
00079 public:
00080 FileOGG(Asset *asset, File *file);
00081 ~FileOGG();
00082
00083 static void get_parameters(BC_WindowBase *parent_window,
00084 Asset *asset,
00085 BC_WindowBase* &format_window,
00086 int audio_options,
00087 int video_options);
00088
00089 int reset_parameters_derived();
00090 int open_file(int rd, int wr);
00091 static int check_sig(Asset *asset);
00092 int close_file();
00093 int close_file_derived();
00094 int64_t get_video_position();
00095 int64_t get_audio_position();
00096 int set_video_position(int64_t x);
00097 int set_audio_position(int64_t x);
00098 int colormodel_supported(int colormodel);
00099 int get_best_colormodel(Asset *asset, int driver);
00100 int write_samples(double **buffer, int64_t len);
00101 int write_frames(VFrame ***frames, int len);
00102 int read_samples(double *buffer, int64_t len);
00103 int read_frame(VFrame *frame);
00104
00105 private:
00106 int write_samples_vorbis(double **buffer, int64_t len, int e_o_s);
00107 int write_frames_theora(VFrame ***frames, int len, int e_o_s);
00108 void flush_ogg(int e_o_s);
00109 int write_audio_page();
00110 int write_video_page();
00111
00112 FILE *stream;
00113 off_t file_length;
00114
00115 theoraframes_info_t *tf;
00116 VFrame *temp_frame;
00117 Mutex *flush_lock;
00118
00119 off_t filedata_begin;
00120
00121 int ogg_get_last_page(sync_window_t *sw, long serialno, ogg_page *og);
00122 int ogg_get_prev_page(sync_window_t *sw, long serialno, ogg_page *og);
00123 int ogg_get_first_page(sync_window_t *sw, long serialno, ogg_page *og);
00124 int ogg_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
00125 int ogg_sync_and_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
00126
00127 int ogg_get_page_of_sample(sync_window_t *sw, long serialno, ogg_page *og, int64_t sample);
00128 int ogg_seek_to_sample(sync_window_t *sw, long serialno, int64_t sample);
00129 int ogg_decode_more_samples(sync_window_t *sw, long serialno);
00130
00131 int ogg_get_page_of_frame(sync_window_t *sw, long serialno, ogg_page *og, int64_t frame);
00132 int ogg_seek_to_keyframe(sync_window_t *sw, long serialno, int64_t frame, int64_t *keyframe_number);
00133 int ogg_seek_to_databegin(sync_window_t *sw, long serialno);
00134
00135
00136 int64_t start_sample;
00137 int64_t last_sample;
00138 int64_t start_frame;
00139 int64_t last_frame;
00140
00141
00142 int64_t ogg_sample_position;
00143 int64_t next_sample_position;
00144
00145 int move_history(int from, int to, int len);
00146
00147 float **pcm_history;
00148 #ifndef HISTORY_MAX
00149 #define HISTORY_MAX 0x100000
00150 #endif
00151 int64_t history_start;
00152 int64_t history_size;
00153
00154 int theora_cmodel;
00155 int64_t ogg_frame_position;
00156 int64_t next_frame_position;
00157 char theora_keyframe_granule_shift;
00158 int final_write;
00159 };
00160
00161 class OGGConfigAudio;
00162 class OGGConfigVideo;
00163
00164 class OGGVorbisFixedBitrate : public BC_Radial
00165 {
00166 public:
00167 OGGVorbisFixedBitrate(int x, int y, OGGConfigAudio *gui);
00168 int handle_event();
00169 OGGConfigAudio *gui;
00170 };
00171
00172 class OGGVorbisVariableBitrate : public BC_Radial
00173 {
00174 public:
00175 OGGVorbisVariableBitrate(int x, int y, OGGConfigAudio *gui);
00176 int handle_event();
00177 OGGConfigAudio *gui;
00178 };
00179
00180 class OGGVorbisMinBitrate : public BC_TextBox
00181 {
00182 public:
00183 OGGVorbisMinBitrate(int x,
00184 int y,
00185 OGGConfigAudio *gui,
00186 char *text);
00187 int handle_event();
00188 OGGConfigAudio *gui;
00189 };
00190
00191 class OGGVorbisMaxBitrate : public BC_TextBox
00192 {
00193 public:
00194 OGGVorbisMaxBitrate(int x,
00195 int y,
00196 OGGConfigAudio *gui,
00197 char *text);
00198 int handle_event();
00199 OGGConfigAudio *gui;
00200 };
00201
00202 class OGGVorbisAvgBitrate : public BC_TextBox
00203 {
00204 public:
00205 OGGVorbisAvgBitrate(int x,
00206 int y,
00207 OGGConfigAudio *gui,
00208 char *text);
00209 int handle_event();
00210 OGGConfigAudio *gui;
00211 };
00212
00213
00214 class OGGConfigAudio: public BC_Window
00215 {
00216 public:
00217 OGGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
00218 ~OGGConfigAudio();
00219
00220 int create_objects();
00221 int close_event();
00222
00223 Asset *asset;
00224 OGGVorbisFixedBitrate *fixed_bitrate;
00225 OGGVorbisVariableBitrate *variable_bitrate;
00226 private:
00227 BC_WindowBase *parent_window;
00228 char string[BCTEXTLEN];
00229 };
00230
00231
00232 class OGGTheoraBitrate : public BC_TextBox
00233 {
00234 public:
00235 OGGTheoraBitrate(int x, int y, OGGConfigVideo *gui);
00236 int handle_event();
00237 OGGConfigVideo *gui;
00238 };
00239
00240 class OGGTheoraKeyframeFrequency : public BC_TumbleTextBox
00241 {
00242 public:
00243 OGGTheoraKeyframeFrequency(int x, int y, OGGConfigVideo *gui);
00244 int handle_event();
00245 OGGConfigVideo *gui;
00246 };
00247
00248 class OGGTheoraKeyframeForceFrequency : public BC_TumbleTextBox
00249 {
00250 public:
00251 OGGTheoraKeyframeForceFrequency(int x, int y, OGGConfigVideo *gui);
00252 int handle_event();
00253 OGGConfigVideo *gui;
00254 };
00255
00256 class OGGTheoraSharpness : public BC_TumbleTextBox
00257 {
00258 public:
00259 OGGTheoraSharpness(int x, int y, OGGConfigVideo *gui);
00260 int handle_event();
00261 OGGConfigVideo *gui;
00262 };
00263
00264 class OGGTheoraFixedBitrate : public BC_Radial
00265 {
00266 public:
00267 OGGTheoraFixedBitrate(int x, int y, OGGConfigVideo *gui);
00268 int handle_event();
00269 OGGConfigVideo *gui;
00270 };
00271
00272 class OGGTheoraFixedQuality : public BC_Radial
00273 {
00274 public:
00275 OGGTheoraFixedQuality(int x, int y, OGGConfigVideo *gui);
00276 int handle_event();
00277 OGGConfigVideo *gui;
00278 };
00279
00280
00281
00282 class OGGConfigVideo: public BC_Window
00283 {
00284 public:
00285 OGGConfigVideo(BC_WindowBase *parent_window, Asset *asset);
00286 ~OGGConfigVideo();
00287
00288 int create_objects();
00289 int close_event();
00290
00291 OGGTheoraFixedBitrate *fixed_bitrate;
00292 OGGTheoraFixedQuality *fixed_quality;
00293 Asset *asset;
00294 private:
00295 BC_WindowBase *parent_window;
00296 };
00297
00298 class PackagingEngineOGG : public PackagingEngine
00299 {
00300 public:
00301 PackagingEngineOGG();
00302 ~PackagingEngineOGG();
00303 int create_packages_single_farm(
00304 EDL *edl,
00305 Preferences *preferences,
00306 Asset *default_asset,
00307 double total_start,
00308 double total_end);
00309 RenderPackage* get_package_single_farm(double frames_per_second,
00310 int client_number,
00311 int use_local_rate);
00312 int64_t get_progress_max();
00313 void get_package_paths(ArrayList<char*> *path_list);
00314 int packages_are_done();
00315
00316 private:
00317 EDL *edl;
00318
00319 RenderPackage **packages;
00320 int total_packages;
00321 double video_package_len;
00322
00323 Asset *default_asset;
00324 Preferences *preferences;
00325 int current_package;
00326 double total_start;
00327 double total_end;
00328 int64_t audio_position;
00329 int64_t video_position;
00330 int64_t audio_start;
00331 int64_t video_start;
00332 int64_t audio_end;
00333 int64_t video_end;
00334
00335 };
00336
00337
00338 #endif