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)
35 ogg_int64_t audio_bytesout
;
36 ogg_int64_t video_bytesout
;
38 ogg_stream_state to
; /* take physical pages, weld into a logical
39 * stream of packets */
40 ogg_stream_state vo
; /* take physical pages, weld into a logical
41 * stream of packets */
42 ogg_page og
; /* one Ogg bitstream page. Vorbis packets are inside */
43 ogg_packet op
; /* one raw packet of data for decode */
50 vorbis_info vi
; /* struct that stores all the static vorbis bitstream settings */
51 vorbis_comment vc
; /* struct that stores all the user comments */
52 vorbis_dsp_state vd
; /* central working state for the packet<->PCM encoder/decoder */
53 vorbis_block vb
; /* local working space for packet<->PCM encode/decode */
55 // stuff needed for reading only
56 sync_window_t
*audiosync
;
57 sync_window_t
*videosync
;
63 class FileOGG
: public FileBase
66 FileOGG(Asset
*asset
, File
*file
);
69 static void get_parameters(BC_WindowBase
*parent_window
,
71 BC_WindowBase
* &format_window
,
75 int reset_parameters_derived();
76 int open_file(int rd
, int wr
);
77 static int check_sig(Asset
*asset
);
79 int close_file_derived();
80 int64_t get_video_position();
81 int64_t get_audio_position();
82 int set_video_position(int64_t x
);
83 int set_audio_position(int64_t x
);
84 int colormodel_supported(int colormodel
);
85 int get_best_colormodel(Asset
*asset
, int driver
);
86 int write_samples(double **buffer
, int64_t len
);
87 int write_frames(VFrame
***frames
, int len
);
88 int read_samples(double *buffer
, int64_t len
);
89 int read_frame(VFrame
*frame
);
92 int write_samples_vorbis(double **buffer
, int64_t len
, int e_o_s
);
93 int write_frames_theora(VFrame
***frames
, int len
, int e_o_s
);
94 int flush_ogg(int e_o_s
);
99 theoraframes_info_t
*tf
;
103 off_t filedata_begin
;
105 int ogg_get_last_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
106 int ogg_get_prev_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
107 int ogg_get_first_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
108 int ogg_get_next_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
109 int ogg_sync_and_get_next_page(sync_window_t
*sw
, long serialno
, ogg_page
*og
);
111 int ogg_get_page_of_sample(sync_window_t
*sw
, long serialno
, ogg_page
*og
, int64_t sample
);
112 int ogg_seek_to_sample(sync_window_t
*sw
, long serialno
, int64_t sample
);
113 int ogg_decode_more_samples(sync_window_t
*sw
, long serialno
);
115 int ogg_get_page_of_frame(sync_window_t
*sw
, long serialno
, ogg_page
*og
, int64_t frame
);
116 int ogg_seek_to_keyframe(sync_window_t
*sw
, long serialno
, int64_t frame
, int64_t *keyframe_number
);
119 int64_t start_sample
; // first and last sample inside this file
121 int64_t start_frame
; // first and last frame inside this file
125 int64_t ogg_sample_position
; // what will be the next sample taken from vorbis decoder
126 int64_t next_sample_position
; // what is the next sample read_samples must deliver
128 int move_history(int from
, int to
, int len
);
131 //#define HISTORY_MAX 0x100000
132 #define HISTORY_MAX 100000
133 int64_t history_start
;
134 int64_t history_size
;
137 int64_t ogg_frame_position
; // LAST decoded frame position
138 int64_t next_frame_position
; // what is the next sample read_frames must deliver
139 char theora_keyframe_granule_shift
;
142 class OGGConfigAudio
;
143 class OGGConfigVideo
;
145 class OGGVorbisFixedBitrate
: public BC_Radial
148 OGGVorbisFixedBitrate(int x
, int y
, OGGConfigAudio
*gui
);
153 class OGGVorbisVariableBitrate
: public BC_Radial
156 OGGVorbisVariableBitrate(int x
, int y
, OGGConfigAudio
*gui
);
161 class OGGVorbisMinBitrate
: public BC_TextBox
164 OGGVorbisMinBitrate(int x
,
172 class OGGVorbisMaxBitrate
: public BC_TextBox
175 OGGVorbisMaxBitrate(int x
,
183 class OGGVorbisAvgBitrate
: public BC_TextBox
186 OGGVorbisAvgBitrate(int x
,
195 class OGGConfigAudio
: public BC_Window
198 OGGConfigAudio(BC_WindowBase
*parent_window
, Asset
*asset
);
201 int create_objects();
205 OGGVorbisFixedBitrate
*fixed_bitrate
;
206 OGGVorbisVariableBitrate
*variable_bitrate
;
208 BC_WindowBase
*parent_window
;
209 char string
[BCTEXTLEN
];
213 class OGGTheoraBitrate
: public BC_TextBox
216 OGGTheoraBitrate(int x
, int y
, OGGConfigVideo
*gui
);
221 class OGGTheoraKeyframeFrequency
: public BC_TumbleTextBox
224 OGGTheoraKeyframeFrequency(int x
, int y
, OGGConfigVideo
*gui
);
229 class OGGTheoraKeyframeForceFrequency
: public BC_TumbleTextBox
232 OGGTheoraKeyframeForceFrequency(int x
, int y
, OGGConfigVideo
*gui
);
237 class OGGTheoraSharpness
: public BC_TumbleTextBox
240 OGGTheoraSharpness(int x
, int y
, OGGConfigVideo
*gui
);
245 class OGGTheoraFixedBitrate
: public BC_Radial
248 OGGTheoraFixedBitrate(int x
, int y
, OGGConfigVideo
*gui
);
253 class OGGTheoraFixedQuality
: public BC_Radial
256 OGGTheoraFixedQuality(int x
, int y
, OGGConfigVideo
*gui
);
263 class OGGConfigVideo
: public BC_Window
266 OGGConfigVideo(BC_WindowBase
*parent_window
, Asset
*asset
);
269 int create_objects();
272 OGGTheoraFixedBitrate
*fixed_bitrate
;
273 OGGTheoraFixedQuality
*fixed_quality
;
276 BC_WindowBase
*parent_window
;