diff mbox series

[FFmpeg-devel] vorbisdec: convert to lavu/tx

Message ID NFXRlzW--3-9@lynne.ee
State New
Headers show
Series [FFmpeg-devel] vorbisdec: convert to lavu/tx | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Lynne Oct. 29, 2022, 6:34 a.m. UTC
This also fixes not checking the return values on transform init.

Total decoder speedup on Zen 3: 9%

Patch attached.
diff mbox series

Patch

From efe3006093cd80182b293f01aa98fb75733a8188 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Sat, 29 Oct 2022 08:30:56 +0200
Subject: [PATCH] vorbisdec: convert to lavu/tx

This also fixes not checking the return values on transform init.

Total decoder speedup on Zen 3: 9%
---
 libavcodec/vorbisdec.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 715a7f7d03..dd856a6dfe 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -31,12 +31,12 @@ 
 
 #include "libavutil/avassert.h"
 #include "libavutil/float_dsp.h"
+#include "libavutil/tx.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
 #include "codec_internal.h"
 #include "decode.h"
-#include "fft.h"
 #include "get_bits.h"
 #include "vorbis.h"
 #include "vorbisdsp.h"
@@ -130,7 +130,9 @@  typedef struct vorbis_context_s {
     VorbisDSPContext dsp;
     AVFloatDSPContext *fdsp;
 
-    FFTContext mdct[2];
+    AVTXContext  *mdct[2];
+    av_tx_fn      mdct_fn[2];
+
     uint8_t       first_frame;
     int64_t       initial_pts;
     uint32_t      version;
@@ -202,8 +204,8 @@  static void vorbis_free(vorbis_context *vc)
     av_freep(&vc->residues);
     av_freep(&vc->modes);
 
-    ff_mdct_end(&vc->mdct[0]);
-    ff_mdct_end(&vc->mdct[1]);
+    av_tx_uninit(&vc->mdct[0]);
+    av_tx_uninit(&vc->mdct[1]);
 
     if (vc->codebooks)
         for (i = 0; i < vc->codebook_count; ++i) {
@@ -964,6 +966,8 @@  static int vorbis_parse_id_hdr(vorbis_context *vc)
 {
     GetBitContext *gb = &vc->gb;
     unsigned bl0, bl1;
+    float scale = -1.0;
+    int ret;
 
     if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
         (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
@@ -1009,8 +1013,16 @@  static int vorbis_parse_id_hdr(vorbis_context *vc)
 
     vc->previous_window  = -1;
 
-    ff_mdct_init(&vc->mdct[0], bl0, 1, -1.0);
-    ff_mdct_init(&vc->mdct[1], bl1, 1, -1.0);
+    ret = av_tx_init(&vc->mdct[0], &vc->mdct_fn[0], AV_TX_FLOAT_MDCT, 1,
+                     vc->blocksize[0] >> 1, &scale, 0);
+    if (ret < 0)
+        return ret;
+
+    ret = av_tx_init(&vc->mdct[1], &vc->mdct_fn[1], AV_TX_FLOAT_MDCT, 1,
+                     vc->blocksize[1] >> 1, &scale, 0);
+    if (ret < 0)
+        return ret;
+
     vc->fdsp = avpriv_float_dsp_alloc(vc->avctx->flags & AV_CODEC_FLAG_BITEXACT);
     if (!vc->fdsp)
         return AVERROR(ENOMEM);
@@ -1585,7 +1597,8 @@  static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr,
 static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
 {
     GetBitContext *gb = &vc->gb;
-    FFTContext *mdct;
+    AVTXContext *mdct;
+    av_tx_fn mdct_fn;
     int previous_window = vc->previous_window;
     unsigned mode_number, blockflag, blocksize;
     int i, j;
@@ -1707,12 +1720,13 @@  static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
 
 // Dotproduct, MDCT
 
-    mdct = &vc->mdct[blockflag];
+    mdct = vc->mdct[blockflag];
+    mdct_fn = vc->mdct_fn[blockflag];
 
     for (j = vc->audio_channels-1;j >= 0; j--) {
         ch_res_ptr   = vc->channel_residues + res_chan[j] * blocksize / 2;
         vc->fdsp->vector_fmul(floor_ptr[j], floor_ptr[j], ch_res_ptr, blocksize / 2);
-        mdct->imdct_half(mdct, ch_res_ptr, floor_ptr[j]);
+        mdct_fn(mdct, ch_res_ptr, floor_ptr[j], sizeof(float));
     }
 
 // Overlap/add, save data for next overlapping
-- 
2.37.2.609.g9ff673ca1a