[FFmpeg-cvslog] avcodec/aacsbr: Make ff_aac_sbr_* funcs accept ChannelElement*

Andreas Rheinhardt git at videolan.org
Tue Apr 23 09:58:02 EEST 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Mar  1 03:04:21 2024 +0100| [6975d965fcb64e8f68dcbe5be88805e401ee72cd] | committer: Lynne

avcodec/aacsbr: Make ff_aac_sbr_* funcs accept ChannelElement*

Each ChannelElement contains exactly one SpectralBandReplication
structure; the latter structure contains lots of buffers
whose size depend upon USE_FIXED (i.e. AAC_FLOAT arrays).
This complicates deduplicating the parts of the AAC decoder
that are duplicated between the fixed-point and the floating
point decoder.

In order to fix this, the SpectralBandReplication structure
will be moved from the part of ChannelElement visible to
the common code. Therefore the ff_aac_sbr_* functions
are ported to accept a ChannelElement*; they will then have
to translate that to the corresponding SpectralBandReplication*
themselves (which is possible, because there are floating-point
and fixed-point versions of these functions).

While just at it, also ensure that these functions are properly
namespaced.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libavcodec/aacdec.c           |  1 -
 libavcodec/aacdec_fixed.c     |  1 -
 libavcodec/aacdec_template.c  | 10 +++++-----
 libavcodec/aacsbr.h           | 18 +++++++-----------
 libavcodec/aacsbr_template.c  | 17 +++++++++++------
 libavcodec/mips/aacsbr_mips.c |  1 +
 libavcodec/sbr.h              |  2 ++
 7 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 9c1b0cdc1f..25a814d18f 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -50,7 +50,6 @@
 #include "aac/aacdec_tab.h"
 #include "adts_header.h"
 #include "cbrt_data.h"
-#include "sbr.h"
 #include "aacsbr.h"
 #include "mpeg4audio.h"
 #include "profiles.h"
diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
index 681e502e42..055b40b547 100644
--- a/libavcodec/aacdec_fixed.c
+++ b/libavcodec/aacdec_fixed.c
@@ -75,7 +75,6 @@
 #include "aac/aacdec_tab.h"
 #include "adts_header.h"
 #include "cbrt_data.h"
-#include "sbr.h"
 #include "aacsbr.h"
 #include "mpeg4audio.h"
 #include "profiles.h"
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index b2f069f83a..17280a16a1 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -137,7 +137,7 @@ static av_cold int che_configure(AACDecContext *ac,
             int ret;
             if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement))))
                 return AVERROR(ENOMEM);
-            ret = AAC_RENAME(ff_aac_sbr_ctx_init)(ac, &ac->che[type][id]->sbr, type);
+            ret = AAC_RENAME(ff_aac_sbr_ctx_init)(ac, ac->che[type][id], type);
             if (ret < 0)
                 return ret;
         }
@@ -154,7 +154,7 @@ static av_cold int che_configure(AACDecContext *ac,
         }
     } else {
         if (ac->che[type][id])
-            AAC_RENAME(ff_aac_sbr_ctx_close)(&ac->che[type][id]->sbr);
+            AAC_RENAME(ff_aac_sbr_ctx_close)(ac->che[type][id]);
         av_freep(&ac->che[type][id]);
     }
     return 0;
@@ -2461,7 +2461,7 @@ static int decode_extension_payload(AACDecContext *ac, GetBitContext *gb, int cn
             ac->oc[1].m4ac.sbr = 1;
             ac->avctx->profile = AV_PROFILE_AAC_HE;
         }
-        res = AAC_RENAME(ff_decode_sbr_extension)(ac, &che->sbr, gb, crc_flag, cnt, elem_type);
+        res = AAC_RENAME(ff_aac_sbr_decode_extension)(ac, che, gb, crc_flag, cnt, elem_type);
         if (ac->oc[1].m4ac.ps == 1 && !ac->warned_he_aac_mono) {
             av_log(ac->avctx, AV_LOG_VERBOSE, "Treating HE-AAC mono as stereo.\n");
             ac->warned_he_aac_mono = 1;
@@ -2942,7 +2942,7 @@ static void spectral_to_sample(AACDecContext *ac, int samples)
                             ac->update_ltp(ac, &che->ch[1]);
                     }
                     if (ac->oc[1].m4ac.sbr > 0) {
-                        AAC_RENAME(ff_sbr_apply)(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret);
+                        AAC_RENAME(ff_aac_sbr_apply)(ac, che, type, che->ch[0].ret, che->ch[1].ret);
                     }
                 }
                 if (type <= TYPE_CCE)
@@ -3382,7 +3382,7 @@ static av_cold int aac_decode_close(AVCodecContext *avctx)
     for (i = 0; i < MAX_ELEM_ID; i++) {
         for (type = 0; type < 4; type++) {
             if (ac->che[type][i])
-                AAC_RENAME(ff_aac_sbr_ctx_close)(&ac->che[type][i]->sbr);
+                AAC_RENAME(ff_aac_sbr_ctx_close)(ac->che[type][i]);
             av_freep(&ac->che[type][i]);
         }
     }
diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h
index cb680cc548..36289d23f2 100644
--- a/libavcodec/aacsbr.h
+++ b/libavcodec/aacsbr.h
@@ -30,14 +30,12 @@
 #define AVCODEC_AACSBR_H
 
 #include "get_bits.h"
+#include "aacdec.h"
 #include "aac_defines.h"
-#include "sbr.h"
 
 #define ENVELOPE_ADJUSTMENT_OFFSET 2
 #define NOISE_FLOOR_OFFSET 6
 
-struct AACDecContext;
-
 /**
  * SBR VLC tables
  */
