History

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.

Andreas Rheinhardt committed 2 years ago

Commit fc3c2ea1 parent 8b2261e6 files · +53 −22Browse files

Unified · Split

6 files
  1. libavcodec/aac.h +0 −17
  2. libavcodec/aac_defines.h +28 −0
  3. libavcodec/aacdec.h +4 −1
  4. libavcodec/aacdec_template.c +4 −4
  5. libavcodec/aacenc.h +14 −0
  6. libavcodec/aacsbr_template.c +3 −0
libavcodec/aac.h+0−17
@@ -30,9 +30,6 @@ · 29 unmodified lines
30#ifndef AVCODEC_AAC_H30#ifndef AVCODEC_AAC_H
31#define AVCODEC_AAC_H31#define AVCODEC_AAC_H
32 32
33
34#include "aac_defines.h"
35
36#define MAX_CHANNELS 6433#define MAX_CHANNELS 64
37#define MAX_ELEM_ID 1634#define MAX_ELEM_ID 16
38 35
@@ -85,20 +82,6 @@ enum ChannelPosition { · 46 unmodified lines
85 AAC_CHANNEL_CC = 5,82 AAC_CHANNEL_CC = 5,
86};83};
87 84
88/**
89 * Predictor State
90 */
91typedef struct PredictorState {
92 AAC_FLOAT cor0;
93 AAC_FLOAT cor1;
94 AAC_FLOAT var0;
95 AAC_FLOAT var1;
96 AAC_FLOAT r0;
97 AAC_FLOAT r1;
98 AAC_FLOAT k1;
99 AAC_FLOAT x_est;
100} PredictorState;
101
102#define MAX_PREDICTORS 67285#define MAX_PREDICTORS 672
103 86
104#define SCALE_DIV_512 36 ///< scalefactor difference that corresponds to scale difference in 512 times87#define SCALE_DIV_512 36 ///< scalefactor difference that corresponds to scale difference in 512 times
libavcodec/aac_defines.h+28−0
@@ -72,6 +72,20 @@ typedef int AAC_SIGNE; · 71 unmodified lines
72 0x40000000) >> 31)72 0x40000000) >> 31)
73#define AAC_HALF_SUM(x, y) (((x) >> 1) + ((y) >> 1))73#define AAC_HALF_SUM(x, y) (((x) >> 1) + ((y) >> 1))
74 74
75/**
76 * Predictor State
77 */
78typedef struct PredictorStateFixed {
79 SoftFloat cor0;
80 SoftFloat cor1;
81 SoftFloat var0;
82 SoftFloat var1;
83 SoftFloat r0;
84 SoftFloat r1;
85 SoftFloat k1;
86 SoftFloat x_est;
87} PredictorState;
88
75#ifdef LPC_USE_FIXED89#ifdef LPC_USE_FIXED
76#error aac_defines.h must be included before lpc_functions.h for fixed point decoder90#error aac_defines.h must be included before lpc_functions.h for fixed point decoder
77#endif91#endif
@@ -112,6 +126,20 @@ typedef unsigned AAC_SIGNE; · 34 unmodified lines
112#define AAC_MSUB31_V3(x, y, z) ((x) - (y)) * (z)126#define AAC_MSUB31_V3(x, y, z) ((x) - (y)) * (z)
113#define AAC_HALF_SUM(x, y) ((x) + (y)) * 0.5f127#define AAC_HALF_SUM(x, y) ((x) + (y)) * 0.5f
114 128
129/**
130 * Predictor State
131 */
132typedef struct PredictorState {
133 float cor0;
134 float cor1;
135 float var0;
136 float var1;
137 float r0;
138 float r1;
139 float k1;
140 float x_est;
141} PredictorState;
142
115#endif /* USE_FIXED */143#endif /* USE_FIXED */
116 144
117#endif /* AVCODEC_AAC_DEFINES_H */145#endif /* AVCODEC_AAC_DEFINES_H */
libavcodec/aacdec.h+4−1
@@ -140,7 +140,10 @@ typedef struct SingleChannelElement { · 139 unmodified lines
140 DECLARE_ALIGNED(32, INTFLOAT, saved)[1536]; ///< overlap140 DECLARE_ALIGNED(32, INTFLOAT, saved)[1536]; ///< overlap
141 DECLARE_ALIGNED(32, INTFLOAT, ret_buf)[2048]; ///< PCM output buffer141 DECLARE_ALIGNED(32, INTFLOAT, ret_buf)[2048]; ///< PCM output buffer
142 DECLARE_ALIGNED(16, INTFLOAT, ltp_state)[3072]; ///< time signal for LTP142 DECLARE_ALIGNED(16, INTFLOAT, ltp_state)[3072]; ///< time signal for LTP
143 PredictorState predictor_state[MAX_PREDICTORS];143 union {
144 struct PredictorStateFixed *RENAME_FIXED(predictor_state);
145 struct PredictorState *predictor_state;
146 };
144 INTFLOAT *ret; ///< PCM output147 INTFLOAT *ret; ///< PCM output
145} SingleChannelElement;148} SingleChannelElement;
146 149
libavcodec/aacdec_template.c+4−4
@@ -1942,7 +1942,7 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce) · 1941 unmodified lines
1942 int sfb, k;1942 int sfb, k;
1943 1943
1944 if (!sce->ics.predictor_initialized) {1944 if (!sce->ics.predictor_initialized) {
1945 reset_all_predictors(sce->predictor_state);1945 reset_all_predictors(sce->AAC_RENAME(predictor_state));
1946 sce->ics.predictor_initialized = 1;1946 sce->ics.predictor_initialized = 1;
1947 }1947 }
1948 1948
@@ -1953,16 +1953,16 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce) · 4 unmodified lines
1953 for (k = sce->ics.swb_offset[sfb];1953 for (k = sce->ics.swb_offset[sfb];
1954 k < sce->ics.swb_offset[sfb + 1];1954 k < sce->ics.swb_offset[sfb + 1];
1955 k++) {1955 k++) {
1956 predict(&sce->predictor_state[k], &sce->coeffs[k],1956 predict(&sce->AAC_RENAME(predictor_state)[k], &sce->coeffs[k],
1957 sce->ics.predictor_present &&1957 sce->ics.predictor_present &&
1958 sce->ics.prediction_used[sfb]);1958 sce->ics.prediction_used[sfb]);
1959 }1959 }
1960 }1960 }
1961 if (sce->ics.predictor_reset_group)1961 if (sce->ics.predictor_reset_group)
1962 reset_predictor_group(sce->predictor_state,1962 reset_predictor_group(sce->AAC_RENAME(predictor_state),
1963 sce->ics.predictor_reset_group);1963 sce->ics.predictor_reset_group);
1964 } else1964 } else
1965 reset_all_predictors(sce->predictor_state);1965 reset_all_predictors(sce->AAC_RENAME(predictor_state));
1966}1966}
1967 1967
1968static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb)1968static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb)
libavcodec/aacenc.h+14−0
@@ -49,6 +49,20 @@ typedef enum AACCoder { · 48 unmodified lines
49 AAC_CODER_NB,49 AAC_CODER_NB,
50}AACCoder;50}AACCoder;
51 51
52/**
53 * Predictor State
54 */
55typedef struct PredictorState {
56 float cor0;
57 float cor1;
58 float var0;
59 float var1;
60 float r0;
61 float r1;
62 float k1;
63 float x_est;
64} PredictorState;
65
52typedef struct AACEncOptions {66typedef struct AACEncOptions {
53 int coder;67 int coder;
54 int pns;68 int pns;
libavcodec/aacsbr_template.c+3−0
@@ -40,6 +40,7 @@ · 39 unmodified lines
40 40
41typedef struct ExtChannelElement {41typedef struct ExtChannelElement {
42 ChannelElement ch;42 ChannelElement ch;
43 PredictorState predictor_state[2][MAX_PREDICTORS];
43 SpectralBandReplication sbr;44 SpectralBandReplication sbr;
44} ExtChannelElement;45} ExtChannelElement;
45 46
@@ -87,6 +88,8 @@ av_cold int AAC_RENAME(ff_aac_sbr_ctx_alloc_init)(AACDecContext *ac, · 41 unmodified lines
87 return AVERROR(ENOMEM);88 return AVERROR(ENOMEM);
88 *che = &ext->ch;89 *che = &ext->ch;
89 sbr = &ext->sbr;90 sbr = &ext->sbr;
91 ext->ch.ch[0].AAC_RENAME(predictor_state) = ext->predictor_state[0];
92 ext->ch.ch[1].AAC_RENAME(predictor_state) = ext->predictor_state[1];
90 93
91 sbr->kx[0] = sbr->kx[1];94 sbr->kx[0] = sbr->kx[1];
92 sbr->id_aac = id_aac;95 sbr->id_aac = id_aac;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t