Browse code

ac3dec_fixed: always use the USE_FIXED=1 variant of the AC3DecodeContext

The AC3DecodeContext has a float (USE_FIXED=0) and an integer
(USE_FIXED=1) variant, both of which can be present in the same binary.
This is not only very confusing, but it also breaks horribly, when one
variant is used by code expecting the other.

This currently happens, because eac3dec.c is only compiled for the float
variant, but also used from ac3dec_fixed.c, which uses the integer
variant.

The result is memory corruption, leading to crashes.

So compile eac3dec.c once for each variant and adapt it, so that it
works with the integer variant.

A loss of precission and scaling bug has been fixed by the committer
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 7b05b5093ea67a3397b0c37cf398bab471e1ce2b)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Andreas Cadhalpun authored on 2015/03/14 06:28:42
Showing 5 changed files
... ...
@@ -217,7 +217,7 @@ OBJS-$(CONFIG_DVVIDEO_DECODER)         += dvdec.o dv.o dvdata.o
217 217
 OBJS-$(CONFIG_DVVIDEO_ENCODER)         += dvenc.o dv.o dvdata.o
218 218
 OBJS-$(CONFIG_DXA_DECODER)             += dxa.o
219 219
 OBJS-$(CONFIG_DXTORY_DECODER)          += dxtory.o
220
-OBJS-$(CONFIG_EAC3_DECODER)            += eac3dec.o eac3_data.o
220
+OBJS-$(CONFIG_EAC3_DECODER)            += eac3_data.o
221 221
 OBJS-$(CONFIG_EAC3_ENCODER)            += eac3enc.o eac3_data.o
222 222
 OBJS-$(CONFIG_EACMV_DECODER)           += eacmv.o
223 223
 OBJS-$(CONFIG_EAMAD_DECODER)           += eamad.o eaidct.o mpeg12.o \
... ...
@@ -243,19 +243,19 @@ typedef struct AC3DecodeContext {
243 243
  * Parse the E-AC-3 frame header.
244 244
  * This parses both the bit stream info and audio frame header.
245 245
  */
246
-int ff_eac3_parse_header(AC3DecodeContext *s);
246
+static int ff_eac3_parse_header(AC3DecodeContext *s);
247 247
 
248 248
 /**
249 249
  * Decode mantissas in a single channel for the entire frame.
250 250
  * This is used when AHT mode is enabled.
251 251
  */
252
-void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch);
252
+static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch);
253 253
 
254 254
 /**
255 255
  * Apply spectral extension to each channel by copying lower frequency
256 256
  * coefficients to higher frequency bins and applying side information to
257 257
  * approximate the original high frequency signal.
258 258
  */
259
-void ff_eac3_apply_spectral_extension(AC3DecodeContext *s);
259
+static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s);
260 260
 
261 261
 #endif /* AVCODEC_AC3DEC_H */
... ...
@@ -164,6 +164,7 @@ static void ac3_downmix_c_fixed16(int16_t **samples, int16_t (*matrix)[2],
164 164
     }
165 165
 }
166 166
 
167
+#include "eac3dec.c"
167 168
 #include "ac3dec.c"
168 169
 
169 170
 static const AVOption options[] = {
... ...
@@ -28,6 +28,7 @@
28 28
  * Upmix delay samples from stereo to original channel layout.
29 29
  */
30 30
 #include "ac3dec.h"
31
+#include "eac3dec.c"
31 32
 #include "ac3dec.c"
32 33
 
33 34
 static const AVOption options[] = {
... ...
@@ -63,7 +63,7 @@ typedef enum {
63 63
 
64 64
 #define EAC3_SR_CODE_REDUCED  3
65 65
 
66
-void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
66
+static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
67 67
 {
68 68
     int bin, bnd, ch, i;
69 69
     uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
... ...
@@ -101,7 +101,7 @@ void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
101 101
         for (i = 0; i < num_copy_sections; i++) {
102 102
             memcpy(&s->transform_coeffs[ch][bin],
103 103
                    &s->transform_coeffs[ch][s->spx_dst_start_freq],
104
-                   copy_sizes[i]*sizeof(float));
104
+                   copy_sizes[i]*sizeof(INTFLOAT));
105 105
             bin += copy_sizes[i];
106 106
         }
107 107
 
... ...
@@ -124,7 +124,7 @@ void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
124 124
             bin = s->spx_src_start_freq - 2;
125 125
             for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
126 126
                 if (wrapflag[bnd]) {
127
-                    float *coeffs = &s->transform_coeffs[ch][bin];
127
+                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
128 128
                     coeffs[0] *= atten_tab[0];
129 129
                     coeffs[1] *= atten_tab[1];
130 130
                     coeffs[2] *= atten_tab[2];
... ...
@@ -142,6 +142,9 @@ void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
142 142
         for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
143 143
             float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
144 144
             float sscale = s->spx_signal_blend[ch][bnd];
145
+#if USE_FIXED
146
+            nscale *= 1.0 / (1<<23);
147
+#endif
145 148
             for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
146 149
                 float noise  = nscale * (int32_t)av_lfg_get(&s->dith_state);
147 150
                 s->transform_coeffs[ch][bin]   *= sscale;
... ...
@@ -195,7 +198,7 @@ static void idct6(int pre_mant[6])
195 195
     pre_mant[5] = even0 - odd0;
196 196
 }
197 197
 
198
-void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
198
+static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
199 199
 {
200 200
     int bin, blk, gs;
201 201
     int end_bap, gaq_mode;
... ...
@@ -288,7 +291,7 @@ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
288 288
     }
289 289
 }
290 290
 
291
-int ff_eac3_parse_header(AC3DecodeContext *s)
291
+static int ff_eac3_parse_header(AC3DecodeContext *s)
292 292
 {
293 293
     int i, blk, ch;
294 294
     int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;