51
51
#ifdef CONFIG_OGGTHEORA
52
#include <theora/theora.h>
53
int _ilog (unsigned int); /* defined in many places in theora/lib/ */
52
#include <theora/theoradec.h>
56
55
#define BLOCK_SIZE 4096
58
57
/* Theora decoder context : we won't be able to interpret granule positions
59
* without using theora_granule_time with the theora_state of the stream.
58
* without using th_granule_time with the th_dec_ctx of the stream.
60
59
* This is duplicated in `vd_theora.c'; put this in a common header?
62
61
#ifdef CONFIG_OGGTHEORA
63
62
typedef struct theora_struct_st {
202
202
duration |= (unsigned char)packet[i];
204
204
if (hdrlen > 0 && duration > 0) {
207
207
if (pack->granulepos == -1)
208
208
pack->granulepos = os->lastpos + os->lastsize;
209
pts = (float)pack->granulepos / (float)os->samplerate;
210
endpts = 1.0 + pts + (float)duration / 1000.0;
209
pts = (double)pack->granulepos / (double)os->samplerate;
210
endpts = 1.0 + pts + (double)duration / 1000.0;
212
212
sub_clear_text(&ogg_sub, MP_NOPTS_VALUE);
213
213
sub_add_text(&ogg_sub, &packet[lcv], pack->bytes - lcv, endpts, 1);
299
299
have theora_state st, until all header packets were passed to the
301
301
if (!pack->bytes || !(*data&0x80)) {
302
int keyframe_granule_shift = _ilog(os->keyframe_frequency_force - 1);
303
int64_t iframemask = (1 << keyframe_granule_shift) - 1;
302
int64_t iframemask = (1 << os->keyframe_granule_shift) - 1;
305
304
if (pack->granulepos >= 0) {
306
os->lastpos = pack->granulepos >> keyframe_granule_shift;
305
os->lastpos = pack->granulepos >> os->keyframe_granule_shift;
307
306
os->lastpos += pack->granulepos & iframemask;
308
307
*flags = (pack->granulepos & iframemask) == 0;
611
610
while (ogg_stream_packetout(oss, &op) == 1) {
615
614
demux_ogg_read_packet(os, &op, &pts, &flags, samplesize);
892
891
#ifdef CONFIG_OGGTHEORA
893
892
} else if (pack.bytes >= 7 && !strncmp (&pack.packet[1], "theora", 6)) {
894
893
int errorCode = 0;
898
theora_info_init (&inf);
899
theora_comment_init (&cc);
901
errorCode = theora_decode_header (&inf, &cc, &pack);
896
th_setup_info *tsi = NULL;
899
th_comment_init (&tc);
901
errorCode = th_decode_headerin(&ti, &tc, &tsi, &pack);
903
903
mp_msg(MSGT_DEMUX, MSGL_ERR,
904
904
"Theora header parsing failed: %i \n", errorCode);
908
908
sh_v->bih = calloc(1, sizeof(*sh_v->bih));
909
909
sh_v->bih->biSize = sizeof(*sh_v->bih);
910
910
sh_v->bih->biCompression = sh_v->format = FOURCC_THEORA;
911
sh_v->fps = ((double)inf.fps_numerator) / (double)inf.fps_denominator;
912
sh_v->frametime = ((double)inf.fps_denominator) / (double)inf.fps_numerator;
913
sh_v->disp_w = sh_v->bih->biWidth = inf.frame_width;
914
sh_v->disp_h = sh_v->bih->biHeight = inf.frame_height;
911
sh_v->fps = ((double)ti.fps_numerator) / (double)ti.fps_denominator;
912
sh_v->frametime = ((double)ti.fps_denominator) / (double)ti.fps_numerator;
913
sh_v->i_bps = ti.target_bitrate / 8;
914
sh_v->disp_w = sh_v->bih->biWidth = ti.frame_width;
915
sh_v->disp_h = sh_v->bih->biHeight = ti.frame_height;
915
916
sh_v->bih->biBitCount = 24;
916
917
sh_v->bih->biPlanes = 3;
917
918
sh_v->bih->biSizeImage = ((sh_v->bih->biBitCount / 8) * sh_v->bih->biWidth * sh_v->bih->biHeight);
918
919
ogg_d->subs[ogg_d->num_sub].samplerate = sh_v->fps;
919
920
ogg_d->subs[ogg_d->num_sub].theora = 1;
920
ogg_d->subs[ogg_d->num_sub].keyframe_frequency_force = inf.keyframe_frequency_force;
921
ogg_d->subs[ogg_d->num_sub].keyframe_granule_shift = ti.keyframe_granule_shift;
921
922
ogg_d->subs[ogg_d->num_sub].id = n_video;
923
924
mp_msg(MSGT_DEMUX, MSGL_INFO,
924
925
"[Ogg] stream %d: video (Theora v%d.%d.%d), -vid %d\n",
926
(int)inf.version_major,
927
(int)inf.version_minor,
928
(int)inf.version_subminor,
927
(int)ti.version_major,
928
(int)ti.version_minor,
929
(int)ti.version_subminor,
930
931
if (mp_msg_test(MSGT_HEADER, MSGL_V))
931
932
print_video_header(sh_v->bih, MSGL_V);
933
theora_comment_clear(&cc);
934
theora_info_clear(&inf);
934
th_comment_clear(&tc);
935
937
#endif /* CONFIG_OGGTHEORA */
936
938
} else if (pack.bytes >= 4 && !strncmp (&pack.packet[0], "fLaC", 4)) {
937
939
sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);