[FFmpeg-devel] [PATCH v2 59/69] avcodec/mpegvideo: Add ptr to main MPVMainContext to slice contexts

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Feb 1 15:06:56 EET 2022


It is a pointer to const to allow the slice threads to inspect
values without modifying them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
I am unsure whether this should be a pointer to const void
or a pointer to const MPVMainContext.

 libavcodec/mpegvideo.c     | 3 +++
 libavcodec/mpegvideo.h     | 2 ++
 libavcodec/mpegvideo_dec.c | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 220f1c39f0..4b22eb746a 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -396,6 +396,8 @@ int ff_mpv_init_duplicate_contexts(MPVMainContext *m)
     MPVContext *const s = &m->s;
     int nb_slices = s->slice_context_count, ret;
 
+    s->parent_ctx = m;
+
     /* 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. */
@@ -524,6 +526,7 @@ void ff_mpv_common_defaults(MPVMainContext *m)
     s->b_code                = 1;
 
     s->slice_context_count   = 1;
+    s->parent_ctx            = m;
 }
 
 int ff_mpv_init_context_frame(MPVMainContext *m)
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 9005dcb58a..1c44e9be2f 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -76,6 +76,8 @@ typedef struct MPVContext {
      *          offsets used in ASM. */
 
     struct AVCodecContext *avctx;
+    /* A pointer to this context's parent MPVMainContext. */
+    const struct MPVMainContext *parent_ctx;
     /* 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_dec.c b/libavcodec/mpegvideo_dec.c
index f202db33e9..fd97e6ac1a 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -72,6 +72,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
         memcpy(s, s1, sizeof(*s));
 
         s->avctx                 = dst;
+        s->parent_ctx            = m;
         s->private_ctx           = private_ctx;
         s->bitstream_buffer      = NULL;
         s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
@@ -83,6 +84,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
             if ((err = ff_mpv_common_init(m)) < 0) {
                 memset(s, 0, sizeof(*s));
                 s->avctx = dst;
+                s->parent_ctx  = m;
                 s->private_ctx = private_ctx;
                 return err;
             }
-- 
2.32.0



More information about the ffmpeg-devel mailing list