avcodec/aac/aacdec: Move init functions to aacdec_fixed/float

This allows to merge it with AACDecDSP.init and remove the latter
(it is called only once anyway); it also allows to make
the fixed/float AACDecDSP and AACDecProc implementations internal
to aacdec_fixed/float.c (which also fixes a violation of our
naming conventions). And it some linker errors when either decoder
is disabled.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-05-06 13:28:19 +02:00
parent 0fc3d8e4d6
commit 8762aa4d62
7 changed files with 50 additions and 64 deletions

View File

@ -1174,13 +1174,10 @@ static av_cold int init_dsp(AVCodecContext *avctx)
if (ret < 0)
return ret;
ac->dsp = is_fixed ? aac_dsp_fixed : aac_dsp;
ac->proc = is_fixed ? aac_proc_fixed : aac_proc;
return ac->dsp.init(ac);
return 0;
}
static av_cold int aac_decode_init_internal(AVCodecContext *avctx)
av_cold int ff_aac_decode_init(AVCodecContext *avctx)
{
AACDecContext *ac = avctx->priv_data;
int ret;
@ -1239,26 +1236,6 @@ static av_cold int aac_decode_init_internal(AVCodecContext *avctx)
return init_dsp(avctx);
}
static av_cold int aac_decode_init(AVCodecContext *avctx)
{
AACDecContext *ac = avctx->priv_data;
ac->is_fixed = 0;
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
return aac_decode_init_internal(avctx);
}
static av_cold int aac_decode_init_fixed(AVCodecContext *avctx)
{
AACDecContext *ac = avctx->priv_data;
ac->is_fixed = 1;
avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
return aac_decode_init_internal(avctx);
}
/**
* Skip data_stream_element; reference: table 4.10.
*/
@ -2555,7 +2532,7 @@ const FFCodec ff_aac_decoder = {
.p.id = AV_CODEC_ID_AAC,
.p.priv_class = &decoder_class,
.priv_data_size = sizeof(AACDecContext),
.init = aac_decode_init,
.init = ff_aac_decode_init_float,
.close = decode_close,
FF_CODEC_DECODE_CB(aac_decode_frame),
.p.sample_fmts = (const enum AVSampleFormat[]) {
@ -2577,7 +2554,7 @@ const FFCodec ff_aac_fixed_decoder = {
.p.id = AV_CODEC_ID_AAC,
.p.priv_class = &decoder_class,
.priv_data_size = sizeof(AACDecContext),
.init = aac_decode_init_fixed,
.init = ff_aac_decode_init_fixed,
.close = decode_close,
FF_CODEC_DECODE_CB(aac_decode_frame),
.p.sample_fmts = (const enum AVSampleFormat[]) {

View File

@ -216,8 +216,6 @@ typedef struct AACDecProc {
* DSP-specific primitives
*/
typedef struct AACDecDSP {
int (*init)(AACDecContext *ac);
void (*dequant_scalefactors)(SingleChannelElement *sce);
void (*apply_mid_side_stereo)(AACDecContext *ac, ChannelElement *cpe);
@ -339,12 +337,9 @@ struct AACDecContext {
#define fdsp RENAME_FIXED(fdsp)
#endif
extern const AACDecDSP aac_dsp;
extern const AACDecDSP aac_dsp_fixed;
extern const AACDecProc aac_proc;
extern const AACDecProc aac_proc_fixed;
int ff_aac_decode_init(struct AVCodecContext *avctx);
int ff_aac_decode_init_float(struct AVCodecContext *avctx);
int ff_aac_decode_init_fixed(struct AVCodecContext *avctx);
int ff_aac_decode_ics(AACDecContext *ac, SingleChannelElement *sce,
GetBitContext *gb, int common_window, int scale_flag);

View File

@ -615,9 +615,7 @@ static void AAC_RENAME(apply_prediction)(AACDecContext *ac, SingleChannelElement
reset_all_predictors(sce->AAC_RENAME(predictor_state));
}
const AACDecDSP AAC_RENAME(aac_dsp) = {
.init = &AAC_RENAME(init),
static const AACDecDSP AAC_RENAME(aac_dsp) = {
.dequant_scalefactors = &AAC_RENAME(dequant_scalefactors),
.apply_mid_side_stereo = &AAC_RENAME(apply_mid_side_stereo),
.apply_intensity_stereo = &AAC_RENAME(apply_intensity_stereo),

View File

@ -63,18 +63,6 @@ static void init_tables_fixed_fn(void)
init_sine_windows_fixed();
}
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] = {
Q30(1.0), //2^(0/8)
Q30(1.0905077327), //2^(1/8)
@ -93,3 +81,23 @@ static const int cce_scale_fixed[8] = {
#include "aacdec_fixed_prediction.h"
#include "aacdec_dsp_template.c"
#include "aacdec_proc_template.c"
av_cold int ff_aac_decode_init_fixed(AVCodecContext *avctx)
{
static AVOnce init_fixed_once = AV_ONCE_INIT;
AACDecContext *ac = avctx->priv_data;
ac->is_fixed = 1;
avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
ac->dsp = aac_dsp_fixed;
ac->proc = aac_proc_fixed;
ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT);
if (!ac->fdsp)
return AVERROR(ENOMEM);
ff_thread_once(&init_fixed_once, init_tables_fixed_fn);
return ff_aac_decode_init(avctx);
}

View File

@ -68,18 +68,6 @@ static void init_tables_float_fn(void)
ff_aac_float_common_init();
}
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);
return 0;
}
static const float cce_scale[] = {
1.09050773266525765921, //2^(1/8)
1.18920711500272106672, //2^(1/4)
@ -163,3 +151,23 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx,
#include "aacdec_float_prediction.h"
#include "aacdec_dsp_template.c"
#include "aacdec_proc_template.c"
av_cold int ff_aac_decode_init_float(AVCodecContext *avctx)
{
static AVOnce init_float_once = AV_ONCE_INIT;
AACDecContext *ac = avctx->priv_data;
ac->is_fixed = 0;
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
ac->dsp = aac_dsp;
ac->proc = aac_proc;
ac->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
if (!ac->fdsp)
return AVERROR(ENOMEM);
ff_thread_once(&init_float_once, init_tables_float_fn);
return ff_aac_decode_init(avctx);
}

View File

@ -315,7 +315,7 @@ static int latm_decode_frame(AVCodecContext *avctx, AVFrame *out,
static av_cold int latm_decode_init(AVCodecContext *avctx)
{
struct LATMContext *latmctx = avctx->priv_data;
int ret = aac_decode_init(avctx);
int ret = ff_aac_decode_init_float(avctx);
if (avctx->extradata_size > 0)
latmctx->initialized = !ret;

View File

@ -433,7 +433,7 @@ static int AAC_RENAME(decode_cce)(AACDecContext *ac, GetBitContext *gb, ChannelE
return 0;
}
const AACDecProc AAC_RENAME(aac_proc) = {
static const AACDecProc AAC_RENAME(aac_proc) = {
.decode_spectrum_and_dequant = AAC_RENAME(decode_spectrum_and_dequant),
.decode_cce = AAC_RENAME(decode_cce),
};