Fixes Ticket868
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -75,6 +75,10 @@ typedef struct Vp3Fragment { |
75 | 75 |
/* special internal mode */ |
76 | 76 |
#define MODE_COPY 8 |
77 | 77 |
|
78 |
+static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb); |
|
79 |
+static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb); |
|
80 |
+ |
|
81 |
+ |
|
78 | 82 |
/* There are 6 preset schemes, plus a free-form scheme */ |
79 | 83 |
static const int ModeAlphabet[6][CODING_MODE_COUNT] = |
80 | 84 |
{ |
... | ... |
@@ -292,6 +296,8 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx) |
292 | 292 |
av_freep(&s->motion_val[1]); |
293 | 293 |
av_freep(&s->edge_emu_buffer); |
294 | 294 |
|
295 |
+ s->theora_tables = 0; |
|
296 |
+ |
|
295 | 297 |
if (avctx->internal->is_copy) |
296 | 298 |
return 0; |
297 | 299 |
|
... | ... |
@@ -1912,16 +1918,46 @@ static int vp3_decode_frame(AVCodecContext *avctx, |
1912 | 1912 |
Vp3DecodeContext *s = avctx->priv_data; |
1913 | 1913 |
GetBitContext gb; |
1914 | 1914 |
int i; |
1915 |
+ int ret; |
|
1915 | 1916 |
|
1916 | 1917 |
init_get_bits(&gb, buf, buf_size * 8); |
1917 | 1918 |
|
1918 | 1919 |
if (s->theora && get_bits1(&gb)) |
1919 | 1920 |
{ |
1921 |
+ int type = get_bits(&gb, 7); |
|
1922 |
+ skip_bits_long(&gb, 6*8); /* "theora" */ |
|
1923 |
+ |
|
1924 |
+ if (type == 0) { |
|
1925 |
+ if (s->avctx->active_thread_type&FF_THREAD_FRAME) { |
|
1926 |
+ av_log(avctx, AV_LOG_ERROR, "midstream reconfiguration with multithreading is unsupported, try -threads 1\n"); |
|
1927 |
+ return AVERROR_PATCHWELCOME; |
|
1928 |
+ } |
|
1929 |
+ vp3_decode_end(avctx); |
|
1930 |
+ ret = theora_decode_header(avctx, &gb); |
|
1931 |
+ |
|
1932 |
+ if (ret < 0) { |
|
1933 |
+ vp3_decode_end(avctx); |
|
1934 |
+ } else |
|
1935 |
+ ret = vp3_decode_init(avctx); |
|
1936 |
+ return ret; |
|
1937 |
+ } else if (type == 2) { |
|
1938 |
+ ret = theora_decode_tables(avctx, &gb); |
|
1939 |
+ if (ret < 0) { |
|
1940 |
+ vp3_decode_end(avctx); |
|
1941 |
+ } else |
|
1942 |
+ ret = vp3_decode_init(avctx); |
|
1943 |
+ return ret; |
|
1944 |
+ } |
|
1945 |
+ |
|
1920 | 1946 |
av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); |
1921 | 1947 |
return -1; |
1922 | 1948 |
} |
1923 | 1949 |
|
1924 | 1950 |
s->keyframe = !get_bits1(&gb); |
1951 |
+ if (!s->all_fragments) { |
|
1952 |
+ av_log(avctx, AV_LOG_ERROR, "Data packet without prior valid headers\n"); |
|
1953 |
+ return -1; |
|
1954 |
+ } |
|
1925 | 1955 |
if (!s->theora) |
1926 | 1956 |
skip_bits(&gb, 1); |
1927 | 1957 |
for (i = 0; i < 3; i++) |