8 #include <theora/theora.h>
9 #include <vorbis/codec.h>
10 #include <vorbis/vorbisenc.h>
15 /* This code was aspired by ffmpeg2theora */
16 /* Special thanks for help on this code goes out to j@v2v.cc */
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)
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 */
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 */
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 */
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
75 class FileOGG
: public FileBase
78 FileOGG(Asset
*asset
, File
*file
);
81 static void get_parameters(BC_WindowBase
*parent_window
,
83 BC_WindowBase
* &format_window
,
87 int reset_parameters_derived();
88 int open_file(int rd
, int wr
);
89 static int check_sig(Asset
*asset
);
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
);
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();
113 theoraframes_info_t
*tf
;
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
135 int64_t start_frame
; // first and last frame inside this file
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
);
146 #define HISTORY_MAX 0x100000
148 int64_t history_start
;
149 int64_t history_size
;
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
163 OGGVorbisFixedBitrate(int x
, int y
, OGGConfigAudio
*gui
);
168 class OGGVorbisVariableBitrate
: public BC_Radial
171 OGGVorbisVariableBitrate(int x
, int y
, OGGConfigAudio
*gui
);
176 class OGGVorbisMinBitrate
: public BC_TextBox
179 OGGVorbisMinBitrate(int x
,
187 class OGGVorbisMaxBitrate
: public BC_TextBox
190 OGGVorbisMaxBitrate(int x
,
198 class OGGVorbisAvgBitrate
: public BC_TextBox
201 OGGVorbisAvgBitrate(int x
,
210 class OGGConfigAudio
: public BC_Window
213 OGGConfigAudio(BC_WindowBase
*parent_window
, Asset
*asset
);
216 int create_objects();
220 OGGVorbisFixedBitrate
*fixed_bitrate
;
221 OGGVorbisVariableBitrate
*variable_bitrate
;
223 BC_WindowBase
*parent_window
;
224 char string
[BCTEXTLEN
];
228 class OGGTheoraBitrate
: public BC_TextBox
231 OGGTheoraBitrate(int x
, int y
, OGGConfigVideo
*gui
);
236 class OGGTheoraKeyframeFrequency
: public BC_TumbleTextBox
239 OGGTheoraKeyframeFrequency(int x
, int y
, OGGConfigVideo
*gui
);
244 class OGGTheoraKeyframeForceFrequency
: public BC_TumbleTextBox
247 OGGTheoraKeyframeForceFrequency(int x
, int y
, OGGConfigVideo
*gui
);
252 class OGGTheoraSharpness
: public BC_TumbleTextBox
255 OGGTheoraSharpness(int x
, int y
, OGGConfigVideo
*gui
);
260 class OGGTheoraFixedBitrate
: public BC_Radial
263 OGGTheoraFixedBitrate(int x
, int y
, OGGConfigVideo
*gui
);
268 class OGGTheoraFixedQuality
: public BC_Radial
271 OGGTheoraFixedQuality(int x
, int y
, OGGConfigVideo
*gui
);
278 class OGGConfigVideo
: public BC_Window
281 OGGConfigVideo(BC_WindowBase
*parent_window
, Asset
*asset
);
284 int create_objects();
287 OGGTheoraFixedBitrate
*fixed_bitrate
;
288 OGGTheoraFixedQuality
*fixed_quality
;
291 BC_WindowBase
*parent_window
;