comparison oggparsetheora.c @ 4017:b2a3ed76122e libavformat

OGG: correct PTS with old theora streams
author mru
date Thu, 06 Nov 2008 01:57:17 +0000
parents 6cd006bc2de9
children 304a0ea063f0
comparison
equal deleted inserted replaced
4016:6cd006bc2de9 4017:b2a3ed76122e
29 #include "oggdec.h" 29 #include "oggdec.h"
30 30
31 struct theora_params { 31 struct theora_params {
32 int gpshift; 32 int gpshift;
33 int gpmask; 33 int gpmask;
34 unsigned version;
34 }; 35 };
35 36
36 static int 37 static int
37 theora_header (AVFormatContext * s, int idx) 38 theora_header (AVFormatContext * s, int idx)
38 { 39 {
52 } 53 }
53 54
54 if (os->buf[os->pstart] == 0x80) { 55 if (os->buf[os->pstart] == 0x80) {
55 GetBitContext gb; 56 GetBitContext gb;
56 int width, height; 57 int width, height;
57 int version;
58 58
59 init_get_bits(&gb, os->buf + os->pstart, os->psize*8); 59 init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
60 60
61 skip_bits(&gb, 7*8); /* 0x80"theora" */ 61 skip_bits(&gb, 7*8); /* 0x80"theora" */
62 62
63 version = get_bits_long(&gb, 24); 63 thp->version = get_bits_long(&gb, 24);
64 if (version < 0x030100) 64 if (thp->version < 0x030100)
65 { 65 {
66 av_log(s, AV_LOG_ERROR, 66 av_log(s, AV_LOG_ERROR,
67 "Too old or unsupported Theora (%x)\n", version); 67 "Too old or unsupported Theora (%x)\n", thp->version);
68 return -1; 68 return -1;
69 } 69 }
70 70
71 width = get_bits(&gb, 16) << 4; 71 width = get_bits(&gb, 16) << 4;
72 height = get_bits(&gb, 16) << 4; 72 height = get_bits(&gb, 16) << 4;
73 avcodec_set_dimensions(st->codec, width, height); 73 avcodec_set_dimensions(st->codec, width, height);
74 74
75 if (version >= 0x030400) 75 if (thp->version >= 0x030400)
76 skip_bits(&gb, 100); 76 skip_bits(&gb, 100);
77 77
78 if (version >= 0x030200) { 78 if (thp->version >= 0x030200) {
79 width = get_bits_long(&gb, 24); 79 width = get_bits_long(&gb, 24);
80 height = get_bits_long(&gb, 24); 80 height = get_bits_long(&gb, 24);
81 if ( width <= st->codec->width && width > st->codec->width-16 81 if ( width <= st->codec->width && width > st->codec->width-16
82 && height <= st->codec->height && height > st->codec->height-16) 82 && height <= st->codec->height && height > st->codec->height-16)
83 avcodec_set_dimensions(st->codec, width, height); 83 avcodec_set_dimensions(st->codec, width, height);
89 st->time_base = st->codec->time_base; 89 st->time_base = st->codec->time_base;
90 90
91 st->sample_aspect_ratio.num = get_bits_long(&gb, 24); 91 st->sample_aspect_ratio.num = get_bits_long(&gb, 24);
92 st->sample_aspect_ratio.den = get_bits_long(&gb, 24); 92 st->sample_aspect_ratio.den = get_bits_long(&gb, 24);
93 93
94 if (version >= 0x030200) 94 if (thp->version >= 0x030200)
95 skip_bits(&gb, 38); 95 skip_bits(&gb, 38);
96 if (version >= 0x304000) 96 if (thp->version >= 0x304000)
97 skip_bits(&gb, 2); 97 skip_bits(&gb, 2);
98 98
99 thp->gpshift = get_bits(&gb, 5); 99 thp->gpshift = get_bits(&gb, 5);
100 thp->gpmask = (1 << thp->gpshift) - 1; 100 thp->gpmask = (1 << thp->gpshift) - 1;
101 101
123 struct ogg_stream *os = ogg->streams + idx; 123 struct ogg_stream *os = ogg->streams + idx;
124 struct theora_params *thp = os->private; 124 struct theora_params *thp = os->private;
125 uint64_t iframe = gp >> thp->gpshift; 125 uint64_t iframe = gp >> thp->gpshift;
126 uint64_t pframe = gp & thp->gpmask; 126 uint64_t pframe = gp & thp->gpmask;
127 127
128 if (thp->version < 0x030201)
129 iframe++;
130
128 if(!pframe) 131 if(!pframe)
129 os->pflags |= PKT_FLAG_KEY; 132 os->pflags |= PKT_FLAG_KEY;
130 133
131 return iframe + pframe; 134 return iframe + pframe;
132 } 135 }