diff mbox series

[FFmpeg-devel,2/4] avcodec/svq1enc: Add SVQ1EncDSPContext, make codec context private

Message ID AS8P250MB0744A468B1388D970F1587438F239@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Headers show
Series [FFmpeg-devel,1/4] avcodec/svq1enc: Inline constants | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Oct. 11, 2022, 1:18 p.m. UTC
Currently, SVQ1EncContext is defined in a header that is also
included by the arch-specific code that initializes the one
and only dsp function that this encoder uses directly.

But the arch-specific functions to set this dsp function
do not need anything from SVQ1EncContext. This commit therefore
adds a small SVQ1EncDSPContext whose only member is said
function pointer and renames svq1enc.h to svq1encdsp.h
to avoid exposing unnecessary internals to these init
functions (and the whole mpegvideo with it).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ppc/svq1enc_altivec.c |  4 +-
 libavcodec/svq1enc.c             | 60 ++++++++++++++++++++--
 libavcodec/svq1enc.h             | 86 --------------------------------
 libavcodec/svq1encdsp.h          | 34 +++++++++++++
 libavcodec/x86/svq1enc_init.c    |  4 +-
 5 files changed, 93 insertions(+), 95 deletions(-)
 delete mode 100644 libavcodec/svq1enc.h
 create mode 100644 libavcodec/svq1encdsp.h
diff mbox series

Patch

diff --git a/libavcodec/ppc/svq1enc_altivec.c b/libavcodec/ppc/svq1enc_altivec.c
index aa66b40996..5721bede34 100644
--- a/libavcodec/ppc/svq1enc_altivec.c
+++ b/libavcodec/ppc/svq1enc_altivec.c
@@ -27,7 +27,7 @@ 
 #include "libavutil/ppc/cpu.h"
 #include "libavutil/ppc/util_altivec.h"
 
-#include "libavcodec/svq1enc.h"
+#include "libavcodec/svq1encdsp.h"
 
 #if HAVE_ALTIVEC
 static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2,
@@ -71,7 +71,7 @@  static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2,
 }
 #endif /* HAVE_ALTIVEC */
 
