diff mbox series

[FFmpeg-devel,28/30] avcodec/mpegaudiodec_float: Avoid indirection with float dsp function

Message ID 20200915074000.102622-28-andreas.rheinhardt@gmail.com
State Accepted
Commit e9831b1e985a61f1f0089eccc877f2e5add2d58c
Headers show
Series [FFmpeg-devel,01/30] avcodec/flashsvenc: Avoid allocation of buffer, fix memleak
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 15, 2020, 7:39 a.m. UTC
Do this by only keeping the only function pointer from the
AVFloatDSPContext that is needed lateron. This also allows to remove the
decoders' close function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/mpegaudiodec_float.c    |  4 ----
 libavcodec/mpegaudiodec_template.c | 30 +++++++++++-------------------
 2 files changed, 11 insertions(+), 23 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mpegaudiodec_float.c b/libavcodec/mpegaudiodec_float.c
index ddfa5e0daa..0defdf3af1 100644
--- a/libavcodec/mpegaudiodec_float.c
+++ b/libavcodec/mpegaudiodec_float.c
@@ -46,7 +46,6 @@  AVCodec ff_mp1float_decoder = {
     .id             = AV_CODEC_ID_MP1,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
-    .close          = decode_close,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
     .flush          = flush,
@@ -64,7 +63,6 @@  AVCodec ff_mp2float_decoder = {
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
     .decode         = decode_frame,
-    .close          = decode_close,
     .capabilities   = AV_CODEC_CAP_DR1,
     .flush          = flush,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
@@ -80,7 +78,6 @@  AVCodec ff_mp3float_decoder = {
     .id             = AV_CODEC_ID_MP3,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
-    .close          = decode_close,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
     .flush          = flush,
@@ -97,7 +94,6 @@  AVCodec ff_mp3adufloat_decoder = {
     .id             = AV_CODEC_ID_MP3ADU,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
-    .close          = decode_close,
     .decode         = decode_frame_adu,
     .capabilities   = AV_CODEC_CAP_DR1,
     .flush          = flush,
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 98759b8e01..d2b72497e1 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -87,7 +87,7 @@  typedef struct MPADecodeContext {
     int err_recognition;
     AVCodecContext* avctx;
     MPADSPContext mpadsp;
-    AVFloatDSPContext *fdsp;
+    void (*butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len);
     AVFrame *frame;
     uint32_t crc;
 } MPADecodeContext;
@@ -410,16 +410,6 @@  static av_cold void decode_init_static(void)
     }
 }
 
-#if USE_FLOATS
-static av_cold int decode_close(AVCodecContext * avctx)
-{
-    MPADecodeContext *s = avctx->priv_data;
-    av_freep(&s->fdsp);
-
-    return 0;
-}
-#endif
-
 static av_cold int decode_init(AVCodecContext * avctx)
 {
     static int initialized_tables = 0;
@@ -433,9 +423,14 @@  static av_cold int decode_init(AVCodecContext * avctx)
     s->avctx = avctx;
 
 #if USE_FLOATS
-    s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
-    if (!s->fdsp)
-        return AVERROR(ENOMEM);
+    {
+        AVFloatDSPContext *fdsp;
+        fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
+        if (!fdsp)
+            return AVERROR(ENOMEM);
+        s->butterflies_float = fdsp->butterflies_float;
+        av_free(fdsp);
+    }
 #endif
 
     ff_mpadsp_init(&s->mpadsp);
@@ -1188,7 +1183,7 @@  found2:
         /* NOTE: the 1/sqrt(2) normalization factor is included in the
            global gain */
 #if USE_FLOATS
-       s->fdsp->butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
+       s->butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
 #else
         tab0 = g0->sb_hybrid;
         tab1 = g1->sb_hybrid;
@@ -1871,9 +1866,6 @@  static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
     MP3On4DecodeContext *s = avctx->priv_data;
     int i;
 
-    if (s->mp3decctx[0])
-        av_freep(&s->mp3decctx[0]->fdsp);
-
     for (i = 0; i < s->frames; i++)
         av_freep(&s->mp3decctx[i]);
 
@@ -1938,7 +1930,7 @@  static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
         s->mp3decctx[i]->adu_mode = 1;
         s->mp3decctx[i]->avctx = avctx;
         s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
-        s->mp3decctx[i]->fdsp = s->mp3decctx[0]->fdsp;
+        s->mp3decctx[i]->butterflies_float = s->mp3decctx[0]->butterflies_float;
     }
 
     return 0;