[FFmpeg-cvslog] avcodec/me_cmp,dvenc,mpegvideo: Move ildct_cmp to its users

Andreas Rheinhardt git at videolan.org
Thu Jun 20 20:00:00 EEST 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun May 12 21:05:58 2024 +0200| [b1a31b32abc19df329cf61fa23febd8252978fd3] | committer: Andreas Rheinhardt

avcodec/me_cmp,dvenc,mpegvideo: Move ildct_cmp to its users

MECmpContext.ildct_cmp is an array of function pointers that
are not set by ff_me_cmp_init(), but that are set by users
to one of the other arrays via ff_set_cmp().

Remove these pointers from MECmpContext and add pointers
for the actually used functions to its users. (The DV encoder
already did so.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libavcodec/dvenc.c         |  7 ++++---
 libavcodec/me_cmp.h        |  2 --
 libavcodec/mpegvideo.h     |  2 ++
 libavcodec/mpegvideo_enc.c | 49 +++++++++++++++++++++++-----------------------
 tests/checkasm/motion.c    |  1 -
 5 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 5336ff149c..1f68c85c48 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -96,15 +96,16 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
 
     if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
         MECmpContext mecc;
+        me_cmp_func ildct_cmp[6];
 
         memset(&mecc,0, sizeof(mecc));
         ff_me_cmp_init(&mecc, avctx);
-        ret = ff_set_cmp(&mecc, mecc.ildct_cmp, avctx->ildct_cmp);
+        ret = ff_set_cmp(&mecc, ildct_cmp, avctx->ildct_cmp);
         if (ret < 0)
             return ret;
-        if (!mecc.ildct_cmp[5])
+        if (!ildct_cmp[5])
             return AVERROR(EINVAL);
-        s->ildct_cmp = mecc.ildct_cmp[5];
+        s->ildct_cmp = ildct_cmp[5];
     }
 
     memset(&fdsp,0, sizeof(fdsp));
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index 4f964ca188..b9abc7fb8e 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -70,8 +70,6 @@ typedef struct MECmpContext {
     me_cmp_func dct_max[6];
     me_cmp_func dct264_sad[6];
 
-    me_cmp_func ildct_cmp[6]; // only width 16 used
-
     me_cmp_func pix_abs[2][4];
     me_cmp_func median_sad[6];
 } MECmpContext;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index df46433a82..44695776ad 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -506,6 +506,8 @@ typedef struct MpegEncContext {
     int mpv_flags;      ///< flags set by private options
     int quantizer_noise_shaping;
 
+    me_cmp_func ildct_cmp[2]; ///< 0 = intra, 1 = non-intra
+
     /**
      * ratecontrol qmin qmax limiting method
      * 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax.
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6ec8fa2e0b..6059bdee11 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -319,6 +319,15 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
     if (ret < 0)
         return ret;
     s->frame_skip_cmp_fn = me_cmp[1];
+    if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
+        ret = ff_set_cmp(&s->mecc, me_cmp, avctx->ildct_cmp);
+        if (ret < 0)
+            return ret;
+        if (!me_cmp[0] || !me_cmp[4])
+            return AVERROR(EINVAL);
+        s->ildct_cmp[0] = me_cmp[0];
+        s->ildct_cmp[1] = me_cmp[4];
+    }
 
     return 0;
 }
@@ -929,14 +938,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 
     s->quant_precision = 5;
 
-    if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
-        ret = ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp);
-        if (ret < 0)
-            return ret;
-        if (!s->mecc.ildct_cmp[0] || !s->mecc.ildct_cmp[4])
-            return AVERROR(EINVAL);
-    }
-
     if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
         ff_h263_encode_init(s);
 #if CONFIG_MSMPEG4ENC
@@ -2209,15 +2210,15 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
             int progressive_score, interlaced_score;
 
             s->interlaced_dct = 0;
-            progressive_score = s->mecc.ildct_cmp[4](s, ptr_y, NULL, wrap_y, 8) +
-                                s->mecc.ildct_cmp[4](s, ptr_y + wrap_y * 8,
-                                                     NULL, wrap_y, 8) - 400;
+            progressive_score = s->ildct_cmp[1](s, ptr_y, NULL, wrap_y, 8) +
+                                s->ildct_cmp[1](s, ptr_y + wrap_y * 8,
+                                                NULL, wrap_y, 8) - 400;
 
             if (progressive_score > 0) {
-                interlaced_score = s->mecc.ildct_cmp[4](s, ptr_y,
-                                                        NULL, wrap_y * 2, 8) +
-                                   s->mecc.ildct_cmp[4](s, ptr_y + wrap_y,
-                                                        NULL, wrap_y * 2, 8);
+                interlaced_score = s->ildct_cmp[1](s, ptr_y,
+                                                   NULL, wrap_y * 2, 8) +
+                                   s->ildct_cmp[1](s, ptr_y + wrap_y,
+                                                   NULL, wrap_y * 2, 8);
                 if (progressive_score > interlaced_score) {
                     s->interlaced_dct = 1;
 
@@ -2288,20 +2289,20 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
             int progressive_score, interlaced_score;
 
             s->interlaced_dct = 0;
-            progressive_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y, wrap_y, 8) +
-                                s->mecc.ildct_cmp[0](s, dest_y + wrap_y * 8,
-                                                     ptr_y + wrap_y * 8,
-                                                     wrap_y, 8) - 400;
+            progressive_score = s->ildct_cmp[0](s, dest_y, ptr_y, wrap_y, 8) +
+                                s->ildct_cmp[0](s, dest_y + wrap_y * 8,
+                                                ptr_y + wrap_y * 8,
+                                                wrap_y, 8) - 400;
 
             if (s->avctx->ildct_cmp == FF_CMP_VSSE)
                 progressive_score -= 400;
 
             if (progressive_score > 0) {
-                interlaced_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y,
-                                                        wrap_y * 2, 8) +
-                                   s->mecc.ildct_cmp[0](s, dest_y + wrap_y,
-                                                        ptr_y + wrap_y,
-                                                        wrap_y * 2, 8);
+                interlaced_score = s->ildct_cmp[0](s, dest_y, ptr_y,
+                                                   wrap_y * 2, 8) +
+                                   s->ildct_cmp[0](s, dest_y + wrap_y,
+                                                   ptr_y + wrap_y,
+                                                   wrap_y * 2, 8);
 
                 if (progressive_score > interlaced_score) {
                     s->interlaced_dct = 1;
diff --git a/tests/checkasm/motion.c b/tests/checkasm/motion.c
index 8f9915c63a..bfd1a3c17b 100644
--- a/tests/checkasm/motion.c
+++ b/tests/checkasm/motion.c
@@ -94,7 +94,6 @@ static void test_motion(const char *name, me_cmp_func test_func)
     XX(vsad)                                                                   \
     XX(vsse)                                                                   \
     XX(nsse)                                                                   \
-    XX(ildct_cmp)                                                              \
     XX(median_sad)
 
 // tests for functions not yet implemented



More information about the ffmpeg-cvslog mailing list