Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 11/12] avcodec/aac/aacdec: Move init functions to aacdec_fixed/float
Date: Mon,  6 May 2024 14:14:33 +0200
Message-ID: <GV1P250MB07374054229B903CD47B3B248F1C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <GV1P250MB0737A4218AC17DD0A60E579C8F1C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2024-05-06 12:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06  9:29 [FFmpeg-devel] [PATCH 1/3] avcodec/aactab: Provide ff_ltp_coef, ff_tns_tmp2_map unconditionally Andreas Rheinhardt
2024-05-06  9:30 ` [FFmpeg-devel] [PATCH 2/3] avcodec/aacsbr: Fix type mismatch Andreas Rheinhardt
2024-05-06 17:54   ` Lynne
2024-05-06  9:30 ` [FFmpeg-devel] [PATCH 3/3] avcodec/aac/aacdec: Fix linking errors with only one decoder enabled Andreas Rheinhardt
2024-05-06 14:03   ` [FFmpeg-devel] [PATCH v2 3/12] " Andreas Rheinhardt
2024-05-06 17:53   ` [FFmpeg-devel] [PATCH 3/3] " Lynne
2024-05-06 19:39     ` Andreas Rheinhardt
2024-05-06 20:00       ` Lynne
2024-05-06 20:08         ` Andreas Rheinhardt
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 04/12] avcodec/aac/aacdec: Remove unnecessary ff_thread_once() Andreas Rheinhardt
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 05/12] avcodec/aac/aacdec: Move channel number check out of init_dsp() Andreas Rheinhardt
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 06/12] avcodec/aac/aacdec: Avoid branch to set sample_fmt Andreas Rheinhardt
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 07/12] avcodec/aac/aacdec_float: Call ff_aac_float_common_init() only once Andreas Rheinhardt
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 08/12] avcodec/aac/aacdec_(fixed|float): Avoid AAC_RENAME, INTFLOAT Andreas Rheinhardt
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 09/12] avcodec/aac/aacdec: Mark flush as cold Andreas Rheinhardt
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 10/12] avcodec/aac/aacdec: Avoid compiling latm decoder if disabled Andreas Rheinhardt
2024-05-06 12:14 ` Andreas Rheinhardt [this message]
2024-05-06 12:14 ` [FFmpeg-devel] [PATCH 12/12] avcodec/aac/aacdec_(fixed|float): Set AACDecDSP, AACDecProc directly Andreas Rheinhardt
2024-05-06 17:59   ` Lynne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GV1P250MB07374054229B903CD47B3B248F1C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git