From 8f232c307727e915d12531736cf959a3abcc445c Mon Sep 17 00:00:00 2001 From: Lynne Date: Sat, 16 Mar 2024 06:05:45 +0100 Subject: [PATCH 30/38] aacdec: move fixed/float DSP initialization to templated init functions --- libavcodec/aac/aacdec.c | 4 +--- libavcodec/aac/aacdec_dsp_template.c | 2 +- libavcodec/aac/aacdec_fixed.c | 10 +++++++- libavcodec/aac/aacdec_float.c | 16 ++++++++++++- libavcodec/aacdec.h | 2 +- libavcodec/aacdec_template.c | 35 ++++------------------------ 6 files changed, 31 insertions(+), 38 deletions(-) diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c index d31c64d08d..3af0e808fd 100644 --- a/libavcodec/aac/aacdec.c +++ b/libavcodec/aac/aacdec.c @@ -124,9 +124,7 @@ av_cold int ff_aac_decode_init_common(AVCodecContext *avctx) ac->dsp = is_fixed ? aac_dsp_fixed : aac_dsp; ac->proc = is_fixed ? aac_proc_fixed : aac_proc; - ac->dsp.init_tables(); - - return 0; + return ac->dsp.init(ac); } #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM diff --git a/libavcodec/aac/aacdec_dsp_template.c b/libavcodec/aac/aacdec_dsp_template.c index 338e512ed2..f260d32e4a 100644 --- a/libavcodec/aac/aacdec_dsp_template.c +++ b/libavcodec/aac/aacdec_dsp_template.c @@ -616,7 +616,7 @@ static void AAC_RENAME(apply_prediction)(AACDecContext *ac, SingleChannelElement } const AACDecDSP AAC_RENAME(aac_dsp) = { - .init_tables = &AAC_RENAME(init_tables), + .init = &AAC_RENAME(init), .dequant_scalefactors = &AAC_RENAME(dequant_scalefactors), .apply_mid_side_stereo = &AAC_RENAME(apply_mid_side_stereo), diff --git a/libavcodec/aac/aacdec_fixed.c b/libavcodec/aac/aacdec_fixed.c index 41f25d8148..d706cfcc92 100644 --- a/libavcodec/aac/aacdec_fixed.c +++ b/libavcodec/aac/aacdec_fixed.c @@ -35,6 +35,8 @@ #include "libavcodec/aac_defines.h" +#include "libavcodec/avcodec.h" +#include "libavcodec/aacdec.h" #include "libavcodec/aactab.h" #include "libavcodec/sinewin_fixed_tablegen.h" #include "libavcodec/kbdwin.h" @@ -58,10 +60,16 @@ static void init_tables_fixed_fn(void) init_sine_windows_fixed(); } -static void init_tables_fixed(void) +static int init_fixed(AACDecContext *ac) { static AVOnce init_fixed_once = AV_ONCE_INIT; ff_thread_once(&init_fixed_once, init_tables_fixed_fn); + + ac->fdsp = avpriv_alloc_fixed_dsp(ac->avctx->flags & AV_CODEC_FLAG_BITEXACT); + if (!ac->fdsp) + return AVERROR(ENOMEM); + + return 0; } static const int cce_scale_fixed[8] = { diff --git a/libavcodec/aac/aacdec_float.c b/libavcodec/aac/aacdec_float.c index 73aaa72f68..6801085098 100644 --- a/libavcodec/aac/aacdec_float.c +++ b/libavcodec/aac/aacdec_float.c @@ -35,6 +35,8 @@ #include "libavcodec/aac_defines.h" +#include "libavcodec/avcodec.h" +#include "libavcodec/aacdec.h" #include "libavcodec/aactab.h" #include "libavcodec/sinewin.h" #include "libavcodec/kbdwin.h" @@ -61,10 +63,22 @@ static void init_tables_float_fn(void) AAC_RENAME(ff_init_ff_sine_windows)(9); } -static void init_tables(void) +static int init(AACDecContext *ac) { static AVOnce init_float_once = AV_ONCE_INIT; ff_thread_once(&init_float_once, init_tables_float_fn); + + ac->fdsp = avpriv_float_dsp_alloc(ac->avctx->flags & AV_CODEC_FLAG_BITEXACT); + if (!ac->fdsp) + return AVERROR(ENOMEM); + + ff_aac_float_common_init(); + +#if ARCH_MIPS + ff_aacdec_init_mips(ac); +#endif + + return 0; } static const float cce_scale[] = { diff --git a/libavcodec/aacdec.h b/libavcodec/aacdec.h index 2a997823ee..2e3ee961b0 100644 --- a/libavcodec/aacdec.h +++ b/libavcodec/aacdec.h @@ -216,7 +216,7 @@ typedef struct AACDecProc { * DSP-specific primitives */ typedef struct AACDecDSP { - void (*init_tables)(void); + int (*init)(AACDecContext *ac); void (*dequant_scalefactors)(SingleChannelElement *sce); diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 6894de7325..76bc28e3d5 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1087,18 +1087,11 @@ static int sample_rate_idx (int rate) else return 11; } -static void aacdec_init(AACDecContext *ac); - static av_cold void aac_static_table_init(void) { AAC_RENAME(ff_aac_sbr_init)(); ff_aacdec_common_init_once(); - -#if !USE_FIXED - ff_aac_float_common_init(); -#else -#endif } static AVOnce aac_table_init = AV_ONCE_INIT; @@ -1120,12 +1113,10 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ac->avctx = avctx; ac->oc[1].m4ac.sample_rate = avctx->sample_rate; - aacdec_init(ac); -#if USE_FIXED - avctx->sample_fmt = AV_SAMPLE_FMT_S32P; -#else - avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; -#endif /* USE_FIXED */ + if (ac->is_fixed) + avctx->sample_fmt = AV_SAMPLE_FMT_S32P; + else + avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; if (avctx->extradata_size > 0) { if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac, @@ -1163,15 +1154,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) } } -#if USE_FIXED - ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT); -#else - ac->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); -#endif /* USE_FIXED */ - if (!ac->fdsp) { - return AVERROR(ENOMEM); - } - return ff_aac_decode_init_common(avctx); } @@ -2410,12 +2392,3 @@ static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, return buf_size > buf_offset ? buf_consumed : buf_size; } - -static void aacdec_init(AACDecContext *c) -{ -#if !USE_FIXED -#if ARCH_MIPS - ff_aacdec_init_mips(c); -#endif -#endif /* !USE_FIXED */ -} -- 2.43.0.381.gb435a96ce8