FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac/aacdec.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 969 1331 72.8%
Functions: 44 46 95.7%
Branches: 628 993 63.2%

Line Branch Exec Source
1 /*
2 * Common parts of the AAC decoders
3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
5 * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com>
6 *
7 * AAC LATM decoder
8 * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
9 * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net>
10 *
11 * AAC decoder fixed-point implementation
12 * Copyright (c) 2013
13 * MIPS Technologies, Inc., California.
14 *
15 * This file is part of FFmpeg.
16 *
17 * FFmpeg is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * FFmpeg is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with FFmpeg; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 */
31
32 /* We use several quantization functions here (Q31, Q30),
33 * for which we need this to be defined for them to work as expected. */
34 #define USE_FIXED 1
35
36 #include "config_components.h"
37
38 #include <limits.h>
39 #include <stddef.h>
40
41 #include "aacdec.h"
42 #include "aacdec_tab.h"
43 #include "aacdec_usac.h"
44
45 #include "libavcodec/aac.h"
46 #include "libavcodec/aac_defines.h"
47 #include "libavcodec/aacsbr.h"
48 #include "libavcodec/aactab.h"
49 #include "libavcodec/adts_header.h"
50
51 #include "libavcodec/avcodec.h"
52 #include "libavcodec/internal.h"
53 #include "libavcodec/codec_internal.h"
54 #include "libavcodec/decode.h"
55 #include "libavcodec/profiles.h"
56
57 #include "libavutil/attributes.h"
58 #include "libavutil/error.h"
59 #include "libavutil/log.h"
60 #include "libavutil/macros.h"
61 #include "libavutil/mem.h"
62 #include "libavutil/opt.h"
63 #include "libavutil/tx.h"
64 #include "libavutil/version.h"
65
66 /*
67 * supported tools
68 *
69 * Support? Name
70 * N (code in SoC repo) gain control
71 * Y block switching
72 * Y window shapes - standard
73 * N window shapes - Low Delay
74 * Y filterbank - standard
75 * N (code in SoC repo) filterbank - Scalable Sample Rate
76 * Y Temporal Noise Shaping
77 * Y Long Term Prediction
78 * Y intensity stereo
79 * Y channel coupling
80 * Y frequency domain prediction
81 * Y Perceptual Noise Substitution
82 * Y Mid/Side stereo
83 * N Scalable Inverse AAC Quantization
84 * N Frequency Selective Switch
85 * N upsampling filter
86 * Y quantization & coding - AAC
87 * N quantization & coding - TwinVQ
88 * N quantization & coding - BSAC
89 * N AAC Error Resilience tools
90 * N Error Resilience payload syntax
91 * N Error Protection tool
92 * N CELP
93 * N Silence Compression
94 * N HVXC
95 * N HVXC 4kbits/s VR
96 * N Structured Audio tools
97 * N Structured Audio Sample Bank Format
98 * N MIDI
99 * N Harmonic and Individual Lines plus Noise
100 * N Text-To-Speech Interface
101 * Y Spectral Band Replication
102 * Y (not in this code) Layer-1
103 * Y (not in this code) Layer-2
104 * Y (not in this code) Layer-3
105 * N SinuSoidal Coding (Transient, Sinusoid, Noise)
106 * Y Parametric Stereo
107 * N Direct Stream Transfer
108 * Y (not in fixed point code) Enhanced AAC Low Delay (ER AAC ELD)
109 *
110 * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication.
111 * - HE AAC v2 comprises LC AAC with Spectral Band Replication and
112 Parametric Stereo.
113 */
114
115 #define overread_err "Input buffer exhausted before END element found\n"
116
117 549 static int count_channels(uint8_t (*layout)[3], int tags)
118 {
119 549 int i, sum = 0;
120
2/2
✓ Branch 0 taken 1111 times.
✓ Branch 1 taken 549 times.
1660 for (i = 0; i < tags; i++) {
121 1111 int syn_ele = layout[i][0];
122 1111 int pos = layout[i][2];
123
2/2
✓ Branch 0 taken 635 times.
✓ Branch 1 taken 476 times.
2222 sum += (1 + (syn_ele == TYPE_CPE)) *
124
3/4
✓ Branch 0 taken 1111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1103 times.
✓ Branch 3 taken 8 times.
1111 (pos != AAC_CHANNEL_OFF && pos != AAC_CHANNEL_CC);
125 }
126 549 return sum;
127 }
128
129 /**
130 * Check for the channel element in the current channel position configuration.
131 * If it exists, make sure the appropriate element is allocated and map the
132 * channel order to match the internal FFmpeg channel layout.
133 *
134 * @param che_pos current channel position configuration
135 * @param type channel element type
136 * @param id channel element id
137 * @param channels count of the number of channels in the configuration
138 *
139 * @return Returns error status. 0 - OK, !0 - error
140 */
141 8492 static av_cold int che_configure(AACDecContext *ac,
142 enum ChannelPosition che_pos,
143 int type, int id, int *channels)
144 {
145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8492 times.
8492 if (*channels >= MAX_CHANNELS)
146 return AVERROR_INVALIDDATA;
147
1/2
✓ Branch 0 taken 8492 times.
✗ Branch 1 not taken.
8492 if (che_pos) {
148
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 8119 times.
8492 if (!ac->che[type][id]) {
149 373 int ret = ac->proc.sbr_ctx_alloc_init(ac, &ac->che[type][id], type);
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 373 times.
373 if (ret < 0)
151 return ret;
152 }
153
2/2
✓ Branch 0 taken 8484 times.
✓ Branch 1 taken 8 times.
8492 if (type != TYPE_CCE) {
154
7/8
✓ Branch 0 taken 842 times.
✓ Branch 1 taken 7642 times.
✓ Branch 2 taken 775 times.
✓ Branch 3 taken 67 times.
✓ Branch 4 taken 366 times.
✓ Branch 5 taken 409 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 8484 times.
8484 if (*channels >= MAX_CHANNELS - (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))) {
155 av_log(ac->avctx, AV_LOG_ERROR, "Too many channels\n");
156 return AVERROR_INVALIDDATA;
157 }
158 8484 ac->output_element[(*channels)++] = &ac->che[type][id]->ch[0];
159
4/4
✓ Branch 0 taken 842 times.
✓ Branch 1 taken 7642 times.
✓ Branch 2 taken 775 times.
✓ Branch 3 taken 67 times.
8484 if (type == TYPE_CPE ||
160
2/2
✓ Branch 0 taken 366 times.
✓ Branch 1 taken 409 times.
775 (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1)) {
161 8008 ac->output_element[(*channels)++] = &ac->che[type][id]->ch[1];
162 }
163 }
164 } else {
165 if (ac->che[type][id]) {
166 ac->proc.sbr_ctx_close(ac->che[type][id]);
167 }
168 av_freep(&ac->che[type][id]);
169 }
170 8492 return 0;
171 }
172
173 54000 static int frame_configure_elements(AVCodecContext *avctx)
174 {
175 54000 AACDecContext *ac = avctx->priv_data;
176 int type, id, ch, ret;
177
178 /* set channel pointers to internal buffers by default */
179
2/2
✓ Branch 0 taken 216000 times.
✓ Branch 1 taken 54000 times.
270000 for (type = 0; type < 4; type++) {
180
2/2
✓ Branch 0 taken 13824000 times.
✓ Branch 1 taken 216000 times.
14040000 for (id = 0; id < MAX_ELEM_ID; id++) {
181 13824000 ChannelElement *che = ac->che[type][id];
182
2/2
✓ Branch 0 taken 67380 times.
✓ Branch 1 taken 13756620 times.
13824000 if (che) {
183 67380 che->ch[0].output = che->ch[0].ret_buf;
184 67380 che->ch[1].output = che->ch[1].ret_buf;
185 }
186 }
187 }
188
189 /* get output buffer */
190 54000 av_frame_unref(ac->frame);
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54000 times.
54000 if (!avctx->ch_layout.nb_channels)
192 return 1;
193
194 54000 ac->frame->nb_samples = 2048;
195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 54000 times.
54000 if ((ret = ff_get_buffer(avctx, ac->frame, 0)) < 0)
196 return ret;
197
198 /* map output channel pointers to AVFrame data */
199
2/2
✓ Branch 0 taken 102541 times.
✓ Branch 1 taken 54000 times.
156541 for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
200
1/2
✓ Branch 0 taken 102541 times.
✗ Branch 1 not taken.
102541 if (ac->output_element[ch])
201 102541 ac->output_element[ch]->output = (void *)ac->frame->extended_data[ch];
202 }
203
204 54000 return 0;
205 }
206
207 struct elem_to_channel {
208 uint64_t av_position;
209 uint8_t syn_ele;
210 uint8_t elem_id;
211 uint8_t aac_position;
212 };
213
214 7646 static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID],
215 uint8_t (*layout_map)[3], int offset, uint64_t left,
216 uint64_t right, int pos, uint64_t *layout)
217 {
218
2/2
✓ Branch 0 taken 7642 times.
✓ Branch 1 taken 4 times.
7646 if (layout_map[offset][0] == TYPE_CPE) {
219 7642 e2c_vec[offset] = (struct elem_to_channel) {
220 7642 .av_position = left | right,
221 .syn_ele = TYPE_CPE,
222 7642 .elem_id = layout_map[offset][1],
223 .aac_position = pos
224 };
225
1/2
✓ Branch 0 taken 7642 times.
✗ Branch 1 not taken.
7642 if (e2c_vec[offset].av_position != UINT64_MAX)
226 7642 *layout |= e2c_vec[offset].av_position;
227
228 7642 return 1;
229 } else {
230 4 e2c_vec[offset] = (struct elem_to_channel) {
231 .av_position = left,
232 .syn_ele = TYPE_SCE,
233 4 .elem_id = layout_map[offset][1],
234 .aac_position = pos
235 };
236 4 e2c_vec[offset + 1] = (struct elem_to_channel) {
237 .av_position = right,
238 .syn_ele = TYPE_SCE,
239 4 .elem_id = layout_map[offset + 1][1],
240 .aac_position = pos
241 };
242
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (left != UINT64_MAX)
243 4 *layout |= left;
244
245
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (right != UINT64_MAX)
246 4 *layout |= right;
247
248 4 return 2;
249 }
250 }
251
252 33164 static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos,
253 int current)
254 {
255 33164 int num_pos_channels = 0;
256 33164 int first_cpe = 0;
257 33164 int sce_parity = 0;
258 int i;
259
2/2
✓ Branch 0 taken 8757 times.
✓ Branch 1 taken 32891 times.
41648 for (i = current; i < tags; i++) {
260
2/2
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 8484 times.
8757 if (layout_map[i][2] != pos)
261 273 break;
262
2/2
✓ Branch 0 taken 7642 times.
✓ Branch 1 taken 842 times.
8484 if (layout_map[i][0] == TYPE_CPE) {
263
2/2
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 7571 times.
7642 if (sce_parity) {
264
2/4
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
71 if (pos == AAC_CHANNEL_FRONT && !first_cpe) {
265 71 sce_parity = 0;
266 } else {
267 return -1;
268 }
269 }
270 7642 num_pos_channels += 2;
271 7642 first_cpe = 1;
272 } else {
273 842 num_pos_channels++;
274 842 sce_parity ^= (pos != AAC_CHANNEL_LFE);
275 }
276 }
277
3/4
✓ Branch 0 taken 696 times.
✓ Branch 1 taken 32468 times.
✓ Branch 2 taken 696 times.
✗ Branch 3 not taken.
33164 if (sce_parity &&
278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 696 times.
696 (pos == AAC_CHANNEL_FRONT && first_cpe))
279 return -1;
280
281 33164 return num_pos_channels;
282 }
283
284 33164 static int assign_channels(struct elem_to_channel e2c_vec[MAX_ELEM_ID], uint8_t (*layout_map)[3],
285 uint64_t *layout, int tags, int layer, int pos, int *current)
286 {
287 33164 int i = *current, j = 0;
288 33164 int nb_channels = count_paired_channels(layout_map, tags, pos, i);
289
290
2/4
✓ Branch 0 taken 33164 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33164 times.
33164 if (nb_channels < 0 || nb_channels > 5)
291 return 0;
292
293
2/2
✓ Branch 0 taken 8291 times.
✓ Branch 1 taken 24873 times.
33164 if (pos == AAC_CHANNEL_LFE) {
294
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 8291 times.
8358 while (nb_channels) {
295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (ff_aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE)
296 return -1;
297 67 e2c_vec[i] = (struct elem_to_channel) {
298 67 .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][j],
299 67 .syn_ele = layout_map[i][0],
300 67 .elem_id = layout_map[i][1],
301 .aac_position = pos
302 };
303 67 *layout |= e2c_vec[i].av_position;
304 67 i++;
305 67 j++;
306 67 nb_channels--;
307 }
308 8291 *current = i;
309
310 8291 return 0;
311 }
312
313
2/2
✓ Branch 0 taken 767 times.
✓ Branch 1 taken 24873 times.
25640 while (nb_channels & 1) {
314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 767 times.
767 if (ff_aac_channel_map[layer][pos - 1][0] == AV_CHAN_NONE)
315 return -1;
316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 767 times.
767 if (ff_aac_channel_map[layer][pos - 1][0] == AV_CHAN_UNUSED)
317 break;
318 767 e2c_vec[i] = (struct elem_to_channel) {
319 767 .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][0],
320 767 .syn_ele = layout_map[i][0],
321 767 .elem_id = layout_map[i][1],
322 .aac_position = pos
323 };
324 767 *layout |= e2c_vec[i].av_position;
325 767 i++;
326 767 nb_channels--;
327 }
328
329
4/4
✓ Branch 0 taken 16582 times.
✓ Branch 1 taken 8291 times.
✓ Branch 2 taken 16574 times.
✓ Branch 3 taken 8 times.
24873 j = (pos != AAC_CHANNEL_SIDE) && nb_channels <= 3 ? 3 : 1;
330
2/2
✓ Branch 0 taken 7646 times.
✓ Branch 1 taken 24873 times.
32519 while (nb_channels >= 2) {
331
1/2
✓ Branch 0 taken 7646 times.
✗ Branch 1 not taken.
7646 if (ff_aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE ||
332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7646 times.
7646 ff_aac_channel_map[layer][pos - 1][j+1] == AV_CHAN_NONE)
333 return -1;
334 15292 i += assign_pair(e2c_vec, layout_map, i,
335 7646 1ULL << ff_aac_channel_map[layer][pos - 1][j],
336 7646 1ULL << ff_aac_channel_map[layer][pos - 1][j+1],
337 pos, layout);
338 7646 j += 2;
339 7646 nb_channels -= 2;
340 }
341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24873 times.
24873 while (nb_channels & 1) {
342 if (ff_aac_channel_map[layer][pos - 1][5] == AV_CHAN_NONE)
343 return -1;
344 e2c_vec[i] = (struct elem_to_channel) {
345 .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][5],
346 .syn_ele = layout_map[i][0],
347 .elem_id = layout_map[i][1],
348 .aac_position = pos
349 };
350 *layout |= e2c_vec[i].av_position;
351 i++;
352 nb_channels--;
353 }
354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24873 times.
24873 if (nb_channels)
355 return -1;
356
357 24873 *current = i;
358
359 24873 return 0;
360 }
361
362 8275 static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
363 {
364 int i, n, total_non_cc_elements;
365 8275 struct elem_to_channel e2c_vec[4 * MAX_ELEM_ID] = { { 0 } };
366 8275 uint64_t layout = 0;
367
368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8275 times.
8275 if (FF_ARRAY_ELEMS(e2c_vec) < tags)
369 return 0;
370
371
4/4
✓ Branch 0 taken 16558 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8291 times.
✓ Branch 3 taken 8267 times.
16566 for (n = 0, i = 0; n < 3 && i < tags; n++) {
372 8291 int ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_FRONT, &i);
373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8291 times.
8291 if (ret < 0)
374 return 0;
375 8291 ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_SIDE, &i);
376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8291 times.
8291 if (ret < 0)
377 return 0;
378 8291 ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_BACK, &i);
379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8291 times.
8291 if (ret < 0)
380 return 0;
381 8291 ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_LFE, &i);
382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8291 times.
8291 if (ret < 0)
383 return 0;
384 }
385
386 8275 total_non_cc_elements = n = i;
387
388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8275 times.
8275 if (layout == AV_CH_LAYOUT_22POINT2) {
389 // For 22.2 reorder the result as needed
390 FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[0]); // FL & FR first (final), FC third
391 FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[1]); // FC second (final), FLc & FRc third
392 FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[2]); // LFE1 third (final), FLc & FRc seventh
393 FFSWAP(struct elem_to_channel, e2c_vec[4], e2c_vec[3]); // BL & BR fourth (final), SiL & SiR fifth
394 FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[4]); // FLc & FRc fifth (final), SiL & SiR seventh
395 FFSWAP(struct elem_to_channel, e2c_vec[7], e2c_vec[6]); // LFE2 seventh (final), SiL & SiR eight (final)
396 FFSWAP(struct elem_to_channel, e2c_vec[9], e2c_vec[8]); // TpFL & TpFR ninth (final), TFC tenth (final)
397 FFSWAP(struct elem_to_channel, e2c_vec[11], e2c_vec[10]); // TC eleventh (final), TpSiL & TpSiR twelth
398 FFSWAP(struct elem_to_channel, e2c_vec[12], e2c_vec[11]); // TpBL & TpBR twelth (final), TpSiL & TpSiR thirteenth (final)
399 } else {
400 // For everything else, utilize the AV channel position define as a
401 // stable sort.
402 do {
403 8354 int next_n = 0;
404
2/2
✓ Branch 0 taken 343 times.
✓ Branch 1 taken 8354 times.
8697 for (i = 1; i < n; i++)
405
2/2
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 197 times.
343 if (e2c_vec[i - 1].av_position > e2c_vec[i].av_position) {
406 146 FFSWAP(struct elem_to_channel, e2c_vec[i - 1], e2c_vec[i]);
407 146 next_n = i;
408 }
409 8354 n = next_n;
410
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 8275 times.
8354 } while (n > 0);
411
412 }
413
414
2/2
✓ Branch 0 taken 8484 times.
✓ Branch 1 taken 8275 times.
16759 for (i = 0; i < total_non_cc_elements; i++) {
415 8484 layout_map[i][0] = e2c_vec[i].syn_ele;
416 8484 layout_map[i][1] = e2c_vec[i].elem_id;
417 8484 layout_map[i][2] = e2c_vec[i].aac_position;
418 }
419
420 8275 return layout;
421 }
422
423 /**
424 * Save current output configuration if and only if it has been locked.
425 */
426 4121 static int push_output_configuration(AACDecContext *ac)
427 {
428 4121 int pushed = 0;
429
430
3/4
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 4059 times.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
4121 if (ac->oc[1].status == OC_LOCKED || ac->oc[0].status == OC_NONE) {
431 4121 ac->oc[0] = ac->oc[1];
432 4121 pushed = 1;
433 }
434 4121 ac->oc[1].status = OC_NONE;
435 4121 return pushed;
436 }
437
438 /**
439 * Restore the previous output configuration if and only if the current
440 * configuration is unlocked.
441 */
442 static void pop_output_configuration(AACDecContext *ac)
443 {
444 if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) {
445 ac->oc[1] = ac->oc[0];
446 ac->avctx->ch_layout = ac->oc[1].ch_layout;
447 ff_aac_output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags,
448 ac->oc[1].status, 0);
449 }
450 }
451
452 /**
453 * Configure output channel order based on the current program
454 * configuration element.
455 *
456 * @return Returns error status. 0 - OK, !0 - error
457 */
458 8275 int ff_aac_output_configure(AACDecContext *ac,
459 uint8_t layout_map[MAX_ELEM_ID * 4][3], int tags,
460 enum OCStatus oc_type, int get_new_frame)
461 {
462 8275 AVCodecContext *avctx = ac->avctx;
463 8275 int i, channels = 0, ret;
464 8275 uint64_t layout = 0;
465 8275 uint8_t id_map[TYPE_END][MAX_ELEM_ID] = {{ 0 }};
466 8275 uint8_t type_counts[TYPE_END] = { 0 };
467
468
2/2
✓ Branch 0 taken 4379 times.
✓ Branch 1 taken 3896 times.
8275 if (ac->oc[1].layout_map != layout_map) {
469 4379 memcpy(ac->oc[1].layout_map, layout_map, tags * sizeof(layout_map[0]));
470 4379 ac->oc[1].layout_map_tags = tags;
471 }
472
2/2
✓ Branch 0 taken 8492 times.
✓ Branch 1 taken 8275 times.
16767 for (i = 0; i < tags; i++) {
473 8492 int type = layout_map[i][0];
474 8492 int id = layout_map[i][1];
475 8492 id_map[type][id] = type_counts[type]++;
476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8492 times.
8492 if (id_map[type][id] >= MAX_ELEM_ID) {
477 avpriv_request_sample(ac->avctx, "Too large remapped id");
478 return AVERROR_PATCHWELCOME;
479 }
480 }
481 // Try to sniff a reasonable channel order, otherwise output the
482 // channels in the order the PCE declared them.
483
1/2
✓ Branch 0 taken 8275 times.
✗ Branch 1 not taken.
8275 if (ac->output_channel_order == CHANNEL_ORDER_DEFAULT)
484 8275 layout = sniff_channel_order(layout_map, tags);
485
2/2
✓ Branch 0 taken 8492 times.
✓ Branch 1 taken 8275 times.
16767 for (i = 0; i < tags; i++) {
486 8492 int type = layout_map[i][0];
487 8492 int id = layout_map[i][1];
488 8492 int iid = id_map[type][id];
489 8492 int position = layout_map[i][2];
490 // Allocate or free elements depending on if they are in the
491 // current program configuration.
492 8492 ret = che_configure(ac, position, type, iid, &channels);
493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8492 times.
8492 if (ret < 0)
494 return ret;
495 8492 ac->tag_che_map[type][id] = ac->che[type][iid];
496 }
497
3/4
✓ Branch 0 taken 366 times.
✓ Branch 1 taken 7909 times.
✓ Branch 2 taken 366 times.
✗ Branch 3 not taken.
8275 if (ac->oc[1].m4ac.ps == 1 && channels == 2) {
498
1/2
✓ Branch 0 taken 366 times.
✗ Branch 1 not taken.
366 if (layout == AV_CH_FRONT_CENTER) {
499 366 layout = AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT;
500 } else {
501 layout = 0;
502 }
503 }
504
505 8275 av_channel_layout_uninit(&ac->oc[1].ch_layout);
506
1/2
✓ Branch 0 taken 8275 times.
✗ Branch 1 not taken.
8275 if (layout)
507 8275 av_channel_layout_from_mask(&ac->oc[1].ch_layout, layout);
508 else {
509 ac->oc[1].ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
510 ac->oc[1].ch_layout.nb_channels = channels;
511 }
512
513 8275 av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout);
514 8275 ac->oc[1].status = oc_type;
515
516
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8263 times.
8275 if (get_new_frame) {
517
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if ((ret = frame_configure_elements(ac->avctx)) < 0)
518 return ret;
519 }
520
521 8275 return 0;
522 }
523
524 9 static av_cold void flush(AVCodecContext *avctx)
525 {
526 9 AACDecContext *ac= avctx->priv_data;
527 int type, i, j;
528
529
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for (type = 3; type >= 0; type--) {
530
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 36 times.
2340 for (i = 0; i < MAX_ELEM_ID; i++) {
531 2304 ChannelElement *che = ac->che[type][i];
532
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2295 times.
2304 if (che) {
533
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for (j = 0; j <= 1; j++) {
534 18 memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved));
535 }
536 }
537 }
538 }
539
540 9 ff_aac_usac_reset_state(ac, &ac->oc[1]);
541 9 }
542
543 /**
544 * Set up channel positions based on a default channel configuration
545 * as specified in table 1.17.
546 *
547 * @return Returns error status. 0 - OK, !0 - error
548 */
549 4658 int ff_aac_set_default_channel_config(AACDecContext *ac, AVCodecContext *avctx,
550 uint8_t (*layout_map)[3],
551 int *tags,
552 int channel_config)
553 {
554
3/8
✓ Branch 0 taken 4658 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4658 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4658 times.
4658 if (channel_config < 1 || (channel_config > 7 && channel_config < 11) ||
555 channel_config > 14) {
556 av_log(avctx, AV_LOG_ERROR,
557 "invalid default channel configuration (%d)\n",
558 channel_config);
559 return AVERROR_INVALIDDATA;
560 }
561 4658 *tags = ff_tags_per_config[channel_config];
562 4658 memcpy(layout_map, ff_aac_channel_layout_map[channel_config - 1],
563 4658 *tags * sizeof(*layout_map));
564
565 /*
566 * AAC specification has 7.1(wide) as a default layout for 8-channel streams.
567 * However, at least Nero AAC encoder encodes 7.1 streams using the default
568 * channel config 7, mapping the side channels of the original audio stream
569 * to the second AAC_CHANNEL_FRONT pair in the AAC stream. Similarly, e.g. FAAD
570 * decodes the second AAC_CHANNEL_FRONT pair as side channels, therefore decoding
571 * the incorrect streams as if they were correct (and as the encoder intended).
572 *
573 * As actual intended 7.1(wide) streams are very rare, default to assuming a
574 * 7.1 layout was intended.
575 */
576
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4658 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4658 if (channel_config == 7 && avctx->strict_std_compliance < FF_COMPLIANCE_STRICT) {
577 layout_map[2][2] = AAC_CHANNEL_BACK;
578
579 if (!ac || !ac->warned_71_wide++) {
580 av_log(avctx, AV_LOG_INFO, "Assuming an incorrectly encoded 7.1 channel layout"
581 " instead of a spec-compliant 7.1(wide) layout, use -strict %d to decode"
582 " according to the specification instead.\n", FF_COMPLIANCE_STRICT);
583 }
584 }
585
586 4658 return 0;
587 }
588
589 67038 ChannelElement *ff_aac_get_che(AACDecContext *ac, int type, int elem_id)
590 {
591 /* For PCE based channel configurations map the channels solely based
592 * on tags. */
593
2/2
✓ Branch 0 taken 24124 times.
✓ Branch 1 taken 42914 times.
67038 if (!ac->oc[1].m4ac.chan_config) {
594 24124 return ac->tag_che_map[type][elem_id];
595 }
596 // Allow single CPE stereo files to be signalled with mono configuration.
597
4/4
✓ Branch 0 taken 40454 times.
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 24528 times.
✓ Branch 3 taken 15926 times.
42914 if (!ac->tags_mapped && type == TYPE_CPE &&
598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24528 times.
24528 ac->oc[1].m4ac.chan_config == 1) {
599 uint8_t layout_map[MAX_ELEM_ID*4][3];
600 int layout_map_tags;
601 push_output_configuration(ac);
602
603 av_log(ac->avctx, AV_LOG_DEBUG, "mono with CPE\n");
604
605 if (ff_aac_set_default_channel_config(ac, ac->avctx, layout_map,
606 &layout_map_tags, 2) < 0)
607 return NULL;
608 if (ff_aac_output_configure(ac, layout_map, layout_map_tags,
609 OC_TRIAL_FRAME, 1) < 0)
610 return NULL;
611
612 ac->oc[1].m4ac.chan_config = 2;
613 ac->oc[1].m4ac.ps = 0;
614 }
615 // And vice-versa
616
4/4
✓ Branch 0 taken 40454 times.
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 15926 times.
✓ Branch 3 taken 24528 times.
42914 if (!ac->tags_mapped && type == TYPE_SCE &&
617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15926 times.
15926 ac->oc[1].m4ac.chan_config == 2) {
618 uint8_t layout_map[MAX_ELEM_ID * 4][3];
619 int layout_map_tags;
620 push_output_configuration(ac);
621
622 av_log(ac->avctx, AV_LOG_DEBUG, "stereo with SCE\n");
623
624 layout_map_tags = 2;
625 layout_map[0][0] = layout_map[1][0] = TYPE_SCE;
626 layout_map[0][2] = layout_map[1][2] = AAC_CHANNEL_FRONT;
627 layout_map[0][1] = 0;
628 layout_map[1][1] = 1;
629 if (ff_aac_output_configure(ac, layout_map, layout_map_tags,
630 OC_TRIAL_FRAME, 1) < 0)
631 return NULL;
632
633 if (ac->oc[1].m4ac.sbr)
634 ac->oc[1].m4ac.ps = -1;
635 }
636 /* For indexed channel configurations map the channels solely based
637 * on position. */
638
3/10
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3280 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 24528 times.
✓ Branch 8 taken 15106 times.
✗ Branch 9 not taken.
42914 switch (ac->oc[1].m4ac.chan_config) {
639 case 14:
640 if (ac->tags_mapped > 2 && ((type == TYPE_CPE && elem_id < 3) ||
641 (type == TYPE_LFE && elem_id < 1))) {
642 ac->tags_mapped++;
643 return ac->tag_che_map[type][elem_id] = ac->che[type][elem_id];
644 }
645 case 13:
646 if (ac->tags_mapped > 3 && ((type == TYPE_CPE && elem_id < 8) ||
647 (type == TYPE_SCE && elem_id < 6) ||
648 (type == TYPE_LFE && elem_id < 2))) {
649 ac->tags_mapped++;
650 return ac->tag_che_map[type][elem_id] = ac->che[type][elem_id];
651 }
652 case 12:
653 case 7:
654 if (ac->tags_mapped == 3 && type == TYPE_CPE) {
655 ac->tags_mapped++;
656 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
657 }
658 case 11:
659 if (ac->tags_mapped == 3 && type == TYPE_SCE) {
660 ac->tags_mapped++;
661 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
662 }
663 case 6:
664 /* Some streams incorrectly code 5.1 audio as
665 * SCE[0] CPE[0] CPE[1] SCE[1]
666 * instead of
667 * SCE[0] CPE[0] CPE[1] LFE[0].
668 * If we seem to have encountered such a stream, transfer
669 * the LFE[0] element to the SCE[1]'s mapping */
670
3/6
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2460 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 820 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3280 if (ac->tags_mapped == ff_tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
671
3/6
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 820 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 820 times.
820 if (!ac->warned_remapping_once && (type != TYPE_LFE || elem_id != 0)) {
672 av_log(ac->avctx, AV_LOG_WARNING,
673 "This stream seems to incorrectly report its last channel as %s[%d], mapping to LFE[0]\n",
674 type == TYPE_SCE ? "SCE" : "LFE", elem_id);
675 ac->warned_remapping_once++;
676 }
677 820 ac->tags_mapped++;
678 820 return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
679 }
680 case 5:
681
3/4
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 1640 times.
✓ Branch 2 taken 820 times.
✗ Branch 3 not taken.
2460 if (ac->tags_mapped == 2 && type == TYPE_CPE) {
682 820 ac->tags_mapped++;
683 820 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
684 }
685 case 4:
686 /* Some streams incorrectly code 4.0 audio as
687 * SCE[0] CPE[0] LFE[0]
688 * instead of
689 * SCE[0] CPE[0] SCE[1].
690 * If we seem to have encountered such a stream, transfer
691 * the SCE[1] element to the LFE[0]'s mapping */
692
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1640 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1640 if (ac->tags_mapped == ff_tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
693 if (!ac->warned_remapping_once && (type != TYPE_SCE || elem_id != 1)) {
694 av_log(ac->avctx, AV_LOG_WARNING,
695 "This stream seems to incorrectly report its last channel as %s[%d], mapping to SCE[1]\n",
696 type == TYPE_SCE ? "SCE" : "LFE", elem_id);
697 ac->warned_remapping_once++;
698 }
699 ac->tags_mapped++;
700 return ac->tag_che_map[type][elem_id] = ac->che[TYPE_SCE][1];
701 }
702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1640 times.
1640 if (ac->tags_mapped == 2 &&
703 ac->oc[1].m4ac.chan_config == 4 &&
704 type == TYPE_SCE) {
705 ac->tags_mapped++;
706 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
707 }
708 case 3:
709 case 2:
710
3/4
✓ Branch 0 taken 25348 times.
✓ Branch 1 taken 820 times.
✓ Branch 2 taken 25348 times.
✗ Branch 3 not taken.
26168 if (ac->tags_mapped == (ac->oc[1].m4ac.chan_config != 2) &&
711 type == TYPE_CPE) {
712 25348 ac->tags_mapped++;
713 25348 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
714
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 820 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
820 } else if (ac->tags_mapped == 1 && ac->oc[1].m4ac.chan_config == 2 &&
715 type == TYPE_SCE) {
716 ac->tags_mapped++;
717 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
718 }
719 case 1:
720
2/4
✓ Branch 0 taken 15926 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15926 times.
✗ Branch 3 not taken.
15926 if (!ac->tags_mapped && type == TYPE_SCE) {
721 15926 ac->tags_mapped++;
722 15926 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
723 }
724 default:
725 return NULL;
726 }
727 }
728
729 /**
730 * Decode an array of 4 bit element IDs, optionally interleaved with a
731 * stereo/mono switching bit.
732 *
733 * @param type speaker type/position for these channels
734 */
735 215 static void decode_channel_map(uint8_t layout_map[][3],
736 enum ChannelPosition type,
737 GetBitContext *gb, int n)
738 {
739
2/2
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 215 times.
310 while (n--) {
740 enum RawDataBlockType syn_ele;
741
3/4
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
95 switch (type) {
742 75 case AAC_CHANNEL_FRONT:
743 case AAC_CHANNEL_BACK:
744 case AAC_CHANNEL_SIDE:
745 75 syn_ele = get_bits1(gb);
746 75 break;
747 8 case AAC_CHANNEL_CC:
748 8 skip_bits1(gb);
749 8 syn_ele = TYPE_CCE;
750 8 break;
751 12 case AAC_CHANNEL_LFE:
752 12 syn_ele = TYPE_LFE;
753 12 break;
754 default:
755 // AAC_CHANNEL_OFF has no channel map
756 av_assert0(0);
757 }
758 95 layout_map[0][0] = syn_ele;
759 95 layout_map[0][1] = get_bits(gb, 4);
760 95 layout_map[0][2] = type;
761 95 layout_map++;
762 }
763 215 }
764
765 43 static inline void relative_align_get_bits(GetBitContext *gb,
766 int reference_position) {
767 43 int n = (reference_position - get_bits_count(gb) & 7);
768
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 4 times.
43 if (n)
769 39 skip_bits(gb, n);
770 43 }
771
772 /**
773 * Decode program configuration element; reference: table 4.2.
774 *
775 * @return Returns error status. 0 - OK, !0 - error
776 */
777 43 static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
778 uint8_t (*layout_map)[3],
779 GetBitContext *gb, int byte_align_ref)
780 {
781 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
782 int sampling_index;
783 int comment_len;
784 int tags;
785
786 43 skip_bits(gb, 2); // object_type
787
788 43 sampling_index = get_bits(gb, 4);
789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (m4ac->sampling_index != sampling_index)
790 av_log(avctx, AV_LOG_WARNING,
791 "Sample rate index in program config element does not "
792 "match the sample rate index configured by the container.\n");
793
794 43 num_front = get_bits(gb, 4);
795 43 num_side = get_bits(gb, 4);
796 43 num_back = get_bits(gb, 4);
797 43 num_lfe = get_bits(gb, 2);
798 43 num_assoc_data = get_bits(gb, 3);
799 43 num_cc = get_bits(gb, 4);
800
801
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
43 if (get_bits1(gb))
802 skip_bits(gb, 4); // mono_mixdown_tag
803
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
43 if (get_bits1(gb))
804 skip_bits(gb, 4); // stereo_mixdown_tag
805
806
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
43 if (get_bits1(gb))
807 skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround
808
809
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
43 if (get_bits_left(gb) < 5 * (num_front + num_side + num_back + num_cc) + 4 *(num_lfe + num_assoc_data + num_cc)) {
810 av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err);
811 return -1;
812 }
813 43 decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front);
814 43 tags = num_front;
815 43 decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side);
816 43 tags += num_side;
817 43 decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back);
818 43 tags += num_back;
819 43 decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe);
820 43 tags += num_lfe;
821
822 43 skip_bits_long(gb, 4 * num_assoc_data);
823
824 43 decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc);
825 43 tags += num_cc;
826
827 43 relative_align_get_bits(gb, byte_align_ref);
828
829 /* comment field, first byte is length */
830 43 comment_len = get_bits(gb, 8) * 8;
831
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
43 if (get_bits_left(gb) < comment_len) {
832 av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err);
833 return AVERROR_INVALIDDATA;
834 }
835 43 skip_bits_long(gb, comment_len);
836 43 return tags;
837 }
838
839 /**
840 * Decode GA "General Audio" specific configuration; reference: table 4.1.
841 *
842 * @param ac pointer to AACDecContext, may be null
843 * @param avctx pointer to AVCCodecContext, used for logging
844 *
845 * @return Returns error status. 0 - OK, !0 - error
846 */
847 549 static int decode_ga_specific_config(AACDecContext *ac, AVCodecContext *avctx,
848 GetBitContext *gb,
849 int get_bit_alignment,
850 MPEG4AudioConfig *m4ac,
851 int channel_config)
852 {
853 int extension_flag, ret, ep_config, res_flags;
854 uint8_t layout_map[MAX_ELEM_ID*4][3];
855 549 int tags = 0;
856
857 549 m4ac->frame_length_short = get_bits1(gb);
858
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 547 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
549 if (m4ac->frame_length_short && m4ac->sbr == 1) {
859 avpriv_report_missing_feature(avctx, "SBR with 960 frame length");
860 if (ac) ac->warned_960_sbr = 1;
861 m4ac->sbr = 0;
862 m4ac->ps = 0;
863 }
864
865
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 549 times.
549 if (get_bits1(gb)) // dependsOnCoreCoder
866 skip_bits(gb, 14); // coreCoderDelay
867 549 extension_flag = get_bits1(gb);
868
869
1/2
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
549 if (m4ac->object_type == AOT_AAC_SCALABLE ||
870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 549 times.
549 m4ac->object_type == AOT_ER_AAC_SCALABLE)
871 skip_bits(gb, 3); // layerNr
872
873
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 506 times.
549 if (channel_config == 0) {
874 43 skip_bits(gb, 4); // element_instance_tag
875 43 tags = decode_pce(avctx, m4ac, layout_map, gb, get_bit_alignment);
876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (tags < 0)
877 return tags;
878 } else {
879
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 506 times.
506 if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map,
880 &tags, channel_config)))
881 return ret;
882 }
883
884
2/2
✓ Branch 1 taken 457 times.
✓ Branch 2 taken 92 times.
549 if (count_channels(layout_map, tags) > 1) {
885 457 m4ac->ps = 0;
886
4/4
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 16 times.
92 } else if (m4ac->sbr == 1 && m4ac->ps == -1)
887 18 m4ac->ps = 1;
888
889
3/4
✓ Branch 0 taken 227 times.
✓ Branch 1 taken 322 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 227 times.
549 if (ac && (ret = ff_aac_output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0)))
890 return ret;
891
892
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 545 times.
549 if (extension_flag) {
893
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 switch (m4ac->object_type) {
894 case AOT_ER_BSAC:
895 skip_bits(gb, 5); // numOfSubFrame
896 skip_bits(gb, 11); // layer_length
897 break;
898 4 case AOT_ER_AAC_LC:
899 case AOT_ER_AAC_LTP:
900 case AOT_ER_AAC_SCALABLE:
901 case AOT_ER_AAC_LD:
902 4 res_flags = get_bits(gb, 3);
903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (res_flags) {
904 avpriv_report_missing_feature(avctx,
905 "AAC data resilience (flags %x)",
906 res_flags);
907 return AVERROR_PATCHWELCOME;
908 }
909 4 break;
910 }
911 4 skip_bits1(gb); // extensionFlag3 (TBD in version 3)
912 }
913
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 545 times.
549 switch (m4ac->object_type) {
914 4 case AOT_ER_AAC_LC:
915 case AOT_ER_AAC_LTP:
916 case AOT_ER_AAC_SCALABLE:
917 case AOT_ER_AAC_LD:
918 4 ep_config = get_bits(gb, 2);
919
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ep_config) {
920 avpriv_report_missing_feature(avctx,
921 "epConfig %d", ep_config);
922 return AVERROR_PATCHWELCOME;
923 }
924 }
925 549 return 0;
926 }
927
928 10 static int decode_eld_specific_config(AACDecContext *ac, AVCodecContext *avctx,
929 GetBitContext *gb,
930 MPEG4AudioConfig *m4ac,
931 int channel_config)
932 {
933 int ret, ep_config, res_flags;
934 uint8_t layout_map[MAX_ELEM_ID*4][3];
935 10 int tags = 0;
936 10 const int ELDEXT_TERM = 0;
937
938 10 m4ac->ps = 0;
939 10 m4ac->sbr = 0;
940 10 m4ac->frame_length_short = get_bits1(gb);
941
942 10 res_flags = get_bits(gb, 3);
943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (res_flags) {
944 avpriv_report_missing_feature(avctx,
945 "AAC data resilience (flags %x)",
946 res_flags);
947 return AVERROR_PATCHWELCOME;
948 }
949
950
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (get_bits1(gb)) { // ldSbrPresentFlag
951 avpriv_report_missing_feature(avctx,
952 "Low Delay SBR");
953 return AVERROR_PATCHWELCOME;
954 }
955
956
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 while (get_bits(gb, 4) != ELDEXT_TERM) {
957 int len = get_bits(gb, 4);
958 if (len == 15)
959 len += get_bits(gb, 8);
960 if (len == 15 + 255)
961 len += get_bits(gb, 16);
962 if (get_bits_left(gb) < len * 8 + 4) {
963 av_log(avctx, AV_LOG_ERROR, overread_err);
964 return AVERROR_INVALIDDATA;
965 }
966 skip_bits_long(gb, 8 * len);
967 }
968
969
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map,
970 &tags, channel_config)))
971 return ret;
972
973
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
10 if (ac && (ret = ff_aac_output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0)))
974 return ret;
975
976 10 ep_config = get_bits(gb, 2);
977
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (ep_config) {
978 avpriv_report_missing_feature(avctx,
979 "epConfig %d", ep_config);
980 return AVERROR_PATCHWELCOME;
981 }
982 10 return 0;
983 }
984
985 /**
986 * Decode audio specific configuration; reference: table 1.13.
987 *
988 * @param ac pointer to AACDecContext, may be null
989 * @param avctx pointer to AVCCodecContext, used for logging
990 * @param m4ac pointer to MPEG4AudioConfig, used for parsing
991 * @param gb buffer holding an audio specific config
992 * @param get_bit_alignment relative alignment for byte align operations
993 * @param sync_extension look for an appended sync extension
994 *
995 * @return Returns error status or number of consumed bits. <0 - error
996 */
997 563 static int decode_audio_specific_config_gb(AACDecContext *ac,
998 AVCodecContext *avctx,
999 OutputConfiguration *oc,
1000 GetBitContext *gb,
1001 int get_bit_alignment,
1002 int sync_extension)
1003 {
1004 int i, ret;
1005 563 GetBitContext gbc = *gb;
1006 563 MPEG4AudioConfig *m4ac = &oc->m4ac;
1007 563 MPEG4AudioConfig m4ac_bak = *m4ac;
1008
1009
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 563 times.
563 if ((i = ff_mpeg4audio_get_config_gb(m4ac, &gbc, sync_extension, avctx)) < 0) {
1010 *m4ac = m4ac_bak;
1011 return AVERROR_INVALIDDATA;
1012 }
1013
1014
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 563 times.
563 if (m4ac->sampling_index > 12) {
1015 av_log(avctx, AV_LOG_ERROR,
1016 "invalid sampling rate index %d\n",
1017 m4ac->sampling_index);
1018 *m4ac = m4ac_bak;
1019 return AVERROR_INVALIDDATA;
1020 }
1021
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 559 times.
563 if (m4ac->object_type == AOT_ER_AAC_LD &&
1022
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 (m4ac->sampling_index < 3 || m4ac->sampling_index > 7)) {
1023 av_log(avctx, AV_LOG_ERROR,
1024 "invalid low delay sampling rate index %d\n",
1025 m4ac->sampling_index);
1026 *m4ac = m4ac_bak;
1027 return AVERROR_INVALIDDATA;
1028 }
1029
1030 563 skip_bits_long(gb, i);
1031
1032
3/4
✓ Branch 0 taken 549 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
563 switch (m4ac->object_type) {
1033 549 case AOT_AAC_MAIN:
1034 case AOT_AAC_LC:
1035 case AOT_AAC_SSR:
1036 case AOT_AAC_LTP:
1037 case AOT_ER_AAC_LC:
1038 case AOT_ER_AAC_LD:
1039
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 549 times.
549 if ((ret = decode_ga_specific_config(ac, avctx, gb, get_bit_alignment,
1040 &oc->m4ac, m4ac->chan_config)) < 0)
1041 return ret;
1042 549 break;
1043 10 case AOT_ER_AAC_ELD:
1044
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if ((ret = decode_eld_specific_config(ac, avctx, gb,
1045 &oc->m4ac, m4ac->chan_config)) < 0)
1046 return ret;
1047 10 break;
1048 #if CONFIG_AAC_DECODER
1049 4 case AOT_USAC:
1050
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if ((ret = ff_aac_usac_config_decode(ac, avctx, gb,
1051 oc, m4ac->chan_config)) < 0)
1052 return ret;
1053 4 break;
1054 #endif
1055 default:
1056 avpriv_report_missing_feature(avctx,
1057 "Audio object type %s%d",
1058 m4ac->sbr == 1 ? "SBR+" : "",
1059 m4ac->object_type);
1060 return AVERROR(ENOSYS);
1061 }
1062
1063 ff_dlog(avctx,
1064 "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
1065 m4ac->object_type, m4ac->chan_config, m4ac->sampling_index,
1066 m4ac->sample_rate, m4ac->sbr,
1067 m4ac->ps);
1068
1069 563 return get_bits_count(gb);
1070 }
1071
1072 241 static int decode_audio_specific_config(AACDecContext *ac,
1073 AVCodecContext *avctx,
1074 OutputConfiguration *oc,
1075 const uint8_t *data, int64_t bit_size,
1076 int sync_extension)
1077 {
1078 int i, ret;
1079 GetBitContext gb;
1080
1081
2/4
✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 241 times.
241 if (bit_size < 0 || bit_size > INT_MAX) {
1082 av_log(avctx, AV_LOG_ERROR, "Audio specific config size is invalid\n");
1083 return AVERROR_INVALIDDATA;
1084 }
1085
1086 ff_dlog(avctx, "audio specific config size %d\n", (int)bit_size >> 3);
1087
2/2
✓ Branch 0 taken 1407 times.
✓ Branch 1 taken 241 times.
1648 for (i = 0; i < bit_size >> 3; i++)
1088 ff_dlog(avctx, "%02x ", data[i]);
1089 ff_dlog(avctx, "\n");
1090
1091
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 241 times.
241 if ((ret = init_get_bits(&gb, data, bit_size)) < 0)
1092 return ret;
1093
1094 241 return decode_audio_specific_config_gb(ac, avctx, oc, &gb, 0,
1095 sync_extension);
1096 }
1097
1098 295 static av_cold int decode_close(AVCodecContext *avctx)
1099 {
1100 295 AACDecContext *ac = avctx->priv_data;
1101
1102
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 295 times.
885 for (int i = 0; i < 2; i++) {
1103 590 OutputConfiguration *oc = &ac->oc[i];
1104 590 AACUSACConfig *usac = &oc->usac;
1105
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 590 times.
598 for (int j = 0; j < usac->nb_elems; j++) {
1106 8 AACUsacElemConfig *ec = &usac->elems[i];
1107 8 av_freep(&ec->ext.pl_data);
1108 }
1109 }
1110
1111
2/2
✓ Branch 0 taken 1180 times.
✓ Branch 1 taken 295 times.
1475 for (int type = 0; type < FF_ARRAY_ELEMS(ac->che); type++) {
1112
2/2
✓ Branch 0 taken 75520 times.
✓ Branch 1 taken 1180 times.
76700 for (int i = 0; i < MAX_ELEM_ID; i++) {
1113
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 75147 times.
75520 if (ac->che[type][i]) {
1114 373 ac->proc.sbr_ctx_close(ac->che[type][i]);
1115 373 av_freep(&ac->che[type][i]);
1116 }
1117 }
1118 }
1119
1120 295 av_tx_uninit(&ac->mdct96);
1121 295 av_tx_uninit(&ac->mdct120);
1122 295 av_tx_uninit(&ac->mdct128);
1123 295 av_tx_uninit(&ac->mdct480);
1124 295 av_tx_uninit(&ac->mdct512);
1125 295 av_tx_uninit(&ac->mdct768);
1126 295 av_tx_uninit(&ac->mdct960);
1127 295 av_tx_uninit(&ac->mdct1024);
1128 295 av_tx_uninit(&ac->mdct_ltp);
1129
1130 // Compiler will optimize this branch away.
1131
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 272 times.
295 if (ac->is_fixed)
1132 23 av_freep(&ac->RENAME_FIXED(fdsp));
1133 else
1134 272 av_freep(&ac->fdsp);
1135
1136 295 return 0;
1137 }
1138
1139 295 static av_cold int init_dsp(AVCodecContext *avctx)
1140 {
1141 295 AACDecContext *ac = avctx->priv_data;
1142 295 int is_fixed = ac->is_fixed, ret;
1143 float scale_fixed, scale_float;
1144
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 272 times.
295 const float *const scalep = is_fixed ? &scale_fixed : &scale_float;
1145
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 272 times.
295 enum AVTXType tx_type = is_fixed ? AV_TX_INT32_MDCT : AV_TX_FLOAT_MDCT;
1146
1147 #define MDCT_INIT(s, fn, len, sval) \
1148 scale_fixed = (sval) * 128.0f; \
1149 scale_float = (sval) / 32768.0f; \
1150 ret = av_tx_init(&s, &fn, tx_type, 1, len, scalep, 0); \
1151 if (ret < 0) \
1152 return ret
1153
1154
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct96, ac->mdct96_fn, 96, 1.0/96);
1155
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct120, ac->mdct120_fn, 120, 1.0/120);
1156
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct128, ac->mdct128_fn, 128, 1.0/128);
1157
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct480, ac->mdct480_fn, 480, 1.0/480);
1158
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct512, ac->mdct512_fn, 512, 1.0/512);
1159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct768, ac->mdct768_fn, 768, 1.0/768);
1160
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct960, ac->mdct960_fn, 960, 1.0/960);
1161
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
295 MDCT_INIT(ac->mdct1024, ac->mdct1024_fn, 1024, 1.0/1024);
1162 #undef MDCT_INIT
1163
1164 /* LTP forward MDCT */
1165 295 scale_fixed = -1.0;
1166 295 scale_float = -32786.0*2 + 36;
1167 295 ret = av_tx_init(&ac->mdct_ltp, &ac->mdct_ltp_fn, tx_type, 0, 1024, scalep, 0);
1168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 295 times.
295 if (ret < 0)
1169 return ret;
1170
1171 295 return 0;
1172 }
1173
1174 295 av_cold int ff_aac_decode_init(AVCodecContext *avctx)
1175 {
1176 295 AACDecContext *ac = avctx->priv_data;
1177 int ret;
1178
1179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 295 times.
295 if (avctx->sample_rate > 96000)
1180 return AVERROR_INVALIDDATA;
1181
1182 295 ff_aacdec_common_init_once();
1183
1184 295 ac->avctx = avctx;
1185 295 ac->oc[1].m4ac.sample_rate = avctx->sample_rate;
1186
1187
2/2
✓ Branch 0 taken 233 times.
✓ Branch 1 taken 62 times.
295 if (avctx->extradata_size > 0) {
1188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 233 times.
233 if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1],
1189 233 avctx->extradata,
1190 233 avctx->extradata_size * 8LL,
1191 1)) < 0)
1192 return ret;
1193 } else {
1194 int sr, i;
1195 uint8_t layout_map[MAX_ELEM_ID*4][3];
1196 int layout_map_tags;
1197
1198 62 sr = ff_aac_sample_rate_idx(avctx->sample_rate);
1199 62 ac->oc[1].m4ac.sampling_index = sr;
1200 62 ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels;
1201 62 ac->oc[1].m4ac.sbr = -1;
1202 62 ac->oc[1].m4ac.ps = -1;
1203
1204
1/2
✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
110 for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++)
1205
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 48 times.
110 if (ff_mpeg4audio_channels[i] == avctx->ch_layout.nb_channels)
1206 62 break;
1207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) {
1208 i = 0;
1209 }
1210 62 ac->oc[1].m4ac.chan_config = i;
1211
1212
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 38 times.
62 if (ac->oc[1].m4ac.chan_config) {
1213 24 int ret = ff_aac_set_default_channel_config(ac, avctx, layout_map,
1214 &layout_map_tags,
1215 ac->oc[1].m4ac.chan_config);
1216
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (!ret)
1217 24 ff_aac_output_configure(ac, layout_map, layout_map_tags,
1218 OC_GLOBAL_HDR, 0);
1219 else if (avctx->err_recognition & AV_EF_EXPLODE)
1220 return AVERROR_INVALIDDATA;
1221 }
1222 }
1223
1224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 295 times.
295 if (avctx->ch_layout.nb_channels > MAX_CHANNELS) {
1225 av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
1226 return AVERROR_INVALIDDATA;
1227 }
1228
1229 295 ac->random_state = 0x1f2e3d4c;
1230
1231 295 return init_dsp(avctx);
1232 }
1233
1234 /**
1235 * Skip data_stream_element; reference: table 4.10.
1236 */
1237 2821 static int skip_data_stream_element(AACDecContext *ac, GetBitContext *gb)
1238 {
1239 2821 int byte_align = get_bits1(gb);
1240 2821 int count = get_bits(gb, 8);
1241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2821 times.
2821 if (count == 255)
1242 count += get_bits(gb, 8);
1243
2/2
✓ Branch 0 taken 2454 times.
✓ Branch 1 taken 367 times.
2821 if (byte_align)
1244 2454 align_get_bits(gb);
1245
1246
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2821 times.
2821 if (get_bits_left(gb) < 8 * count) {
1247 av_log(ac->avctx, AV_LOG_ERROR, "skip_data_stream_element: "overread_err);
1248 return AVERROR_INVALIDDATA;
1249 }
1250 2821 skip_bits_long(gb, 8 * count);
1251 2821 return 0;
1252 }
1253
1254 1426 static int decode_prediction(AACDecContext *ac, IndividualChannelStream *ics,
1255 GetBitContext *gb)
1256 {
1257 int sfb;
1258
2/2
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 1067 times.
1426 if (get_bits1(gb)) {
1259 359 ics->predictor_reset_group = get_bits(gb, 5);
1260
1/2
✓ Branch 0 taken 359 times.
✗ Branch 1 not taken.
359 if (ics->predictor_reset_group == 0 ||
1261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
359 ics->predictor_reset_group > 30) {
1262 av_log(ac->avctx, AV_LOG_ERROR,
1263 "Invalid Predictor Reset Group.\n");
1264 return AVERROR_INVALIDDATA;
1265 }
1266 }
1267
2/2
✓ Branch 0 taken 46375 times.
✓ Branch 1 taken 1426 times.
47801 for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]); sfb++) {
1268 46375 ics->prediction_used[sfb] = get_bits1(gb);
1269 }
1270 1426 return 0;
1271 }
1272
1273 /**
1274 * Decode Long Term Prediction data; reference: table 4.xx.
1275 */
1276 786 static void decode_ltp(AACDecContext *ac, LongTermPrediction *ltp,
1277 GetBitContext *gb, uint8_t max_sfb)
1278 {
1279 int sfb;
1280
1281 786 ltp->lag = get_bits(gb, 11);
1282
2/2
✓ Branch 0 taken 393 times.
✓ Branch 1 taken 393 times.
786 if (CONFIG_AAC_FIXED_DECODER && ac->is_fixed)
1283 393 ltp->coef_fixed = Q30(ff_ltp_coef[get_bits(gb, 3)]);
1284 else if (CONFIG_AAC_DECODER)
1285 393 ltp->coef = ff_ltp_coef[get_bits(gb, 3)];
1286
1287
2/2
✓ Branch 0 taken 31440 times.
✓ Branch 1 taken 786 times.
32226 for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++)
1288 31440 ltp->used[sfb] = get_bits1(gb);
1289 786 }
1290
1291 /**
1292 * Decode Individual Channel Stream info; reference: table 4.6.
1293 */
1294 63372 static int decode_ics_info(AACDecContext *ac, IndividualChannelStream *ics,
1295 GetBitContext *gb)
1296 {
1297 63372 const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac;
1298 63372 const int aot = m4ac->object_type;
1299 63372 const int sampling_index = m4ac->sampling_index;
1300 63372 int ret_fail = AVERROR_INVALIDDATA;
1301
1302
2/2
✓ Branch 0 taken 47007 times.
✓ Branch 1 taken 16365 times.
63372 if (aot != AOT_ER_AAC_ELD) {
1303
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 47007 times.
47007 if (get_bits1(gb)) {
1304 av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n");
1305 if (ac->avctx->err_recognition & AV_EF_BITSTREAM)
1306 return AVERROR_INVALIDDATA;
1307 }
1308 47007 ics->window_sequence[1] = ics->window_sequence[0];
1309 47007 ics->window_sequence[0] = get_bits(gb, 2);
1310
2/2
✓ Branch 0 taken 2424 times.
✓ Branch 1 taken 44583 times.
47007 if (aot == AOT_ER_AAC_LD &&
1311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 ics->window_sequence[0] != ONLY_LONG_SEQUENCE) {
1312 av_log(ac->avctx, AV_LOG_ERROR,
1313 "AAC LD is only defined for ONLY_LONG_SEQUENCE but "
1314 "window sequence %d found.\n", ics->window_sequence[0]);
1315 ics->window_sequence[0] = ONLY_LONG_SEQUENCE;
1316 return AVERROR_INVALIDDATA;
1317 }
1318 47007 ics->use_kb_window[1] = ics->use_kb_window[0];
1319 47007 ics->use_kb_window[0] = get_bits1(gb);
1320 }
1321 63372 ics->prev_num_window_groups = FFMAX(ics->num_window_groups, 1);
1322 63372 ics->num_window_groups = 1;
1323 63372 ics->group_len[0] = 1;
1324
2/2
✓ Branch 0 taken 1331 times.
✓ Branch 1 taken 62041 times.
63372 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1325 int i;
1326 1331 ics->max_sfb = get_bits(gb, 4);
1327
2/2
✓ Branch 0 taken 9317 times.
✓ Branch 1 taken 1331 times.
10648 for (i = 0; i < 7; i++) {
1328
2/2
✓ Branch 1 taken 5889 times.
✓ Branch 2 taken 3428 times.
9317 if (get_bits1(gb)) {
1329 5889 ics->group_len[ics->num_window_groups - 1]++;
1330 } else {
1331 3428 ics->num_window_groups++;
1332 3428 ics->group_len[ics->num_window_groups - 1] = 1;
1333 }
1334 }
1335 1331 ics->num_windows = 8;
1336
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1330 times.
1331 if (m4ac->frame_length_short) {
1337 1 ics->swb_offset = ff_swb_offset_120[sampling_index];
1338 1 ics->num_swb = ff_aac_num_swb_120[sampling_index];
1339 } else {
1340 1330 ics->swb_offset = ff_swb_offset_128[sampling_index];
1341 1330 ics->num_swb = ff_aac_num_swb_128[sampling_index];
1342 }
1343 1331 ics->tns_max_bands = ff_tns_max_bands_128[sampling_index];
1344 1331 ics->predictor_present = 0;
1345 } else {
1346 62041 ics->max_sfb = get_bits(gb, 6);
1347 62041 ics->num_windows = 1;
1348
4/4
✓ Branch 0 taken 59617 times.
✓ Branch 1 taken 2424 times.
✓ Branch 2 taken 16365 times.
✓ Branch 3 taken 43252 times.
62041 if (aot == AOT_ER_AAC_LD || aot == AOT_ER_AAC_ELD) {
1349
2/2
✓ Branch 0 taken 3559 times.
✓ Branch 1 taken 15230 times.
18789 if (m4ac->frame_length_short) {
1350 3559 ics->swb_offset = ff_swb_offset_480[sampling_index];
1351 3559 ics->num_swb = ff_aac_num_swb_480[sampling_index];
1352 3559 ics->tns_max_bands = ff_tns_max_bands_480[sampling_index];
1353 } else {
1354 15230 ics->swb_offset = ff_swb_offset_512[sampling_index];
1355 15230 ics->num_swb = ff_aac_num_swb_512[sampling_index];
1356 15230 ics->tns_max_bands = ff_tns_max_bands_512[sampling_index];
1357 }
1358
2/4
✓ Branch 0 taken 18789 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18789 times.
18789 if (!ics->num_swb || !ics->swb_offset) {
1359 ret_fail = AVERROR_BUG;
1360 goto fail;
1361 }
1362 } else {
1363
2/2
✓ Branch 0 taken 386 times.
✓ Branch 1 taken 42866 times.
43252 if (m4ac->frame_length_short) {
1364 386 ics->num_swb = ff_aac_num_swb_960[sampling_index];
1365 386 ics->swb_offset = ff_swb_offset_960[sampling_index];
1366 } else {
1367 42866 ics->num_swb = ff_aac_num_swb_1024[sampling_index];
1368 42866 ics->swb_offset = ff_swb_offset_1024[sampling_index];
1369 }
1370 43252 ics->tns_max_bands = ff_tns_max_bands_1024[sampling_index];
1371 }
1372
2/2
✓ Branch 0 taken 45676 times.
✓ Branch 1 taken 16365 times.
62041 if (aot != AOT_ER_AAC_ELD) {
1373 45676 ics->predictor_present = get_bits1(gb);
1374 45676 ics->predictor_reset_group = 0;
1375 }
1376
2/2
✓ Branch 0 taken 1964 times.
✓ Branch 1 taken 60077 times.
62041 if (ics->predictor_present) {
1377
2/2
✓ Branch 0 taken 1426 times.
✓ Branch 1 taken 538 times.
1964 if (aot == AOT_AAC_MAIN) {
1378
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1426 times.
1426 if (decode_prediction(ac, ics, gb)) {
1379 goto fail;
1380 }
1381
2/4
✓ Branch 0 taken 538 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 538 times.
538 } else if (aot == AOT_AAC_LC ||
1382 aot == AOT_ER_AAC_LC) {
1383 av_log(ac->avctx, AV_LOG_ERROR,
1384 "Prediction is not allowed in AAC-LC.\n");
1385 goto fail;
1386 } else {
1387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
538 if (aot == AOT_ER_AAC_LD) {
1388 av_log(ac->avctx, AV_LOG_ERROR,
1389 "LTP in ER AAC LD not yet implemented.\n");
1390 ret_fail = AVERROR_PATCHWELCOME;
1391 goto fail;
1392 }
1393
2/2
✓ Branch 1 taken 382 times.
✓ Branch 2 taken 156 times.
538 if ((ics->ltp.present = get_bits(gb, 1)))
1394 382 decode_ltp(ac, &ics->ltp, gb, ics->max_sfb);
1395 }
1396 }
1397 }
1398
1399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63372 times.
63372 if (ics->max_sfb > ics->num_swb) {
1400 av_log(ac->avctx, AV_LOG_ERROR,
1401 "Number of scalefactor bands in group (%d) "
1402 "exceeds limit (%d).\n",
1403 ics->max_sfb, ics->num_swb);
1404 goto fail;
1405 }
1406
1407 63372 return 0;
1408 fail:
1409 ics->max_sfb = 0;
1410 return ret_fail;
1411 }
1412
1413 /**
1414 * Decode band types (section_data payload); reference: table 4.46.
1415 *
1416 * @param band_type array of the used band type
1417 * @param band_type_run_end array of the last scalefactor band of a band type run
1418 *
1419 * @return Returns error status. 0 - OK, !0 - error
1420 */
1421 93936 static int decode_band_types(AACDecContext *ac, SingleChannelElement *sce,
1422 GetBitContext *gb)
1423 {
1424 93936 IndividualChannelStream *ics = &sce->ics;
1425
2/2
✓ Branch 0 taken 2089 times.
✓ Branch 1 taken 91847 times.
93936 const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5;
1426
1427
2/2
✓ Branch 0 taken 99174 times.
✓ Branch 1 taken 93936 times.
193110 for (int g = 0; g < ics->num_window_groups; g++) {
1428 99174 int k = 0;
1429
2/2
✓ Branch 0 taken 464655 times.
✓ Branch 1 taken 99174 times.
563829 while (k < ics->max_sfb) {
1430 464655 uint8_t sect_end = k;
1431 int sect_len_incr;
1432 464655 int sect_band_type = get_bits(gb, 4);
1433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 464655 times.
464655 if (sect_band_type == 12) {
1434 av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n");
1435 return AVERROR_INVALIDDATA;
1436 }
1437 do {
1438 483418 sect_len_incr = get_bits(gb, bits);
1439 483418 sect_end += sect_len_incr;
1440
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 483418 times.
483418 if (get_bits_left(gb) < 0) {
1441 av_log(ac->avctx, AV_LOG_ERROR, "decode_band_types: "overread_err);
1442 return AVERROR_INVALIDDATA;
1443 }
1444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 483418 times.
483418 if (sect_end > ics->max_sfb) {
1445 av_log(ac->avctx, AV_LOG_ERROR,
1446 "Number of bands (%d) exceeds limit (%d).\n",
1447 sect_end, ics->max_sfb);
1448 return AVERROR_INVALIDDATA;
1449 }
1450
2/2
✓ Branch 0 taken 18763 times.
✓ Branch 1 taken 464655 times.
483418 } while (sect_len_incr == (1 << bits) - 1);
1451
2/2
✓ Branch 0 taken 3478656 times.
✓ Branch 1 taken 464655 times.
3943311 for (; k < sect_end; k++)
1452 3478656 sce->band_type[g*ics->max_sfb + k] = sect_band_type;
1453 }
1454 }
1455 93936 return 0;
1456 }
1457
1458 /**
1459 * Decode scalefactors; reference: table 4.47.
1460 *
1461 * @param global_gain first scalefactor value as scalefactors are differentially coded
1462 * @param band_type array of the used band type
1463 * @param band_type_run_end array of the last scalefactor band of a band type run
1464 * @param sf array of scalefactors or intensity stereo positions
1465 *
1466 * @return Returns error status. 0 - OK, !0 - error
1467 */
1468 93936 static int decode_scalefactors(AACDecContext *ac, SingleChannelElement *sce,
1469 GetBitContext *gb, unsigned int global_gain)
1470 {
1471 93936 IndividualChannelStream *ics = &sce->ics;
1472 93936 int offset[3] = { global_gain, global_gain - NOISE_OFFSET, 0 };
1473 int clipped_offset;
1474 93936 int noise_flag = 1;
1475
1476
2/2
✓ Branch 0 taken 99174 times.
✓ Branch 1 taken 93936 times.
193110 for (int g = 0; g < ics->num_window_groups; g++) {
1477
2/2
✓ Branch 0 taken 3478656 times.
✓ Branch 1 taken 99174 times.
3577830 for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
1478
4/4
✓ Branch 0 taken 537005 times.
✓ Branch 1 taken 66207 times.
✓ Branch 2 taken 281615 times.
✓ Branch 3 taken 2593829 times.
3478656 switch (sce->band_type[g*ics->max_sfb + sfb]) {
1479 537005 case ZERO_BT:
1480 537005 sce->sfo[g*ics->max_sfb + sfb] = 0;
1481 537005 break;
1482 66207 case INTENSITY_BT: /* fallthrough */
1483 case INTENSITY_BT2:
1484 66207 offset[2] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
1485 66207 clipped_offset = av_clip(offset[2], -155, 100);
1486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66207 times.
66207 if (offset[2] != clipped_offset) {
1487 avpriv_request_sample(ac->avctx,
1488 "If you heard an audible artifact, there may be a bug in the decoder. "
1489 "Clipped intensity stereo position (%d -> %d)",
1490 offset[2], clipped_offset);
1491 }
1492 66207 sce->sfo[g*ics->max_sfb + sfb] = clipped_offset - 100;
1493 66207 break;
1494 281615 case NOISE_BT:
1495
2/2
✓ Branch 0 taken 6715 times.
✓ Branch 1 taken 274900 times.
281615 if (noise_flag-- > 0)
1496 6715 offset[1] += get_bits(gb, NOISE_PRE_BITS) - NOISE_PRE;
1497 else
1498 274900 offset[1] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
1499 281615 clipped_offset = av_clip(offset[1], -100, 155);
1500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 281615 times.
281615 if (offset[1] != clipped_offset) {
1501 avpriv_request_sample(ac->avctx,
1502 "If you heard an audible artifact, there may be a bug in the decoder. "
1503 "Clipped noise gain (%d -> %d)",
1504 offset[1], clipped_offset);
1505 }
1506 281615 sce->sfo[g*ics->max_sfb + sfb] = clipped_offset;
1507 281615 break;
1508 2593829 default:
1509 2593829 offset[0] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
1510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2593829 times.
2593829 if (offset[0] > 255U) {
1511 av_log(ac->avctx, AV_LOG_ERROR,
1512 "Scalefactor (%d) out of range.\n", offset[0]);
1513 return AVERROR_INVALIDDATA;
1514 }
1515 2593829 sce->sfo[g*ics->max_sfb + sfb] = offset[0] - 100;
1516 2593829 break;
1517 }
1518 }
1519 }
1520
1521 93936 return 0;
1522 }
1523
1524 /**
1525 * Decode pulse data; reference: table 4.7.
1526 */
1527 1098 static int decode_pulses(Pulse *pulse, GetBitContext *gb,
1528 const uint16_t *swb_offset, int num_swb)
1529 {
1530 int i, pulse_swb;
1531 1098 pulse->num_pulse = get_bits(gb, 2) + 1;
1532 1098 pulse_swb = get_bits(gb, 6);
1533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
1098 if (pulse_swb >= num_swb)
1534 return -1;
1535 1098 pulse->pos[0] = swb_offset[pulse_swb];
1536 1098 pulse->pos[0] += get_bits(gb, 5);
1537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
1098 if (pulse->pos[0] >= swb_offset[num_swb])
1538 return -1;
1539 1098 pulse->amp[0] = get_bits(gb, 4);
1540
2/2
✓ Branch 0 taken 1646 times.
✓ Branch 1 taken 1098 times.
2744 for (i = 1; i < pulse->num_pulse; i++) {
1541 1646 pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i - 1];
1542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1646 times.
1646 if (pulse->pos[i] >= swb_offset[num_swb])
1543 return -1;
1544 1646 pulse->amp[i] = get_bits(gb, 4);
1545 }
1546 1098 return 0;
1547 }
1548
1549 /**
1550 * Decode Temporal Noise Shaping data; reference: table 4.48.
1551 *
1552 * @return Returns error status. 0 - OK, !0 - error
1553 */
1554 6955 int ff_aac_decode_tns(AACDecContext *ac, TemporalNoiseShaping *tns,
1555 GetBitContext *gb, const IndividualChannelStream *ics)
1556 {
1557 6955 int tns_max_order = INT32_MAX;
1558 6955 const int is_usac = ac->oc[1].m4ac.object_type == AOT_USAC;
1559 int w, filt, i, coef_len, coef_res, coef_compress;
1560 6955 const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE;
1561
1562 /* USAC doesn't seem to have a limit */
1563
1/2
✓ Branch 0 taken 6955 times.
✗ Branch 1 not taken.
6955 if (!is_usac)
1564
4/4
✓ Branch 0 taken 6296 times.
✓ Branch 1 taken 659 times.
✓ Branch 2 taken 163 times.
✓ Branch 3 taken 6133 times.
6955 tns_max_order = is8 ? 7 : ac->oc[1].m4ac.object_type == AOT_AAC_MAIN ? 20 : 12;
1565
1566
2/2
✓ Branch 0 taken 11568 times.
✓ Branch 1 taken 6955 times.
18523 for (w = 0; w < ics->num_windows; w++) {
1567
2/2
✓ Branch 1 taken 7946 times.
✓ Branch 2 taken 3622 times.
11568 if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) {
1568 7946 coef_res = get_bits1(gb);
1569
1570
2/2
✓ Branch 0 taken 9407 times.
✓ Branch 1 taken 7946 times.
17353 for (filt = 0; filt < tns->n_filt[w]; filt++) {
1571 int tmp2_idx;
1572 9407 tns->length[w][filt] = get_bits(gb, 6 - 2 * is8);
1573
1574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9407 times.
9407 if (is_usac)
1575 tns->order[w][filt] = get_bits(gb, 4 - is8);
1576 else
1577 9407 tns->order[w][filt] = get_bits(gb, 5 - (2 * is8));
1578
1579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9407 times.
9407 if (tns->order[w][filt] > tns_max_order) {
1580 av_log(ac->avctx, AV_LOG_ERROR,
1581 "TNS filter order %d is greater than maximum %d.\n",
1582 tns->order[w][filt], tns_max_order);
1583 tns->order[w][filt] = 0;
1584 return AVERROR_INVALIDDATA;
1585 }
1586
2/2
✓ Branch 0 taken 8887 times.
✓ Branch 1 taken 520 times.
9407 if (tns->order[w][filt]) {
1587 8887 tns->direction[w][filt] = get_bits1(gb);
1588 8887 coef_compress = get_bits1(gb);
1589 8887 coef_len = coef_res + 3 - coef_compress;
1590 8887 tmp2_idx = 2 * coef_compress + coef_res;
1591
1592
2/2
✓ Branch 0 taken 58548 times.
✓ Branch 1 taken 8887 times.
67435 for (i = 0; i < tns->order[w][filt]; i++) {
1593
2/2
✓ Branch 0 taken 14113 times.
✓ Branch 1 taken 44435 times.
58548 if (CONFIG_AAC_FIXED_DECODER && ac->is_fixed)
1594 14113 tns->coef_fixed[w][filt][i] = Q31(ff_tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)]);
1595 else if (CONFIG_AAC_DECODER)
1596 44435 tns->coef[w][filt][i] = ff_tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)];
1597 }
1598 }
1599 }
1600 }
1601 }
1602 6955 return 0;
1603 }
1604
1605 /**
1606 * Decode Mid/Side data; reference: table 4.54.
1607 *
1608 * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
1609 * [1] mask is decoded from bitstream; [2] mask is all 1s;
1610 * [3] reserved for scalable AAC
1611 */
1612 27052 static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb,
1613 int ms_present)
1614 {
1615 int idx;
1616 27052 int max_idx = cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb;
1617 27052 cpe->max_sfb_ste = cpe->ch[0].ics.max_sfb;
1618
2/2
✓ Branch 0 taken 12687 times.
✓ Branch 1 taken 14365 times.
27052 if (ms_present == 1) {
1619
2/2
✓ Branch 0 taken 497864 times.
✓ Branch 1 taken 12687 times.
510551 for (idx = 0; idx < max_idx; idx++)
1620 497864 cpe->ms_mask[idx] = get_bits1(gb);
1621
1/2
✓ Branch 0 taken 14365 times.
✗ Branch 1 not taken.
14365 } else if (ms_present == 2) {
1622 14365 memset(cpe->ms_mask, 1, max_idx * sizeof(cpe->ms_mask[0]));
1623 }
1624 27052 }
1625
1626 static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb)
1627 {
1628 // wd_num, wd_test, aloc_size
1629 static const uint8_t gain_mode[4][3] = {
1630 {1, 0, 5}, // ONLY_LONG_SEQUENCE = 0,
1631 {2, 1, 2}, // LONG_START_SEQUENCE,
1632 {8, 0, 2}, // EIGHT_SHORT_SEQUENCE,
1633 {2, 1, 5}, // LONG_STOP_SEQUENCE
1634 };
1635
1636 const int mode = sce->ics.window_sequence[0];
1637 uint8_t bd, wd, ad;
1638
1639 // FIXME: Store the gain control data on |sce| and do something with it.
1640 uint8_t max_band = get_bits(gb, 2);
1641 for (bd = 0; bd < max_band; bd++) {
1642 for (wd = 0; wd < gain_mode[mode][0]; wd++) {
1643 uint8_t adjust_num = get_bits(gb, 3);
1644 for (ad = 0; ad < adjust_num; ad++) {
1645 skip_bits(gb, 4 + ((wd == 0 && gain_mode[mode][1])
1646 ? 4
1647 : gain_mode[mode][2]));
1648 }
1649 }
1650 }
1651 }
1652
1653 /**
1654 * Decode an individual_channel_stream payload; reference: table 4.44.
1655 *
1656 * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information.
1657 * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.)
1658 *
1659 * @return Returns error status. 0 - OK, !0 - error
1660 */
1661 93936 int ff_aac_decode_ics(AACDecContext *ac, SingleChannelElement *sce,
1662 GetBitContext *gb, int common_window, int scale_flag)
1663 {
1664 Pulse pulse;
1665 93936 TemporalNoiseShaping *tns = &sce->tns;
1666 93936 IndividualChannelStream *ics = &sce->ics;
1667 93936 int global_gain, eld_syntax, er_syntax, pulse_present = 0;
1668 int ret;
1669
1670 93936 eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
1671 281808 er_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_LC ||
1672
1/2
✓ Branch 0 taken 93936 times.
✗ Branch 1 not taken.
93936 ac->oc[1].m4ac.object_type == AOT_ER_AAC_LTP ||
1673
3/4
✓ Branch 0 taken 93936 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90300 times.
✓ Branch 3 taken 3636 times.
278172 ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD ||
1674
2/2
✓ Branch 0 taken 26598 times.
✓ Branch 1 taken 63702 times.
90300 ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
1675
1676 /* This assignment is to silence a GCC warning about the variable being used
1677 * uninitialized when in fact it always is.
1678 */
1679 93936 pulse.num_pulse = 0;
1680
1681 93936 global_gain = get_bits(gb, 8);
1682
1683
3/4
✓ Branch 0 taken 32808 times.
✓ Branch 1 taken 61128 times.
✓ Branch 2 taken 32808 times.
✗ Branch 3 not taken.
93936 if (!common_window && !scale_flag) {
1684 32808 ret = decode_ics_info(ac, ics, gb);
1685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32808 times.
32808 if (ret < 0)
1686 goto fail;
1687 }
1688
1689
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 93936 times.
93936 if ((ret = decode_band_types(ac, sce, gb)) < 0)
1690 goto fail;
1691
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 93936 times.
93936 if ((ret = decode_scalefactors(ac, sce, gb, global_gain)) < 0)
1692 goto fail;
1693
1694 93936 ac->dsp.dequant_scalefactors(sce);
1695
1696 93936 pulse_present = 0;
1697
1/2
✓ Branch 0 taken 93936 times.
✗ Branch 1 not taken.
93936 if (!scale_flag) {
1698
4/4
✓ Branch 0 taken 67338 times.
✓ Branch 1 taken 26598 times.
✓ Branch 3 taken 1098 times.
✓ Branch 4 taken 66240 times.
93936 if (!eld_syntax && (pulse_present = get_bits1(gb))) {
1699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
1098 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1700 av_log(ac->avctx, AV_LOG_ERROR,
1701 "Pulse tool not allowed in eight short sequence.\n");
1702 ret = AVERROR_INVALIDDATA;
1703 goto fail;
1704 }
1705
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1098 times.
1098 if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) {
1706 av_log(ac->avctx, AV_LOG_ERROR,
1707 "Pulse data corrupt or invalid.\n");
1708 ret = AVERROR_INVALIDDATA;
1709 goto fail;
1710 }
1711 }
1712 93936 tns->present = get_bits1(gb);
1713
4/4
✓ Branch 0 taken 6955 times.
✓ Branch 1 taken 86981 times.
✓ Branch 2 taken 5691 times.
✓ Branch 3 taken 1264 times.
93936 if (tns->present && !er_syntax) {
1714 5691 ret = ff_aac_decode_tns(ac, tns, gb, ics);
1715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5691 times.
5691 if (ret < 0)
1716 goto fail;
1717 }
1718
3/4
✓ Branch 0 taken 67338 times.
✓ Branch 1 taken 26598 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 67338 times.
93936 if (!eld_syntax && get_bits1(gb)) {
1719 decode_gain_control(sce, gb);
1720 if (!ac->warned_gain_control) {
1721 avpriv_report_missing_feature(ac->avctx, "Gain control");
1722 ac->warned_gain_control = 1;
1723 }
1724 }
1725 // I see no textual basis in the spec for this occurring after SSR gain
1726 // control, but this is what both reference and real implmentations do
1727
4/4
✓ Branch 0 taken 6955 times.
✓ Branch 1 taken 86981 times.
✓ Branch 2 taken 1264 times.
✓ Branch 3 taken 5691 times.
93936 if (tns->present && er_syntax) {
1728 1264 ret = ff_aac_decode_tns(ac, tns, gb, ics);
1729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1264 times.
1264 if (ret < 0)
1730 goto fail;
1731 }
1732 }
1733
1734
2/2
✓ Branch 0 taken 1098 times.
✓ Branch 1 taken 92838 times.
93936 ret = ac->proc.decode_spectrum_and_dequant(ac, gb,
1735 pulse_present ? &pulse : NULL,
1736 sce);
1737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93936 times.
93936 if (ret < 0)
1738 goto fail;
1739
1740
4/4
✓ Branch 0 taken 7388 times.
✓ Branch 1 taken 86548 times.
✓ Branch 2 taken 6094 times.
✓ Branch 3 taken 1294 times.
93936 if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window)
1741 6094 ac->dsp.apply_prediction(ac, sce);
1742
1743 93936 return 0;
1744 fail:
1745 tns->present = 0;
1746 return ret;
1747 }
1748
1749 /**
1750 * Decode a channel_pair_element; reference: table 4.4.
1751 *
1752 * @return Returns error status. 0 - OK, !0 - error
1753 */
1754 30786 static int decode_cpe(AACDecContext *ac, GetBitContext *gb, ChannelElement *cpe)
1755 {
1756 30786 int i, ret, common_window, ms_present = 0;
1757 30786 int eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
1758
1759
4/4
✓ Branch 0 taken 20553 times.
✓ Branch 1 taken 10233 times.
✓ Branch 3 taken 20331 times.
✓ Branch 4 taken 222 times.
30786 common_window = eld_syntax || get_bits1(gb);
1760
2/2
✓ Branch 0 taken 30564 times.
✓ Branch 1 taken 222 times.
30786 if (common_window) {
1761
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30564 times.
30564 if (decode_ics_info(ac, &cpe->ch[0].ics, gb))
1762 return AVERROR_INVALIDDATA;
1763 30564 i = cpe->ch[1].ics.use_kb_window[0];
1764 30564 cpe->ch[1].ics = cpe->ch[0].ics;
1765 30564 cpe->ch[1].ics.use_kb_window[1] = i;
1766
2/2
✓ Branch 0 taken 723 times.
✓ Branch 1 taken 29841 times.
30564 if (cpe->ch[1].ics.predictor_present &&
1767
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 185 times.
723 (ac->oc[1].m4ac.object_type != AOT_AAC_MAIN))
1768
2/2
✓ Branch 1 taken 404 times.
✓ Branch 2 taken 134 times.
538 if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1)))
1769 404 decode_ltp(ac, &cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb);
1770 30564 ms_present = get_bits(gb, 2);
1771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30564 times.
30564 if (ms_present == 3) {
1772 av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
1773 return AVERROR_INVALIDDATA;
1774
2/2
✓ Branch 0 taken 27052 times.
✓ Branch 1 taken 3512 times.
30564 } else if (ms_present)
1775 27052 decode_mid_side_stereo(cpe, gb, ms_present);
1776 }
1777
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30786 times.
30786 if ((ret = ff_aac_decode_ics(ac, &cpe->ch[0], gb, common_window, 0)))
1778 return ret;
1779
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30786 times.
30786 if ((ret = ff_aac_decode_ics(ac, &cpe->ch[1], gb, common_window, 0)))
1780 return ret;
1781
1782
2/2
✓ Branch 0 taken 30564 times.
✓ Branch 1 taken 222 times.
30786 if (common_window) {
1783
2/2
✓ Branch 0 taken 27052 times.
✓ Branch 1 taken 3512 times.
30564 if (ms_present)
1784 27052 ac->dsp.apply_mid_side_stereo(ac, cpe);
1785
2/2
✓ Branch 0 taken 647 times.
✓ Branch 1 taken 29917 times.
30564 if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN) {
1786 647 ac->dsp.apply_prediction(ac, &cpe->ch[0]);
1787 647 ac->dsp.apply_prediction(ac, &cpe->ch[1]);
1788 }
1789 }
1790
1791 30786 ac->dsp.apply_intensity_stereo(ac, cpe, ms_present);
1792 30786 return 0;
1793 }
1794
1795 /**
1796 * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53.
1797 *
1798 * @return Returns number of bytes consumed.
1799 */
1800 4 static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc,
1801 GetBitContext *gb)
1802 {
1803 int i;
1804 4 int num_excl_chan = 0;
1805
1806 do {
1807
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 4 times.
32 for (i = 0; i < 7; i++)
1808 28 che_drc->exclude_mask[num_excl_chan++] = get_bits1(gb);
1809
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
4 } while (num_excl_chan < MAX_CHANNELS - 7 && get_bits1(gb));
1810
1811 4 return num_excl_chan / 7;
1812 }
1813
1814 /**
1815 * Decode dynamic range information; reference: table 4.52.
1816 *
1817 * @return Returns number of bytes consumed.
1818 */
1819 880 static int decode_dynamic_range(DynamicRangeControl *che_drc,
1820 GetBitContext *gb)
1821 {
1822 880 int n = 1;
1823 880 int drc_num_bands = 1;
1824 int i;
1825
1826 /* pce_tag_present? */
1827
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 880 times.
880 if (get_bits1(gb)) {
1828 che_drc->pce_instance_tag = get_bits(gb, 4);
1829 skip_bits(gb, 4); // tag_reserved_bits
1830 n++;
1831 }
1832
1833 /* excluded_chns_present? */
1834
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 876 times.
880 if (get_bits1(gb)) {
1835 4 n += decode_drc_channel_exclusions(che_drc, gb);
1836 }
1837
1838 /* drc_bands_present? */
1839
2/2
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 845 times.
880 if (get_bits1(gb)) {
1840 35 che_drc->band_incr = get_bits(gb, 4);
1841 35 che_drc->interpolation_scheme = get_bits(gb, 4);
1842 35 n++;
1843 35 drc_num_bands += che_drc->band_incr;
1844
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 35 times.
140 for (i = 0; i < drc_num_bands; i++) {
1845 105 che_drc->band_top[i] = get_bits(gb, 8);
1846 105 n++;
1847 }
1848 }
1849
1850 /* prog_ref_level_present? */
1851
2/2
✓ Branch 1 taken 878 times.
✓ Branch 2 taken 2 times.
880 if (get_bits1(gb)) {
1852 878 che_drc->prog_ref_level = get_bits(gb, 7);
1853 878 skip_bits1(gb); // prog_ref_level_reserved_bits
1854 878 n++;
1855 }
1856
1857
2/2
✓ Branch 0 taken 950 times.
✓ Branch 1 taken 880 times.
1830 for (i = 0; i < drc_num_bands; i++) {
1858 950 che_drc->dyn_rng_sgn[i] = get_bits1(gb);
1859 950 che_drc->dyn_rng_ctl[i] = get_bits(gb, 7);
1860 950 n++;
1861 }
1862
1863 880 return n;
1864 }
1865
1866 8953 static int decode_fill(AACDecContext *ac, GetBitContext *gb, int len) {
1867 uint8_t buf[256];
1868 int i, major, minor;
1869
1870
2/2
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 8573 times.
8953 if (len < 13+7*8)
1871 380 goto unknown;
1872
1873 8573 get_bits(gb, 13); len -= 13;
1874
1875
4/4
✓ Branch 0 taken 1136851 times.
✓ Branch 1 taken 443 times.
✓ Branch 2 taken 1128721 times.
✓ Branch 3 taken 8130 times.
1137294 for(i=0; i+1<sizeof(buf) && len>=8; i++, len-=8)
1876 1128721 buf[i] = get_bits(gb, 8);
1877
1878 8573 buf[i] = 0;
1879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8573 times.
8573 if (ac->avctx->debug & FF_DEBUG_PICT_INFO)
1880 av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf);
1881
1882
2/2
✓ Branch 0 taken 8554 times.
✓ Branch 1 taken 19 times.
8573 if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){
1883 19 ac->avctx->internal->skip_samples = 1024;
1884 }
1885
1886 8554 unknown:
1887 8953 skip_bits_long(gb, len);
1888
1889 8953 return 0;
1890 }
1891
1892 /**
1893 * Decode extension data (incomplete); reference: table 4.51.
1894 *
1895 * @param cnt length of TYPE_FIL syntactic element in bytes
1896 *
1897 * @return Returns number of bytes consumed
1898 */
1899 23684 static int decode_extension_payload(AACDecContext *ac, GetBitContext *gb, int cnt,
1900 ChannelElement *che, enum RawDataBlockType elem_type)
1901 {
1902 23684 int crc_flag = 0;
1903 23684 int res = cnt;
1904 23684 int type = get_bits(gb, 4);
1905
1906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23684 times.
23684 if (ac->avctx->debug & FF_DEBUG_STARTCODE)
1907 av_log(ac->avctx, AV_LOG_DEBUG, "extension type: %d len:%d\n", type, cnt);
1908
1909
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
✓ Branch 2 taken 880 times.
✓ Branch 3 taken 8953 times.
✓ Branch 4 taken 2950 times.
23684 switch (type) { // extension type
1910 case EXT_SBR_DATA_CRC:
1911 crc_flag++;
1912 10901 case EXT_SBR_DATA:
1913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
10901 if (!che) {
1914 av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n");
1915 return res;
1916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
10901 } else if (ac->oc[1].m4ac.frame_length_short) {
1917 if (!ac->warned_960_sbr)
1918 avpriv_report_missing_feature(ac->avctx,
1919 "SBR with 960 frame length");
1920 ac->warned_960_sbr = 1;
1921 skip_bits_long(gb, 8 * cnt - 4);
1922 return res;
1923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
10901 } else if (!ac->oc[1].m4ac.sbr) {
1924 av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n");
1925 skip_bits_long(gb, 8 * cnt - 4);
1926 return res;
1927
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 10879 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
10901 } else if (ac->oc[1].m4ac.sbr == -1 && ac->oc[1].status == OC_LOCKED) {
1928 av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n");
1929 skip_bits_long(gb, 8 * cnt - 4);
1930 return res;
1931
3/4
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 10807 times.
✓ Branch 2 taken 94 times.
✗ Branch 3 not taken.
10901 } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED &&
1932
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 82 times.
94 ac->avctx->ch_layout.nb_channels == 1) {
1933 12 ac->oc[1].m4ac.sbr = 1;
1934 12 ac->oc[1].m4ac.ps = 1;
1935 12 ac->avctx->profile = AV_PROFILE_AAC_HE_V2;
1936 12 ff_aac_output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags,
1937 ac->oc[1].status, 1);
1938 } else {
1939 10889 ac->oc[1].m4ac.sbr = 1;
1940 10889 ac->avctx->profile = AV_PROFILE_AAC_HE;
1941 }
1942
1943 10901 ac->proc.sbr_decode_extension(ac, che, gb, crc_flag, cnt, elem_type);
1944
1945
4/4
✓ Branch 0 taken 1999 times.
✓ Branch 1 taken 8902 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1977 times.
10901 if (ac->oc[1].m4ac.ps == 1 && !ac->warned_he_aac_mono) {
1946 22 av_log(ac->avctx, AV_LOG_VERBOSE, "Treating HE-AAC mono as stereo.\n");
1947 22 ac->warned_he_aac_mono = 1;
1948 }
1949 10901 break;
1950 880 case EXT_DYNAMIC_RANGE:
1951 880 res = decode_dynamic_range(&ac->che_drc, gb);
1952 880 break;
1953 8953 case EXT_FILL:
1954 8953 decode_fill(ac, gb, 8 * cnt - 4);
1955 8953 break;
1956 2950 case EXT_FILL_DATA:
1957 case EXT_DATA_ELEMENT:
1958 default:
1959 2950 skip_bits_long(gb, 8 * cnt - 4);
1960 2950 break;
1961 };
1962 23684 return res;
1963 }
1964
1965 /**
1966 * channel coupling transformation interface
1967 *
1968 * @param apply_coupling_method pointer to (in)dependent coupling function
1969 */
1970 176590 static void apply_channel_coupling(AACDecContext *ac, ChannelElement *cc,
1971 enum RawDataBlockType type, int elem_id,
1972 enum CouplingPoint coupling_point,
1973 void (*apply_coupling_method)(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index))
1974 {
1975 int i, c;
1976
1977
2/2
✓ Branch 0 taken 11301760 times.
✓ Branch 1 taken 176590 times.
11478350 for (i = 0; i < MAX_ELEM_ID; i++) {
1978 11301760 ChannelElement *cce = ac->che[TYPE_CCE][i];
1979 11301760 int index = 0;
1980
1981
4/4
✓ Branch 0 taken 11740 times.
✓ Branch 1 taken 11290020 times.
✓ Branch 2 taken 3915 times.
✓ Branch 3 taken 7825 times.
11301760 if (cce && cce->coup.coupling_point == coupling_point) {
1982 3915 ChannelCoupling *coup = &cce->coup;
1983
1984
2/2
✓ Branch 0 taken 9402 times.
✓ Branch 1 taken 3915 times.
13317 for (c = 0; c <= coup->num_coupled; c++) {
1985
4/4
✓ Branch 0 taken 5089 times.
✓ Branch 1 taken 4313 times.
✓ Branch 2 taken 2741 times.
✓ Branch 3 taken 2348 times.
9402 if (coup->type[c] == type && coup->id_select[c] == elem_id) {
1986
2/2
✓ Branch 0 taken 2561 times.
✓ Branch 1 taken 180 times.
2741 if (coup->ch_select[c] != 1) {
1987 2561 apply_coupling_method(ac, &cc->ch[0], cce, index);
1988
1/2
✓ Branch 0 taken 2561 times.
✗ Branch 1 not taken.
2561 if (coup->ch_select[c] != 0)
1989 2561 index++;
1990 }
1991
2/2
✓ Branch 0 taken 2147 times.
✓ Branch 1 taken 594 times.
2741 if (coup->ch_select[c] != 2)
1992 2147 apply_coupling_method(ac, &cc->ch[1], cce, index++);
1993 } else
1994
2/2
✓ Branch 0 taken 4720 times.
✓ Branch 1 taken 1941 times.
6661 index += 1 + (coup->ch_select[c] == 3);
1995 }
1996 }
1997 }
1998 176590 }
1999
2000 /**
2001 * Convert spectral data to samples, applying all supported tools as appropriate.
2002 */
2003 50104 static void spectral_to_sample(AACDecContext *ac, int samples)
2004 {
2005 int i, type;
2006 void (*imdct_and_window)(AACDecContext *ac, SingleChannelElement *sce);
2007
3/3
✓ Branch 0 taken 606 times.
✓ Branch 1 taken 16365 times.
✓ Branch 2 taken 33133 times.
50104 switch (ac->oc[1].m4ac.object_type) {
2008 606 case AOT_ER_AAC_LD:
2009 606 imdct_and_window = ac->dsp.imdct_and_windowing_ld;
2010 606 break;
2011 16365 case AOT_ER_AAC_ELD:
2012 16365 imdct_and_window = ac->dsp.imdct_and_windowing_eld;
2013 16365 break;
2014 33133 default:
2015
2/2
✓ Branch 0 taken 387 times.
✓ Branch 1 taken 32746 times.
33133 if (ac->oc[1].m4ac.frame_length_short)
2016 387 imdct_and_window = ac->dsp.imdct_and_windowing_960;
2017 else
2018 32746 imdct_and_window = ac->dsp.imdct_and_windowing;
2019 }
2020
2/2
✓ Branch 0 taken 200416 times.
✓ Branch 1 taken 50104 times.
250520 for (type = 3; type >= 0; type--) {
2021
2/2
✓ Branch 0 taken 12826624 times.
✓ Branch 1 taken 200416 times.
13027040 for (i = 0; i < MAX_ELEM_ID; i++) {
2022 12826624 ChannelElement *che = ac->che[type][i];
2023
4/4
✓ Branch 0 taken 63479 times.
✓ Branch 1 taken 12763145 times.
✓ Branch 2 taken 63150 times.
✓ Branch 3 taken 329 times.
12826624 if (che && che->present) {
2024
2/2
✓ Branch 0 taken 58472 times.
✓ Branch 1 taken 4678 times.
63150 if (type <= TYPE_CPE)
2025 58472 apply_channel_coupling(ac, che, type, i, BEFORE_TNS, ac->dsp.apply_dependent_coupling);
2026
2/2
✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 61366 times.
63150 if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) {
2027
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 1246 times.
1784 if (che->ch[0].ics.predictor_present) {
2028
2/2
✓ Branch 0 taken 382 times.
✓ Branch 1 taken 156 times.
538 if (che->ch[0].ics.ltp.present)
2029 382 ac->dsp.apply_ltp(ac, &che->ch[0]);
2030
3/4
✓ Branch 0 taken 404 times.
✓ Branch 1 taken 134 times.
✓ Branch 2 taken 404 times.
✗ Branch 3 not taken.
538 if (che->ch[1].ics.ltp.present && type == TYPE_CPE)
2031 404 ac->dsp.apply_ltp(ac, &che->ch[1]);
2032 }
2033 }
2034
2/2
✓ Branch 0 taken 4647 times.
✓ Branch 1 taken 58503 times.
63150 if (che->ch[0].tns.present)
2035 4647 ac->dsp.apply_tns(che->ch[0].coeffs,
2036 &che->ch[0].tns, &che->ch[0].ics, 1);
2037
2/2
✓ Branch 0 taken 2308 times.
✓ Branch 1 taken 60842 times.
63150 if (che->ch[1].tns.present)
2038 2308 ac->dsp.apply_tns(che->ch[1].coeffs,
2039 &che->ch[1].tns, &che->ch[1].ics, 1);
2040
2/2
✓ Branch 0 taken 58472 times.
✓ Branch 1 taken 4678 times.
63150 if (type <= TYPE_CPE)
2041 58472 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, ac->dsp.apply_dependent_coupling);
2042
4/4
✓ Branch 0 taken 1174 times.
✓ Branch 1 taken 61976 times.
✓ Branch 2 taken 393 times.
✓ Branch 3 taken 781 times.
63150 if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) {
2043 62369 imdct_and_window(ac, &che->ch[0]);
2044
2/2
✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 60585 times.
62369 if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
2045 1784 ac->dsp.update_ltp(ac, &che->ch[0]);
2046
2/2
✓ Branch 0 taken 30786 times.
✓ Branch 1 taken 31583 times.
62369 if (type == TYPE_CPE) {
2047 30786 imdct_and_window(ac, &che->ch[1]);
2048
2/2
✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 29002 times.
30786 if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
2049 1784 ac->dsp.update_ltp(ac, &che->ch[1]);
2050 }
2051
2/2
✓ Branch 0 taken 12411 times.
✓ Branch 1 taken 49958 times.
62369 if (ac->oc[1].m4ac.sbr > 0) {
2052 12411 ac->proc.sbr_apply(ac, che, type,
2053 12411 che->ch[0].output,
2054 12411 che->ch[1].output);
2055 }
2056 }
2057
2/2
✓ Branch 0 taken 59646 times.
✓ Branch 1 taken 3504 times.
63150 if (type <= TYPE_CCE)
2058 59646 apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, ac->dsp.apply_independent_coupling);
2059 63150 ac->dsp.clip_output(ac, che, type, samples);
2060 63150 che->present = 0;
2061
2/2
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 12763145 times.
12763474 } else if (che) {
2062 329 av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i);
2063 }
2064 }
2065 }
2066 50104 }
2067
2068 4114 static int parse_adts_frame_header(AACDecContext *ac, GetBitContext *gb)
2069 {
2070 int size;
2071 AACADTSHeaderInfo hdr_info;
2072 uint8_t layout_map[MAX_ELEM_ID*4][3];
2073 int layout_map_tags, ret;
2074
2075 4114 size = ff_adts_header_parse(gb, &hdr_info);
2076
1/2
✓ Branch 0 taken 4114 times.
✗ Branch 1 not taken.
4114 if (size > 0) {
2077
2/4
✓ Branch 0 taken 4114 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4114 times.
4114 if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) {
2078 // This is 2 for "VLB " audio in NSV files.
2079