[FFmpeg-cvslog] avcodec/aacdec: PredictorState array out of SingleChannelElement

Andreas Rheinhardt git at videolan.org
Tue Apr 23 09:58:08 EEST 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Feb 29 22:12:48 2024 +0100| [fc3c2ea8dce682eeaaa53b4fed02bebc7a684c46] | committer: Lynne

avcodec/aacdec: PredictorState array out of SingleChannelElement

sizeof(PredictorState) is different for the floating-point and
the fixed-point AAC decoders; this is an obstacle for deduplicating
code between these decoders. So don't include this array in
SingleChannelElement, instead add a union of pointers to the
fixed-point PredictorState and the floating-point PredictorState.
The actual arrays are part of the extended ChannelElement
to be allocated by ff_aac_sbr_ctx_alloc_init(); it also
sets the pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fc3c2ea8dce682eeaaa53b4fed02bebc7a684c46
---

 libavcodec/aac.h             | 17 -----------------
 libavcodec/aac_defines.h     | 28 ++++++++++++++++++++++++++++
 libavcodec/aacdec.h          |  5 ++++-
 libavcodec/aacdec_template.c |  8 ++++----
 libavcodec/aacenc.h          | 14 ++++++++++++++
 libavcodec/aacsbr_template.c |  3 +++
 6 files changed, 53 insertions(+), 22 deletions(-)

diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index 89f838eab5..9508760fa6 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -30,9 +30,6 @@
 #ifndef AVCODEC_AAC_H
 #define AVCODEC_AAC_H
 
-
-#include "aac_defines.h"
-
 #define MAX_CHANNELS 64
 #define MAX_ELEM_ID 16
 
@@ -85,20 +82,6 @@ enum ChannelPosition {
     AAC_CHANNEL_CC    = 5,
 };
 
-/**
- * Predictor State
- */
-typedef struct PredictorState {
-    AAC_FLOAT cor0;
-    AAC_FLOAT cor1;
-    AAC_FLOAT var0;
-    AAC_FLOAT var1;
-    AAC_FLOAT r0;
-    AAC_FLOAT r1;
-    AAC_FLOAT k1;
-    AAC_FLOAT x_est;
-} PredictorState;
-
 #define MAX_PREDICTORS 672
 
 #define SCALE_DIV_512    36    ///< scalefactor difference that corresponds to scale difference in 512 times
diff --git a/libavcodec/aac_defines.h b/libavcodec/aac_defines.h
index a0c23c33ff..75bc40744a 100644
--- a/libavcodec/aac_defines.h
+++ b/libavcodec/aac_defines.h
@@ -72,6 +72,20 @@ typedef int                 AAC_SIGNE;
                                         0x40000000) >> 31)
 #define AAC_HALF_SUM(x, y)  (((x) >> 1) + ((y) >> 1))
 
+/**
+ * Predictor State
+ */
+typedef struct PredictorStateFixed {
+    SoftFloat cor0;
+    SoftFloat cor1;
+    SoftFloat var0;
+    SoftFloat var1;
+    SoftFloat r0;
+    SoftFloat r1;
+    SoftFloat k1;
+    SoftFloat x_est;
+} PredictorState;
+
 #ifdef LPC_USE_FIXED
 #error aac_defines.h must be included before lpc_functions.h for fixed point decoder
 #endif
@@ -112,6 +126,20 @@ typedef unsigned            AAC_SIGNE;
 #define AAC_MSUB31_V3(x, y, z)    ((x) - (y)) * (z)
 #define AAC_HALF_SUM(x, y)  ((x) + (y)) * 0.5f
 
+/**
+ * Predictor State
+ */
+typedef struct PredictorState {
+    float cor0;
+    float cor1;
+    float var0;
+    float var1;
+    float r0;
+    float r1;
+    float k1;
+    float x_est;
+} PredictorState;
+
 #endif /* USE_FIXED */
 
 #endif /* AVCODEC_AAC_DEFINES_H */
diff --git a/libavcodec/aacdec.h b/libavcodec/aacdec.h
index e5165e9b54..a64c375d1f 100644
--- a/libavcodec/aacdec.h
+++ b/libavcodec/aacdec.h
@@ -140,7 +140,10 @@ typedef struct SingleChannelElement {
     DECLARE_ALIGNED(32, INTFLOAT, saved)[1536];     ///< overlap
     DECLARE_ALIGNED(32, INTFLOAT, ret_buf)[2048];   ///< PCM output buffer
     DECLARE_ALIGNED(16, INTFLOAT, ltp_state)[3072]; ///< time signal for LTP
-    PredictorState predictor_state[MAX_PREDICTORS];
+    union {
+        struct PredictorStateFixed *RENAME_FIXED(predictor_state);
+        struct PredictorState      *predictor_state;
+    };
     INTFLOAT *ret;                                  ///< PCM output
 } SingleChannelElement;
 
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 6362e6c25c..b169f404c8 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1942,7 +1942,7 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce)
     int sfb, k;
 
     if (!sce->ics.predictor_initialized) {
-        reset_all_predictors(sce->predictor_state);
+        reset_all_predictors(sce->AAC_RENAME(predictor_state));
         sce->ics.predictor_initialized = 1;
     }
 
@@ -1953,16 +1953,16 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce)
             for (k = sce->ics.swb_offset[sfb];
                  k < sce->ics.swb_offset[sfb + 1];
                  k++) {
-                predict(&sce->predictor_state[k], &sce->coeffs[k],
+                predict(&sce->AAC_RENAME(predictor_state)[k], &sce->coeffs[k],
                         sce->ics.predictor_present &&
                         sce->ics.prediction_used[sfb]);
             }
         }
         if (sce->ics.predictor_reset_group)
-            reset_predictor_group(sce->predictor_state,
+            reset_predictor_group(sce->AAC_RENAME(predictor_state),
                                   sce->ics.predictor_reset_group);
     } else
-        reset_all_predictors(sce->predictor_state);
+        reset_all_predictors(sce->AAC_RENAME(predictor_state));
 }
 
 static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb)
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index 8899f90ac7..d07960620e 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -49,6 +49,20 @@ typedef enum AACCoder {
     AAC_CODER_NB,
 }AACCoder;
 
+/**
+ * Predictor State
+ */
+typedef struct PredictorState {
+    float cor0;
+    float cor1;
+    float var0;
+    float var1;
+    float r0;
+    float r1;
+    float k1;
+    float x_est;
+} PredictorState;
+
 typedef struct AACEncOptions {
     int coder;
     int pns;
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index 89e8bee75a..f1c3b0f4e0 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -40,6 +40,7 @@
 
 typedef struct ExtChannelElement {
     ChannelElement ch;
+    PredictorState predictor_state[2][MAX_PREDICTORS];
     SpectralBandReplication sbr;
 } ExtChannelElement;
 
@@ -87,6 +88,8 @@ av_cold int AAC_RENAME(ff_aac_sbr_ctx_alloc_init)(AACDecContext *ac,
         return AVERROR(ENOMEM);
     *che = &ext->ch;
     sbr  = &ext->sbr;
+    ext->ch.ch[0].AAC_RENAME(predictor_state) = ext->predictor_state[0];
+    ext->ch.ch[1].AAC_RENAME(predictor_state) = ext->predictor_state[1];
 
     sbr->kx[0] = sbr->kx[1];
     sbr->id_aac = id_aac;



More information about the ffmpeg-cvslog mailing list