ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Tue Mar 25 12:42:45 2025 +0100| [bd6e6495aebc016ab12bc0a60276c6d3fe43663b] | 
committer: Andreas Rheinhardt

avcodec/mpegvideo: Move clear_context() to mpeg4videodec.c

There is only one source of dirty MpegEncContexts:
update_mpvctx() (which copies an MpegEncContext
over another one in order to initialize it). So only clear
these contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bd6e6495aebc016ab12bc0a60276c6d3fe43663b
---

 libavcodec/mpeg4videodec.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 libavcodec/mpegvideo.c     | 38 --------------------------------------
 2 files changed, 40 insertions(+), 41 deletions(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 60b06ad750..ad2dfbd0fb 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3774,15 +3774,52 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const 
AVPacket *pkt)
 
 #if CONFIG_MPEG4_DECODER
 #if HAVE_THREADS
-static int update_mpvctx(MpegEncContext *s, const MpegEncContext *s1)
+static av_cold void clear_context(MpegEncContext *s)
+{
+    memset(&s->buffer_pools, 0, sizeof(s->buffer_pools));
+    memset(&s->next_pic, 0, sizeof(s->next_pic));
+    memset(&s->last_pic, 0, sizeof(s->last_pic));
+    memset(&s->cur_pic,  0, sizeof(s->cur_pic));
+
+    memset(s->thread_context, 0, sizeof(s->thread_context));
+
+    s->block = NULL;
+    s->blocks = NULL;
+    s->ac_val_base = NULL;
+    s->ac_val[0] =
+    s->ac_val[1] =
+    s->ac_val[2] =NULL;
+    memset(&s->sc, 0, sizeof(s->sc));
+
+    s->p_field_mv_table_base = NULL;
+    for (int i = 0; i < 2; i++)
+        for (int j = 0; j < 2; j++)
+            s->p_field_mv_table[i][j] = NULL;
+
+    s->dc_val_base = NULL;
+    s->coded_block_base = NULL;
+    s->mbintra_table = NULL;
+    s->cbp_table = NULL;
+    s->pred_dir_table = NULL;
+
+    s->mbskip_table = NULL;
+
+    s->er.error_status_table = NULL;
+    s->er.er_temp_buffer = NULL;
+    s->mb_index2xy = NULL;
+
+    s->context_initialized   = 0;
+    s->context_reinit        = 0;
+}
+
+static av_cold int update_mpvctx(MpegEncContext *s, const MpegEncContext *s1)
 {
     AVCodecContext *avctx = s->avctx;
     // FIXME the following leads to a data race; instead copy only
     // the necessary fields.
     memcpy(s, s1, sizeof(*s));
+    clear_context(s);
 
-    s->context_initialized = 0;
-    s->context_reinit      = 0;
     s->avctx = avctx;
 
     if (s1->context_initialized) {
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index d09eb1211d..a783ccdbdd 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -379,42 +379,6 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
     return !CONFIG_MPEGVIDEODEC || s->encoding ? 0 : ff_mpeg_er_init(s);
 }
 
-static void clear_context(MpegEncContext *s)
-{
-    memset(&s->buffer_pools, 0, sizeof(s->buffer_pools));
-    memset(&s->next_pic, 0, sizeof(s->next_pic));
-    memset(&s->last_pic, 0, sizeof(s->last_pic));
-    memset(&s->cur_pic,  0, sizeof(s->cur_pic));
-
-    memset(s->thread_context, 0, sizeof(s->thread_context));
-
-    s->block = NULL;
-    s->blocks = NULL;
-    s->ac_val_base = NULL;
-    s->ac_val[0] =
-    s->ac_val[1] =
-    s->ac_val[2] =NULL;
-    memset(&s->sc, 0, sizeof(s->sc));
-
-
-    s->p_field_mv_table_base = NULL;
-    for (int i = 0; i < 2; i++)
-        for (int j = 0; j < 2; j++)
-            s->p_field_mv_table[i][j] = NULL;
-
-    s->dc_val_base = NULL;
-    s->coded_block_base = NULL;
-    s->mbintra_table = NULL;
-    s->cbp_table = NULL;
-    s->pred_dir_table = NULL;
-
-    s->mbskip_table = NULL;
-
-    s->er.error_status_table = NULL;
-    s->er.er_temp_buffer = NULL;
-    s->mb_index2xy = NULL;
-}
-
 /**
  * init common structure for both encoder and decoder.
  * this assumes that some variables like width/height are already set
@@ -426,8 +390,6 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
                     s->avctx->thread_count : 1;
     int ret;
 
-    clear_context(s);
-
     if (s->encoding && s->avctx->slices)
         nb_slices = s->avctx->slices;
 

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to