From 23b72a64cc044216380b0f815ef5b752aceb63ed Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 25 Mar 2025 05:56:33 +0100 Subject: [PATCH 10/44] avcodec/mpegvideo_dec: Add ff_mpv_decode_reinit() The rationale for adding ff_mpv_common_frame_size_change() instead of a simple ff_mpv_common_end()+ff_mpv_common_init() was that it would avoid freeing the "Picture" array and the AVFrames contained in it. Yet this is obsolete because said array no longer exists since 9ce56f91c0e74b7cc34985fdb15050aa98aeded6. This commit therefore adds a simple end+init function designed to replace ff_mpv_common_frame_size_change() and also ff_mpv_common_init() for decoders. It also calls ff_set_dimensions(), so that it does not allow 0x0 dimensions. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_dec.c | 13 +++++++++++++ libavcodec/mpegvideodec.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 4019b4f0da..089c50dcca 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -142,6 +142,19 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, return 0; } +av_cold int ff_mpv_decode_reinit(MpegEncContext *const s) +{ + int ret; + + if (s->context_initialized) + ff_mpv_common_end(s); + + ret = ff_set_dimensions(s->avctx, s->width, s->height); + if (ret < 0) + return ret; + return ff_mpv_common_init(s); +} + av_cold int ff_mpv_decode_close(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; diff --git a/libavcodec/mpegvideodec.h b/libavcodec/mpegvideodec.h index 6100364715..19b9587600 100644 --- a/libavcodec/mpegvideodec.h +++ b/libavcodec/mpegvideodec.h @@ -48,6 +48,11 @@ * Also initialize the picture pool. */ int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx); +/** + * Close the MpegEncContext (if initialized) and initialize it for decoding. + * Also set the AVCodecContext's dimensions. + */ +int ff_mpv_decode_reinit(MpegEncContext *s); int ff_mpv_common_frame_size_change(MpegEncContext *s); -- 2.45.2