From 28557d01c7ca42abc2fc18edf704bd7af945ae7e Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 1 Mar 2024 03:04:21 +0100 Subject: [PATCH 02/38] 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 --- 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 0a9ff1bfaf..6907d348f8 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -49,7 +49,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 aa856d7fe1..3d64c376d4 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -136,7 +136,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; } @@ -153,7 +153,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; @@ -2460,7 +2460,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; @@ -2941,7 +2941,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) @@ -3381,7 +3381,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 eadd6fa2d3..fe9bf982b2 100644 --- a/libavcodec/aacsbr_template.c +++ b/libavcodec/aacsbr_template.c @@ -64,8 +64,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; @@ -102,8 +103,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); } @@ -1090,9 +1092,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; @@ -1456,9 +1460,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 */ -- 2.43.0.381.gb435a96ce8