From 93aea509729e4bf740669aa79fba5b4340c65817 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Wed, 30 Apr 2025 04:09:11 +0200 Subject: [PATCH 44/44] avcodec/mpegvideo: Move parent to MPVEncContext This is more type-safe and avoids having parent contexts when unnecessary. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 2 -- libavcodec/mpegvideo.h | 4 ---- libavcodec/mpegvideo_enc.c | 1 + libavcodec/mpegvideoenc.h | 4 +++- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 6d6f126fd3..1297c584f2 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -140,8 +140,6 @@ av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s) int nb_slices = s->slice_context_count, ret; size_t slice_size = s->slice_ctx_size ? s->slice_ctx_size : sizeof(*s); - s->parent = s; - /* We initialize the copies before the original so that * fields allocated in init_duplicate_context are NULL after * copying. This prevents double-frees upon allocation error. */ diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 3a769db569..e79d93c48b 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -80,10 +80,6 @@ typedef struct MpegEncContext { uint8_t permutated_intra_v_scantable[64]; struct AVCodecContext *avctx; - union { - const struct MpegEncContext *parent; - const struct MPVMainEncContext *encparent; - }; /* The following pointer is intended for codecs sharing code * between decoder and encoder and in need of a common context to do so. */ void *private_ctx; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index f1de7f6ff6..503906efeb 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1023,6 +1023,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) /* ff_mpv_init_duplicate_contexts() will copy (memdup) the contents of the * main slice to the slice contexts, so we initialize various fields of it * before calling ff_mpv_init_duplicate_contexts(). */ + s->parent = m; ff_mpv_idct_init(&s->c); init_unquantize(&s->c, avctx); ff_fdctdsp_init(&s->fdsp, avctx); diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 76e3780923..ec0304c4a0 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -69,6 +69,8 @@ typedef struct MPVEncContext { */ AVFrame *new_pic; + struct MPVMainEncContext *parent; + FDCTDSPContext fdsp; MpegvideoEncDSPContext mpvencdsp; PixblockDSPContext pdsp; @@ -254,7 +256,7 @@ static inline const MPVMainEncContext *slice_to_mainenc(const MPVEncContext *s) !(s->c.avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)); return (const MPVMainEncContext*)s; #else - return s->c.encparent; + return s->parent; #endif } -- 2.45.2