[FFmpeg-cvslog] dca_core: convert to lavu/tx

Lynne git at videolan.org
Sun Nov 6 15:41:39 EET 2022


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Sun Oct 30 11:14:15 2022 +0100| [e0661fc805a30b7c5cef682f179d113ac1934f9f] | committer: Lynne

dca_core: convert to lavu/tx

Thanks to Martin Storsjö <martin at martin.st> for fixing and testing the
arm32 and aarch64 changes.

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

 libavcodec/aarch64/synth_filter_init.c |  6 +++---
 libavcodec/aarch64/synth_filter_neon.S |  3 ++-
 libavcodec/arm/synth_filter_init_arm.c | 12 ++++++------
 libavcodec/arm/synth_filter_neon.S     |  5 ++++-
 libavcodec/arm/synth_filter_vfp.S      |  5 ++++-
 libavcodec/dca_core.c                  | 23 ++++++++++++++++-------
 libavcodec/dca_core.h                  |  5 +++--
 libavcodec/dcadsp.c                    | 10 ++++++----
 libavcodec/dcadsp.h                    |  5 +++--
 libavcodec/synth_filter.c              | 14 ++++++++------
 libavcodec/synth_filter.h              | 13 +++++++------
 libavcodec/x86/synth_filter_init.c     |  7 ++++---
 tests/checkasm/synth_filter.c          | 25 ++++++++++++++-----------
 13 files changed, 80 insertions(+), 53 deletions(-)

diff --git a/libavcodec/aarch64/synth_filter_init.c b/libavcodec/aarch64/synth_filter_init.c
index 767b01112a..801b46e217 100644
--- a/libavcodec/aarch64/synth_filter_init.c
+++ b/libavcodec/aarch64/synth_filter_init.c
@@ -32,11 +32,11 @@
 AV_CHECK_OFFSET(FFTContext, imdct_half, IMDCT_HALF);
 #endif
 
