diff mbox series

[FFmpeg-devel,v3] avcodec/aac/aacdec: Fix linking errors with only one decoder enabled

Message ID GV1P250MB0737A29C0776175536E98E1D8F1C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Headers show
Series [FFmpeg-devel,v3] avcodec/aac/aacdec: Fix linking errors with only one decoder enabled | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt May 6, 2024, 10:37 p.m. UTC
This is achieved by using function pointers for AAC SBR functions.
This unfortunately necessitated to use void* in
ff_aac_sbr_apply(_fixed).
Fixes ticket #10999.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/aac/aacdec.c               | 35 ++++++---------------------
 libavcodec/aac/aacdec.h               |  7 ++++++
 libavcodec/aac/aacdec_proc_template.c |  6 +++++
 libavcodec/aacsbr.h                   |  4 +--
 libavcodec/aacsbr_template.c          |  3 ++-
 5 files changed, 25 insertions(+), 30 deletions(-)

Comments

Lynne May 6, 2024, 10:47 p.m. UTC | #1
May 7, 2024, 00:38 by andreas.rheinhardt@outlook.com:

> This is achieved by using function pointers for AAC SBR functions.
> This unfortunately necessitated to use void* in
> ff_aac_sbr_apply(_fixed).
> Fixes ticket #10999.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/aac/aacdec.c               | 35 ++++++---------------------
> libavcodec/aac/aacdec.h               |  7 ++++++
> libavcodec/aac/aacdec_proc_template.c |  6 +++++
> libavcodec/aacsbr.h                   |  4 +--
> libavcodec/aacsbr_template.c          |  3 ++-
> 5 files changed, 25 insertions(+), 30 deletions(-)
>

Very nice, thanks
This sets us up to detemplate SBR too in the future.
LGTM
diff mbox series

Patch

diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c
index 4206ad1b5d..7457fe6c97 100644
--- a/libavcodec/aac/aacdec.c
+++ b/libavcodec/aac/aacdec.c
@@ -149,11 +149,7 @@  static av_cold int che_configure(AACDecContext *ac,
         return AVERROR_INVALIDDATA;
     if (che_pos) {
         if (!ac->che[type][id]) {
-            int ret;
-            if (ac->is_fixed)
-                ret = ff_aac_sbr_ctx_alloc_init_fixed(ac, &ac->che[type][id], type);
-            else
-                ret = ff_aac_sbr_ctx_alloc_init(ac, &ac->che[type][id], type);
+            int ret = ac->proc.sbr_ctx_alloc_init(ac, &ac->che[type][id], type);
             if (ret < 0)
                 return ret;
         }
@@ -170,10 +166,7 @@  static av_cold int che_configure(AACDecContext *ac,
         }
     } else {
         if (ac->che[type][id]) {
-            if (ac->is_fixed)
-                ff_aac_sbr_ctx_close_fixed(ac->che[type][id]);
-            else
-                ff_aac_sbr_ctx_close(ac->che[type][id]);
+            ac->proc.sbr_ctx_close(ac->che[type][id]);
         }
         av_freep(&ac->che[type][id]);
     }
@@ -1114,14 +1107,11 @@  static int sample_rate_idx (int rate)
 static av_cold int decode_close(AVCodecContext *avctx)
 {
     AACDecContext *ac = avctx->priv_data;
-    int is_fixed = ac->is_fixed;
-    void (*sbr_close)(ChannelElement *che) = is_fixed ? ff_aac_sbr_ctx_close_fixed :
-                                                        ff_aac_sbr_ctx_close;
 
     for (int type = 0; type < FF_ARRAY_ELEMS(ac->che); type++) {
         for (int i = 0; i < MAX_ELEM_ID; i++) {
             if (ac->che[type][i]) {
-                sbr_close(ac->che[type][i]);
+                ac->proc.sbr_ctx_close(ac->che[type][i]);
                 av_freep(&ac->che[type][i]);
             }
         }
@@ -1136,7 +1126,7 @@  static av_cold int decode_close(AVCodecContext *avctx)
     av_tx_uninit(&ac->mdct_ltp);
 
     // Compiler will optimize this branch away.
-    if (is_fixed)
+    if (ac->is_fixed)
         av_freep(&ac->RENAME_FIXED(fdsp));
     else
         av_freep(&ac->fdsp);
@@ -1946,11 +1936,7 @@  static int decode_extension_payload(AACDecContext *ac, GetBitContext *gb, int cn
             ac->avctx->profile = AV_PROFILE_AAC_HE;
         }
 
-        if (CONFIG_AAC_FIXED_DECODER && ac->is_fixed)
-            res = ff_aac_sbr_decode_extension_fixed(ac, che, gb, crc_flag, cnt, elem_type);
-        else if (CONFIG_AAC_DECODER)
-            res = ff_aac_sbr_decode_extension(ac, che, gb, crc_flag, cnt, elem_type);
-
+        ac->proc.sbr_decode_extension(ac, che, gb, crc_flag, cnt, elem_type);
 
         if (ac->oc[1].m4ac.ps == 1 && !ac->warned_he_aac_mono) {
             av_log(ac->avctx, AV_LOG_VERBOSE, "Treating HE-AAC mono as stereo.\n");
@@ -2059,14 +2045,9 @@  static void spectral_to_sample(AACDecContext *ac, int samples)
                             ac->dsp.update_ltp(ac, &che->ch[1]);
                     }
                     if (ac->oc[1].m4ac.sbr > 0) {
-                        if (CONFIG_AAC_FIXED_DECODER && ac->is_fixed)
-                            ff_aac_sbr_apply_fixed(ac, che, type,
-                                                   (void *)che->ch[0].output,
-                                                   (void *)che->ch[1].output);
-                        else if (CONFIG_AAC_DECODER)
-                            ff_aac_sbr_apply(ac, che, type,
-                                             (void *)che->ch[0].output,
-                                             (void *)che->ch[1].output);
+                        ac->proc.sbr_apply(ac, che, type,
+                                           che->ch[0].output,
+                                           che->ch[1].output);
                     }
                 }
                 if (type <= TYPE_CCE)
diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h
index 775c007aeb..eed53c6c96 100644
--- a/libavcodec/aac/aacdec.h
+++ b/libavcodec/aac/aacdec.h
@@ -210,6 +210,13 @@  typedef struct AACDecProc {
                                        SingleChannelElement *sce);
 
     int (*decode_cce)(AACDecContext *ac, GetBitContext *gb, ChannelElement *che);
+
+    int (*sbr_ctx_alloc_init)(AACDecContext *ac, ChannelElement **che, int id_aac);
+    int (*sbr_decode_extension)(AACDecContext *ac, ChannelElement *che,
+                                GetBitContext *gb, int crc, int cnt, int id_aac);
+    void (*sbr_apply)(AACDecContext *ac, ChannelElement *che,
+                      int id_aac, void /* INTFLOAT */ *L, void /* INTFLOAT */ *R);
+    void (*sbr_ctx_close)(ChannelElement *che);
 } AACDecProc;
 
 /**
diff --git a/libavcodec/aac/aacdec_proc_template.c b/libavcodec/aac/aacdec_proc_template.c
index fecf228b3b..327f3117b5 100644
--- a/libavcodec/aac/aacdec_proc_template.c
+++ b/libavcodec/aac/aacdec_proc_template.c
@@ -439,4 +439,10 @@  static av_cold void AAC_RENAME(aac_proc_init)(AACDecProc *aac_proc)
     SET(decode_spectrum_and_dequant);
     SET(decode_cce);
 #undef SET
+#define SET(member) aac_proc->member = AV_JOIN(ff_aac_, AAC_RENAME(member));
+    SET(sbr_ctx_alloc_init);
+    SET(sbr_decode_extension);
+    SET(sbr_apply);
+    SET(sbr_ctx_close);
+#undef SET
 }
diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h
index 656ef5258e..ee31e2fcde 100644
--- a/libavcodec/aacsbr.h
+++ b/libavcodec/aacsbr.h
@@ -90,9 +90,9 @@  int ff_aac_sbr_decode_extension_fixed(AACDecContext *ac, ChannelElement *che,
 
 /** Apply one SBR element to one AAC element. */
 void ff_aac_sbr_apply(AACDecContext *ac, ChannelElement *che,
-                      int id_aac, float *L, float *R);
+                      int id_aac, void *L, void *R);
 void ff_aac_sbr_apply_fixed(AACDecContext *ac, ChannelElement *che,
-                            int id_aac, int *L, int *R);
+                            int id_aac, void *L, void *R);
 
 FF_VISIBILITY_POP_HIDDEN
 
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index a6e3bc54bd..86f4d8c26e 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -1469,8 +1469,9 @@  static void sbr_env_estimate(AAC_FLOAT (*e_curr)[48], INTFLOAT X_high[64][40][2]
 }
 
 void AAC_RENAME(ff_aac_sbr_apply)(AACDecContext *ac, ChannelElement *che,
-                                  int id_aac, INTFLOAT* L, INTFLOAT* R)
+                                  int id_aac, void *L_, void *R_)
 {
+    INTFLOAT *L = L_, *R = R_;
     SpectralBandReplication *sbr = get_sbr(che);
     int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->sample_rate;
     int ch;