typedef struct Vp3DecodeContext {
AVCodecContext *avctx;
- int theora, theora_tables;
+ int theora, theora_tables, theora_header;
int version;
int width, height;
int chroma_x_shift, chroma_y_shift;
int16_t *dct_tokens[3][64];
int16_t *dct_tokens_base;
#define TOKEN_EOB(eob_run) ((eob_run) << 2)
-#define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) << 9) + ((zero_run) << 2) + 1)
-#define TOKEN_COEFF(coeff) (((coeff) << 2) + 2)
+#define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) * 512) + ((zero_run) << 2) + 1)
+#define TOKEN_COEFF(coeff) (((coeff) * 4) + 2)
/**
* number of blocks that contain DCT coefficients at
vp3_decode_end(avctx);
ret = theora_decode_header(avctx, &gb);
+ if (ret >= 0)
+ ret = vp3_decode_init(avctx);
if (ret < 0) {
vp3_decode_end(avctx);
- } else
- ret = vp3_decode_init(avctx);
+ }
return ret;
} else if (type == 2) {
+ vp3_decode_end(avctx);
ret = theora_decode_tables(avctx, &gb);
+ if (ret >= 0)
+ ret = vp3_decode_init(avctx);
if (ret < 0) {
vp3_decode_end(avctx);
- } else
- ret = vp3_decode_init(avctx);
+ }
return ret;
}
int ret;
AVRational fps, aspect;
+ s->theora_header = 0;
s->theora = get_bits_long(gb, 24);
av_log(avctx, AV_LOG_DEBUG, "Theora bitstream version %X\n", s->theora);
return AVERROR_INVALIDDATA;
}
skip_bits(gb, 3); /* reserved */
- }
+ } else
+ avctx->pix_fmt = AV_PIX_FMT_YUV420P;
ret = ff_set_dimensions(avctx, s->width, s->height);
if (ret < 0)
avctx->color_trc = AVCOL_TRC_BT709;
}
+ s->theora_header = 1;
return 0;
}
Vp3DecodeContext *s = avctx->priv_data;
int i, n, matrices, inter, plane;
+ if (!s->theora_header)
+ return AVERROR_INVALIDDATA;
+
if (s->theora >= 0x030200) {
n = get_bits(gb, 3);
/* loop filter limit values table */