-void ff_synth_filter_float_neon(FFTContext *imdct,
+void ff_synth_filter_float_neon(AVTXContext *imdct,
                                 float *synth_buf_ptr, int *synth_buf_offset,
                                 float synth_buf2[32], const float window[512],
-                                float out[32], const float in[32],
-                                float scale);
+                                float out[32], float in[32],
+                                float scale, av_tx_fn imdct_fn);
 
 av_cold void ff_synth_filter_init_aarch64(SynthFilterContext *s)
 {
diff --git a/libavcodec/aarch64/synth_filter_neon.S b/libavcodec/aarch64/synth_filter_neon.S
index 4f8494ce30..259fa6e66c 100644
--- a/libavcodec/aarch64/synth_filter_neon.S
+++ b/libavcodec/aarch64/synth_filter_neon.S
@@ -43,8 +43,8 @@
 .endm
 
 function ff_synth_filter_float_neon, export=1
+        mov             x9,  x7                 // imdct_fn parameter
         ldr             w7,  [x2]               // *synth_buf_offset
-        ldr             x9,  [x0, #IMDCT_HALF]  // imdct_half function pointer
         sxtw            x7,  w7
         stp             x3,  x4,  [sp, #-64]!
         add             x1,  x1,  x7,  lsl #2   // synth_buf
@@ -58,6 +58,7 @@ function ff_synth_filter_float_neon, export=1
         str             s0,  [sp, #48]
 
         mov             x2,  x6                 // in
+        mov             x3,  #4                 // sizeof(float)
 
         blr             x9
 
diff --git a/libavcodec/arm/synth_filter_init_arm.c b/libavcodec/arm/synth_filter_init_arm.c
index ea0ce148d4..858c117d39 100644
--- a/libavcodec/arm/synth_filter_init_arm.c
+++ b/libavcodec/arm/synth_filter_init_arm.c
@@ -26,17 +26,17 @@
 #include "libavcodec/fft.h"
 #include "libavcodec/synth_filter.h"
 
-void ff_synth_filter_float_vfp(FFTContext *imdct,
+void ff_synth_filter_float_vfp(AVTXContext *imdct,
                                float *synth_buf_ptr, int *synth_buf_offset,
                                float synth_buf2[32], const float window[512],
-                               float out[32], const float in[32],
-                               float scale);
+                               float out[32], float in[32],
+                               float scale, av_tx_fn imdct_fn);
 
-void ff_synth_filter_float_neon(FFTContext *imdct,
+void ff_synth_filter_float_neon(AVTXContext *imdct,
                                 float *synth_buf_ptr, int *synth_buf_offset,
                                 float synth_buf2[32], const float window[512],
-                                float out[32], const float in[32],
-                                float scale);
+                                float out[32], float in[32],
+                                float scale, av_tx_fn imdct_fn);
 
 av_cold void ff_synth_filter_init_arm(SynthFilterContext *s)
 {
diff --git a/libavcodec/arm/synth_filter_neon.S b/libavcodec/arm/synth_filter_neon.S
index 5417be7d53..17dd5c89ad 100644
--- a/libavcodec/arm/synth_filter_neon.S
+++ b/libavcodec/arm/synth_filter_neon.S
@@ -31,10 +31,13 @@ function ff_synth_filter_float_neon, export=1
         str             r12, [r2]
 
         ldr             r2,  [sp, #12*4]        @ in
+VFP     ldr             r12, [sp, #13*4]        @ imdct_fn
+NOVFP   ldr             r12, [sp, #14*4]        @ imdct_fn
+        mov             r3,  #4                 @ sizeof(float)
         mov             r9,  r1                 @ synth_buf
 
 VFP     vpush           {d0}
-        bl              X(ff_imdct_half_neon)
+        blx             r12
 VFP     vpop            {d0}
         pop             {r3}
 
diff --git a/libavcodec/arm/synth_filter_vfp.S b/libavcodec/arm/synth_filter_vfp.S
index 596734c5bc..4ff69ada4a 100644
--- a/libavcodec/arm/synth_filter_vfp.S
+++ b/libavcodec/arm/synth_filter_vfp.S
@@ -131,8 +131,11 @@ function ff_synth_filter_float_vfp, export=1
         and     lr, lr, #512-32
         str     lr, [P_SB_OFF]            @ rotate offset, modulo buffer size, ready for next call
         ldr     a3, [sp, #(16+6+2)*4]     @ fetch in from stack, to pass to imdct_half
+        mov     a4, #4                    @ sizeof(float)
+VFP     ldr     r12, [sp, #(16+6+3)*4]    @ fetch imdct_fn from stack
+NOVFP   ldr     r12, [sp, #(16+6+4)*4]    @ fetch imdct_fn from stack
 VFP     vmov    s16, SCALE                @ imdct_half is free to corrupt s0, but it contains one of our arguments in hardfp case
-        bl      X(ff_imdct_half_vfp)
+        blx     r12
 VFP     vmov    SCALE, s16
 
         fmrx    OLDFPSCR, FPSCR
diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index c204e41cb7..c50d005a56 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -2235,7 +2235,8 @@ static int filter_frame_float(DCACoreDecoder *s, AVFrame *frame)
         // Filter bank reconstruction
         s->dcadsp->sub_qmf_float[x96_synth](
             &s->synth,
-            &s->imdct[x96_synth],
+            s->imdct[x96_synth],
+            s->imdct_fn[x96_synth],
             output_samples[spkr],
             s->subband_samples[ch],
             ch < x96_nchannels ? s->x96_subband_samples[ch] : NULL,
@@ -2424,16 +2425,24 @@ av_cold void ff_dca_core_flush(DCACoreDecoder *s)
 
 av_cold int ff_dca_core_init(DCACoreDecoder *s)
 {
+    int ret;
+    float scale = 1.0f;
+
     if (!(s->float_dsp = avpriv_float_dsp_alloc(0)))
         return -1;
     if (!(s->fixed_dsp = avpriv_alloc_fixed_dsp(0)))
         return -1;
 
     ff_dcadct_init(&s->dcadct);
-    if (ff_mdct_init(&s->imdct[0], 6, 1, 1.0) < 0)
-        return -1;
-    if (ff_mdct_init(&s->imdct[1], 7, 1, 1.0) < 0)
-        return -1;
+
+    if ((ret = av_tx_init(&s->imdct[0], &s->imdct_fn[0], AV_TX_FLOAT_MDCT,
+                          1, 32, &scale, 0)) < 0)
+        return ret;
+
+    if ((ret = av_tx_init(&s->imdct[1], &s->imdct_fn[1], AV_TX_FLOAT_MDCT,
+                          1, 64, &scale, 0)) < 0)
+        return ret;
+
     ff_synth_filter_init(&s->synth);
 
     s->x96_rand = 1;
@@ -2445,8 +2454,8 @@ av_cold void ff_dca_core_close(DCACoreDecoder *s)
     av_freep(&s->float_dsp);
     av_freep(&s->fixed_dsp);
 
-    ff_mdct_end(&s->imdct[0]);
-    ff_mdct_end(&s->imdct[1]);
+    av_tx_uninit(&s->imdct[0]);
+    av_tx_uninit(&s->imdct[1]);
 
     av_freep(&s->subband_buffer);
     s->subband_size = 0;
diff --git a/libavcodec/dca_core.h b/libavcodec/dca_core.h
index a01d642e77..347566d6ed 100644
--- a/libavcodec/dca_core.h
+++ b/libavcodec/dca_core.h
@@ -24,6 +24,7 @@
 #include "libavutil/float_dsp.h"
 #include "libavutil/fixed_dsp.h"
 #include "libavutil/mem_internal.h"
+#include "libavutil/tx.h"
 
 #include "avcodec.h"
 #include "get_bits.h"
@@ -33,7 +34,6 @@
 #include "dcadct.h"
 #include "dcamath.h"
 #include "dcahuff.h"
-#include "fft.h"
 #include "synth_filter.h"
 
 #define DCA_CHANNELS            7
@@ -190,7 +190,8 @@ typedef struct DCACoreDecoder {
     DCADSPData              dcadsp_data[DCA_CHANNELS];    ///< FIR history buffers
     DCADSPContext           *dcadsp;
     DCADCTContext           dcadct;
-    FFTContext              imdct[2];
+    AVTXContext            *imdct[2];
+    av_tx_fn                imdct_fn[2];
     SynthFilterContext      synth;
     AVFloatDSPContext       *float_dsp;
     AVFixedDSPContext       *fixed_dsp;
diff --git a/libavcodec/dcadsp.c b/libavcodec/dcadsp.c
index d7e0328c88..5ad1f644f2 100644
--- a/libavcodec/dcadsp.c
+++ b/libavcodec/dcadsp.c
@@ -114,7 +114,8 @@ static void lfe_x96_float_c(float *dst, const float *src,
 }
 
 static void sub_qmf32_float_c(SynthFilterContext *synth,
-                              FFTContext *imdct,
+                              AVTXContext *imdct,
+                              av_tx_fn imdct_fn,
                               float *pcm_samples,
                               int32_t **subband_samples_lo,
                               int32_t **subband_samples_hi,
@@ -137,13 +138,14 @@ static void sub_qmf32_float_c(SynthFilterContext *synth,
         // One subband sample generates 32 interpolated ones
         synth->synth_filter_float(imdct, hist1, offset,
                                   hist2, filter_coeff,
-                                  pcm_samples, input, scale);
+                                  pcm_samples, input, scale, imdct_fn);
         pcm_samples += 32;
     }
 }
 
 static void sub_qmf64_float_c(SynthFilterContext *synth,
-                              FFTContext *imdct,
+                              AVTXContext *imdct,
+                              av_tx_fn imdct_fn,
                               float *pcm_samples,
                               int32_t **subband_samples_lo,
                               int32_t **subband_samples_hi,
@@ -186,7 +188,7 @@ static void sub_qmf64_float_c(SynthFilterContext *synth,
         // One subband sample generates 64 interpolated ones
         synth->synth_filter_float_64(imdct, hist1, offset,
                                      hist2, filter_coeff,
-                                     pcm_samples, input, scale);
+                                     pcm_samples, input, scale, imdct_fn);
         pcm_samples += 64;
     }
 }
diff --git a/libavcodec/dcadsp.h b/libavcodec/dcadsp.h
index 8f2f467070..c29755267b 100644
--- a/libavcodec/dcadsp.h
+++ b/libavcodec/dcadsp.h
@@ -22,8 +22,8 @@
 #define AVCODEC_DCADSP_H
 
 #include "libavutil/common.h"
+#include "libavutil/tx.h"
 
-#include "fft.h"
 #include "dcadct.h"
 #include "synth_filter.h"
 
@@ -47,7 +47,8 @@ typedef struct DCADSPContext {
                           float *hist, ptrdiff_t len);
 
     void (*sub_qmf_float[2])(SynthFilterContext *synth,
-                             FFTContext *imdct,
+                             AVTXContext *imdct,
+                             av_tx_fn imdct_fn,
                              float *pcm_samples,
                              int32_t **subband_samples_lo,
                              int32_t **subband_samples_hi,
diff --git a/libavcodec/synth_filter.c b/libavcodec/synth_filter.c
index f30cf360df..d6c4d1bf10 100644
--- a/libavcodec/synth_filter.c
+++ b/libavcodec/synth_filter.c
@@ -24,15 +24,16 @@
 #include "dcamath.h"
 #include "synth_filter.h"
 
-static void synth_filter_float(FFTContext *imdct,
+static void synth_filter_float(AVTXContext *imdct,
                                float *synth_buf_ptr, int *synth_buf_offset,
                                float synth_buf2[32], const float window[512],
-                               float out[32], const float in[32], float scale)
+                               float out[32], float in[32], float scale,
+                               av_tx_fn imdct_fn)
 {
     float *synth_buf = synth_buf_ptr + *synth_buf_offset;
     int i, j;
 
-    imdct->imdct_half(imdct, synth_buf, in);
+    imdct_fn(imdct, synth_buf, in, sizeof(float));
 
     for (i = 0; i < 16; i++) {
         float a = synth_buf2[i     ];
@@ -60,15 +61,16 @@ static void synth_filter_float(FFTContext *imdct,
     *synth_buf_offset = (*synth_buf_offset - 32) & 511;
 }
 
-static void synth_filter_float_64(FFTContext *imdct,
+static void synth_filter_float_64(AVTXContext *imdct,
                                   float *synth_buf_ptr, int *synth_buf_offset,
                                   float synth_buf2[64], const float window[1024],
-                                  float out[64], const float in[64], float scale)
+                                  float out[64], float in[64], float scale,
+                                  av_tx_fn imdct_fn)
 {
     float *synth_buf = synth_buf_ptr + *synth_buf_offset;
     int i, j;
 
-    imdct->imdct_half(imdct, synth_buf, in);
+    imdct_fn(imdct, synth_buf, in, sizeof(float));
 
     for (i = 0; i < 32; i++) {
         float a = synth_buf2[i     ];
diff --git a/libavcodec/synth_filter.h b/libavcodec/synth_filter.h
index df3589a8d5..cf6f2678b7 100644
--- a/libavcodec/synth_filter.h
+++ b/libavcodec/synth_filter.h
@@ -21,19 +21,20 @@
 #ifndef AVCODEC_SYNTH_FILTER_H
 #define AVCODEC_SYNTH_FILTER_H
 
-#include "fft.h"
+#include "libavutil/tx.h"
 #include "dcadct.h"
 
 typedef struct SynthFilterContext {
-    void (*synth_filter_float)(FFTContext *imdct,
+    void (*synth_filter_float)(AVTXContext *imdct,
                                float *synth_buf_ptr, int *synth_buf_offset,
                                float synth_buf2[32], const float window[512],
-                               float out[32], const float in[32],
-                               float scale);
-    void (*synth_filter_float_64)(FFTContext *imdct,
+                               float out[32], float in[32],
+                               float scale, av_tx_fn imdct_fn);
+    void (*synth_filter_float_64)(AVTXContext *imdct,
                                   float *synth_buf_ptr, int *synth_buf_offset,
                                   float synth_buf2[64], const float window[1024],
-                                  float out[64], const float in[64], float scale);
+                                  float out[64], float in[64], float scale,
+                                  av_tx_fn imdct_fn);
     void (*synth_filter_fixed)(DCADCTContext *imdct,
                                int32_t *synth_buf_ptr, int *synth_buf_offset,
                                int32_t synth_buf2[32], const int32_t window[512],
diff --git a/libavcodec/x86/synth_filter_init.c b/libavcodec/x86/synth_filter_init.c
index 7c76ac8d05..e09870b23d 100644
--- a/libavcodec/x86/synth_filter_init.c
+++ b/libavcodec/x86/synth_filter_init.c
@@ -27,14 +27,15 @@
 void ff_synth_filter_inner_##opt(float *synth_buf_ptr, float synth_buf2[32],   \
                                  const float window[512],                      \
                                  float out[32], intptr_t offset, float scale); \
-static void synth_filter_##opt(FFTContext *imdct,                              \
+static void synth_filter_##opt(AVTXContext *imdct,                             \
                                float *synth_buf_ptr, int *synth_buf_offset,    \
                                float synth_buf2[32], const float window[512],  \
-                               float out[32], const float in[32], float scale) \
+                               float out[32], float in[32], float scale,       \
+                               av_tx_fn imdct_fn)                              \
 {                                                                              \
     float *synth_buf= synth_buf_ptr + *synth_buf_offset;                       \
                                                                                \
-    imdct->imdct_half(imdct, synth_buf, in);                                   \
+    imdct_fn(imdct, synth_buf, in, sizeof(float));                             \
                                                                                \
     ff_synth_filter_inner_##opt(synth_buf, synth_buf2, window,                 \
                                 out, *synth_buf_offset, scale);                \
diff --git a/tests/checkasm/synth_filter.c b/tests/checkasm/synth_filter.c
index 9a0d746c96..4744e77aac 100644
--- a/tests/checkasm/synth_filter.c
+++ b/tests/checkasm/synth_filter.c
@@ -26,6 +26,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/mem_internal.h"
+#include "libavutil/tx.h"
 
 #include "libavcodec/dcadata.h"
 #include "libavcodec/synth_filter.h"
@@ -45,10 +46,12 @@
 
 void checkasm_check_synth_filter(void)
 {
-    FFTContext imdct;
+    float scale = 1.0;
+    AVTXContext *imdct;
+    av_tx_fn imdct_fn;
     SynthFilterContext synth;
 
-    ff_mdct_init(&imdct, 6, 1, 1.0);
+    av_tx_init(&imdct, &imdct_fn, AV_TX_FLOAT_MDCT, 0, 16, &scale, 0);
     ff_synth_filter_init(&synth);
 
     if (check_func(synth.synth_filter_float, "synth_filter_float")) {
@@ -65,8 +68,8 @@ void checkasm_check_synth_filter(void)
         float scale = 1.0f;
         int i, offset0 = 0, offset1 = 0, offset_b = 0;
 
-        declare_func(void, FFTContext *, float *, int *, float[32], const float[512],
-                     float[32], float[32], float);
+        declare_func(void, AVTXContext *, float *, int *,
+                     float[32], const float[512], float[32], float[32], float, av_tx_fn);
 
         memset(buf2_0, 0, sizeof(*buf2_0) * BUF_SIZE);
         memset(buf2_1, 0, sizeof(*buf2_1) * BUF_SIZE);
@@ -86,10 +89,10 @@ void checkasm_check_synth_filter(void)
 
             randomize_input();
 
-            call_ref(&imdct, buf0, &offset0, buf2_0, window,
-                     out0, in, scale);
-            call_new(&imdct, buf1, &offset1, buf2_1, window,
-                     out1, in, scale);
+            call_ref(imdct, buf0, &offset0, buf2_0, window,
+                     out0, in, scale, imdct_fn);
+            call_new(imdct, buf1, &offset1, buf2_1, window,
+                     out1, in, scale, imdct_fn);
 
             if (offset0 != offset1) {
                 fail();
@@ -113,11 +116,11 @@ void checkasm_check_synth_filter(void)
                 }
             }
 
-            bench_new(&imdct, buf_b, &offset_b, buf2_b, window,
-                      out_b, in, scale);
+            bench_new(imdct, buf_b, &offset_b, buf2_b, window,
+                      out_b, in, scale, imdct_fn);
         }
     }
-    ff_mdct_end(&imdct);
+    av_tx_uninit(&imdct);
 
     report("synth_filter");
 }



More information about the ffmpeg-cvslog mailing list