[FFmpeg-devel] [PATCH 11/12] avcodec/aac/aacdec: Move init functions to aacdec_fixed/float
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Mon May 6 15:14:33 EEST 2024
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 avoids a -Wunused-function warning
when either decoder is disabled.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
One could also move the FFCodecs, too. This would necessitate
using external linkage for several decode_frame-related functions
as well as flush and close; but it would allow to make the
fixed/float init function static.
libavcodec/aac/aacdec.c | 31 ++++----------------------
libavcodec/aac/aacdec.h | 11 +++------
libavcodec/aac/aacdec_dsp_template.c | 4 +---
libavcodec/aac/aacdec_fixed.c | 32 +++++++++++++++++----------
libavcodec/aac/aacdec_float.c | 32 +++++++++++++++++----------
libavcodec/aac/aacdec_latm.h | 2 +-
libavcodec/aac/aacdec_proc_template.c | 2 +-
7 files changed, 50 insertions(+), 64 deletions(-)
diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c
index cd80dd1d7a..dc81df174c 100644
--- a/libavcodec/aac/aacdec.c
+++ b/libavcodec/aac/aacdec.c
@@ -1181,13 +1181,10 @@ static av_cold int init_dsp(AVCodecContext *avctx)
if (ret < 0)
return ret;
- ac->dsp = FIXED_OR_FLOAT(is_fixed, aac_dsp, );
- ac->proc = FIXED_OR_FLOAT(is_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;
@@ -1246,26 +1243,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[]) {
diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h
index 4cf764e2e9..775c007aeb 100644
--- a/libavcodec/aac/aacdec.h
+++ b/libavcodec/aac/aacdec.h
@@ -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);
diff --git a/libavcodec/aac/aacdec_dsp_template.c b/libavcodec/aac/aacdec_dsp_template.c
index a42b40f674..70f0a3cce6 100644
--- a/libavcodec/aac/aacdec_dsp_template.c
+++ b/libavcodec/aac/aacdec_dsp_template.c
@@ -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),
diff --git a/libavcodec/aac/aacdec_fixed.c b/libavcodec/aac/aacdec_fixed.c
index 083f3b073e..79d35e05fb 100644
--- a/libavcodec/aac/aacdec_fixed.c
+++ b/libavcodec/aac/aacdec_fixed.c
@@ -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);
+}
diff --git a/libavcodec/aac/aacdec_float.c b/libavcodec/aac/aacdec_float.c
index 5efc0c1e54..d48a21eef2 100644
--- a/libavcodec/aac/aacdec_float.c
+++ b/libavcodec/aac/aacdec_float.c
@@ -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);
+}
diff --git a/libavcodec/aac/aacdec_latm.h b/libavcodec/aac/aacdec_latm.h
index 22153dec83..e40a2fe1a7 100644
--- a/libavcodec/aac/aacdec_latm.h
+++ b/libavcodec/aac/aacdec_latm.h
@@ -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;
diff --git a/libavcodec/aac/aacdec_proc_template.c b/libavcodec/aac/aacdec_proc_template.c
index 319bf61993..1ffea2f93b 100644
--- a/libavcodec/aac/aacdec_proc_template.c
+++ b/libavcodec/aac/aacdec_proc_template.c
@@ -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),
};
--
2.40.1
More information about the ffmpeg-devel
mailing list