From 68781f3bc021fe96c4b4b4a355e03d7c5bd3539b Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Thu, 10 Nov 2022 11:26:59 +0100
Subject: [PATCH 3/3] avfft: wrap lavu/tx instead of ff_rdft
---
libavcodec/avfft.c | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
@@ -125,33 +125,44 @@ av_cold void av_mdct_end(FFTContext *s)
av_fft_end(s);
}
-#if CONFIG_RDFT
-
RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
{
- RDFTContext *s = av_malloc(sizeof(*s));
+ int ret;
+ float scale = 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);
+
+ return (RDFTContext *)s;
}
void av_rdft_calc(RDFTContext *s, FFTSample *data)
{
- s->rdft_calc(s, data);
+ AVTXWrapper *w = (AVTXWrapper *)s;
+ w->fn(w->ctx, data, (void *)data, w->stride);
}
av_cold void av_rdft_end(RDFTContext *s)
{
- if (s) {
- ff_rdft_end(s);
- av_free(s);
- }
+ av_fft_end((FFTContext *)s);
}
-#endif /* CONFIG_RDFT */
-
#if CONFIG_DCT
DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
--
2.40.1