FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/eac3dec.c
Date: 2026-08-29 16:27:19
Exec Total Coverage
Lines: 221 250 88.4%
Functions: 4 4 100.0%
Branches: 148 178 83.1%

Line Branch Exec Source
1 /*
2 * E-AC-3 decoder
3 * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
4 * Copyright (c) 2008 Justin Ruggles
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /*
24 * There are several features of E-AC-3 that this decoder does not yet support.
25 *
26 * Enhanced Coupling
27 * No known samples exist. If any ever surface, this feature should not be
28 * too difficult to implement.
29 *
30 * Reduced Sample Rates
31 * No known samples exist. The spec also does not give clear information
32 * on how this is to be implemented.
33 *
34 * Transient Pre-noise Processing
35 * This is side information which a decoder should use to reduce artifacts
36 * caused by transients. There are samples which are known to have this
37 * information, but this decoder currently ignores it.
38 */
39
40
41 #include "avcodec.h"
42 #include "ac3.h"
43 #include "ac3_parser_internal.h"
44 #include "ac3dec.h"
45 #include "ac3dec_data.h"
46 #include "eac3_data.h"
47
48 /** gain adaptive quantization mode */
49 typedef enum {
50 EAC3_GAQ_NO =0,
51 EAC3_GAQ_12,
52 EAC3_GAQ_14,
53 EAC3_GAQ_124
54 } EAC3GaqMode;
55
56 6474 static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
57 {
58 int bin, bnd, ch, i;
59 6474 uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60 float rms_energy[SPX_MAX_BANDS];
61
62 /* Set copy index mapping table. Set wrap flags to apply a notch filter at
63 wrap points later on. */
64 6474 bin = s->spx_dst_start_freq;
65 6474 num_copy_sections = 0;
66
2/2
✓ Branch 0 taken 14676 times.
✓ Branch 1 taken 6474 times.
21150 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67 int copysize;
68 14676 int bandsize = s->spx_band_sizes[bnd];
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14676 times.
14676 if (bin + bandsize > s->spx_src_start_freq) {
70 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71 bin = s->spx_dst_start_freq;
72 wrapflag[bnd] = 1;
73 }
74
2/2
✓ Branch 0 taken 14676 times.
✓ Branch 1 taken 14676 times.
29352 for (i = 0; i < bandsize; i += copysize) {
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14676 times.
14676 if (bin == s->spx_src_start_freq) {
76 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77 bin = s->spx_dst_start_freq;
78 }
79 14676 copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80 14676 bin += copysize;
81 }
82 }
83 6474 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
2/2
✓ Branch 0 taken 14676 times.
✓ Branch 1 taken 6474 times.
21150 for (ch = 1; ch <= s->fbw_channels; ch++) {
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14676 times.
14676 if (!s->channel_uses_spx[ch])
87 continue;
88
89 /* Copy coeffs from normal bands to extension bands */
90 14676 bin = s->spx_src_start_freq;
91
2/2
✓ Branch 0 taken 14676 times.
✓ Branch 1 taken 14676 times.
29352 for (i = 0; i < num_copy_sections; i++) {
92 14676 memcpy(&s->transform_coeffs[ch][bin],
93 14676 &s->transform_coeffs[ch][s->spx_dst_start_freq],
94 14676 copy_sizes[i]*sizeof(INTFLOAT));
95 14676 bin += copy_sizes[i];
96 }
97
98 /* Calculate RMS energy for each SPX band. */
99 14676 bin = s->spx_src_start_freq;
100
2/2
✓ Branch 0 taken 37992 times.
✓ Branch 1 taken 14676 times.
52668 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101 37992 int bandsize = s->spx_band_sizes[bnd];
102 37992 float accum = 0.0f;
103
2/2
✓ Branch 0 taken 490464 times.
✓ Branch 1 taken 37992 times.
528456 for (i = 0; i < bandsize; i++) {
104 490464 float coeff = s->transform_coeffs[ch][bin++];
105 490464 accum += coeff * coeff;
106 }
107 37992 rms_energy[bnd] = sqrtf(accum / bandsize);
108 }
109
110 /* Apply a notch filter at transitions between normal and extension
111 bands and at all wrap points. */
112
2/2
✓ Branch 0 taken 12600 times.
✓ Branch 1 taken 2076 times.
14676 if (s->spx_atten_code[ch] >= 0) {
113 12600 const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114 12600 bin = s->spx_src_start_freq - 2;
115
2/2
✓ Branch 0 taken 27612 times.
✓ Branch 1 taken 12600 times.
40212 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
2/2
✓ Branch 0 taken 12600 times.
✓ Branch 1 taken 15012 times.
27612 if (wrapflag[bnd]) {
117 12600 INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118 12600 coeffs[0] *= atten_tab[0];
119 12600 coeffs[1] *= atten_tab[1];
120 12600 coeffs[2] *= atten_tab[2];
121 12600 coeffs[3] *= atten_tab[1];
122 12600 coeffs[4] *= atten_tab[0];
123 }
124 27612 bin += s->spx_band_sizes[bnd];
125 }
126 }
127
128 /* Apply noise-blended coefficient scaling based on previously
129 calculated RMS energy, blending factors, and SPX coordinates for
130 each band. */
131 14676 bin = s->spx_src_start_freq;
132
2/2
✓ Branch 0 taken 37992 times.
✓ Branch 1 taken 14676 times.
52668 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133 37992 float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134 37992 float sscale = s->spx_signal_blend[ch][bnd];
135 #if USE_FIXED
136 // spx_noise_blend and spx_signal_blend are both FP.23
137 18936 nscale *= 1.0 / (1<<23);
138 18936 sscale *= 1.0 / (1<<23);
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18936 times.
18936 if (nscale < -1.0)
140 nscale = -1.0;
141 #endif
142
2/2
✓ Branch 0 taken 490464 times.
✓ Branch 1 taken 37992 times.
528456 for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143 490464 UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144 490464 s->transform_coeffs[ch][bin] *= sscale;
145 490464 s->transform_coeffs[ch][bin++] += noise;
146 }
147 }
148 }
149 6474 }
150
151
152 /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
153 #define COEFF_0 10273905LL
154
155 /** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
156 #define COEFF_1 11863283LL
157
158 /** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
159 #define COEFF_2 3070444LL
160
161 /**
162 * Calculate 6-point IDCT of the pre-mantissas.
163 * All calculations are 24-bit fixed-point.
164 */
165 198410 static void idct6(int pre_mant[6])
166 {
167 int tmp;
168 int even0, even1, even2, odd0, odd1, odd2;
169
170 198410 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172 198410 even2 = ( pre_mant[2] * COEFF_0) >> 23;
173 198410 tmp = ( pre_mant[4] * COEFF_1) >> 23;
174 198410 odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176 198410 even0 = pre_mant[0] + (tmp >> 1);
177 198410 even1 = pre_mant[0] - tmp;
178
179 198410 tmp = even0;
180 198410 even0 = tmp + even2;
181 198410 even2 = tmp - even2;
182
183 198410 tmp = odd0;
184 198410 odd0 = tmp + pre_mant[1] + pre_mant[3];
185 198410 odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187 198410 pre_mant[0] = even0 + odd0;
188 198410 pre_mant[1] = even1 + odd1;
189 198410 pre_mant[2] = even2 + odd2;
190 198410 pre_mant[3] = even2 - odd2;
191 198410 pre_mant[4] = even1 - odd1;
192 198410 pre_mant[5] = even0 - odd0;
193 198410 }
194
195 1622 static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
196 {
197 int bin, blk, gs;
198 int end_bap, gaq_mode;
199 1622 GetBitContext *gbc = &s->gbc;
200 int gaq_gain[AC3_MAX_COEFS];
201
202 1622 gaq_mode = get_bits(gbc, 2);
203
2/2
✓ Branch 0 taken 1226 times.
✓ Branch 1 taken 396 times.
1622 end_bap = (gaq_mode < 2) ? 12 : 17;
204
205 /* if GAQ gain is used, decode gain codes for bins with hebap between
206 8 and end_bap */
207 1622 gs = 0;
208
4/4
✓ Branch 0 taken 518 times.
✓ Branch 1 taken 1104 times.
✓ Branch 2 taken 292 times.
✓ Branch 3 taken 226 times.
1622 if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209 /* read 1-bit GAQ gain codes */
210
2/2
✓ Branch 0 taken 173788 times.
✓ Branch 1 taken 1396 times.
175184 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
4/4
✓ Branch 0 taken 64530 times.
✓ Branch 1 taken 109258 times.
✓ Branch 2 taken 62716 times.
✓ Branch 3 taken 1814 times.
173788 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212 62716 gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213 }
214
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 122 times.
226 } else if (gaq_mode == EAC3_GAQ_124) {
215 /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216 104 int gc = 2;
217
2/2
✓ Branch 0 taken 13016 times.
✓ Branch 1 taken 104 times.
13120 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
3/4
✓ Branch 0 taken 3810 times.
✓ Branch 1 taken 9206 times.
✓ Branch 2 taken 3810 times.
✗ Branch 3 not taken.
13016 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
2/2
✓ Branch 0 taken 1310 times.
✓ Branch 1 taken 2500 times.
3810 if (gc++ == 2) {
220 1310 int group_code = get_bits(gbc, 5);
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1310 times.
1310 if (group_code > 26) {
222 av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223 group_code = 26;
224 }
225 1310 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226 1310 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227 1310 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228 1310 gc = 0;
229 }
230 }
231 }
232 }
233
234 1622 gs=0;
235
2/2
✓ Branch 0 taken 198410 times.
✓ Branch 1 taken 1622 times.
200032 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236 198410 int hebap = s->bap[ch][bin];
237 198410 int bits = ff_eac3_bits_vs_hebap[hebap];
238
2/2
✓ Branch 0 taken 63906 times.
✓ Branch 1 taken 134504 times.
198410 if (!hebap) {
239 /* zero-mantissa dithering */
240
2/2
✓ Branch 0 taken 383436 times.
✓ Branch 1 taken 63906 times.
447342 for (blk = 0; blk < 6; blk++) {
241 383436 s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242 }
243
2/2
✓ Branch 0 taken 62110 times.
✓ Branch 1 taken 72394 times.
134504 } else if (hebap < 8) {
244 /* Vector Quantization */
245 62110 int v = get_bits(gbc, bits);
246
2/2
✓ Branch 0 taken 372660 times.
✓ Branch 1 taken 62110 times.
434770 for (blk = 0; blk < 6; blk++) {
247 372660 s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248 }
249 } else {
250 /* Gain Adaptive Quantization */
251 int gbits, log_gain;
252
4/4
✓ Branch 0 taken 68340 times.
✓ Branch 1 taken 4054 times.
✓ Branch 2 taken 66526 times.
✓ Branch 3 taken 1814 times.
72394 if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253 66526 log_gain = gaq_gain[gs++];
254 } else {
255 5868 log_gain = 0;
256 }
257 72394 gbits = bits - log_gain;
258
259
2/2
✓ Branch 0 taken 434364 times.
✓ Branch 1 taken 72394 times.
506758 for (blk = 0; blk < 6; blk++) {
260 434364 int mant = get_sbits(gbc, gbits);
261
4/4
✓ Branch 0 taken 204258 times.
✓ Branch 1 taken 230106 times.
✓ Branch 2 taken 48987 times.
✓ Branch 3 taken 155271 times.
434364 if (log_gain && mant == -(1 << (gbits-1))) {
262 /* large mantissa */
263 int b;
264 48987 int mbits = bits - (2 - log_gain);
265 48987 mant = get_sbits(gbc, mbits);
266 48987 mant = ((unsigned)mant) << (23 - (mbits - 1));
267 /* remap mantissa value to correct for asymmetric quantization */
268
2/2
✓ Branch 0 taken 24336 times.
✓ Branch 1 taken 24651 times.
48987 if (mant >= 0)
269 24336 b = 1 << (23 - log_gain);
270 else
271 24651 b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272 48987 mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273 } else {
274 /* small mantissa, no GAQ, or Gk=1 */
275 385377 mant *= (1 << 24 - bits);
276
2/2
✓ Branch 0 taken 230106 times.
✓ Branch 1 taken 155271 times.
385377 if (!log_gain) {
277 /* remap mantissa value for no GAQ or Gk=1 */
278 230106 mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279 }
280 }
281 434364 s->pre_mantissa[ch][bin][blk] = mant;
282 }
283 }
284 198410 idct6(s->pre_mantissa[ch][bin]);
285 }
286 1622 }
287
288 2163 static int ff_eac3_parse_header(AC3DecodeContext *s, const AC3HeaderInfo *hdr)
289 {
290 int i, blk, ch;
291 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292 int parse_transient_proc_info;
293 int num_cpl_blocks;
294 2163 GetBitContext *gbc = &s->gbc;
295
296 /* An E-AC-3 stream can have multiple independent streams which the
297 application can select from. each independent stream can also contain
298 dependent streams which are used to add or replace channels. */
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2163 times.
2163 if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
300 av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
301 return AC3_PARSE_ERROR_FRAME_TYPE;
302 }
303
304 /* The substream id indicates which substream this frame belongs to. each
305 independent stream has its own substream id, and the dependent streams
306 associated to an independent stream have matching substream id's. */
307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2163 times.
2163 if (s->substreamid) {
308 /* only decode substream with id=0. skip any additional substreams. */
309 if (!s->eac3_subsbtreamid_found) {
310 s->eac3_subsbtreamid_found = 1;
311 avpriv_request_sample(s->avctx, "Additional substreams");
312 }
313 return AC3_PARSE_ERROR_FRAME_TYPE;
314 }
315
316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2163 times.
2163 if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
317 /* The E-AC-3 specification does not tell how to handle reduced sample
318 rates in bit allocation. The best assumption would be that it is
319 handled like AC-3 DolbyNet, but we cannot be sure until we have a
320 sample which utilizes this feature. */
321 avpriv_request_sample(s->avctx, "Reduced sampling rate");
322 return AVERROR_PATCHWELCOME;
323 }
324
325 /* volume control params */
326
3/4
✓ Branch 0 taken 4326 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2163 times.
✓ Branch 3 taken 2163 times.
4326 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327 2163 s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2163 times.
2163 if (s->dialog_normalization[i] == 0) {
329 s->dialog_normalization[i] = -31;
330 }
331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2163 times.
2163 if (s->target_level != 0) {
332 s->level_gain[i] = powf(2.0f,
333 (float)(s->target_level - s->dialog_normalization[i])/6.0f);
334 }
335
2/2
✓ Branch 0 taken 1856 times.
✓ Branch 1 taken 307 times.
2163 if (hdr->compression_exists[i]) {
336 1856 s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337 }
338 }
339
340 2163 s->channel_map = hdr->channel_map;
341
342 /* mixing metadata */
343 2163 s->preferred_downmix = hdr->preferred_downmix;
344 2163 s->center_mix_level_ltrt = hdr->center_mix_level_ltrt;
345 2163 s->center_mix_level = hdr->center_mix_level;
346 2163 s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347 2163 s->surround_mix_level = hdr->surround_mix_level;
348 2163 s->lfe_mix_level_exists = hdr->lfe_mix_level_exists;
349 2163 s->lfe_mix_level = hdr->lfe_mix_level;
350 2163 s->dolby_surround_mode = hdr->dolby_surround_mode;
351 2163 s->dolby_headphone_mode = hdr->dolby_headphone_mode;
352 2163 s->dolby_surround_ex_mode = hdr->dolby_surround_ex_mode;
353
354 /* informational metadata */
355 2163 s->bitstream_mode = hdr->bitstream_mode;
356
357 /* additional bitstream info */
358 2163 s->eac3_extension_type_a = hdr->eac3_extension_type_a;
359
360 /* audio frame syntax flags, strategy data, and per-frame data */
361
362
2/2
✓ Branch 0 taken 1967 times.
✓ Branch 1 taken 196 times.
2163 if (s->num_blocks == 6) {
363 1967 ac3_exponent_strategy = get_bits1(gbc);
364 1967 parse_aht_info = get_bits1(gbc);
365 } else {
366 /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367 do not use AHT */
368 196 ac3_exponent_strategy = 1;
369 196 parse_aht_info = 0;
370 }
371
372 2163 s->snr_offset_strategy = get_bits(gbc, 2);
373 2163 parse_transient_proc_info = get_bits1(gbc);
374
375 2163 s->block_switch_syntax = get_bits1(gbc);
376
1/2
✓ Branch 0 taken 2163 times.
✗ Branch 1 not taken.
2163 if (!s->block_switch_syntax)
377 2163 memset(s->block_switch, 0, sizeof(s->block_switch));
378
379 2163 s->dither_flag_syntax = get_bits1(gbc);
380
1/2
✓ Branch 0 taken 2163 times.
✗ Branch 1 not taken.
2163 if (!s->dither_flag_syntax) {
381
2/2
✓ Branch 0 taken 5840 times.
✓ Branch 1 taken 2163 times.
8003 for (ch = 1; ch <= s->fbw_channels; ch++)
382 5840 s->dither_flag[ch] = 1;
383 }
384 2163 s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386 2163 s->bit_allocation_syntax = get_bits1(gbc);
387
2/2
✓ Branch 0 taken 1590 times.
✓ Branch 1 taken 573 times.
2163 if (!s->bit_allocation_syntax) {
388 /* set default bit allocation parameters */
389 1590 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390 1590 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391 1590 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab [1];
392 1590 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393 1590 s->bit_alloc_params.floor = ff_ac3_floor_tab [7];
394 }
395
396 2163 s->fast_gain_syntax = get_bits1(gbc);
397 2163 s->dba_syntax = get_bits1(gbc);
398 2163 s->skip_syntax = get_bits1(gbc);
399 2163 parse_spx_atten_data = get_bits1(gbc);
400
401 /* coupling strategy occurrence and coupling use per block */
402 2163 num_cpl_blocks = 0;
403
1/2
✓ Branch 0 taken 2163 times.
✗ Branch 1 not taken.
2163 if (s->channel_mode > 1) {
404
2/2
✓ Branch 0 taken 11998 times.
✓ Branch 1 taken 2163 times.
14161 for (blk = 0; blk < s->num_blocks; blk++) {
405
3/4
✓ Branch 0 taken 9835 times.
✓ Branch 1 taken 2163 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9835 times.
11998 s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
2/2
✓ Branch 0 taken 2163 times.
✓ Branch 1 taken 9835 times.
11998 if (s->cpl_strategy_exists[blk]) {
407 2163 s->cpl_in_use[blk] = get_bits1(gbc);
408 } else {
409 9835 s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410 }
411 11998 num_cpl_blocks += s->cpl_in_use[blk];
412 }
413 } else {
414 memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415 }
416
417 /* exponent strategy data */
418
2/2
✓ Branch 0 taken 196 times.
✓ Branch 1 taken 1967 times.
2163 if (ac3_exponent_strategy) {
419 /* AC-3-style exponent strategy syntax */
420
2/2
✓ Branch 0 taken 196 times.
✓ Branch 1 taken 196 times.
392 for (blk = 0; blk < s->num_blocks; blk++) {
421
2/2
✓ Branch 0 taken 980 times.
✓ Branch 1 taken 196 times.
1176 for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422 980 s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423 }
424 }
425 } else {
426 /* LUT-based exponent strategy syntax */
427
5/6
✓ Branch 0 taken 1967 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1398 times.
✓ Branch 3 taken 569 times.
✓ Branch 4 taken 5429 times.
✓ Branch 5 taken 1967 times.
7396 for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428 5429 int frmchexpstr = get_bits(gbc, 5);
429
2/2
✓ Branch 0 taken 32574 times.
✓ Branch 1 taken 5429 times.
38003 for (blk = 0; blk < 6; blk++) {
430 32574 s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431 }
432 }
433 }
434 /* LFE exponent strategy */
435
2/2
✓ Branch 0 taken 292 times.
✓ Branch 1 taken 1871 times.
2163 if (s->lfe_on) {
436
2/2
✓ Branch 0 taken 772 times.
✓ Branch 1 taken 292 times.
1064 for (blk = 0; blk < s->num_blocks; blk++) {
437 772 s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438 }
439 }
440 /* original exponent strategies if this stream was converted from AC-3 */
441
2/2
✓ Branch 0 taken 1844 times.
✓ Branch 1 taken 319 times.
2163 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
4/4
✓ Branch 0 taken 196 times.
✓ Branch 1 taken 1648 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 164 times.
1844 (s->num_blocks == 6 || get_bits1(gbc))) {
443 1680 skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444 }
445
446 /* determine which channels use AHT */
447
2/2
✓ Branch 0 taken 891 times.
✓ Branch 1 taken 1272 times.
2163 if (parse_aht_info) {
448 /* For AHT to be used, all non-zero blocks must reuse exponents from
449 the first block. Furthermore, for AHT to be used in the coupling
450 channel, all blocks must use coupling and use the same coupling
451 strategy. */
452 891 s->channel_uses_aht[CPL_CH]=0;
453
2/2
✓ Branch 0 taken 2166 times.
✓ Branch 1 taken 891 times.
3057 for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454 2166 int use_aht = 1;
455
2/2
✓ Branch 0 taken 9418 times.
✓ Branch 1 taken 1622 times.
11040 for (blk = 1; blk < 6; blk++) {
456
3/4
✓ Branch 0 taken 8874 times.
✓ Branch 1 taken 544 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8874 times.
9418 if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457 (!ch && s->cpl_strategy_exists[blk])) {
458 544 use_aht = 0;
459 544 break;
460 }
461 }
462
3/4
✓ Branch 0 taken 1622 times.
✓ Branch 1 taken 544 times.
✓ Branch 3 taken 1622 times.
✗ Branch 4 not taken.
2166 s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463 }
464 } else {
465 1272 memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466 }
467
468 /* per-frame SNR offset */
469
1/2
✓ Branch 0 taken 2163 times.
✗ Branch 1 not taken.
2163 if (!s->snr_offset_strategy) {
470 2163 int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471 2163 int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
2/2
✓ Branch 0 taken 8295 times.
✓ Branch 1 taken 2163 times.
10458 for (ch = 0; ch <= s->channels; ch++)
473 8295 s->snr_offset[ch] = snroffst;
474 }
475
476 /* transient pre-noise processing data */
477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2163 times.
2163 if (parse_transient_proc_info) {
478 for (ch = 1; ch <= s->fbw_channels; ch++) {
479 if (get_bits1(gbc)) { // channel in transient processing
480 skip_bits(gbc, 10); // skip transient processing location
481 skip_bits(gbc, 8); // skip transient processing length
482 }
483 }
484 }
485
486 /* spectral extension attenuation data */
487
2/2
✓ Branch 0 taken 5840 times.
✓ Branch 1 taken 2163 times.
8003 for (ch = 1; ch <= s->fbw_channels; ch++) {
488
4/4
✓ Branch 0 taken 2446 times.
✓ Branch 1 taken 3394 times.
✓ Branch 3 taken 2100 times.
✓ Branch 4 taken 346 times.
5840 if (parse_spx_atten_data && get_bits1(gbc)) {
489 2100 s->spx_atten_code[ch] = get_bits(gbc, 5);
490 } else {
491 3740 s->spx_atten_code[ch] = -1;
492 }
493 }
494
495 /* block start information */
496
3/4
✓ Branch 0 taken 1967 times.
✓ Branch 1 taken 196 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1967 times.
2163 if (s->num_blocks > 1 && get_bits1(gbc)) {
497 /* reference: Section E2.3.2.27
498 nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
499 The spec does not say what this data is or what it's used for.
500 It is likely the offset of each block within the frame. */
501 int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502 skip_bits_long(gbc, block_start_bits);
503 avpriv_request_sample(s->avctx, "Block start info");
504 }
505
506 /* syntax state initialization */
507
2/2
✓ Branch 0 taken 5840 times.
✓ Branch 1 taken 2163 times.
8003 for (ch = 1; ch <= s->fbw_channels; ch++) {
508 5840 s->first_spx_coords[ch] = 1;
509 5840 s->first_cpl_coords[ch] = 1;
510 }
511 2163 s->first_cpl_leak = 1;
512
513 2163 return 0;
514 }
515