From 6efa820818470d33d32899f24c9924f2deac872c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 25 Mar 2025 07:31:22 +0100 Subject: [PATCH 16/44] avcodec/h263dec: Defer initializing FLV, H263I contexts These codec's frame headers can contain new dimensions, so defer initializing the MpegEncContext and rely on the existing check for uninitialized MpegEncContexts in ff_h263_decode_frame(). Signed-off-by: Andreas Rheinhardt --- libavcodec/h263dec.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index fd1e36b68a..19029e8d97 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -92,6 +92,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; MPVUnquantDSPContext unquant_dsp_ctx; + int init_now = 0; int ret; s->out_format = FMT_H263; @@ -125,26 +126,33 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) case AV_CODEC_ID_MSMPEG4V1: s->h263_pred = 1; s->msmpeg4_version = MSMP4_V1; + init_now = 1; break; case AV_CODEC_ID_MSMPEG4V2: s->h263_pred = 1; s->msmpeg4_version = MSMP4_V2; + init_now = 1; break; case AV_CODEC_ID_MSMPEG4V3: s->h263_pred = 1; s->msmpeg4_version = MSMP4_V3; + init_now = 1; break; case AV_CODEC_ID_WMV1: s->h263_pred = 1; s->msmpeg4_version = MSMP4_WMV1; + init_now = 1; break; case AV_CODEC_ID_WMV2: s->h263_pred = 1; s->msmpeg4_version = MSMP4_WMV2; + init_now = 1; break; - case AV_CODEC_ID_H263I: case AV_CODEC_ID_RV10: case AV_CODEC_ID_RV20: + init_now = 1; + break; + case AV_CODEC_ID_H263I: break; case AV_CODEC_ID_FLV1: s->h263_flv = 1; @@ -155,19 +163,17 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) return AVERROR(ENOSYS); } - if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263")) - if (avctx->extradata_size == 56 && avctx->extradata[0] == 1) - s->ehc_mode = 1; - - /* for H.263, we allocate the images after having read the header */ - if (avctx->codec->id != AV_CODEC_ID_H263 && - avctx->codec->id != AV_CODEC_ID_H263P && - avctx->codec->id != AV_CODEC_ID_MPEG4) { + /* Defer initializing the context for codecs with in-band dimensions. */ + if (init_now) { avctx->pix_fmt = h263_get_format(avctx); if ((ret = ff_mpv_common_init(s)) < 0) return ret; } + if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263")) + if (avctx->extradata_size == 56 && avctx->extradata[0] == 1) + s->ehc_mode = 1; + ff_h263dsp_init(&s->h263dsp); ff_h263_decode_init_vlc(); -- 2.45.2