Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

fileogg.h

Go to the documentation of this file.
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 /* This code was aspired by ffmpeg2theora */
00016 /* Special thanks for help on this code goes out to j@v2v.cc */
00017 
00018 typedef struct 
00019 {
00020         ogg_sync_state sync;
00021         off_t file_bufpos; // position of the start of the buffer inside the file
00022         off_t file_pagepos; // position of the page that will be next read 
00023         off_t file_pagepos_found; // position of last page that was returned (in seeking operations)
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;    /* one Ogg bitstream page.  Vorbis packets are inside */
00038     ogg_packet op;  /* one raw packet of data for decode */
00039 
00040     theora_info ti;
00041     theora_comment tc;
00042     theora_state td;
00043 
00044     vorbis_info vi;       /* struct that stores all the static vorbis bitstream settings */
00045     vorbis_comment vc;    /* struct that stores all the user comments */
00046     vorbis_dsp_state vd; /* central working state for the packet<->PCM encoder/decoder */
00047     vorbis_block vb;     /* local working space for packet<->PCM encode/decode */
00048 
00049     /* used for muxing */
00050     ogg_stream_state to;    /* take physical pages, weld into a logical
00051                              * stream of packets */
00052     ogg_stream_state vo;    /* take physical pages, weld into a logical
00053                              * stream of packets */
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 // stuff needed for reading only
00066         sync_window_t *audiosync;
00067         sync_window_t *videosync;
00068         
00069 
00070 }
00071 theoraframes_info_t;
00072 
00073 class FileOGG : public FileBase
00074 {
00075 public:
00076         FileOGG(Asset *asset, File *file);
00077         ~FileOGG();
00078 
00079         static void get_parameters(BC_WindowBase *parent_window,
00080                 Asset *asset,
00081                 BC_WindowBase* &format_window,
00082                 int audio_options,
00083                 int video_options);
00084         
00085         int reset_parameters_derived();
00086         int open_file(int rd, int wr);
00087         static int check_sig(Asset *asset);
00088         int close_file();
00089         int close_file_derived();
00090         int64_t get_video_position();
00091         int64_t get_audio_position();
00092         int set_video_position(int64_t x);
00093         int set_audio_position(int64_t x);
00094         int colormodel_supported(int colormodel);
00095         int get_best_colormodel(Asset *asset, int driver);
00096         int write_samples(double **buffer, int64_t len);
00097         int write_frames(VFrame ***frames, int len);
00098         int read_samples(double *buffer, int64_t len);
00099         int read_frame(VFrame *frame);
00100 
00101 private:
00102         int write_samples_vorbis(double **buffer, int64_t len, int e_o_s);
00103         int write_frames_theora(VFrame ***frames, int len, int e_o_s);
00104         void flush_ogg(int e_o_s);
00105         int write_audio_page();
00106         int write_video_page();
00107         
00108         FILE *stream;
00109         off_t file_length;
00110         
00111         theoraframes_info_t *tf;
00112         VFrame *temp_frame;
00113         Mutex *flush_lock;
00114 
00115         off_t filedata_begin;
00116 
00117         int ogg_get_last_page(sync_window_t *sw, long serialno, ogg_page *og);
00118         int ogg_get_prev_page(sync_window_t *sw, long serialno, ogg_page *og);
00119         int ogg_get_first_page(sync_window_t *sw, long serialno, ogg_page *og);
00120         int ogg_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
00121         int ogg_sync_and_get_next_page(sync_window_t *sw, long serialno, ogg_page *og);
00122 
00123         int ogg_get_page_of_sample(sync_window_t *sw, long serialno, ogg_page *og, int64_t sample);
00124         int ogg_seek_to_sample(sync_window_t *sw, long serialno, int64_t sample);
00125         int ogg_decode_more_samples(sync_window_t *sw, long serialno);
00126 
00127         int ogg_get_page_of_frame(sync_window_t *sw, long serialno, ogg_page *og, int64_t frame);
00128         int ogg_seek_to_keyframe(sync_window_t *sw, long serialno, int64_t frame, int64_t *keyframe_number);
00129 
00130 
00131         int64_t start_sample; // first and last sample inside this file
00132         int64_t last_sample;    
00133         int64_t start_frame; // first and last frame inside this file
00134         int64_t last_frame;     
00135         
00136 
00137         int64_t ogg_sample_position;  // what will be the next sample taken from vorbis decoder
00138         int64_t next_sample_position; // what is the next sample read_samples must deliver
00139 
00140         int move_history(int from, int to, int len);
00141 
00142         float **pcm_history;
00143 #ifndef HISTORY_MAX
00144 #define HISTORY_MAX 0x100000
00145 #endif
00146         int64_t history_start;
00147         int64_t history_size;
00148 
00149         int theora_cmodel;
00150         int64_t ogg_frame_position;    // LAST decoded frame position
00151         int64_t next_frame_position;   // what is the next sample read_frames must deliver
00152         char theora_keyframe_granule_shift;
00153 };
00154 
00155 class OGGConfigAudio;
00156 class OGGConfigVideo;
00157 
00158 class OGGVorbisFixedBitrate : public BC_Radial
00159 {
00160 public:
00161         OGGVorbisFixedBitrate(int x, int y, OGGConfigAudio *gui);
00162         int handle_event();
00163         OGGConfigAudio *gui;
00164 };
00165 
00166 class OGGVorbisVariableBitrate : public BC_Radial
00167 {
00168 public:
00169         OGGVorbisVariableBitrate(int x, int y, OGGConfigAudio *gui);
00170         int handle_event();
00171         OGGConfigAudio *gui;
00172 };
00173 
00174 class OGGVorbisMinBitrate : public BC_TextBox
00175 {
00176 public:
00177         OGGVorbisMinBitrate(int x, 
00178                 int y, 
00179                 OGGConfigAudio *gui, 
00180                 char *text);
00181         int handle_event();
00182         OGGConfigAudio *gui;
00183 };
00184 
00185 class OGGVorbisMaxBitrate : public BC_TextBox
00186 {
00187 public:
00188         OGGVorbisMaxBitrate(int x, 
00189                 int y, 
00190                 OGGConfigAudio *gui, 
00191                 char *text);
00192         int handle_event();
00193         OGGConfigAudio *gui;
00194 };
00195 
00196 class OGGVorbisAvgBitrate : public BC_TextBox
00197 {
00198 public:
00199         OGGVorbisAvgBitrate(int x, 
00200                 int y, 
00201                 OGGConfigAudio *gui, 
00202                 char *text);
00203         int handle_event();
00204         OGGConfigAudio *gui;
00205 };
00206 
00207 
00208 class OGGConfigAudio: public BC_Window
00209 {
00210 public:
00211         OGGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
00212         ~OGGConfigAudio();
00213 
00214         int create_objects();
00215         int close_event();
00216 
00217         Asset *asset;
00218         OGGVorbisFixedBitrate *fixed_bitrate;
00219         OGGVorbisVariableBitrate *variable_bitrate;
00220 private:
00221         BC_WindowBase *parent_window;
00222         char string[BCTEXTLEN];
00223 };
00224 
00225 
00226 class OGGTheoraBitrate : public BC_TextBox
00227 {
00228 public:
00229         OGGTheoraBitrate(int x, int y, OGGConfigVideo *gui);
00230         int handle_event();
00231         OGGConfigVideo *gui;
00232 };
00233 
00234 class OGGTheoraKeyframeFrequency : public BC_TumbleTextBox
00235 {
00236 public:
00237         OGGTheoraKeyframeFrequency(int x, int y, OGGConfigVideo *gui);
00238         int handle_event();
00239         OGGConfigVideo *gui;
00240 };
00241 
00242 class OGGTheoraKeyframeForceFrequency : public BC_TumbleTextBox
00243 {
00244 public:
00245         OGGTheoraKeyframeForceFrequency(int x, int y, OGGConfigVideo *gui);
00246         int handle_event();
00247         OGGConfigVideo *gui;
00248 };
00249 
00250 class OGGTheoraSharpness : public BC_TumbleTextBox
00251 {
00252 public:
00253         OGGTheoraSharpness(int x, int y, OGGConfigVideo *gui);
00254         int handle_event();
00255         OGGConfigVideo *gui;
00256 };
00257 
00258 class OGGTheoraFixedBitrate : public BC_Radial
00259 {
00260 public:
00261         OGGTheoraFixedBitrate(int x, int y, OGGConfigVideo *gui);
00262         int handle_event();
00263         OGGConfigVideo *gui;
00264 };
00265 
00266 class OGGTheoraFixedQuality : public BC_Radial
00267 {
00268 public:
00269         OGGTheoraFixedQuality(int x, int y, OGGConfigVideo *gui);
00270         int handle_event();
00271         OGGConfigVideo *gui;
00272 };
00273 
00274 
00275 
00276 class OGGConfigVideo: public BC_Window
00277 {
00278 public:
00279         OGGConfigVideo(BC_WindowBase *parent_window, Asset *asset);
00280         ~OGGConfigVideo();
00281 
00282         int create_objects();
00283         int close_event();
00284 
00285         OGGTheoraFixedBitrate *fixed_bitrate;
00286         OGGTheoraFixedQuality *fixed_quality;
00287         Asset *asset;
00288 private:
00289         BC_WindowBase *parent_window;
00290 };
00291 
00292 
00293 #endif

Generated on Sun Jan 8 13:38:55 2006 for Cinelerra-svn by  doxygen 1.4.4