From b77de4fb3b253c8ab9459853d092825dddd9af1b Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Mon, 3 Mar 2025 17:26:00 +0100
Subject: [PATCH 08/77] avcodec/mpegvideo: Don't initialize [yc]_dc_scale_table
 by default

Only the H.263-based decoders as well as the encoders need it;
so move it to ff_h263_decode_init() as well as ff_mpv_encode_init().
Also for the latter make it only set these tables if none are
already set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h263dec.c       | 5 ++++-
 libavcodec/mpegvideo.c     | 2 --
 libavcodec/mpegvideo_enc.c | 6 +++++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 2d806fc703..8434f6e7cf 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -41,8 +41,8 @@
 #include "mpeg_er.h"
 #include "mpeg4video.h"
 #include "mpeg4videodec.h"
-#include "mpeg4videodefs.h"
 #include "mpegvideo.h"
+#include "mpegvideodata.h"
 #include "mpegvideodec.h"
 #include "msmpeg4dec.h"
 #include "thread.h"
@@ -102,6 +102,9 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
     s->decode_mb       = ff_h263_decode_mb;
     s->low_delay       = 1;
 
+    s->y_dc_scale_table =
+    s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
+
     // dct_unquantize defaults for H.263;
     // they might change on a per-frame basis for MPEG-4.
     s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 4b69b5b65c..9cd67151aa 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -482,8 +482,6 @@ int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
  */
 av_cold void ff_mpv_common_defaults(MpegEncContext *s)
 {
-    s->y_dc_scale_table      =
-    s->c_dc_scale_table      = ff_mpeg1_dc_scale_table;
     s->chroma_qscale_table   = ff_default_chroma_qscale_table;
     s->progressive_frame     = 1;
     s->progressive_sequence  = 1;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 5c2f73b2d1..7eb381af36 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -276,7 +276,6 @@ static av_cold void mpv_encode_init_static(void)
 
 /**
  * Set the given MpegEncContext to defaults for encoding.
- * the changed fields will not depend upon the prior state of the MpegEncContext.
  */
 static av_cold void mpv_encode_defaults(MpegEncContext *s)
 {
@@ -288,6 +287,11 @@ static av_cold void mpv_encode_defaults(MpegEncContext *s)
 
     s->fcode_tab     = default_fcode_tab + MAX_MV;
 
+    if (!s->y_dc_scale_table) {
+        s->y_dc_scale_table =
+        s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
+    }
+
     s->input_picture_number  = 0;
     s->picture_in_gop_number = 0;
 }
-- 
2.45.2