aacdec: move fixed/float DSP initialization to templated init functions

This commit is contained in:
Lynne 2024-03-16 06:05:45 +01:00
parent 905fdb0601
commit 2f90d83981
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
6 changed files with 31 additions and 38 deletions

View File

@ -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

View File

@ -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),

View File

@ -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] = {

View File

@ -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[] = {

View File

@ -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);

View File

@ -1088,18 +1088,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;
@ -1121,12 +1114,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,
@ -1164,15 +1155,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);
}
@ -2411,12 +2393,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 */
}