@@ -71,16 +69,14 @@ enum {
 /** Initialize SBR. */
 void AAC_RENAME(ff_aac_sbr_init)(void);
 /** Initialize one SBR context. */
-int AAC_RENAME(ff_aac_sbr_ctx_init)(struct AACDecContext *ac, SpectralBandReplication *sbr, int id_aac);
+int AAC_RENAME(ff_aac_sbr_ctx_init)(AACDecContext *ac, ChannelElement *che, int id_aac);
 /** Close one SBR context. */
-void AAC_RENAME(ff_aac_sbr_ctx_close)(SpectralBandReplication *sbr);
+void AAC_RENAME(ff_aac_sbr_ctx_close)(ChannelElement *che);
 /** Decode one SBR element. */
-int AAC_RENAME(ff_decode_sbr_extension)(struct AACDecContext *ac, SpectralBandReplication *sbr,
-                            GetBitContext *gb, int crc, int cnt, int id_aac);
+int AAC_RENAME(ff_aac_sbr_decode_extension)(AACDecContext *ac, ChannelElement *che,
+                                            GetBitContext *gb, int crc, int cnt, int id_aac);
 /** Apply one SBR element to one AAC element. */
-void AAC_RENAME(ff_sbr_apply)(struct AACDecContext *ac, SpectralBandReplication *sbr, int id_aac,
-                  INTFLOAT* L, INTFLOAT *R);
-
-void ff_aacsbr_func_ptr_init_mips(AACSBRContext *c);
+void AAC_RENAME(ff_aac_sbr_apply)(AACDecContext *ac, ChannelElement *che,
+                                  int id_aac, INTFLOAT* L, INTFLOAT* R);
 
 #endif /* AVCODEC_AACSBR_H */
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index f1dfa0da36..9a29fdc66a 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -65,8 +65,9 @@ static void sbr_turnoff(SpectralBandReplication *sbr) {
     memset(&sbr->spectrum_params, -1, sizeof(SpectrumParameters));
 }
 
-av_cold int AAC_RENAME(ff_aac_sbr_ctx_init)(AACDecContext *ac, SpectralBandReplication *sbr, int id_aac)
+av_cold int AAC_RENAME(ff_aac_sbr_ctx_init)(AACDecContext *ac, ChannelElement *che, int id_aac)
 {
+    SpectralBandReplication *sbr = &che->sbr;
     int ret;
     float scale;
 
@@ -103,8 +104,9 @@ av_cold int AAC_RENAME(ff_aac_sbr_ctx_init)(AACDecContext *ac, SpectralBandRepli
     return 0;
 }
 
-av_cold void AAC_RENAME(ff_aac_sbr_ctx_close)(SpectralBandReplication *sbr)
+av_cold void AAC_RENAME(ff_aac_sbr_ctx_close)(ChannelElement *che)
 {
+    SpectralBandReplication *sbr = &che->sbr;
     av_tx_uninit(&sbr->mdct);
     av_tx_uninit(&sbr->mdct_ana);
 }
@@ -1091,9 +1093,11 @@ static void sbr_reset(AACDecContext *ac, SpectralBandReplication *sbr)
  *
  * @return  Returns number of bytes consumed from the TYPE_FIL element.
  */
-int AAC_RENAME(ff_decode_sbr_extension)(AACDecContext *ac, SpectralBandReplication *sbr,
-                            GetBitContext *gb_host, int crc, int cnt, int id_aac)
+int AAC_RENAME(ff_aac_sbr_decode_extension)(AACDecContext *ac, ChannelElement *che,
+                                            GetBitContext *gb_host, int crc,
+                                            int cnt, int id_aac)
 {
+    SpectralBandReplication *sbr = &che->sbr;
     unsigned int num_sbr_bits = 0, num_align_bits;
     unsigned bytes_read;
     GetBitContext gbc = *gb_host, *gb = &gbc;
@@ -1457,9 +1461,10 @@ static void sbr_env_estimate(AAC_FLOAT (*e_curr)[48], INTFLOAT X_high[64][40][2]
     }
 }
 
-void AAC_RENAME(ff_sbr_apply)(AACDecContext *ac, SpectralBandReplication *sbr, int id_aac,
-                  INTFLOAT* L, INTFLOAT* R)
+void AAC_RENAME(ff_aac_sbr_apply)(AACDecContext *ac, ChannelElement *che,
+                                  int id_aac, INTFLOAT* L, INTFLOAT* R)
 {
+    SpectralBandReplication *sbr = &che->sbr;
     int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->sample_rate;
     int ch;
     int nch = (id_aac == TYPE_CPE) ? 2 : 1;
diff --git a/libavcodec/mips/aacsbr_mips.c b/libavcodec/mips/aacsbr_mips.c
index e0715491e6..eea48b360b 100644
--- a/libavcodec/mips/aacsbr_mips.c
+++ b/libavcodec/mips/aacsbr_mips.c
@@ -53,6 +53,7 @@
 
 #include "libavcodec/aacdec.h"
 #include "libavcodec/aacsbr.h"
+#include "libavcodec/sbr.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/mips/asmdefs.h"
 
diff --git a/libavcodec/sbr.h b/libavcodec/sbr.h
index fe3a39603a..d17b52aa4f 100644
--- a/libavcodec/sbr.h
+++ b/libavcodec/sbr.h
@@ -217,4 +217,6 @@ struct SpectralBandReplication {
     AACSBRContext      c;
 };
 
+void ff_aacsbr_func_ptr_init_mips(AACSBRContext *c);
+
 #endif /* AVCODEC_SBR_H */



More information about the ffmpeg-cvslog mailing list