From 130b7d34ab4652e140c240e63355bad0a09bcd64 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 25 Mar 2025 09:08:50 +0100 Subject: [PATCH 20/44] avcodec/mpegvideo_dec: Notify users of reinit Namely of reinititialization performed by ff_mpeg_update_thread_context(), so that they can simply update their own dimension-based buffers accordingly. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_dec.c | 6 ++++-- libavcodec/mpegvideodec.h | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 089c50dcca..5e445d0d83 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -80,7 +80,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, { MpegEncContext *const s1 = src->priv_data; MpegEncContext *const s = dst->priv_data; - int ret; + int ret = 0; if (dst == src) return 0; @@ -102,6 +102,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, if (s1->context_initialized) { if ((err = ff_mpv_common_init(s)) < 0) return err; + ret = 1; } } @@ -110,6 +111,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, s->width = s1->width; if ((ret = ff_mpv_common_frame_size_change(s)) < 0) return ret; + ret = 1; } s->quarter_sample = s1->quarter_sample; @@ -139,7 +141,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, memcpy(&s->progressive_sequence, &s1->progressive_sequence, (char *) &s1->first_field + sizeof(s1->first_field) - (char *) &s1->progressive_sequence); - return 0; + return ret; } av_cold int ff_mpv_decode_reinit(MpegEncContext *const s) diff --git a/libavcodec/mpegvideodec.h b/libavcodec/mpegvideodec.h index 19b9587600..ef6e657c0b 100644 --- a/libavcodec/mpegvideodec.h +++ b/libavcodec/mpegvideodec.h @@ -67,6 +67,15 @@ void ff_mpv_frame_end(MpegEncContext *s); int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const MPVPicture *p, int qp_type); +/** + * update_thread_context for mpegvideo-based decoders. It updates + * the MPVPictures and generic stream-level parameters. If necessary + * (on dimension changes), it also performs reinitialization. + * + * @retval 1 if a reinitialization happened + * @retval 0 on success if no reinitialization happened + * @retval "<0" error code + */ int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src); void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h); void ff_mpeg_flush(AVCodecContext *avctx); -- 2.45.2