diff options
author | James Almer <jamrial@gmail.com> | 2025-02-02 22:55:45 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2025-02-06 13:46:58 -0300 |
commit | 3d3ce9647f9b7a002080c7af12be654a90d2ba7c (patch) | |
tree | 9038e74a2475d377eb5237f0bf390b20a34851ce /libavcodec/ffv1dec.c | |
parent | 6da82b448568a1875b32a7135fe30b7da8d197e7 (diff) | |
download | ffmpeg-3d3ce9647f9b7a002080c7af12be654a90d2ba7c.tar.gz |
avcodec/ffv1: split off and share frame header parsing code
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/ffv1dec.c')
-rw-r--r-- | libavcodec/ffv1dec.c | 459 |
1 files changed, 28 insertions, 431 deletions
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 0284845503..7de161f442 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -42,35 +42,6 @@ #include "thread.h" #include "decode.h" -static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, - int is_signed) -{ - if (get_rac(c, state + 0)) - return 0; - else { - int e; - unsigned a; - e = 0; - while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10 - e++; - if (e > 31) - return AVERROR_INVALIDDATA; - } - - a = 1; - for (int i = e - 1; i >= 0; i--) - a += a + get_rac(c, state + 22 + FFMIN(i, 9)); // 22..31 - - e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21 - return (a ^ e) - e; - } -} - -static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed) -{ - return get_symbol_inline(c, state, is_signed); -} - static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, int bits) { @@ -174,10 +145,10 @@ static int decode_slice_header(const FFV1Context *f, int sx, sy, sw, sh; memset(state, 128, sizeof(state)); - sx = get_symbol(c, state, 0); - sy = get_symbol(c, state, 0); - sw = get_symbol(c, state, 0) + 1U; - sh = get_symbol(c, state, 0) + 1U; + sx = ff_ffv1_get_symbol(c, state, 0); + sy = ff_ffv1_get_symbol(c, state, 0); + sw = ff_ffv1_get_symbol(c, state, 0) + 1U; + sh = ff_ffv1_get_symbol(c, state, 0) + 1U; av_assert0(f->version > 2); @@ -202,7 +173,7 @@ static int decode_slice_header(const FFV1Context *f, for (unsigned i = 0; i < f->plane_count; i++) { PlaneContext * const p = &sc->plane[i]; - int idx = get_symbol(c, state, 0); + int idx = ff_ffv1_get_symbol(c, state, 0); if (idx >= (unsigned)f->quant_table_count) { av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n"); return -1; @@ -217,7 +188,7 @@ static int decode_slice_header(const FFV1Context *f, p->context_count = context_count; } - ps = get_symbol(c, state, 0); + ps = ff_ffv1_get_symbol(c, state, 0); if (ps == 1) { frame->flags |= AV_FRAME_FLAG_INTERLACED; frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; @@ -227,8 +198,8 @@ static int decode_slice_header(const FFV1Context *f, } else if (ps == 3) { frame->flags &= ~AV_FRAME_FLAG_INTERLACED; } - frame->sample_aspect_ratio.num = get_symbol(c, state, 0); - frame->sample_aspect_ratio.den = get_symbol(c, state, 0); + frame->sample_aspect_ratio.num = ff_ffv1_get_symbol(c, state, 0); + frame->sample_aspect_ratio.den = ff_ffv1_get_symbol(c, state, 0); if (av_image_check_sar(f->width, f->height, frame->sample_aspect_ratio) < 0) { @@ -240,10 +211,10 @@ static int decode_slice_header(const FFV1Context *f, if (f->version > 3) { sc->slice_reset_contexts = get_rac(c, state); - sc->slice_coding_mode = get_symbol(c, state, 0); + sc->slice_coding_mode = ff_ffv1_get_symbol(c, state, 0); if (sc->slice_coding_mode != 1 && f->colorspace == 1) { - sc->slice_rct_by_coef = get_symbol(c, state, 0); - sc->slice_rct_ry_coef = get_symbol(c, state, 0); + sc->slice_rct_by_coef = ff_ffv1_get_symbol(c, state, 0); + sc->slice_rct_ry_coef = ff_ffv1_get_symbol(c, state, 0); if ((uint64_t)sc->slice_rct_by_coef + (uint64_t)sc->slice_rct_ry_coef > 4) { av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of range\n"); return AVERROR_INVALIDDATA; @@ -364,182 +335,6 @@ static int decode_slice(AVCodecContext *c, void *arg) return 0; } -static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale) -{ - int v; - int i = 0; - uint8_t state[CONTEXT_SIZE]; - - memset(state, 128, sizeof(state)); - - for (v = 0; i < 128; v++) { - unsigned len = get_symbol(c, state, 0) + 1U; - - if (len > 128 - i || !len) - return AVERROR_INVALIDDATA; - - while (len--) { - quant_table[i] = scale * v; - i++; - } - } - - for (i = 1; i < 128; i++) - quant_table[256 - i] = -quant_table[i]; - quant_table[128] = -quant_table[127]; - - return 2 * v - 1; -} - -static int read_quant_tables(RangeCoder *c, - int16_t quant_table[MAX_CONTEXT_INPUTS][256]) -{ - int i; - int context_count = 1; - - for (i = 0; i < 5; i++) { - int ret = read_quant_table(c, quant_table[i], context_count); - if (ret < 0) - return ret; - context_count *= ret; - if (context_count > 32768U) { - return AVERROR_INVALIDDATA; - } - } - return (context_count + 1) / 2; -} - -static int read_extra_header(FFV1Context *f) -{ - RangeCoder c; - uint8_t state[CONTEXT_SIZE]; - int ret; - uint8_t state2[32][CONTEXT_SIZE]; - unsigned crc = 0; - - memset(state2, 128, sizeof(state2)); - memset(state, 128, sizeof(state)); - - ff_init_range_decoder(&c, f->avctx->extradata, f->avctx->extradata_size); - ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); - - f->version = get_symbol(&c, state, 0); - if (f->version < 2) { - av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n"); - return AVERROR_INVALIDDATA; - } - if (f->version > 4) { - av_log(f->avctx, AV_LOG_ERROR, "unsupported version %d\n", - f->version); - return AVERROR_PATCHWELCOME; - } - f->combined_version = f->version << 16; - if (f->version > 2) { - c.bytestream_end -= 4; - f->micro_version = get_symbol(&c, state, 0); - if (f->micro_version < 0 || f->micro_version > 65535) - return AVERROR_INVALIDDATA; - f->combined_version += f->micro_version; - } - f->ac = get_symbol(&c, state, 0); - - if (f->ac == AC_RANGE_CUSTOM_TAB) { - for (int i = 1; i < 256; i++) - f->state_transition[i] = get_symbol(&c, state, 1) + c.one_state[i]; - } - - f->colorspace = get_symbol(&c, state, 0); //YUV cs type - f->avctx->bits_per_raw_sample = get_symbol(&c, state, 0); - f->chroma_planes = get_rac(&c, state); - f->chroma_h_shift = get_symbol(&c, state, 0); - f->chroma_v_shift = get_symbol(&c, state, 0); - f->transparency = get_rac(&c, state); - f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency; - f->num_h_slices = 1 + get_symbol(&c, state, 0); - f->num_v_slices = 1 + get_symbol(&c, state, 0); - - if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) { - av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", - f->chroma_h_shift, f->chroma_v_shift); - return AVERROR_INVALIDDATA; - } - - if (f->num_h_slices > (unsigned)f->width || !f->num_h_slices || - f->num_v_slices > (unsigned)f->height || !f->num_v_slices - ) { - av_log(f->avctx, AV_LOG_ERROR, "slice count invalid\n"); - return AVERROR_INVALIDDATA; - } - - if (f->num_h_slices > MAX_SLICES / f->num_v_slices) { - av_log(f->avctx, AV_LOG_ERROR, "slice count unsupported\n"); - return AVERROR_PATCHWELCOME; - } - - f->quant_table_count = get_symbol(&c, state, 0); - if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) { - av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count); - f->quant_table_count = 0; - return AVERROR_INVALIDDATA; - } - - for (int i = 0; i < f->quant_table_count; i++) { - f->context_count[i] = read_quant_tables(&c, f->quant_tables[i]); - if (f->context_count[i] < 0) { - av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); - return AVERROR_INVALIDDATA; - } - } - if ((ret = ff_ffv1_allocate_initial_states(f)) < 0) - return ret; - - for (int i = 0; i < f->quant_table_count; i++) - if (get_rac(&c, state)) { - for (int j = 0; j < f->context_count[i]; j++) - for (int k = 0; k < CONTEXT_SIZE; k++) { - int pred = j ? f->initial_states[i][j - 1][k] : 128; - f->initial_states[i][j][k] = - (pred + get_symbol(&c, state2[k], 1)) & 0xFF; - } - } - - if (f->version > 2) { - f->ec = get_symbol(&c, state, 0); - if (f->ec >= 2) - f->crcref = 0x7a8c4079; - if (f->combined_version >= 0x30003) - f->intra = get_symbol(&c, state, 0); - } - - if (f->version > 2) { - unsigned v; - v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, - f->avctx->extradata, f->avctx->extradata_size); - if (v != f->crcref || f->avctx->extradata_size < 4) { - av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v); - return AVERROR_INVALIDDATA; - } - crc = AV_RB32(f->avctx->extradata + f->avctx->extradata_size - 4); - } - - if (f->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(f->avctx, AV_LOG_DEBUG, - "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d CRC:0x%08X\n", - f->version, f->micro_version, - f->ac, - f->colorspace, - f->avctx->bits_per_raw_sample, - f->chroma_planes, f->chroma_h_shift, f->chroma_v_shift, - f->transparency, - f->num_h_slices, f->num_v_slices, - f->quant_table_count, - f->ec, - f->intra, - crc - ); - return 0; -} - static enum AVPixelFormat get_pixel_format(FFV1Context *f) { enum AVPixelFormat pix_fmts[] = { @@ -554,214 +349,13 @@ static int read_header(FFV1Context *f, RangeCoder *c) { uint8_t state[CONTEXT_SIZE]; int context_count = -1; //-1 to avoid warning + int ret; memset(state, 128, sizeof(state)); - if (f->version < 2) { - int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample; - unsigned v= get_symbol(c, state, 0); - if (v >= 2) { - av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v); - return AVERROR_INVALIDDATA; - } - f->version = v; - f->ac = get_symbol(c, state, 0); - - if (f->ac == AC_RANGE_CUSTOM_TAB) { - for (int i = 1; i < 256; i++) { - int st = get_symbol(c, state, 1) + c->one_state[i]; - if (st < 1 || st > 255) { - av_log(f->avctx, AV_LOG_ERROR, "invalid state transition %d\n", st); - return AVERROR_INVALIDDATA; - } - f->state_transition[i] = st; - } - } - - colorspace = get_symbol(c, state, 0); //YUV cs type - bits_per_raw_sample = f->version > 0 ? get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample; - chroma_planes = get_rac(c, state); - chroma_h_shift = get_symbol(c, state, 0); - chroma_v_shift = get_symbol(c, state, 0); - transparency = get_rac(c, state); - if (colorspace == 0 && f->avctx->skip_alpha) - transparency = 0; - - if (f->plane_count) { - if (colorspace != f->colorspace || - bits_per_raw_sample != f->avctx->bits_per_raw_sample || - chroma_planes != f->chroma_planes || - chroma_h_shift != f->chroma_h_shift || - chroma_v_shift != f->chroma_v_shift || - transparency != f->transparency) { - av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n"); - return AVERROR_INVALIDDATA; - } - } - - if (chroma_h_shift > 4U || chroma_v_shift > 4U) { - av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", - chroma_h_shift, chroma_v_shift); - return AVERROR_INVALIDDATA; - } - - f->colorspace = colorspace; - f->avctx->bits_per_raw_sample = bits_per_raw_sample; - f->chroma_planes = chroma_planes; - f->chroma_h_shift = chroma_h_shift; - f->chroma_v_shift = chroma_v_shift; - f->transparency = transparency; - - f->plane_count = 2 + f->transparency; - } - - if (f->colorspace == 0) { - if (!f->transparency && !f->chroma_planes) { - if (f->avctx->bits_per_raw_sample <= 8) - f->pix_fmt = AV_PIX_FMT_GRAY8; - else if (f->avctx->bits_per_raw_sample == 9) { - f->packed_at_lsb = 1; - f->pix_fmt = AV_PIX_FMT_GRAY9; - } else if (f->avctx->bits_per_raw_sample == 10) { - f->packed_at_lsb = 1; - f->pix_fmt = AV_PIX_FMT_GRAY10; - } else if (f->avctx->bits_per_raw_sample == 12) { - f->packed_at_lsb = 1; - f->pix_fmt = AV_PIX_FMT_GRAY12; - } else if (f->avctx->bits_per_raw_sample == 14) { - f->packed_at_lsb = 1; - f->pix_fmt = AV_PIX_FMT_GRAY14; - } else if (f->avctx->bits_per_raw_sample == 16) { - f->packed_at_lsb = 1; - f->pix_fmt = AV_PIX_FMT_GRAY16; - } else if (f->avctx->bits_per_raw_sample < 16) { - f->pix_fmt = AV_PIX_FMT_GRAY16; - } else - return AVERROR(ENOSYS); - } else if (f->transparency && !f->chroma_planes) { - if (f->avctx->bits_per_raw_sample <= 8) - f->pix_fmt = AV_PIX_FMT_YA8; - else - return AVERROR(ENOSYS); - } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) { - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P; break; - case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P; break; - case 0x20: f->pix_fmt = AV_PIX_FMT_YUV411P; break; - case 0x22: f->pix_fmt = AV_PIX_FMT_YUV410P; break; - } - } else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) { - switch(16*f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P; break; - } - } else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) { - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P9; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P9; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P9; break; - } - } else if (f->avctx->bits_per_raw_sample == 9 && f->transparency) { - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P9; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P9; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P9; break; - } - } else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) { - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P10; break; - case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P10; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P10; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P10; break; - } - } else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) { - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P10; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P10; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P10; break; - } - } else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency) { - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P12; break; - case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P12; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P12; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P12; break; - } - } else if (f->avctx->bits_per_raw_sample == 12 && f->transparency) { - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P12; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P12; break; - } - } else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) { - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P14; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P14; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P14; break; - } - } else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency){ - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P16; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P16; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P16; break; - } - } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency){ - f->packed_at_lsb = 1; - switch(16 * f->chroma_h_shift + f->chroma_v_shift) { - case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P16; break; - case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P16; break; - case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P16; break; - } - } - } else if (f->colorspace == 1) { - if (f->chroma_h_shift || f->chroma_v_shift) { - av_log(f->avctx, AV_LOG_ERROR, - "chroma subsampling not supported in this colorspace\n"); - return AVERROR(ENOSYS); - } - if ( f->avctx->bits_per_raw_sample <= 8 && !f->transparency) - f->pix_fmt = AV_PIX_FMT_0RGB32; - else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) - f->pix_fmt = AV_PIX_FMT_RGB32; - else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) - f->pix_fmt = AV_PIX_FMT_GBRP9; - else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) - f->pix_fmt = AV_PIX_FMT_GBRP10; - else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) - f->pix_fmt = AV_PIX_FMT_GBRAP10; - else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency) - f->pix_fmt = AV_PIX_FMT_GBRP12; - else if (f->avctx->bits_per_raw_sample == 12 && f->transparency) - f->pix_fmt = AV_PIX_FMT_GBRAP12; - else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) - f->pix_fmt = AV_PIX_FMT_GBRP14; - else if (f->avctx->bits_per_raw_sample == 14 && f->transparency) - f->pix_fmt = AV_PIX_FMT_GBRAP14; - else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) { - f->pix_fmt = AV_PIX_FMT_GBRP16; - f->use32bit = 1; - } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency) { - f->pix_fmt = AV_PIX_FMT_GBRAP16; - f->use32bit = 1; - } - } else { - av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n"); - return AVERROR(ENOSYS); - } - if (f->pix_fmt == AV_PIX_FMT_NONE) { - av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); - return AVERROR(ENOSYS); - } + ret = ff_ffv1_parse_header(f, c, state); + if (ret < 0) + return ret; f->avctx->pix_fmt = get_pixel_format(f); if (f->avctx->pix_fmt < 0) @@ -770,14 +364,14 @@ static int read_header(FFV1Context *f, RangeCoder *c) ff_dlog(f->avctx, "%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift, f->pix_fmt); if (f->version < 2) { - context_count = read_quant_tables(c, f->quant_tables[0]); + context_count = ff_ffv1_read_quant_tables(c, f->quant_tables[0]); if (context_count < 0) { av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); return AVERROR_INVALIDDATA; } f->slice_count = f->max_slice_count; } else if (f->version < 3) { - f->slice_count = get_symbol(c, state, 0); + f->slice_count = ff_ffv1_get_symbol(c, state, 0); } else { const uint8_t *p = c->bytestream_end; for (f->slice_count = 0; @@ -804,10 +398,10 @@ static int read_header(FFV1Context *f, RangeCoder *c) FFV1SliceContext *sc = &f->slices[j]; if (f->version == 2) { - int sx = get_symbol(c, state, 0); - int sy = get_symbol(c, state, 0); - int sw = get_symbol(c, state, 0) + 1U; - int sh = get_symbol(c, state, 0) + 1U; + int sx = ff_ffv1_get_symbol(c, state, 0); + int sy = ff_ffv1_get_symbol(c, state, 0); + int sw = ff_ffv1_get_symbol(c, state, 0) + 1U; + int sh = ff_ffv1_get_symbol(c, state, 0) + 1U; if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0) return AVERROR_INVALIDDATA; @@ -834,7 +428,7 @@ static int read_header(FFV1Context *f, RangeCoder *c) PlaneContext *const p = &sc->plane[i]; if (f->version == 2) { - int idx = get_symbol(c, state, 0); + int idx = ff_ffv1_get_symbol(c, state, 0); if (idx >= (unsigned)f->quant_table_count) { av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n"); @@ -858,10 +452,10 @@ static av_cold int decode_init(AVCodecContext *avctx) FFV1Context *f = avctx->priv_data; int ret; - if ((ret = ff_ffv1_common_init(avctx)) < 0) + if ((ret = ff_ffv1_common_init(avctx, f)) < 0) return ret; - if (avctx->extradata_size > 0 && (ret = read_extra_header(f)) < 0) + if (avctx->extradata_size > 0 && (ret = ff_ffv1_read_extra_header(f)) < 0) return ret; if ((ret = ff_ffv1_init_slice_contexts(f)) < 0) @@ -1161,8 +755,11 @@ static av_cold int ffv1_decode_close(AVCodecContext *avctx) ff_progress_frame_unref(&s->picture); ff_progress_frame_unref(&s->last_picture); + av_freep(&avctx->stats_out); + + ff_ffv1_close(s); - return ff_ffv1_close(avctx); + return 0; } const FFCodec ff_ffv1_decoder = { |