From 4212330a8945bc16cb7e8d2a0f9ce09aeff71111 Mon Sep 17 00:00:00 2001 From: Lynne Date: Thu, 10 Nov 2022 11:26:59 +0100 Subject: [PATCH 08/11] avfft: wrap lavu/tx instead of ff_rdft --- 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) -- 2.40.1