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
76 class FileOGG
: public FileBase
78 friend class PackagingEngineOGG
;
80 FileOGG(Asset_GC asset
, File
*file
);
83 static void get_parameters(BC_WindowBase
*parent_window
,
85 BC_WindowBase
* &format_window
,
89 int reset_parameters_derived();
90 int open_file(int rd
, int wr
);
91 static int check_sig(Asset_GC asset
);
93 int close_file_derived();
94 int64_t get_video_position();
95 int64_t get_audio_position();
96 int set_video_position(int64_t x
);
97 int set_audio_position(int64_t x
);
98 int colormodel_supported(int colormodel
);
99 int get_best_colormodel(Asset_GC asset
, int driver
);
100 int write_samples(double **buffer
, int64_t len
);
101 int write_frames(VFrame
***frames
, int len
);
102 int read_samples(double *buffer
, int64_t len
);
103 int read_frame(VFrame
*frame
);
106 int write_samples_vorbis(double **buffer
, int64_t len
, int e_o_s
);
107 int write_frames_theora(VFrame
***frames
, int len
, int e_o_s
);
108 void flush_ogg(int e_o_s
);
109 int write_audio_page();
110 int write_video_page();
115 theoraframes_info_t
*tf
;
119 off_t filedata_begin
;
121 int ogg_get_last_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
122 int ogg_get_prev_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
123 int ogg_get_first_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
124 int ogg_get_next_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
125 int ogg_sync_and_get_next_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
127 int ogg_get_page_of_sample(sync_window_t
*sw
, long serialno
, ogg_page
*og
, int64_t sample
);
128 int ogg_seek_to_sample(sync_window_t
*sw
, long serialno
, int64_t sample
);
129 int ogg_decode_more_samples(sync_window_t
*sw
, long serialno
);
131 int ogg_get_page_of_frame(sync_window_t
*sw
, long serialno
, ogg_page
*og
, int64_t frame
);
132 int ogg_seek_to_keyframe(sync_window_t
*sw
, long serialno
, int64_t frame
, int64_t *keyframe_number
);
133 int ogg_seek_to_databegin(sync_window_t
*sw
, long serialno
);
136 int64_t start_sample
; // first and last sample inside this file
138 int64_t start_frame
; // first and last frame inside this file
142 int64_t ogg_sample_position
; // what will be the next sample taken from vorbis decoder
143 int64_t next_sample_position
; // what is the next sample read_samples must deliver
145 int move_history(int from
, int to
, int len
);
149 #define HISTORY_MAX 0x100000
151 int64_t history_start
;
152 int64_t history_size
;
155 int64_t ogg_frame_position
; // LAST decoded frame position
156 int64_t next_frame_position
; // what is the next sample read_frames must deliver
157 char theora_keyframe_granule_shift
;
161 class OGGConfigAudio
;
162 class OGGConfigVideo
;
164 class OGGVorbisFixedBitrate
: public BC_Radial
167 OGGVorbisFixedBitrate(int x
, int y
, OGGConfigAudio
*gui
);
172 class OGGVorbisVariableBitrate
: public BC_Radial
175 OGGVorbisVariableBitrate(int x
, int y
, OGGConfigAudio
*gui
);
180 class OGGVorbisMinBitrate
: public BC_TextBox
183 OGGVorbisMinBitrate(int x
,
191 class OGGVorbisMaxBitrate
: public BC_TextBox
194 OGGVorbisMaxBitrate(int x
,
202 class OGGVorbisAvgBitrate
: public BC_TextBox
205 OGGVorbisAvgBitrate(int x
,
214 class OGGConfigAudio
: public BC_Window
217 OGGConfigAudio(BC_WindowBase
*parent_window
, Asset_GC asset
);
220 int create_objects();
224 OGGVorbisFixedBitrate
*fixed_bitrate
;
225 OGGVorbisVariableBitrate
*variable_bitrate
;
227 BC_WindowBase
*parent_window
;
228 char string
[BCTEXTLEN
];
232 class OGGTheoraBitrate
: public BC_TextBox
235 OGGTheoraBitrate(int x
, int y
, OGGConfigVideo
*gui
);
240 class OGGTheoraKeyframeFrequency
: public BC_TumbleTextBox
243 OGGTheoraKeyframeFrequency(int x
, int y
, OGGConfigVideo
*gui
);
248 class OGGTheoraKeyframeForceFrequency
: public BC_TumbleTextBox
251 OGGTheoraKeyframeForceFrequency(int x
, int y
, OGGConfigVideo
*gui
);
256 class OGGTheoraSharpness
: public BC_TumbleTextBox
259 OGGTheoraSharpness(int x
, int y
, OGGConfigVideo
*gui
);
264 class OGGTheoraFixedBitrate
: public BC_Radial
267 OGGTheoraFixedBitrate(int x
, int y
, OGGConfigVideo
*gui
);
272 class OGGTheoraFixedQuality
: public BC_Radial
275 OGGTheoraFixedQuality(int x
, int y
, OGGConfigVideo
*gui
);
282 class OGGConfigVideo
: public BC_Window
285 OGGConfigVideo(BC_WindowBase
*parent_window
, Asset_GC asset
);
288 int create_objects();
291 OGGTheoraFixedBitrate
*fixed_bitrate
;
292 OGGTheoraFixedQuality
*fixed_quality
;
295 BC_WindowBase
*parent_window
;
298 class PackagingEngineOGG
: public PackagingEngine
301 PackagingEngineOGG();
302 ~PackagingEngineOGG();
303 int create_packages_single_farm(
305 Preferences
*preferences
,
306 Asset_GC default_asset
,
309 RenderPackage
* get_package_single_farm(double frames_per_second
,
312 int64_t get_progress_max();
313 void get_package_paths(ArrayList
<char*> *path_list
);
314 int packages_are_done();
319 RenderPackage
**packages
;
321 double video_package_len
; // Target length of a single package
323 Asset_GC default_asset
;
324 Preferences
*preferences
;
328 int64_t audio_position
;
329 int64_t video_position
;
342 // c-file-style: "linux"