-av_cold void ff_svq1enc_init_ppc(SVQ1EncContext *c)
+av_cold void ff_svq1enc_init_ppc(SVQ1EncDSPContext *c)
 {
 #if HAVE_ALTIVEC
     if (!PPC_ALTIVEC(av_get_cpu_flags()))
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 79e9e578ac..67a6de5cc0 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -37,11 +37,61 @@ 
 #include "internal.h"
 #include "mpegutils.h"
 #include "packet_internal.h"
+#include "put_bits.h"
 #include "svq1.h"
-#include "svq1enc.h"
+#include "svq1encdsp.h"
 #include "svq1enc_cb.h"
+
 #include "libavutil/avassert.h"
+#include "libavutil/frame.h"
+#include "libavutil/mem_internal.h"
+
+typedef struct SVQ1EncContext {
+    /* FIXME: Needed for motion estimation, should not be used for anything
+     * else, the idea is to make the motion estimation eventually independent
+     * of MpegEncContext, so this will be removed then. */
+    MpegEncContext m;
+    AVCodecContext *avctx;
+    MECmpContext mecc;
+    HpelDSPContext hdsp;
+    AVFrame *current_picture;
+    AVFrame *last_picture;
+    PutBitContext pb;
+
+    /* Some compression statistics */
+    enum AVPictureType pict_type;
+    int quality;
+
+    /* why ooh why this sick breadth first order,
+     * everything is slower and more complex */
+    PutBitContext reorder_pb[6];
+
+    int frame_width;
+    int frame_height;
+
+    /* Y plane block dimensions */
+    int y_block_width;
+    int y_block_height;
+
+    /* U & V plane (C planes) block dimensions */
+    int c_block_width;
+    int c_block_height;
+
+    DECLARE_ALIGNED(16, int16_t, encoded_block_levels)[6][7][256];
+
+    uint16_t *mb_type;
+    uint32_t *dummy;
+    int16_t (*motion_val8[3])[2];
+    int16_t (*motion_val16[3])[2];
+
+    int64_t rd_total;
+
+    uint8_t *scratchbuf;
+
+    int motion_est;
 
+    SVQ1EncDSPContext svq1encdsp;
+} SVQ1EncContext;
 
 static void svq1_write_header(SVQ1EncContext *s, int frame_type)
 {
@@ -154,7 +204,7 @@  static int encode_block(SVQ1EncContext *s, uint8_t *src, uint8_t *ref,
                 int sqr, diff, score;
 
                 vector = codebook + stage * size * 16 + i * size;
-                sqr    = s->ssd_int8_vs_int16(vector, block[stage], size);
+                sqr    = s->svq1encdsp.ssd_int8_vs_int16(vector, block[stage], size);
                 diff   = block_sum[stage] - sum;
                 score  = sqr - (diff * (int64_t)diff >> (level + 3)); // FIXME: 64 bits slooow
                 if (score < best_vector_score) {
@@ -558,7 +608,7 @@  static av_cold int svq1_encode_init(AVCodecContext *avctx)
                                         s->y_block_height * sizeof(int16_t));
     s->dummy               = av_mallocz((s->y_block_width + 1) *
                                         s->y_block_height * sizeof(int32_t));
-    s->ssd_int8_vs_int16   = ssd_int8_vs_int16_c;
+    s->svq1encdsp.ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
 
     if (!s->m.me.temp || !s->m.me.scratchpad || !s->m.me.map ||
         !s->m.me.score_map || !s->mb_type || !s->dummy) {
@@ -566,9 +616,9 @@  static av_cold int svq1_encode_init(AVCodecContext *avctx)
     }
 
 #if ARCH_PPC
-    ff_svq1enc_init_ppc(s);
+    ff_svq1enc_init_ppc(&s->svq1encdsp);
 #elif ARCH_X86
-    ff_svq1enc_init_x86(s);
+    ff_svq1enc_init_x86(&s->svq1encdsp);
 #endif
 
     ff_h263_encode_init(&s->m); // mv_penalty
diff --git a/libavcodec/svq1enc.h b/libavcodec/svq1enc.h
deleted file mode 100644
index bb6af082d5..0000000000
--- a/libavcodec/svq1enc.h
+++ /dev/null
@@ -1,86 +0,0 @@ 
-/*
- * SVQ1 encoder
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVCODEC_SVQ1ENC_H
-#define AVCODEC_SVQ1ENC_H
-
-#include <stdint.h>
-
-#include "libavutil/frame.h"
-#include "libavutil/mem_internal.h"
-
-#include "avcodec.h"
-#include "hpeldsp.h"
-#include "me_cmp.h"
-#include "mpegvideo.h"
-#include "put_bits.h"
-
-typedef struct SVQ1EncContext {
-    /* FIXME: Needed for motion estimation, should not be used for anything
-     * else, the idea is to make the motion estimation eventually independent
-     * of MpegEncContext, so this will be removed then. */
-    MpegEncContext m;
-    AVCodecContext *avctx;
-    MECmpContext mecc;
-    HpelDSPContext hdsp;
-    AVFrame *current_picture;
-    AVFrame *last_picture;
-    PutBitContext pb;
-
-    /* Some compression statistics */
-    enum AVPictureType pict_type;
-    int quality;
-
-    /* why ooh why this sick breadth first order,
-     * everything is slower and more complex */
-    PutBitContext reorder_pb[6];
-
-    int frame_width;
-    int frame_height;
-
-    /* Y plane block dimensions */
-    int y_block_width;
-    int y_block_height;
-
-    /* U & V plane (C planes) block dimensions */
-    int c_block_width;
-    int c_block_height;
-
-    DECLARE_ALIGNED(16, int16_t, encoded_block_levels)[6][7][256];
-
-    uint16_t *mb_type;
-    uint32_t *dummy;
-    int16_t (*motion_val8[3])[2];
-    int16_t (*motion_val16[3])[2];
-
-    int64_t rd_total;
-
-    uint8_t *scratchbuf;
-
-    int motion_est;
-
-    int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
-                             intptr_t size);
-} SVQ1EncContext;
-
-void ff_svq1enc_init_ppc(SVQ1EncContext *c);
-void ff_svq1enc_init_x86(SVQ1EncContext *c);
-
-#endif /* AVCODEC_SVQ1ENC_H */
diff --git a/libavcodec/svq1encdsp.h b/libavcodec/svq1encdsp.h
new file mode 100644
index 0000000000..91b36735d7
--- /dev/null
+++ b/libavcodec/svq1encdsp.h
@@ -0,0 +1,34 @@ 
+/*
+ * SVQ1 encoder DSP
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_SVQ1ENCDSP_H
+#define AVCODEC_SVQ1ENCDSP_H
+
+#include <stdint.h>
+
+typedef struct SVQ1EncDSPContext {
+    int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
+                             intptr_t size);
+} SVQ1EncDSPContext;
+
+void ff_svq1enc_init_ppc(SVQ1EncDSPContext *c);
+void ff_svq1enc_init_x86(SVQ1EncDSPContext *c);
+
+#endif /* AVCODEC_SVQ1ENCDSP_H */
diff --git a/libavcodec/x86/svq1enc_init.c b/libavcodec/x86/svq1enc_init.c
index 787a5245f3..daf573beba 100644
--- a/libavcodec/x86/svq1enc_init.c
+++ b/libavcodec/x86/svq1enc_init.c
@@ -22,12 +22,12 @@ 
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/svq1enc.h"
+#include "libavcodec/svq1encdsp.h"
 
 int ff_ssd_int8_vs_int16_sse2(const int8_t *pix1, const int16_t *pix2,
                               intptr_t size);
 
-av_cold void ff_svq1enc_init_x86(SVQ1EncContext *c)
+av_cold void ff_svq1enc_init_x86(SVQ1EncDSPContext *c)
 {
     int cpu_flags = av_get_cpu_flags();