[FFmpeg-cvslog] avfft: wrap lavu/tx instead of ff_rdft

Lynne git at videolan.org
Sat Sep 2 01:00:16 EEST 2023


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Thu Nov 10 11:26:59 2022 +0100| [83ede01bb08239428fd65de62adc260f4233d229] | committer: Lynne

avfft: wrap lavu/tx instead of ff_rdft

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

 libavcodec/avfft.c | 45 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
index 107b510828..9f5d256773 100644
--- a/libavcodec/avfft.c
+++ b/libavcodec/avfft.c
@@ -32,6 +32,8 @@ typedef struct AVTXWrapper {
     av_tx_fn fn2;
 
     ptrdiff_t stride;
+    int len;
+    int inv;
 } AVTXWrapper;
 
 /* FFT */
@@ -129,33 +131,54 @@ av_cold void av_mdct_end(FFTContext *s)
     }
 }
 
-#if CONFIG_RDFT
-
 RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
 {
-    RDFTContext *s = av_malloc(sizeof(*s));
+    int ret;
+    float scale = trans == IDFT_C2R ? 0.5f : 1.0f;
+    AVTXWrapper *s;
 
-    if (s && ff_rdft_init(s, nbits, trans))
-        av_freep(&s);
+    /* The other 2 modes are unconventional, do not form an orthogonal
+     * transform, have never been useful, and so they're not implemented. */
+    if (trans != IDFT_C2R && trans != DFT_R2C)
+        return NULL;
 
-    return s;
+    s = av_malloc(sizeof(*s));
+    if (!s)
+        return NULL;
+
+    ret = av_tx_init(&s->ctx, &s->fn, AV_TX_FLOAT_RDFT, trans == IDFT_C2R,
+                     1 << nbits, &scale, AV_TX_INPLACE);
+    if (ret < 0) {
+        av_free(s);
+        return NULL;
+    }
+
+    s->stride = (trans == DFT_C2R) ? sizeof(float) : sizeof(AVComplexFloat);
+    s->len = 1 << nbits;
+    s->inv = trans == IDFT_C2R;
+
+    return (RDFTContext *)s;
 }
 
 void av_rdft_calc(RDFTContext *s, FFTSample *data)
 {
-    s->rdft_calc(s, data);
+    AVTXWrapper *w = (AVTXWrapper *)s;
+    if (w->inv)
+        FFSWAP(float, data[1], data[w->len]);
+    w->fn(w->ctx, data, (void *)data, w->stride);
+    if (!w->inv)
+        FFSWAP(float, data[1], data[w->len]);
 }
 
 av_cold void av_rdft_end(RDFTContext *s)
 {
     if (s) {
-        ff_rdft_end(s);
-        av_free(s);
+        AVTXWrapper *w = (AVTXWrapper *)s;
+        av_tx_uninit(&w->ctx);
+        av_free(w);
     }
 }
 
-#endif /* CONFIG_RDFT */
-
 #if CONFIG_DCT
 
 DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)



More information about the ffmpeg-cvslog mailing list