From 319914ee082f7646dfba5346aac62a8298847007 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 25 Mar 2025 11:56:42 +0100 Subject: [PATCH 24/44] avcodec/mpegvideo_dec, rv34: Avoid ff_mpv_common_frame_size_change() Replace the function by ff_mpv_decode_reinit(). This avoids having to track two variables to see whether the context is properly initialized. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_dec.c | 13 +++++++++---- libavcodec/rv34.c | 16 ++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 54987a19df..eb9e69871f 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -87,12 +87,17 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, av_assert0(s != s1); - if (s->height != s1->height || s->width != s1->width || s->context_reinit) { + if (s->height != s1->height || s->width != s1->width || !s1->context_initialized) { s->height = s1->height; s->width = s1->width; - if ((ret = ff_mpv_common_frame_size_change(s)) < 0) - return ret; - ret = 1; + if (s1->context_initialized) { + ret = ff_mpv_decode_reinit(s); + if (ret < 0) + return ret; + ret = 1; + } else { + ff_mpv_common_end(s); + } } s->quarter_sample = s1->quarter_sample; diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 5dcbe9a222..0545f77b44 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -32,7 +32,6 @@ #include "libavutil/thread.h" #include "avcodec.h" -#include "decode.h" #include "error_resilience.h" #include "mpegutils.h" #include "mpegvideo.h" @@ -1403,7 +1402,7 @@ static int rv34_decoder_alloc(RV34DecContext *r) if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs && r->intra_types_hist && r->mb_type)) { - r->s.context_reinit = 1; + ff_mpv_common_end(&r->s); rv34_decoder_free(r); return AVERROR(ENOMEM); } @@ -1538,10 +1537,9 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx) int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { RV34DecContext *r = dst->priv_data, *r1 = src->priv_data; - MpegEncContext *const s1 = &r1->s; int ret; - if (dst == src || !s1->context_initialized) + if (dst == src) return 0; ret = ff_mpeg_update_thread_context(dst, src); @@ -1671,12 +1669,12 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, if (s->mb_num_left > 0 && s->cur_pic.ptr) { av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n", s->mb_num_left); - if (!s->context_reinit) + if (s->context_initialized) ff_er_frame_end(&s->er, NULL); ff_mpv_frame_end(s); } - if (s->width != si.width || s->height != si.height || s->context_reinit) { + if (!s->context_initialized || s->width != si.width || s->height != si.height) { int err; av_log(s->avctx, AV_LOG_WARNING, "Changing dimensions to %dx%d\n", @@ -1691,11 +1689,9 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, s->width = si.width; s->height = si.height; - err = ff_set_dimensions(s->avctx, s->width, s->height); + err = ff_mpv_decode_reinit(s); if (err < 0) return err; - if ((err = ff_mpv_common_frame_size_change(s)) < 0) - return err; if ((err = rv34_decoder_realloc(r)) < 0) return err; } @@ -1750,7 +1746,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, } s->mb_x = s->mb_y = 0; ff_thread_finish_setup(s->avctx); - } else if (s->context_reinit) { + } else if (!s->context_initialized) { av_log(s->avctx, AV_LOG_ERROR, "Decoder needs full frames to " "reinitialize (start MB is %d).\n", si.start); return AVERROR_INVALIDDATA; -- 2.45.2