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 | #include "libavutil/refstruct.h" | ||
66 | |||
67 | /* | ||
68 | * supported tools | ||
69 | * | ||
70 | * Support? Name | ||
71 | * N (code in SoC repo) gain control | ||
72 | * Y block switching | ||
73 | * Y window shapes - standard | ||
74 | * N window shapes - Low Delay | ||
75 | * Y filterbank - standard | ||
76 | * N (code in SoC repo) filterbank - Scalable Sample Rate | ||
77 | * Y Temporal Noise Shaping | ||
78 | * Y Long Term Prediction | ||
79 | * Y intensity stereo | ||
80 | * Y channel coupling | ||
81 | * Y frequency domain prediction | ||
82 | * Y Perceptual Noise Substitution | ||
83 | * Y Mid/Side stereo | ||
84 | * N Scalable Inverse AAC Quantization | ||
85 | * N Frequency Selective Switch | ||
86 | * N upsampling filter | ||
87 | * Y quantization & coding - AAC | ||
88 | * N quantization & coding - TwinVQ | ||
89 | * N quantization & coding - BSAC | ||
90 | * N AAC Error Resilience tools | ||
91 | * N Error Resilience payload syntax | ||
92 | * N Error Protection tool | ||
93 | * N CELP | ||
94 | * N Silence Compression | ||
95 | * N HVXC | ||
96 | * N HVXC 4kbits/s VR | ||
97 | * N Structured Audio tools | ||
98 | * N Structured Audio Sample Bank Format | ||
99 | * N MIDI | ||
100 | * N Harmonic and Individual Lines plus Noise | ||
101 | * N Text-To-Speech Interface | ||
102 | * Y Spectral Band Replication | ||
103 | * Y (not in this code) Layer-1 | ||
104 | * Y (not in this code) Layer-2 | ||
105 | * Y (not in this code) Layer-3 | ||
106 | * N SinuSoidal Coding (Transient, Sinusoid, Noise) | ||
107 | * Y Parametric Stereo | ||
108 | * N Direct Stream Transfer | ||
109 | * Y (not in fixed point code) Enhanced AAC Low Delay (ER AAC ELD) | ||
110 | * | ||
111 | * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. | ||
112 | * - HE AAC v2 comprises LC AAC with Spectral Band Replication and | ||
113 | Parametric Stereo. | ||
114 | */ | ||
115 | |||
116 | #define overread_err "Input buffer exhausted before END element found\n" | ||
117 | |||
118 | 562 | static int count_channels(uint8_t (*layout)[3], int tags) | |
119 | { | ||
120 | 562 | int i, sum = 0; | |
121 |
2/2✓ Branch 0 taken 1150 times.
✓ Branch 1 taken 562 times.
|
1712 | for (i = 0; i < tags; i++) { |
122 | 1150 | int syn_ele = layout[i][0]; | |
123 | 1150 | int pos = layout[i][2]; | |
124 |
2/2✓ Branch 0 taken 656 times.
✓ Branch 1 taken 494 times.
|
2300 | sum += (1 + (syn_ele == TYPE_CPE)) * |
125 |
3/4✓ Branch 0 taken 1150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1142 times.
✓ Branch 3 taken 8 times.
|
1150 | (pos != AAC_CHANNEL_OFF && pos != AAC_CHANNEL_CC); |
126 | } | ||
127 | 562 | return sum; | |
128 | } | ||
129 | |||
130 | /** | ||
131 | * Check for the channel element in the current channel position configuration. | ||
132 | * If it exists, make sure the appropriate element is allocated and map the | ||
133 | * channel order to match the internal FFmpeg channel layout. | ||
134 | * | ||
135 | * @param che_pos current channel position configuration | ||
136 | * @param type channel element type | ||
137 | * @param id channel element id | ||
138 | * @param channels count of the number of channels in the configuration | ||
139 | * | ||
140 | * @return Returns error status. 0 - OK, !0 - error | ||
141 | */ | ||
142 | 8118 | static av_cold int che_configure(AACDecContext *ac, | |
143 | enum ChannelPosition che_pos, | ||
144 | int type, int id, int *channels) | ||
145 | { | ||
146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8118 times.
|
8118 | if (*channels >= MAX_CHANNELS) |
147 | ✗ | return AVERROR_INVALIDDATA; | |
148 |
1/2✓ Branch 0 taken 8118 times.
✗ Branch 1 not taken.
|
8118 | if (che_pos) { |
149 |
2/2✓ Branch 0 taken 410 times.
✓ Branch 1 taken 7708 times.
|
8118 | if (!ac->che[type][id]) { |
150 | 410 | int ret = ac->proc.sbr_ctx_alloc_init(ac, &ac->che[type][id], type); | |
151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 410 times.
|
410 | if (ret < 0) |
152 | ✗ | return ret; | |
153 | } | ||
154 |
2/2✓ Branch 0 taken 8110 times.
✓ Branch 1 taken 8 times.
|
8118 | if (type != TYPE_CCE) { |
155 |
7/8✓ Branch 0 taken 860 times.
✓ Branch 1 taken 7250 times.
✓ Branch 2 taken 793 times.
✓ Branch 3 taken 67 times.
✓ Branch 4 taken 366 times.
✓ Branch 5 taken 427 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 8110 times.
|
8110 | if (*channels >= MAX_CHANNELS - (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))) { |
156 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "Too many channels\n"); | |
157 | ✗ | return AVERROR_INVALIDDATA; | |
158 | } | ||
159 | 8110 | ac->output_element[(*channels)++] = &ac->che[type][id]->ch[0]; | |
160 |
4/4✓ Branch 0 taken 860 times.
✓ Branch 1 taken 7250 times.
✓ Branch 2 taken 793 times.
✓ Branch 3 taken 67 times.
|
8110 | if (type == TYPE_CPE || |
161 |
2/2✓ Branch 0 taken 366 times.
✓ Branch 1 taken 427 times.
|
793 | (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1)) { |
162 | 7616 | ac->output_element[(*channels)++] = &ac->che[type][id]->ch[1]; | |
163 | } | ||
164 | } | ||
165 | } else { | ||
166 | ✗ | if (ac->che[type][id]) { | |
167 | ✗ | ac->proc.sbr_ctx_close(ac->che[type][id]); | |
168 | } | ||
169 | ✗ | av_freep(&ac->che[type][id]); | |
170 | ✗ | memset(ac->output_element, 0, sizeof(ac->output_element)); | |
171 | } | ||
172 | 8118 | return 0; | |
173 | } | ||
174 | |||
175 | 53596 | static int frame_configure_elements(AVCodecContext *avctx) | |
176 | { | ||
177 | 53596 | AACDecContext *ac = avctx->priv_data; | |
178 | int type, id, ch, ret; | ||
179 | |||
180 | /* set channel pointers to internal buffers by default */ | ||
181 |
2/2✓ Branch 0 taken 214384 times.
✓ Branch 1 taken 53596 times.
|
267980 | for (type = 0; type < 4; type++) { |
182 |
2/2✓ Branch 0 taken 13720576 times.
✓ Branch 1 taken 214384 times.
|
13934960 | for (id = 0; id < MAX_ELEM_ID; id++) { |
183 | 13720576 | ChannelElement *che = ac->che[type][id]; | |
184 |
2/2✓ Branch 0 taken 66996 times.
✓ Branch 1 taken 13653580 times.
|
13720576 | if (che) { |
185 | 66996 | che->ch[0].output = che->ch[0].ret_buf; | |
186 | 66996 | che->ch[1].output = che->ch[1].ret_buf; | |
187 | } | ||
188 | } | ||
189 | } | ||
190 | |||
191 | /* get output buffer */ | ||
192 | 53596 | av_frame_unref(ac->frame); | |
193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53596 times.
|
53596 | if (!avctx->ch_layout.nb_channels) |
194 | ✗ | return 1; | |
195 | |||
196 | 53596 | ac->frame->nb_samples = 2048; | |
197 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53596 times.
|
53596 | if ((ret = ff_get_buffer(avctx, ac->frame, 0)) < 0) |
198 | ✗ | return ret; | |
199 | |||
200 | /* map output channel pointers to AVFrame data */ | ||
201 |
2/2✓ Branch 0 taken 101759 times.
✓ Branch 1 taken 53596 times.
|
155355 | for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { |
202 |
1/2✓ Branch 0 taken 101759 times.
✗ Branch 1 not taken.
|
101759 | if (ac->output_element[ch]) |
203 | 101759 | ac->output_element[ch]->output = (void *)ac->frame->extended_data[ch]; | |
204 | } | ||
205 | |||
206 | 53596 | return 0; | |
207 | } | ||
208 | |||
209 | struct elem_to_channel { | ||
210 | uint64_t av_position; | ||
211 | uint8_t syn_ele; | ||
212 | uint8_t elem_id; | ||
213 | uint8_t aac_position; | ||
214 | }; | ||
215 | |||
216 | 7238 | static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID], | |
217 | uint8_t (*layout_map)[3], int offset, uint64_t left, | ||
218 | uint64_t right, int pos, uint64_t *layout) | ||
219 | { | ||
220 |
2/2✓ Branch 0 taken 7234 times.
✓ Branch 1 taken 4 times.
|
7238 | if (layout_map[offset][0] == TYPE_CPE) { |
221 | 7234 | e2c_vec[offset] = (struct elem_to_channel) { | |
222 | 7234 | .av_position = left | right, | |
223 | .syn_ele = TYPE_CPE, | ||
224 | 7234 | .elem_id = layout_map[offset][1], | |
225 | .aac_position = pos | ||
226 | }; | ||
227 |
1/2✓ Branch 0 taken 7234 times.
✗ Branch 1 not taken.
|
7234 | if (e2c_vec[offset].av_position != UINT64_MAX) |
228 | 7234 | *layout |= e2c_vec[offset].av_position; | |
229 | |||
230 | 7234 | return 1; | |
231 | } else { | ||
232 | 4 | e2c_vec[offset] = (struct elem_to_channel) { | |
233 | .av_position = left, | ||
234 | .syn_ele = TYPE_SCE, | ||
235 | 4 | .elem_id = layout_map[offset][1], | |
236 | .aac_position = pos | ||
237 | }; | ||
238 | 4 | e2c_vec[offset + 1] = (struct elem_to_channel) { | |
239 | .av_position = right, | ||
240 | .syn_ele = TYPE_SCE, | ||
241 | 4 | .elem_id = layout_map[offset + 1][1], | |
242 | .aac_position = pos | ||
243 | }; | ||
244 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (left != UINT64_MAX) |
245 | 4 | *layout |= left; | |
246 | |||
247 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (right != UINT64_MAX) |
248 | 4 | *layout |= right; | |
249 | |||
250 | 4 | return 2; | |
251 | } | ||
252 | } | ||
253 | |||
254 | 31628 | static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, | |
255 | int current) | ||
256 | { | ||
257 | 31628 | int num_pos_channels = 0; | |
258 | 31628 | int first_cpe = 0; | |
259 | 31628 | int sce_parity = 0; | |
260 | int i; | ||
261 |
2/2✓ Branch 0 taken 8495 times.
✓ Branch 1 taken 31259 times.
|
39754 | for (i = current; i < tags; i++) { |
262 |
2/2✓ Branch 0 taken 369 times.
✓ Branch 1 taken 8126 times.
|
8495 | if (layout_map[i][2] != pos) |
263 | 369 | break; | |
264 |
2/2✓ Branch 0 taken 7258 times.
✓ Branch 1 taken 868 times.
|
8126 | if (layout_map[i][0] == TYPE_CPE) { |
265 |
2/2✓ Branch 0 taken 73 times.
✓ Branch 1 taken 7185 times.
|
7258 | if (sce_parity) { |
266 |
2/4✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73 times.
✗ Branch 3 not taken.
|
73 | if (pos == AAC_CHANNEL_FRONT && !first_cpe) { |
267 | 73 | sce_parity = 0; | |
268 | } else { | ||
269 | ✗ | return -1; | |
270 | } | ||
271 | } | ||
272 | 7258 | num_pos_channels += 2; | |
273 | 7258 | first_cpe = 1; | |
274 | } else { | ||
275 | 868 | num_pos_channels++; | |
276 | 868 | sce_parity ^= (pos != AAC_CHANNEL_LFE); | |
277 | } | ||
278 | } | ||
279 |
3/4✓ Branch 0 taken 720 times.
✓ Branch 1 taken 30908 times.
✓ Branch 2 taken 720 times.
✗ Branch 3 not taken.
|
31628 | if (sce_parity && |
280 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 696 times.
|
720 | (pos == AAC_CHANNEL_FRONT && first_cpe)) |
281 | 24 | return -1; | |
282 | |||
283 | 31604 | return num_pos_channels; | |
284 | } | ||
285 | |||
286 | 31628 | static int assign_channels(struct elem_to_channel e2c_vec[MAX_ELEM_ID], uint8_t (*layout_map)[3], | |
287 | uint64_t *layout, int tags, int layer, int pos, int *current) | ||
288 | { | ||
289 | 31628 | int i = *current, j = 0; | |
290 | 31628 | int nb_channels = count_paired_channels(layout_map, tags, pos, i); | |
291 | |||
292 |
3/4✓ Branch 0 taken 31604 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31604 times.
|
31628 | if (nb_channels < 0 || nb_channels > 5) |
293 | 24 | return 0; | |
294 | |||
295 |
2/2✓ Branch 0 taken 7907 times.
✓ Branch 1 taken 23697 times.
|
31604 | if (pos == AAC_CHANNEL_LFE) { |
296 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 7907 times.
|
7974 | while (nb_channels) { |
297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (ff_aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE) |
298 | ✗ | return -1; | |
299 | 67 | e2c_vec[i] = (struct elem_to_channel) { | |
300 | 67 | .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][j], | |
301 | 67 | .syn_ele = layout_map[i][0], | |
302 | 67 | .elem_id = layout_map[i][1], | |
303 | .aac_position = pos | ||
304 | }; | ||
305 | 67 | *layout |= e2c_vec[i].av_position; | |
306 | 67 | i++; | |
307 | 67 | j++; | |
308 | 67 | nb_channels--; | |
309 | } | ||
310 | 7907 | *current = i; | |
311 | |||
312 | 7907 | return 0; | |
313 | } | ||
314 | |||
315 |
2/2✓ Branch 0 taken 769 times.
✓ Branch 1 taken 23697 times.
|
24466 | while (nb_channels & 1) { |
316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 769 times.
|
769 | if (ff_aac_channel_map[layer][pos - 1][0] == AV_CHAN_NONE) |
317 | ✗ | return -1; | |
318 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 769 times.
|
769 | if (ff_aac_channel_map[layer][pos - 1][0] == AV_CHAN_UNUSED) |
319 | ✗ | break; | |
320 | 769 | e2c_vec[i] = (struct elem_to_channel) { | |
321 | 769 | .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][0], | |
322 | 769 | .syn_ele = layout_map[i][0], | |
323 | 769 | .elem_id = layout_map[i][1], | |
324 | .aac_position = pos | ||
325 | }; | ||
326 | 769 | *layout |= e2c_vec[i].av_position; | |
327 | 769 | i++; | |
328 | 769 | nb_channels--; | |
329 | } | ||
330 | |||
331 |
4/4✓ Branch 0 taken 15790 times.
✓ Branch 1 taken 7907 times.
✓ Branch 2 taken 15782 times.
✓ Branch 3 taken 8 times.
|
23697 | j = (pos != AAC_CHANNEL_SIDE) && nb_channels <= 3 ? 3 : 1; |
332 |
2/2✓ Branch 0 taken 7238 times.
✓ Branch 1 taken 23697 times.
|
30935 | while (nb_channels >= 2) { |
333 |
1/2✓ Branch 0 taken 7238 times.
✗ Branch 1 not taken.
|
7238 | if (ff_aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE || |
334 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7238 times.
|
7238 | ff_aac_channel_map[layer][pos - 1][j+1] == AV_CHAN_NONE) |
335 | ✗ | return -1; | |
336 | 14476 | i += assign_pair(e2c_vec, layout_map, i, | |
337 | 7238 | 1ULL << ff_aac_channel_map[layer][pos - 1][j], | |
338 | 7238 | 1ULL << ff_aac_channel_map[layer][pos - 1][j+1], | |
339 | pos, layout); | ||
340 | 7238 | j += 2; | |
341 | 7238 | nb_channels -= 2; | |
342 | } | ||
343 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23697 times.
|
23697 | while (nb_channels & 1) { |
344 | ✗ | if (ff_aac_channel_map[layer][pos - 1][5] == AV_CHAN_NONE) | |
345 | ✗ | return -1; | |
346 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
347 | ✗ | .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][5], | |
348 | ✗ | .syn_ele = layout_map[i][0], | |
349 | ✗ | .elem_id = layout_map[i][1], | |
350 | .aac_position = pos | ||
351 | }; | ||
352 | ✗ | *layout |= e2c_vec[i].av_position; | |
353 | ✗ | i++; | |
354 | ✗ | nb_channels--; | |
355 | } | ||
356 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23697 times.
|
23697 | if (nb_channels) |
357 | ✗ | return -1; | |
358 | |||
359 | 23697 | *current = i; | |
360 | |||
361 | 23697 | return 0; | |
362 | } | ||
363 | |||
364 | 7875 | static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) | |
365 | { | ||
366 | int i, n, total_non_cc_elements; | ||
367 | 7875 | struct elem_to_channel e2c_vec[4 * MAX_ELEM_ID] = { { 0 } }; | |
368 | 7875 | uint64_t layout = 0; | |
369 | |||
370 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7875 times.
|
7875 | if (FF_ARRAY_ELEMS(e2c_vec) < tags) |
371 | ✗ | return 0; | |
372 | |||
373 |
4/4✓ Branch 0 taken 15766 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 7907 times.
✓ Branch 3 taken 7859 times.
|
15782 | for (n = 0, i = 0; n < 3 && i < tags; n++) { |
374 | 7907 | int ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_FRONT, &i); | |
375 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7907 times.
|
7907 | if (ret < 0) |
376 | ✗ | return 0; | |
377 | 7907 | ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_SIDE, &i); | |
378 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7907 times.
|
7907 | if (ret < 0) |
379 | ✗ | return 0; | |
380 | 7907 | ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_BACK, &i); | |
381 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7907 times.
|
7907 | if (ret < 0) |
382 | ✗ | return 0; | |
383 | 7907 | ret = assign_channels(e2c_vec, layout_map, &layout, tags, n, AAC_CHANNEL_LFE, &i); | |
384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7907 times.
|
7907 | if (ret < 0) |
385 | ✗ | return 0; | |
386 | } | ||
387 | |||
388 | 7875 | total_non_cc_elements = n = i; | |
389 | |||
390 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7875 times.
|
7875 | if (layout == AV_CH_LAYOUT_22POINT2) { |
391 | // For 22.2 reorder the result as needed | ||
392 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[0]); // FL & FR first (final), FC third | |
393 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[1]); // FC second (final), FLc & FRc third | |
394 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[2]); // LFE1 third (final), FLc & FRc seventh | |
395 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[4], e2c_vec[3]); // BL & BR fourth (final), SiL & SiR fifth | |
396 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[4]); // FLc & FRc fifth (final), SiL & SiR seventh | |
397 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[7], e2c_vec[6]); // LFE2 seventh (final), SiL & SiR eight (final) | |
398 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[9], e2c_vec[8]); // TpFL & TpFR ninth (final), TFC tenth (final) | |
399 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[11], e2c_vec[10]); // TC eleventh (final), TpSiL & TpSiR twelfth | |
400 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[12], e2c_vec[11]); // TpBL & TpBR twelfth (final), TpSiL & TpSiR thirteenth (final) | |
401 | } else { | ||
402 | // For everything else, utilize the AV channel position define as a | ||
403 | // stable sort. | ||
404 | do { | ||
405 | 7956 | int next_n = 0; | |
406 |
2/2✓ Branch 0 taken 345 times.
✓ Branch 1 taken 7956 times.
|
8301 | for (i = 1; i < n; i++) |
407 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 197 times.
|
345 | if (e2c_vec[i - 1].av_position > e2c_vec[i].av_position) { |
408 | 148 | FFSWAP(struct elem_to_channel, e2c_vec[i - 1], e2c_vec[i]); | |
409 | 148 | next_n = i; | |
410 | } | ||
411 | 7956 | n = next_n; | |
412 |
2/2✓ Branch 0 taken 81 times.
✓ Branch 1 taken 7875 times.
|
7956 | } while (n > 0); |
413 | |||
414 | } | ||
415 | |||
416 |
2/2✓ Branch 0 taken 8078 times.
✓ Branch 1 taken 7875 times.
|
15953 | for (i = 0; i < total_non_cc_elements; i++) { |
417 | 8078 | layout_map[i][0] = e2c_vec[i].syn_ele; | |
418 | 8078 | layout_map[i][1] = e2c_vec[i].elem_id; | |
419 | 8078 | layout_map[i][2] = e2c_vec[i].aac_position; | |
420 | } | ||
421 | |||
422 | 7875 | return layout; | |
423 | } | ||
424 | |||
425 | 3709 | static void copy_oc(OutputConfiguration *dst, OutputConfiguration *src) | |
426 | { | ||
427 | int i; | ||
428 | |||
429 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3709 times.
|
3709 | for (i = 0; i < src->usac.nb_elems; i++) { |
430 | ✗ | AACUsacElemConfig *src_e = &src->usac.elems[i]; | |
431 | ✗ | AACUsacElemConfig *dst_e = &dst->usac.elems[i]; | |
432 | /* dst_e->ext.pl_buf is guaranteed to be set to src_e->ext.pl_buf | ||
433 | * upon this function's return */ | ||
434 | ✗ | av_refstruct_replace(&dst_e->ext.pl_buf, src_e->ext.pl_buf); | |
435 | } | ||
436 | |||
437 | /* Unref all additional buffers to close leaks */ | ||
438 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3709 times.
|
3709 | for (; i < dst->usac.nb_elems; i++) |
439 | ✗ | av_refstruct_unref(&dst->usac.elems[i].ext.pl_buf); | |
440 | |||
441 | /* Set all other properties */ | ||
442 | 3709 | *dst = *src; | |
443 | 3709 | } | |
444 | |||
445 | /** | ||
446 | * Save current output configuration if and only if it has been locked. | ||
447 | */ | ||
448 | 3709 | static int push_output_configuration(AACDecContext *ac) | |
449 | { | ||
450 | 3709 | int pushed = 0; | |
451 | |||
452 |
3/4✓ Branch 0 taken 60 times.
✓ Branch 1 taken 3649 times.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
|
3709 | if (ac->oc[1].status == OC_LOCKED || ac->oc[0].status == OC_NONE) { |
453 | 3709 | copy_oc(&ac->oc[0], &ac->oc[1]); | |
454 | 3709 | pushed = 1; | |
455 | } | ||
456 | 3709 | ac->oc[1].status = OC_NONE; | |
457 | 3709 | return pushed; | |
458 | } | ||
459 | |||
460 | /** | ||
461 | * Restore the previous output configuration if and only if the current | ||
462 | * configuration is unlocked. | ||
463 | */ | ||
464 | ✗ | static void pop_output_configuration(AACDecContext *ac) | |
465 | { | ||
466 | ✗ | if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) { | |
467 | ✗ | copy_oc(&ac->oc[1], &ac->oc[0]); | |
468 | |||
469 | ✗ | ac->avctx->ch_layout = ac->oc[1].ch_layout; | |
470 | ✗ | ff_aac_output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, | |
471 | ac->oc[1].status, 0); | ||
472 | } | ||
473 | ✗ | } | |
474 | |||
475 | /** | ||
476 | * Configure output channel order based on the current program | ||
477 | * configuration element. | ||
478 | * | ||
479 | * @return Returns error status. 0 - OK, !0 - error | ||
480 | */ | ||
481 | 7875 | int ff_aac_output_configure(AACDecContext *ac, | |
482 | uint8_t layout_map[MAX_ELEM_ID * 4][3], int tags, | ||
483 | enum OCStatus oc_type, int get_new_frame) | ||
484 | { | ||
485 | 7875 | AVCodecContext *avctx = ac->avctx; | |
486 | 7875 | int i, channels = 0, ret; | |
487 | 7875 | uint64_t layout = 0; | |
488 | 7875 | uint8_t id_map[TYPE_END][MAX_ELEM_ID] = {{ 0 }}; | |
489 | 7875 | uint8_t type_counts[TYPE_END] = { 0 }; | |
490 | |||
491 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7863 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
|
7875 | if (get_new_frame && !ac->frame) |
492 | ✗ | return AVERROR_INVALIDDATA; | |
493 | |||
494 |
2/2✓ Branch 0 taken 3979 times.
✓ Branch 1 taken 3896 times.
|
7875 | if (ac->oc[1].layout_map != layout_map) { |
495 | 3979 | memcpy(ac->oc[1].layout_map, layout_map, tags * sizeof(layout_map[0])); | |
496 | 3979 | ac->oc[1].layout_map_tags = tags; | |
497 | } | ||
498 |
2/2✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 7875 times.
|
15993 | for (i = 0; i < tags; i++) { |
499 | 8118 | int type = layout_map[i][0]; | |
500 | 8118 | int id = layout_map[i][1]; | |
501 | 8118 | id_map[type][id] = type_counts[type]++; | |
502 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8118 times.
|
8118 | if (id_map[type][id] >= MAX_ELEM_ID) { |
503 | ✗ | avpriv_request_sample(ac->avctx, "Too large remapped id"); | |
504 | ✗ | return AVERROR_PATCHWELCOME; | |
505 | } | ||
506 | } | ||
507 | // Try to sniff a reasonable channel order, otherwise output the | ||
508 | // channels in the order the PCE declared them. | ||
509 |
1/2✓ Branch 0 taken 7875 times.
✗ Branch 1 not taken.
|
7875 | if (ac->output_channel_order == CHANNEL_ORDER_DEFAULT) |
510 | 7875 | layout = sniff_channel_order(layout_map, tags); | |
511 |
2/2✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 7875 times.
|
15993 | for (i = 0; i < tags; i++) { |
512 | 8118 | int type = layout_map[i][0]; | |
513 | 8118 | int id = layout_map[i][1]; | |
514 | 8118 | int iid = id_map[type][id]; | |
515 | 8118 | int position = layout_map[i][2]; | |
516 | // Allocate or free elements depending on if they are in the | ||
517 | // current program configuration. | ||
518 | 8118 | ret = che_configure(ac, position, type, iid, &channels); | |
519 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8118 times.
|
8118 | if (ret < 0) |
520 | ✗ | return ret; | |
521 | 8118 | ac->tag_che_map[type][id] = ac->che[type][iid]; | |
522 | } | ||
523 |
3/4✓ Branch 0 taken 366 times.
✓ Branch 1 taken 7509 times.
✓ Branch 2 taken 366 times.
✗ Branch 3 not taken.
|
7875 | if (ac->oc[1].m4ac.ps == 1 && channels == 2) { |
524 |
1/2✓ Branch 0 taken 366 times.
✗ Branch 1 not taken.
|
366 | if (layout == AV_CH_FRONT_CENTER) { |
525 | 366 | layout = AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT; | |
526 | } else { | ||
527 | ✗ | layout = 0; | |
528 | } | ||
529 | } | ||
530 | |||
531 | 7875 | av_channel_layout_uninit(&ac->oc[1].ch_layout); | |
532 |
2/2✓ Branch 0 taken 7867 times.
✓ Branch 1 taken 8 times.
|
7875 | if (layout) |
533 | 7867 | av_channel_layout_from_mask(&ac->oc[1].ch_layout, layout); | |
534 | else { | ||
535 | 8 | ac->oc[1].ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; | |
536 | 8 | ac->oc[1].ch_layout.nb_channels = channels; | |
537 | } | ||
538 | |||
539 | 7875 | av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout); | |
540 | 7875 | ac->oc[1].status = oc_type; | |
541 | |||
542 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7863 times.
|
7875 | if (get_new_frame) { |
543 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if ((ret = frame_configure_elements(ac->avctx)) < 0) |
544 | ✗ | return ret; | |
545 | } | ||
546 | |||
547 | 7875 | return 0; | |
548 | } | ||
549 | |||
550 | 9 | static av_cold void flush(AVCodecContext *avctx) | |
551 | { | ||
552 | 9 | AACDecContext *ac= avctx->priv_data; | |
553 | int type, i, j; | ||
554 | |||
555 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
|
45 | for (type = 3; type >= 0; type--) { |
556 |
2/2✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 36 times.
|
2340 | for (i = 0; i < MAX_ELEM_ID; i++) { |
557 | 2304 | ChannelElement *che = ac->che[type][i]; | |
558 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2295 times.
|
2304 | if (che) { |
559 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
|
27 | for (j = 0; j <= 1; j++) { |
560 | 18 | memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved)); | |
561 | } | ||
562 | } | ||
563 | } | ||
564 | } | ||
565 | |||
566 | #if CONFIG_AAC_DECODER | ||
567 | 9 | ff_aac_usac_reset_state(ac, &ac->oc[1]); | |
568 | #endif | ||
569 | 9 | } | |
570 | |||
571 | /** | ||
572 | * Set up channel positions based on a default channel configuration | ||
573 | * as specified in table 1.17. | ||
574 | * | ||
575 | * @return Returns error status. 0 - OK, !0 - error | ||
576 | */ | ||
577 | 4248 | int ff_aac_set_default_channel_config(AACDecContext *ac, AVCodecContext *avctx, | |
578 | uint8_t (*layout_map)[3], | ||
579 | int *tags, | ||
580 | int channel_config) | ||
581 | { | ||
582 |
3/8✓ Branch 0 taken 4248 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4248 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4248 times.
|
4248 | if (channel_config < 1 || (channel_config > 7 && channel_config < 11) || |
583 | channel_config > 14) { | ||
584 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
585 | "invalid default channel configuration (%d)\n", | ||
586 | channel_config); | ||
587 | ✗ | return AVERROR_INVALIDDATA; | |
588 | } | ||
589 | 4248 | *tags = ff_tags_per_config[channel_config]; | |
590 | 4248 | memcpy(layout_map, ff_aac_channel_layout_map[channel_config - 1], | |
591 | 4248 | *tags * sizeof(*layout_map)); | |
592 | |||
593 | /* | ||
594 | * AAC specification has 7.1(wide) as a default layout for 8-channel streams. | ||
595 | * However, at least Nero AAC encoder encodes 7.1 streams using the default | ||
596 | * channel config 7, mapping the side channels of the original audio stream | ||
597 | * to the second AAC_CHANNEL_FRONT pair in the AAC stream. Similarly, e.g. FAAD | ||
598 | * decodes the second AAC_CHANNEL_FRONT pair as side channels, therefore decoding | ||
599 | * the incorrect streams as if they were correct (and as the encoder intended). | ||
600 | * | ||
601 | * As actual intended 7.1(wide) streams are very rare, default to assuming a | ||
602 | * 7.1 layout was intended. | ||
603 | */ | ||
604 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4248 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4248 | if (channel_config == 7 && avctx->strict_std_compliance < FF_COMPLIANCE_STRICT) { |
605 | ✗ | layout_map[2][2] = AAC_CHANNEL_BACK; | |
606 | |||
607 | ✗ | if (!ac || !ac->warned_71_wide++) { | |
608 | ✗ | av_log(avctx, AV_LOG_INFO, "Assuming an incorrectly encoded 7.1 channel layout" | |
609 | " instead of a spec-compliant 7.1(wide) layout, use -strict %d to decode" | ||
610 | " according to the specification instead.\n", FF_COMPLIANCE_STRICT); | ||
611 | } | ||
612 | } | ||
613 | |||
614 | 4248 | return 0; | |
615 | } | ||
616 | |||
617 | 66654 | ChannelElement *ff_aac_get_che(AACDecContext *ac, int type, int elem_id) | |
618 | { | ||
619 | /* For PCE based channel configurations map the channels solely based | ||
620 | * on tags. */ | ||
621 |
2/2✓ Branch 0 taken 24152 times.
✓ Branch 1 taken 42502 times.
|
66654 | if (!ac->oc[1].m4ac.chan_config) { |
622 | 24152 | return ac->tag_che_map[type][elem_id]; | |
623 | } | ||
624 | // Allow single CPE stereo files to be signalled with mono configuration. | ||
625 |
4/4✓ Branch 0 taken 40042 times.
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 24116 times.
✓ Branch 3 taken 15926 times.
|
42502 | if (!ac->tags_mapped && type == TYPE_CPE && |
626 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24116 times.
|
24116 | ac->oc[1].m4ac.chan_config == 1) { |
627 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
628 | int layout_map_tags; | ||
629 | ✗ | push_output_configuration(ac); | |
630 | |||
631 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "mono with CPE\n"); | |
632 | |||
633 | ✗ | if (ff_aac_set_default_channel_config(ac, ac->avctx, layout_map, | |
634 | &layout_map_tags, 2) < 0) | ||
635 | ✗ | return NULL; | |
636 | ✗ | if (ff_aac_output_configure(ac, layout_map, layout_map_tags, | |
637 | OC_TRIAL_FRAME, 1) < 0) | ||
638 | ✗ | return NULL; | |
639 | |||
640 | ✗ | ac->oc[1].m4ac.chan_config = 2; | |
641 | ✗ | ac->oc[1].m4ac.ps = 0; | |
642 | } | ||
643 | // And vice-versa | ||
644 |
4/4✓ Branch 0 taken 40042 times.
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 15926 times.
✓ Branch 3 taken 24116 times.
|
42502 | if (!ac->tags_mapped && type == TYPE_SCE && |
645 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15926 times.
|
15926 | ac->oc[1].m4ac.chan_config == 2) { |
646 | uint8_t layout_map[MAX_ELEM_ID * 4][3]; | ||
647 | int layout_map_tags; | ||
648 | ✗ | push_output_configuration(ac); | |
649 | |||
650 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "stereo with SCE\n"); | |
651 | |||
652 | ✗ | layout_map_tags = 2; | |
653 | ✗ | layout_map[0][0] = layout_map[1][0] = TYPE_SCE; | |
654 | ✗ | layout_map[0][2] = layout_map[1][2] = AAC_CHANNEL_FRONT; | |
655 | ✗ | layout_map[0][1] = 0; | |
656 | ✗ | layout_map[1][1] = 1; | |
657 | ✗ | if (ff_aac_output_configure(ac, layout_map, layout_map_tags, | |
658 | OC_TRIAL_FRAME, 1) < 0) | ||
659 | ✗ | return NULL; | |
660 | |||
661 | ✗ | if (ac->oc[1].m4ac.sbr) | |
662 | ✗ | ac->oc[1].m4ac.ps = -1; | |
663 | } | ||
664 | /* For indexed channel configurations map the channels solely based | ||
665 | * on position. */ | ||
666 |
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 24116 times.
✓ Branch 8 taken 15106 times.
✗ Branch 9 not taken.
|
42502 | switch (ac->oc[1].m4ac.chan_config) { |
667 | ✗ | case 14: | |
668 | ✗ | if (ac->tags_mapped > 2 && ((type == TYPE_CPE && elem_id < 3) || | |
669 | ✗ | (type == TYPE_LFE && elem_id < 1))) { | |
670 | ✗ | ac->tags_mapped++; | |
671 | ✗ | return ac->tag_che_map[type][elem_id] = ac->che[type][elem_id]; | |
672 | } | ||
673 | case 13: | ||
674 | ✗ | if (ac->tags_mapped > 3 && ((type == TYPE_CPE && elem_id < 8) || | |
675 | ✗ | (type == TYPE_SCE && elem_id < 6) || | |
676 | ✗ | (type == TYPE_LFE && elem_id < 2))) { | |
677 | ✗ | ac->tags_mapped++; | |
678 | ✗ | return ac->tag_che_map[type][elem_id] = ac->che[type][elem_id]; | |
679 | } | ||
680 | case 12: | ||
681 | case 7: | ||
682 | ✗ | if (ac->tags_mapped == 3 && type == TYPE_CPE) { | |
683 | ✗ | ac->tags_mapped++; | |
684 | ✗ | return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2]; | |
685 | } | ||
686 | case 11: | ||
687 | ✗ | if (ac->tags_mapped == 3 && type == TYPE_SCE) { | |
688 | ✗ | ac->tags_mapped++; | |
689 | ✗ | return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; | |
690 | } | ||
691 | case 6: | ||
692 | /* Some streams incorrectly code 5.1 audio as | ||
693 | * SCE[0] CPE[0] CPE[1] SCE[1] | ||
694 | * instead of | ||
695 | * SCE[0] CPE[0] CPE[1] LFE[0]. | ||
696 | * If we seem to have encountered such a stream, transfer | ||
697 | * the LFE[0] element to the SCE[1]'s mapping */ | ||
698 |
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)) { |
699 |
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)) { |
700 | ✗ | av_log(ac->avctx, AV_LOG_WARNING, | |
701 | "This stream seems to incorrectly report its last channel as %s[%d], mapping to LFE[0]\n", | ||
702 | type == TYPE_SCE ? "SCE" : "LFE", elem_id); | ||
703 | ✗ | ac->warned_remapping_once++; | |
704 | } | ||
705 | 820 | ac->tags_mapped++; | |
706 | 820 | return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0]; | |
707 | } | ||
708 | case 5: | ||
709 |
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) { |
710 | 820 | ac->tags_mapped++; | |
711 | 820 | return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1]; | |
712 | } | ||
713 | case 4: | ||
714 | /* Some streams incorrectly code 4.0 audio as | ||
715 | * SCE[0] CPE[0] LFE[0] | ||
716 | * instead of | ||
717 | * SCE[0] CPE[0] SCE[1]. | ||
718 | * If we seem to have encountered such a stream, transfer | ||
719 | * the SCE[1] element to the LFE[0]'s mapping */ | ||
720 |
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)) { |
721 | ✗ | if (!ac->warned_remapping_once && (type != TYPE_SCE || elem_id != 1)) { | |
722 | ✗ | av_log(ac->avctx, AV_LOG_WARNING, | |
723 | "This stream seems to incorrectly report its last channel as %s[%d], mapping to SCE[1]\n", | ||
724 | type == TYPE_SCE ? "SCE" : "LFE", elem_id); | ||
725 | ✗ | ac->warned_remapping_once++; | |
726 | } | ||
727 | ✗ | ac->tags_mapped++; | |
728 | ✗ | return ac->tag_che_map[type][elem_id] = ac->che[TYPE_SCE][1]; | |
729 | } | ||
730 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1640 times.
|
1640 | if (ac->tags_mapped == 2 && |
731 | ✗ | ac->oc[1].m4ac.chan_config == 4 && | |
732 | type == TYPE_SCE) { | ||
733 | ✗ | ac->tags_mapped++; | |
734 | ✗ | return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; | |
735 | } | ||
736 | case 3: | ||
737 | case 2: | ||
738 |
3/4✓ Branch 0 taken 24936 times.
✓ Branch 1 taken 820 times.
✓ Branch 2 taken 24936 times.
✗ Branch 3 not taken.
|
25756 | if (ac->tags_mapped == (ac->oc[1].m4ac.chan_config != 2) && |
739 | type == TYPE_CPE) { | ||
740 | 24936 | ac->tags_mapped++; | |
741 | 24936 | return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0]; | |
742 |
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 && |
743 | type == TYPE_SCE) { | ||
744 | ✗ | ac->tags_mapped++; | |
745 | ✗ | return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; | |
746 | } | ||
747 | case 1: | ||
748 |
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) { |
749 | 15926 | ac->tags_mapped++; | |
750 | 15926 | return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0]; | |
751 | } | ||
752 | default: | ||
753 | ✗ | return NULL; | |
754 | } | ||
755 | } | ||
756 | |||
757 | /** | ||
758 | * Decode an array of 4 bit element IDs, optionally interleaved with a | ||
759 | * stereo/mono switching bit. | ||
760 | * | ||
761 | * @param type speaker type/position for these channels | ||
762 | */ | ||
763 | 265 | static void decode_channel_map(uint8_t layout_map[][3], | |
764 | enum ChannelPosition type, | ||
765 | GetBitContext *gb, int n) | ||
766 | { | ||
767 |
2/2✓ Branch 0 taken 131 times.
✓ Branch 1 taken 265 times.
|
396 | while (n--) { |
768 | enum RawDataBlockType syn_ele; | ||
769 |
3/4✓ Branch 0 taken 111 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
131 | switch (type) { |
770 | 111 | case AAC_CHANNEL_FRONT: | |
771 | case AAC_CHANNEL_BACK: | ||
772 | case AAC_CHANNEL_SIDE: | ||
773 | 111 | syn_ele = get_bits1(gb); | |
774 | 111 | break; | |
775 | 8 | case AAC_CHANNEL_CC: | |
776 | 8 | skip_bits1(gb); | |
777 | 8 | syn_ele = TYPE_CCE; | |
778 | 8 | break; | |
779 | 12 | case AAC_CHANNEL_LFE: | |
780 | 12 | syn_ele = TYPE_LFE; | |
781 | 12 | break; | |
782 | ✗ | default: | |
783 | // AAC_CHANNEL_OFF has no channel map | ||
784 | ✗ | av_assert0(0); | |
785 | } | ||
786 | 131 | layout_map[0][0] = syn_ele; | |
787 | 131 | layout_map[0][1] = get_bits(gb, 4); | |
788 | 131 | layout_map[0][2] = type; | |
789 | 131 | layout_map++; | |
790 | } | ||
791 | 265 | } | |
792 | |||
793 | 53 | static inline void relative_align_get_bits(GetBitContext *gb, | |
794 | int reference_position) { | ||
795 | 53 | int n = (reference_position - get_bits_count(gb) & 7); | |
796 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 6 times.
|
53 | if (n) |
797 | 47 | skip_bits(gb, n); | |
798 | 53 | } | |
799 | |||
800 | /** | ||
801 | * Decode program configuration element; reference: table 4.2. | ||
802 | * | ||
803 | * @return Returns error status. 0 - OK, !0 - error | ||
804 | */ | ||
805 | 53 | static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, | |
806 | uint8_t (*layout_map)[3], | ||
807 | GetBitContext *gb, int byte_align_ref) | ||
808 | { | ||
809 | int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc; | ||
810 | int sampling_index; | ||
811 | int comment_len; | ||
812 | int tags; | ||
813 | |||
814 | 53 | skip_bits(gb, 2); // object_type | |
815 | |||
816 | 53 | sampling_index = get_bits(gb, 4); | |
817 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | if (m4ac->sampling_index != sampling_index) |
818 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
819 | "Sample rate index in program config element does not " | ||
820 | "match the sample rate index configured by the container.\n"); | ||
821 | |||
822 | 53 | num_front = get_bits(gb, 4); | |
823 | 53 | num_side = get_bits(gb, 4); | |
824 | 53 | num_back = get_bits(gb, 4); | |
825 | 53 | num_lfe = get_bits(gb, 2); | |
826 | 53 | num_assoc_data = get_bits(gb, 3); | |
827 | 53 | num_cc = get_bits(gb, 4); | |
828 | |||
829 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
|
53 | if (get_bits1(gb)) |
830 | ✗ | skip_bits(gb, 4); // mono_mixdown_tag | |
831 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
|
53 | if (get_bits1(gb)) |
832 | ✗ | skip_bits(gb, 4); // stereo_mixdown_tag | |
833 | |||
834 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
|
53 | if (get_bits1(gb)) |
835 | ✗ | skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround | |
836 | |||
837 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
|
53 | if (get_bits_left(gb) < 5 * (num_front + num_side + num_back + num_cc) + 4 *(num_lfe + num_assoc_data + num_cc)) { |
838 | ✗ | av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err); | |
839 | ✗ | return -1; | |
840 | } | ||
841 | 53 | decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front); | |
842 | 53 | tags = num_front; | |
843 | 53 | decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side); | |
844 | 53 | tags += num_side; | |
845 | 53 | decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back); | |
846 | 53 | tags += num_back; | |
847 | 53 | decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe); | |
848 | 53 | tags += num_lfe; | |
849 | |||
850 | 53 | skip_bits_long(gb, 4 * num_assoc_data); | |
851 | |||
852 | 53 | decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc); | |
853 | 53 | tags += num_cc; | |
854 | |||
855 | 53 | relative_align_get_bits(gb, byte_align_ref); | |
856 | |||
857 | /* comment field, first byte is length */ | ||
858 | 53 | comment_len = get_bits(gb, 8) * 8; | |
859 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
|
53 | if (get_bits_left(gb) < comment_len) { |
860 | ✗ | av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err); | |
861 | ✗ | return AVERROR_INVALIDDATA; | |
862 | } | ||
863 | 53 | skip_bits_long(gb, comment_len); | |
864 | 53 | return tags; | |
865 | } | ||
866 | |||
867 | /** | ||
868 | * Decode GA "General Audio" specific configuration; reference: table 4.1. | ||
869 | * | ||
870 | * @param ac pointer to AACDecContext, may be null | ||
871 | * @param avctx pointer to AVCCodecContext, used for logging | ||
872 | * | ||
873 | * @return Returns error status. 0 - OK, !0 - error | ||
874 | */ | ||
875 | 562 | static int decode_ga_specific_config(AACDecContext *ac, AVCodecContext *avctx, | |
876 | GetBitContext *gb, | ||
877 | int get_bit_alignment, | ||
878 | MPEG4AudioConfig *m4ac, | ||
879 | int channel_config) | ||
880 | { | ||
881 | int extension_flag, ret, ep_config, res_flags; | ||
882 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
883 | 562 | int tags = 0; | |
884 | |||
885 | 562 | m4ac->frame_length_short = get_bits1(gb); | |
886 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 560 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
562 | if (m4ac->frame_length_short && m4ac->sbr == 1) { |
887 | ✗ | avpriv_report_missing_feature(avctx, "SBR with 960 frame length"); | |
888 | ✗ | if (ac) ac->warned_960_sbr = 1; | |
889 | ✗ | m4ac->sbr = 0; | |
890 | ✗ | m4ac->ps = 0; | |
891 | } | ||
892 | |||
893 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 562 times.
|
562 | if (get_bits1(gb)) // dependsOnCoreCoder |
894 | ✗ | skip_bits(gb, 14); // coreCoderDelay | |
895 | 562 | extension_flag = get_bits1(gb); | |
896 | |||
897 |
1/2✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
|
562 | if (m4ac->object_type == AOT_AAC_SCALABLE || |
898 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 562 times.
|
562 | m4ac->object_type == AOT_ER_AAC_SCALABLE) |
899 | ✗ | skip_bits(gb, 3); // layerNr | |
900 | |||
901 |
2/2✓ Branch 0 taken 53 times.
✓ Branch 1 taken 509 times.
|
562 | if (channel_config == 0) { |
902 | 53 | skip_bits(gb, 4); // element_instance_tag | |
903 | 53 | tags = decode_pce(avctx, m4ac, layout_map, gb, get_bit_alignment); | |
904 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | if (tags < 0) |
905 | ✗ | return tags; | |
906 | } else { | ||
907 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 509 times.
|
509 | if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map, |
908 | &tags, channel_config))) | ||
909 | ✗ | return ret; | |
910 | } | ||
911 | |||
912 |
2/2✓ Branch 1 taken 470 times.
✓ Branch 2 taken 92 times.
|
562 | if (count_channels(layout_map, tags) > 1) { |
913 | 470 | m4ac->ps = 0; | |
914 |
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) |
915 | 18 | m4ac->ps = 1; | |
916 | |||
917 |
3/4✓ Branch 0 taken 240 times.
✓ Branch 1 taken 322 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 240 times.
|
562 | if (ac && (ret = ff_aac_output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0))) |
918 | ✗ | return ret; | |
919 | |||
920 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 558 times.
|
562 | if (extension_flag) { |
921 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | switch (m4ac->object_type) { |
922 | ✗ | case AOT_ER_BSAC: | |
923 | ✗ | skip_bits(gb, 5); // numOfSubFrame | |
924 | ✗ | skip_bits(gb, 11); // layer_length | |
925 | ✗ | break; | |
926 | 4 | case AOT_ER_AAC_LC: | |
927 | case AOT_ER_AAC_LTP: | ||
928 | case AOT_ER_AAC_SCALABLE: | ||
929 | case AOT_ER_AAC_LD: | ||
930 | 4 | res_flags = get_bits(gb, 3); | |
931 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (res_flags) { |
932 | ✗ | avpriv_report_missing_feature(avctx, | |
933 | "AAC data resilience (flags %x)", | ||
934 | res_flags); | ||
935 | ✗ | return AVERROR_PATCHWELCOME; | |
936 | } | ||
937 | 4 | break; | |
938 | } | ||
939 | 4 | skip_bits1(gb); // extensionFlag3 (TBD in version 3) | |
940 | } | ||
941 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 558 times.
|
562 | switch (m4ac->object_type) { |
942 | 4 | case AOT_ER_AAC_LC: | |
943 | case AOT_ER_AAC_LTP: | ||
944 | case AOT_ER_AAC_SCALABLE: | ||
945 | case AOT_ER_AAC_LD: | ||
946 | 4 | ep_config = get_bits(gb, 2); | |
947 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ep_config) { |
948 | ✗ | avpriv_report_missing_feature(avctx, | |
949 | "epConfig %d", ep_config); | ||
950 | ✗ | return AVERROR_PATCHWELCOME; | |
951 | } | ||
952 | } | ||
953 | 562 | return 0; | |
954 | } | ||
955 | |||
956 | 10 | static int decode_eld_specific_config(AACDecContext *ac, AVCodecContext *avctx, | |
957 | GetBitContext *gb, | ||
958 | MPEG4AudioConfig *m4ac, | ||
959 | int channel_config) | ||
960 | { | ||
961 | int ret, ep_config, res_flags; | ||
962 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
963 | 10 | int tags = 0; | |
964 | 10 | const int ELDEXT_TERM = 0; | |
965 | |||
966 | 10 | m4ac->ps = 0; | |
967 | 10 | m4ac->sbr = 0; | |
968 | 10 | m4ac->frame_length_short = get_bits1(gb); | |
969 | |||
970 | 10 | res_flags = get_bits(gb, 3); | |
971 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (res_flags) { |
972 | ✗ | avpriv_report_missing_feature(avctx, | |
973 | "AAC data resilience (flags %x)", | ||
974 | res_flags); | ||
975 | ✗ | return AVERROR_PATCHWELCOME; | |
976 | } | ||
977 | |||
978 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (get_bits1(gb)) { // ldSbrPresentFlag |
979 | ✗ | avpriv_report_missing_feature(avctx, | |
980 | "Low Delay SBR"); | ||
981 | ✗ | return AVERROR_PATCHWELCOME; | |
982 | } | ||
983 | |||
984 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | while (get_bits(gb, 4) != ELDEXT_TERM) { |
985 | ✗ | int len = get_bits(gb, 4); | |
986 | ✗ | if (len == 15) | |
987 | ✗ | len += get_bits(gb, 8); | |
988 | ✗ | if (len == 15 + 255) | |
989 | ✗ | len += get_bits(gb, 16); | |
990 | ✗ | if (get_bits_left(gb) < len * 8 + 4) { | |
991 | ✗ | av_log(avctx, AV_LOG_ERROR, overread_err); | |
992 | ✗ | return AVERROR_INVALIDDATA; | |
993 | } | ||
994 | ✗ | skip_bits_long(gb, 8 * len); | |
995 | } | ||
996 | |||
997 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map, |
998 | &tags, channel_config))) | ||
999 | ✗ | return ret; | |
1000 | |||
1001 |
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))) |
1002 | ✗ | return ret; | |
1003 | |||
1004 | 10 | ep_config = get_bits(gb, 2); | |
1005 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ep_config) { |
1006 | ✗ | avpriv_report_missing_feature(avctx, | |
1007 | "epConfig %d", ep_config); | ||
1008 | ✗ | return AVERROR_PATCHWELCOME; | |
1009 | } | ||
1010 | 10 | return 0; | |
1011 | } | ||
1012 | |||
1013 | /** | ||
1014 | * Decode audio specific configuration; reference: table 1.13. | ||
1015 | * | ||
1016 | * @param ac pointer to AACDecContext, may be null | ||
1017 | * @param avctx pointer to AVCCodecContext, used for logging | ||
1018 | * @param m4ac pointer to MPEG4AudioConfig, used for parsing | ||
1019 | * @param gb buffer holding an audio specific config | ||
1020 | * @param get_bit_alignment relative alignment for byte align operations | ||
1021 | * @param sync_extension look for an appended sync extension | ||
1022 | * | ||
1023 | * @return Returns error status or number of consumed bits. <0 - error | ||
1024 | */ | ||
1025 | 576 | static int decode_audio_specific_config_gb(AACDecContext *ac, | |
1026 | AVCodecContext *avctx, | ||
1027 | OutputConfiguration *oc, | ||
1028 | GetBitContext *gb, | ||
1029 | int get_bit_alignment, | ||
1030 | int sync_extension) | ||
1031 | { | ||
1032 | int i, ret; | ||
1033 | 576 | GetBitContext gbc = *gb; | |
1034 | 576 | MPEG4AudioConfig *m4ac = &oc->m4ac; | |
1035 | 576 | MPEG4AudioConfig m4ac_bak = *m4ac; | |
1036 | |||
1037 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 576 times.
|
576 | if ((i = ff_mpeg4audio_get_config_gb(m4ac, &gbc, sync_extension, avctx)) < 0) { |
1038 | ✗ | *m4ac = m4ac_bak; | |
1039 | ✗ | return AVERROR_INVALIDDATA; | |
1040 | } | ||
1041 | |||
1042 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 576 times.
|
576 | if (m4ac->sampling_index > 12) { |
1043 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1044 | "invalid sampling rate index %d\n", | ||
1045 | m4ac->sampling_index); | ||
1046 | ✗ | *m4ac = m4ac_bak; | |
1047 | ✗ | return AVERROR_INVALIDDATA; | |
1048 | } | ||
1049 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 572 times.
|
576 | if (m4ac->object_type == AOT_ER_AAC_LD && |
1050 |
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)) { |
1051 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1052 | "invalid low delay sampling rate index %d\n", | ||
1053 | m4ac->sampling_index); | ||
1054 | ✗ | *m4ac = m4ac_bak; | |
1055 | ✗ | return AVERROR_INVALIDDATA; | |
1056 | } | ||
1057 | |||
1058 | 576 | skip_bits_long(gb, i); | |
1059 | |||
1060 |
3/4✓ Branch 0 taken 562 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
576 | switch (m4ac->object_type) { |
1061 | 562 | case AOT_AAC_MAIN: | |
1062 | case AOT_AAC_LC: | ||
1063 | case AOT_AAC_SSR: | ||
1064 | case AOT_AAC_LTP: | ||
1065 | case AOT_ER_AAC_LC: | ||
1066 | case AOT_ER_AAC_LD: | ||
1067 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 562 times.
|
562 | if ((ret = decode_ga_specific_config(ac, avctx, gb, get_bit_alignment, |
1068 | &oc->m4ac, m4ac->chan_config)) < 0) | ||
1069 | ✗ | return ret; | |
1070 | 562 | break; | |
1071 | 10 | case AOT_ER_AAC_ELD: | |
1072 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = decode_eld_specific_config(ac, avctx, gb, |
1073 | &oc->m4ac, m4ac->chan_config)) < 0) | ||
1074 | ✗ | return ret; | |
1075 | 10 | break; | |
1076 | #if CONFIG_AAC_DECODER | ||
1077 | 4 | case AOT_USAC: | |
1078 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if ((ret = ff_aac_usac_config_decode(ac, avctx, gb, |
1079 | oc, m4ac->chan_config)) < 0) | ||
1080 | ✗ | return ret; | |
1081 | 4 | break; | |
1082 | #endif | ||
1083 | ✗ | default: | |
1084 | ✗ | avpriv_report_missing_feature(avctx, | |
1085 | "Audio object type %s%d", | ||
1086 | ✗ | m4ac->sbr == 1 ? "SBR+" : "", | |
1087 | m4ac->object_type); | ||
1088 | ✗ | return AVERROR(ENOSYS); | |
1089 | } | ||
1090 | |||
1091 | ff_dlog(avctx, | ||
1092 | "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n", | ||
1093 | m4ac->object_type, m4ac->chan_config, m4ac->sampling_index, | ||
1094 | m4ac->sample_rate, m4ac->sbr, | ||
1095 | m4ac->ps); | ||
1096 | |||
1097 | 576 | return get_bits_count(gb); | |
1098 | } | ||
1099 | |||
1100 | 254 | static int decode_audio_specific_config(AACDecContext *ac, | |
1101 | AVCodecContext *avctx, | ||
1102 | OutputConfiguration *oc, | ||
1103 | const uint8_t *data, int64_t bit_size, | ||
1104 | int sync_extension) | ||
1105 | { | ||
1106 | int i, ret; | ||
1107 | GetBitContext gb; | ||
1108 | |||
1109 |
2/4✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 254 times.
|
254 | if (bit_size < 0 || bit_size > INT_MAX) { |
1110 | ✗ | av_log(avctx, AV_LOG_ERROR, "Audio specific config size is invalid\n"); | |
1111 | ✗ | return AVERROR_INVALIDDATA; | |
1112 | } | ||
1113 | |||
1114 | ff_dlog(avctx, "audio specific config size %d\n", (int)bit_size >> 3); | ||
1115 |
2/2✓ Branch 0 taken 1639 times.
✓ Branch 1 taken 254 times.
|
1893 | for (i = 0; i < bit_size >> 3; i++) |
1116 | ff_dlog(avctx, "%02x ", data[i]); | ||
1117 | ff_dlog(avctx, "\n"); | ||
1118 | |||
1119 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 254 times.
|
254 | if ((ret = init_get_bits(&gb, data, bit_size)) < 0) |
1120 | ✗ | return ret; | |
1121 | |||
1122 | 254 | return decode_audio_specific_config_gb(ac, avctx, oc, &gb, 0, | |
1123 | sync_extension); | ||
1124 | } | ||
1125 | |||
1126 | 306 | static av_cold int decode_close(AVCodecContext *avctx) | |
1127 | { | ||
1128 | 306 | AACDecContext *ac = avctx->priv_data; | |
1129 | |||
1130 |
2/2✓ Branch 0 taken 612 times.
✓ Branch 1 taken 306 times.
|
918 | for (int i = 0; i < 2; i++) { |
1131 | 612 | OutputConfiguration *oc = &ac->oc[i]; | |
1132 | 612 | AACUSACConfig *usac = &oc->usac; | |
1133 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 612 times.
|
620 | for (int j = 0; j < usac->nb_elems; j++) { |
1134 | 8 | AACUsacElemConfig *ec = &usac->elems[j]; | |
1135 | 8 | av_refstruct_unref(&ec->ext.pl_buf); | |
1136 | } | ||
1137 | |||
1138 | 612 | av_channel_layout_uninit(&ac->oc[i].ch_layout); | |
1139 | } | ||
1140 | |||
1141 |
2/2✓ Branch 0 taken 1224 times.
✓ Branch 1 taken 306 times.
|
1530 | for (int type = 0; type < FF_ARRAY_ELEMS(ac->che); type++) { |
1142 |
2/2✓ Branch 0 taken 78336 times.
✓ Branch 1 taken 1224 times.
|
79560 | for (int i = 0; i < MAX_ELEM_ID; i++) { |
1143 |
2/2✓ Branch 0 taken 410 times.
✓ Branch 1 taken 77926 times.
|
78336 | if (ac->che[type][i]) { |
1144 | 410 | ac->proc.sbr_ctx_close(ac->che[type][i]); | |
1145 | 410 | av_freep(&ac->che[type][i]); | |
1146 | } | ||
1147 | } | ||
1148 | } | ||
1149 | |||
1150 | 306 | av_tx_uninit(&ac->mdct96); | |
1151 | 306 | av_tx_uninit(&ac->mdct120); | |
1152 | 306 | av_tx_uninit(&ac->mdct128); | |
1153 | 306 | av_tx_uninit(&ac->mdct480); | |
1154 | 306 | av_tx_uninit(&ac->mdct512); | |
1155 | 306 | av_tx_uninit(&ac->mdct768); | |
1156 | 306 | av_tx_uninit(&ac->mdct960); | |
1157 | 306 | av_tx_uninit(&ac->mdct1024); | |
1158 | 306 | av_tx_uninit(&ac->mdct_ltp); | |
1159 | |||
1160 | // Compiler will optimize this branch away. | ||
1161 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 283 times.
|
306 | if (ac->is_fixed) |
1162 | 23 | av_freep(&ac->RENAME_FIXED(fdsp)); | |
1163 | else | ||
1164 | 283 | av_freep(&ac->fdsp); | |
1165 | |||
1166 | 306 | return 0; | |
1167 | } | ||
1168 | |||
1169 | 306 | static av_cold int init_dsp(AVCodecContext *avctx) | |
1170 | { | ||
1171 | 306 | AACDecContext *ac = avctx->priv_data; | |
1172 | 306 | int is_fixed = ac->is_fixed, ret; | |
1173 | float scale_fixed, scale_float; | ||
1174 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 283 times.
|
306 | const float *const scalep = is_fixed ? &scale_fixed : &scale_float; |
1175 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 283 times.
|
306 | enum AVTXType tx_type = is_fixed ? AV_TX_INT32_MDCT : AV_TX_FLOAT_MDCT; |
1176 | |||
1177 | #define MDCT_INIT(s, fn, len, sval) \ | ||
1178 | scale_fixed = (sval) * 128.0f; \ | ||
1179 | scale_float = (sval) / 32768.0f; \ | ||
1180 | ret = av_tx_init(&s, &fn, tx_type, 1, len, scalep, 0); \ | ||
1181 | if (ret < 0) \ | ||
1182 | return ret | ||
1183 | |||
1184 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct96, ac->mdct96_fn, 96, 1.0/96); |
1185 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct120, ac->mdct120_fn, 120, 1.0/120); |
1186 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct128, ac->mdct128_fn, 128, 1.0/128); |
1187 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct480, ac->mdct480_fn, 480, 1.0/480); |
1188 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct512, ac->mdct512_fn, 512, 1.0/512); |
1189 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct768, ac->mdct768_fn, 768, 1.0/768); |
1190 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct960, ac->mdct960_fn, 960, 1.0/960); |
1191 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
|
306 | MDCT_INIT(ac->mdct1024, ac->mdct1024_fn, 1024, 1.0/1024); |
1192 | #undef MDCT_INIT | ||
1193 | |||
1194 | /* LTP forward MDCT */ | ||
1195 | 306 | scale_fixed = -1.0; | |
1196 | 306 | scale_float = -32786.0*2 + 36; | |
1197 | 306 | ret = av_tx_init(&ac->mdct_ltp, &ac->mdct_ltp_fn, tx_type, 0, 1024, scalep, 0); | |
1198 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 306 times.
|
306 | if (ret < 0) |
1199 | ✗ | return ret; | |
1200 | |||
1201 | 306 | return 0; | |
1202 | } | ||
1203 | |||
1204 | 306 | av_cold int ff_aac_decode_init(AVCodecContext *avctx) | |
1205 | { | ||
1206 | 306 | AACDecContext *ac = avctx->priv_data; | |
1207 | int ret; | ||
1208 | |||
1209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 306 times.
|
306 | if (avctx->sample_rate > 96000) |
1210 | ✗ | return AVERROR_INVALIDDATA; | |
1211 | |||
1212 | 306 | ff_aacdec_common_init_once(); | |
1213 | |||
1214 | 306 | ac->avctx = avctx; | |
1215 | 306 | ac->oc[1].m4ac.sample_rate = avctx->sample_rate; | |
1216 | |||
1217 |
2/2✓ Branch 0 taken 246 times.
✓ Branch 1 taken 60 times.
|
306 | if (avctx->extradata_size > 0) { |
1218 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
|
246 | if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1], |
1219 | 246 | avctx->extradata, | |
1220 | 246 | avctx->extradata_size * 8LL, | |
1221 | 1)) < 0) | ||
1222 | ✗ | return ret; | |
1223 | } else { | ||
1224 | int sr, i; | ||
1225 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
1226 | int layout_map_tags; | ||
1227 | |||
1228 | 60 | sr = ff_aac_sample_rate_idx(avctx->sample_rate); | |
1229 | 60 | ac->oc[1].m4ac.sampling_index = sr; | |
1230 | 60 | ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels; | |
1231 | 60 | ac->oc[1].m4ac.sbr = -1; | |
1232 | 60 | ac->oc[1].m4ac.ps = -1; | |
1233 | |||
1234 |
1/2✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
|
106 | for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) |
1235 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 46 times.
|
106 | if (ff_mpeg4audio_channels[i] == avctx->ch_layout.nb_channels) |
1236 | 60 | break; | |
1237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { |
1238 | ✗ | i = 0; | |
1239 | } | ||
1240 | 60 | ac->oc[1].m4ac.chan_config = i; | |
1241 | |||
1242 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 37 times.
|
60 | if (ac->oc[1].m4ac.chan_config) { |
1243 | 23 | int ret = ff_aac_set_default_channel_config(ac, avctx, layout_map, | |
1244 | &layout_map_tags, | ||
1245 | ac->oc[1].m4ac.chan_config); | ||
1246 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | if (!ret) |
1247 | 23 | ff_aac_output_configure(ac, layout_map, layout_map_tags, | |
1248 | OC_GLOBAL_HDR, 0); | ||
1249 | ✗ | else if (avctx->err_recognition & AV_EF_EXPLODE) | |
1250 | ✗ | return AVERROR_INVALIDDATA; | |
1251 | } | ||
1252 | } | ||
1253 | |||
1254 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 306 times.
|
306 | if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { |
1255 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); | |
1256 | ✗ | return AVERROR_INVALIDDATA; | |
1257 | } | ||
1258 | |||
1259 | 306 | ac->random_state = 0x1f2e3d4c; | |
1260 | |||
1261 | 306 | return init_dsp(avctx); | |
1262 | } | ||
1263 | |||
1264 | /** | ||
1265 | * Skip data_stream_element; reference: table 4.10. | ||
1266 | */ | ||
1267 | 2823 | static int skip_data_stream_element(AACDecContext *ac, GetBitContext *gb) | |
1268 | { | ||
1269 | 2823 | int byte_align = get_bits1(gb); | |
1270 | 2823 | int count = get_bits(gb, 8); | |
1271 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2823 times.
|
2823 | if (count == 255) |
1272 | ✗ | count += get_bits(gb, 8); | |
1273 |
2/2✓ Branch 0 taken 2456 times.
✓ Branch 1 taken 367 times.
|
2823 | if (byte_align) |
1274 | 2456 | align_get_bits(gb); | |
1275 | |||
1276 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2823 times.
|
2823 | if (get_bits_left(gb) < 8 * count) { |
1277 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "skip_data_stream_element: "overread_err); | |
1278 | ✗ | return AVERROR_INVALIDDATA; | |
1279 | } | ||
1280 | 2823 | skip_bits_long(gb, 8 * count); | |
1281 | 2823 | return 0; | |
1282 | } | ||
1283 | |||
1284 | 1273 | static int decode_prediction(AACDecContext *ac, IndividualChannelStream *ics, | |
1285 | GetBitContext *gb) | ||
1286 | { | ||
1287 | int sfb; | ||
1288 |
2/2✓ Branch 1 taken 212 times.
✓ Branch 2 taken 1061 times.
|
1273 | if (get_bits1(gb)) { |
1289 | 212 | ics->predictor_reset_group = get_bits(gb, 5); | |
1290 |
1/2✓ Branch 0 taken 212 times.
✗ Branch 1 not taken.
|
212 | if (ics->predictor_reset_group == 0 || |
1291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 212 times.
|
212 | ics->predictor_reset_group > 30) { |
1292 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1293 | "Invalid Predictor Reset Group.\n"); | ||
1294 | ✗ | return AVERROR_INVALIDDATA; | |
1295 | } | ||
1296 | } | ||
1297 |
2/2✓ Branch 0 taken 40255 times.
✓ Branch 1 taken 1273 times.
|
41528 | for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]); sfb++) { |
1298 | 40255 | ics->prediction_used[sfb] = get_bits1(gb); | |
1299 | } | ||
1300 | 1273 | return 0; | |
1301 | } | ||
1302 | |||
1303 | /** | ||
1304 | * Decode Long Term Prediction data; reference: table 4.xx. | ||
1305 | */ | ||
1306 | 786 | static void decode_ltp(AACDecContext *ac, LongTermPrediction *ltp, | |
1307 | GetBitContext *gb, uint8_t max_sfb) | ||
1308 | { | ||
1309 | int sfb; | ||
1310 | |||
1311 | 786 | ltp->lag = get_bits(gb, 11); | |
1312 |
2/2✓ Branch 0 taken 393 times.
✓ Branch 1 taken 393 times.
|
786 | if (CONFIG_AAC_FIXED_DECODER && ac->is_fixed) |
1313 | 393 | ltp->coef_fixed = Q30(ff_ltp_coef[get_bits(gb, 3)]); | |
1314 | else if (CONFIG_AAC_DECODER) | ||
1315 | 393 | ltp->coef = ff_ltp_coef[get_bits(gb, 3)]; | |
1316 | |||
1317 |
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++) |
1318 | 31440 | ltp->used[sfb] = get_bits1(gb); | |
1319 | 786 | } | |
1320 | |||
1321 | /** | ||
1322 | * Decode Individual Channel Stream info; reference: table 4.6. | ||
1323 | */ | ||
1324 | 62961 | static int decode_ics_info(AACDecContext *ac, IndividualChannelStream *ics, | |
1325 | GetBitContext *gb) | ||
1326 | { | ||
1327 | 62961 | const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac; | |
1328 | 62961 | const int aot = m4ac->object_type; | |
1329 | 62961 | const int sampling_index = m4ac->sampling_index; | |
1330 | 62961 | int ret_fail = AVERROR_INVALIDDATA; | |
1331 | |||
1332 |
2/2✓ Branch 0 taken 46596 times.
✓ Branch 1 taken 16365 times.
|
62961 | if (aot != AOT_ER_AAC_ELD) { |
1333 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 46596 times.
|
46596 | if (get_bits1(gb)) { |
1334 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n"); | |
1335 | ✗ | if (ac->avctx->err_recognition & AV_EF_BITSTREAM) | |
1336 | ✗ | return AVERROR_INVALIDDATA; | |
1337 | } | ||
1338 | 46596 | ics->window_sequence[1] = ics->window_sequence[0]; | |
1339 | 46596 | ics->window_sequence[0] = get_bits(gb, 2); | |
1340 |
2/2✓ Branch 0 taken 2424 times.
✓ Branch 1 taken 44172 times.
|
46596 | if (aot == AOT_ER_AAC_LD && |
1341 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
|
2424 | ics->window_sequence[0] != ONLY_LONG_SEQUENCE) { |
1342 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1343 | "AAC LD is only defined for ONLY_LONG_SEQUENCE but " | ||
1344 | ✗ | "window sequence %d found.\n", ics->window_sequence[0]); | |
1345 | ✗ | ics->window_sequence[0] = ONLY_LONG_SEQUENCE; | |
1346 | ✗ | return AVERROR_INVALIDDATA; | |
1347 | } | ||
1348 | 46596 | ics->use_kb_window[1] = ics->use_kb_window[0]; | |
1349 | 46596 | ics->use_kb_window[0] = get_bits1(gb); | |
1350 | } | ||
1351 | 62961 | ics->prev_num_window_groups = FFMAX(ics->num_window_groups, 1); | |
1352 | 62961 | ics->num_window_groups = 1; | |
1353 | 62961 | ics->group_len[0] = 1; | |
1354 |
2/2✓ Branch 0 taken 1316 times.
✓ Branch 1 taken 61645 times.
|
62961 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
1355 | int i; | ||
1356 | 1316 | ics->max_sfb = get_bits(gb, 4); | |
1357 |
2/2✓ Branch 0 taken 9212 times.
✓ Branch 1 taken 1316 times.
|
10528 | for (i = 0; i < 7; i++) { |
1358 |
2/2✓ Branch 1 taken 5827 times.
✓ Branch 2 taken 3385 times.
|
9212 | if (get_bits1(gb)) { |
1359 | 5827 | ics->group_len[ics->num_window_groups - 1]++; | |
1360 | } else { | ||
1361 | 3385 | ics->num_window_groups++; | |
1362 | 3385 | ics->group_len[ics->num_window_groups - 1] = 1; | |
1363 | } | ||
1364 | } | ||
1365 | 1316 | ics->num_windows = 8; | |
1366 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1315 times.
|
1316 | if (m4ac->frame_length_short) { |
1367 | 1 | ics->swb_offset = ff_swb_offset_120[sampling_index]; | |
1368 | 1 | ics->num_swb = ff_aac_num_swb_120[sampling_index]; | |
1369 | } else { | ||
1370 | 1315 | ics->swb_offset = ff_swb_offset_128[sampling_index]; | |
1371 | 1315 | ics->num_swb = ff_aac_num_swb_128[sampling_index]; | |
1372 | } | ||
1373 | 1316 | ics->tns_max_bands = ff_tns_max_bands_128[sampling_index]; | |
1374 | 1316 | ics->predictor_present = 0; | |
1375 | } else { | ||
1376 | 61645 | ics->max_sfb = get_bits(gb, 6); | |
1377 | 61645 | ics->num_windows = 1; | |
1378 |
4/4✓ Branch 0 taken 59221 times.
✓ Branch 1 taken 2424 times.
✓ Branch 2 taken 16365 times.
✓ Branch 3 taken 42856 times.
|
61645 | if (aot == AOT_ER_AAC_LD || aot == AOT_ER_AAC_ELD) { |
1379 |
2/2✓ Branch 0 taken 3559 times.
✓ Branch 1 taken 15230 times.
|
18789 | if (m4ac->frame_length_short) { |
1380 | 3559 | ics->swb_offset = ff_swb_offset_480[sampling_index]; | |
1381 | 3559 | ics->num_swb = ff_aac_num_swb_480[sampling_index]; | |
1382 | 3559 | ics->tns_max_bands = ff_tns_max_bands_480[sampling_index]; | |
1383 | } else { | ||
1384 | 15230 | ics->swb_offset = ff_swb_offset_512[sampling_index]; | |
1385 | 15230 | ics->num_swb = ff_aac_num_swb_512[sampling_index]; | |
1386 | 15230 | ics->tns_max_bands = ff_tns_max_bands_512[sampling_index]; | |
1387 | } | ||
1388 |
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) { |
1389 | ✗ | ret_fail = AVERROR_BUG; | |
1390 | ✗ | goto fail; | |
1391 | } | ||
1392 | } else { | ||
1393 |
2/2✓ Branch 0 taken 386 times.
✓ Branch 1 taken 42470 times.
|
42856 | if (m4ac->frame_length_short) { |
1394 | 386 | ics->num_swb = ff_aac_num_swb_960[sampling_index]; | |
1395 | 386 | ics->swb_offset = ff_swb_offset_960[sampling_index]; | |
1396 | } else { | ||
1397 | 42470 | ics->num_swb = ff_aac_num_swb_1024[sampling_index]; | |
1398 | 42470 | ics->swb_offset = ff_swb_offset_1024[sampling_index]; | |
1399 | } | ||
1400 | 42856 | ics->tns_max_bands = ff_tns_max_bands_1024[sampling_index]; | |
1401 | } | ||
1402 |
2/2✓ Branch 0 taken 45280 times.
✓ Branch 1 taken 16365 times.
|
61645 | if (aot != AOT_ER_AAC_ELD) { |
1403 | 45280 | ics->predictor_present = get_bits1(gb); | |
1404 | 45280 | ics->predictor_reset_group = 0; | |
1405 | } | ||
1406 |
2/2✓ Branch 0 taken 1811 times.
✓ Branch 1 taken 59834 times.
|
61645 | if (ics->predictor_present) { |
1407 |
2/2✓ Branch 0 taken 1273 times.
✓ Branch 1 taken 538 times.
|
1811 | if (aot == AOT_AAC_MAIN) { |
1408 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1273 times.
|
1273 | if (decode_prediction(ac, ics, gb)) { |
1409 | ✗ | goto fail; | |
1410 | } | ||
1411 |
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 || |
1412 | aot == AOT_ER_AAC_LC) { | ||
1413 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1414 | "Prediction is not allowed in AAC-LC.\n"); | ||
1415 | ✗ | goto fail; | |
1416 | } else { | ||
1417 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
|
538 | if (aot == AOT_ER_AAC_LD) { |
1418 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1419 | "LTP in ER AAC LD not yet implemented.\n"); | ||
1420 | ✗ | ret_fail = AVERROR_PATCHWELCOME; | |
1421 | ✗ | goto fail; | |
1422 | } | ||
1423 |
2/2✓ Branch 1 taken 382 times.
✓ Branch 2 taken 156 times.
|
538 | if ((ics->ltp.present = get_bits(gb, 1))) |
1424 | 382 | decode_ltp(ac, &ics->ltp, gb, ics->max_sfb); | |
1425 | } | ||
1426 | } | ||
1427 | } | ||
1428 | |||
1429 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62961 times.
|
62961 | if (ics->max_sfb > ics->num_swb) { |
1430 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1431 | "Number of scalefactor bands in group (%d) " | ||
1432 | "exceeds limit (%d).\n", | ||
1433 | ✗ | ics->max_sfb, ics->num_swb); | |
1434 | ✗ | goto fail; | |
1435 | } | ||
1436 | |||
1437 | 62961 | return 0; | |
1438 | ✗ | fail: | |
1439 | ✗ | ics->max_sfb = 0; | |
1440 | ✗ | return ret_fail; | |
1441 | } | ||
1442 | |||
1443 | /** | ||
1444 | * Decode band types (section_data payload); reference: table 4.46. | ||
1445 | * | ||
1446 | * @param band_type array of the used band type | ||
1447 | * @param band_type_run_end array of the last scalefactor band of a band type run | ||
1448 | * | ||
1449 | * @return Returns error status. 0 - OK, !0 - error | ||
1450 | */ | ||
1451 | 93154 | static int decode_band_types(AACDecContext *ac, SingleChannelElement *sce, | |
1452 | GetBitContext *gb) | ||
1453 | { | ||
1454 | 93154 | IndividualChannelStream *ics = &sce->ics; | |
1455 |
2/2✓ Branch 0 taken 2070 times.
✓ Branch 1 taken 91084 times.
|
93154 | const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5; |
1456 | |||
1457 |
2/2✓ Branch 0 taken 98339 times.
✓ Branch 1 taken 93154 times.
|
191493 | for (int g = 0; g < ics->num_window_groups; g++) { |
1458 | 98339 | int k = 0; | |
1459 |
2/2✓ Branch 0 taken 459204 times.
✓ Branch 1 taken 98339 times.
|
557543 | while (k < ics->max_sfb) { |
1460 | 459204 | uint8_t sect_end = k; | |
1461 | int sect_len_incr; | ||
1462 | 459204 | int sect_band_type = get_bits(gb, 4); | |
1463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 459204 times.
|
459204 | if (sect_band_type == 12) { |
1464 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n"); | |
1465 | ✗ | return AVERROR_INVALIDDATA; | |
1466 | } | ||
1467 | do { | ||
1468 | 477854 | sect_len_incr = get_bits(gb, bits); | |
1469 | 477854 | sect_end += sect_len_incr; | |
1470 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 477854 times.
|
477854 | if (get_bits_left(gb) < 0) { |
1471 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "decode_band_types: "overread_err); | |
1472 | ✗ | return AVERROR_INVALIDDATA; | |
1473 | } | ||
1474 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 477854 times.
|
477854 | if (sect_end > ics->max_sfb) { |
1475 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1476 | "Number of bands (%d) exceeds limit (%d).\n", | ||
1477 | ✗ | sect_end, ics->max_sfb); | |
1478 | ✗ | return AVERROR_INVALIDDATA; | |
1479 | } | ||
1480 |
2/2✓ Branch 0 taken 18650 times.
✓ Branch 1 taken 459204 times.
|
477854 | } while (sect_len_incr == (1 << bits) - 1); |
1481 |
2/2✓ Branch 0 taken 3438545 times.
✓ Branch 1 taken 459204 times.
|
3897749 | for (; k < sect_end; k++) |
1482 | 3438545 | sce->band_type[g*ics->max_sfb + k] = sect_band_type; | |
1483 | } | ||
1484 | } | ||
1485 | 93154 | return 0; | |
1486 | } | ||
1487 | |||
1488 | /** | ||
1489 | * Decode scalefactors; reference: table 4.47. | ||
1490 | * | ||
1491 | * @param global_gain first scalefactor value as scalefactors are differentially coded | ||
1492 | * @param band_type array of the used band type | ||
1493 | * @param band_type_run_end array of the last scalefactor band of a band type run | ||
1494 | * @param sf array of scalefactors or intensity stereo positions | ||
1495 | * | ||
1496 | * @return Returns error status. 0 - OK, !0 - error | ||
1497 | */ | ||
1498 | 93154 | static int decode_scalefactors(AACDecContext *ac, SingleChannelElement *sce, | |
1499 | GetBitContext *gb, unsigned int global_gain) | ||
1500 | { | ||
1501 | 93154 | IndividualChannelStream *ics = &sce->ics; | |
1502 | 93154 | int offset[3] = { global_gain, global_gain - NOISE_OFFSET, 0 }; | |
1503 | int clipped_offset; | ||
1504 | 93154 | int noise_flag = 1; | |
1505 | |||
1506 |
2/2✓ Branch 0 taken 98339 times.
✓ Branch 1 taken 93154 times.
|
191493 | for (int g = 0; g < ics->num_window_groups; g++) { |
1507 |
2/2✓ Branch 0 taken 3438545 times.
✓ Branch 1 taken 98339 times.
|
3536884 | for (int sfb = 0; sfb < ics->max_sfb; sfb++) { |
1508 |
4/4✓ Branch 0 taken 535841 times.
✓ Branch 1 taken 66188 times.
✓ Branch 2 taken 281876 times.
✓ Branch 3 taken 2554640 times.
|
3438545 | switch (sce->band_type[g*ics->max_sfb + sfb]) { |
1509 | 535841 | case ZERO_BT: | |
1510 | 535841 | sce->sfo[g*ics->max_sfb + sfb] = 0; | |
1511 | 535841 | break; | |
1512 | 66188 | case INTENSITY_BT: /* fallthrough */ | |
1513 | case INTENSITY_BT2: | ||
1514 | 66188 | offset[2] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO; | |
1515 | 66188 | clipped_offset = av_clip(offset[2], -155, 100); | |
1516 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66188 times.
|
66188 | if (offset[2] != clipped_offset) { |
1517 | ✗ | avpriv_request_sample(ac->avctx, | |
1518 | "If you heard an audible artifact, there may be a bug in the decoder. " | ||
1519 | "Clipped intensity stereo position (%d -> %d)", | ||
1520 | offset[2], clipped_offset); | ||
1521 | } | ||
1522 | 66188 | sce->sfo[g*ics->max_sfb + sfb] = clipped_offset - 100; | |
1523 | 66188 | break; | |
1524 | 281876 | case NOISE_BT: | |
1525 |
2/2✓ Branch 0 taken 6756 times.
✓ Branch 1 taken 275120 times.
|
281876 | if (noise_flag-- > 0) |
1526 | 6756 | offset[1] += get_bits(gb, NOISE_PRE_BITS) - NOISE_PRE; | |
1527 | else | ||
1528 | 275120 | offset[1] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO; | |
1529 | 281876 | clipped_offset = av_clip(offset[1], -100, 155); | |
1530 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 281876 times.
|
281876 | if (offset[1] != clipped_offset) { |
1531 | ✗ | avpriv_request_sample(ac->avctx, | |
1532 | "If you heard an audible artifact, there may be a bug in the decoder. " | ||
1533 | "Clipped noise gain (%d -> %d)", | ||
1534 | offset[1], clipped_offset); | ||
1535 | } | ||
1536 | 281876 | sce->sfo[g*ics->max_sfb + sfb] = clipped_offset; | |
1537 | 281876 | break; | |
1538 | 2554640 | default: | |
1539 | 2554640 | offset[0] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO; | |
1540 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2554640 times.
|
2554640 | if (offset[0] > 255U) { |
1541 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1542 | "Scalefactor (%d) out of range.\n", offset[0]); | ||
1543 | ✗ | return AVERROR_INVALIDDATA; | |
1544 | } | ||
1545 | 2554640 | sce->sfo[g*ics->max_sfb + sfb] = offset[0] - 100; | |
1546 | 2554640 | break; | |
1547 | } | ||
1548 | } | ||
1549 | } | ||
1550 | |||
1551 | 93154 | return 0; | |
1552 | } | ||
1553 | |||
1554 | /** | ||
1555 | * Decode pulse data; reference: table 4.7. | ||
1556 | */ | ||
1557 | 1098 | static int decode_pulses(Pulse *pulse, GetBitContext *gb, | |
1558 | const uint16_t *swb_offset, int num_swb) | ||
1559 | { | ||
1560 | int i, pulse_swb; | ||
1561 | 1098 | pulse->num_pulse = get_bits(gb, 2) + 1; | |
1562 | 1098 | pulse_swb = get_bits(gb, 6); | |
1563 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
|
1098 | if (pulse_swb >= num_swb) |
1564 | ✗ | return -1; | |
1565 | 1098 | pulse->pos[0] = swb_offset[pulse_swb]; | |
1566 | 1098 | pulse->pos[0] += get_bits(gb, 5); | |
1567 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
|
1098 | if (pulse->pos[0] >= swb_offset[num_swb]) |
1568 | ✗ | return -1; | |
1569 | 1098 | pulse->amp[0] = get_bits(gb, 4); | |
1570 |
2/2✓ Branch 0 taken 1646 times.
✓ Branch 1 taken 1098 times.
|
2744 | for (i = 1; i < pulse->num_pulse; i++) { |
1571 | 1646 | pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i - 1]; | |
1572 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1646 times.
|
1646 | if (pulse->pos[i] >= swb_offset[num_swb]) |
1573 | ✗ | return -1; | |
1574 | 1646 | pulse->amp[i] = get_bits(gb, 4); | |
1575 | } | ||
1576 | 1098 | return 0; | |
1577 | } | ||
1578 | |||
1579 | /** | ||
1580 | * Decode Temporal Noise Shaping data; reference: table 4.48. | ||
1581 | * | ||
1582 | * @return Returns error status. 0 - OK, !0 - error | ||
1583 | */ | ||
1584 | 6955 | int ff_aac_decode_tns(AACDecContext *ac, TemporalNoiseShaping *tns, | |
1585 | GetBitContext *gb, const IndividualChannelStream *ics) | ||
1586 | { | ||
1587 | 6955 | int tns_max_order = INT32_MAX; | |
1588 | 6955 | const int is_usac = ac->oc[1].m4ac.object_type == AOT_USAC; | |
1589 | int w, filt, i, coef_len, coef_res, coef_compress; | ||
1590 | 6955 | const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE; | |
1591 | |||
1592 | /* USAC doesn't seem to have a limit */ | ||
1593 |
1/2✓ Branch 0 taken 6955 times.
✗ Branch 1 not taken.
|
6955 | if (!is_usac) |
1594 |
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; |
1595 | |||
1596 |
2/2✓ Branch 0 taken 11568 times.
✓ Branch 1 taken 6955 times.
|
18523 | for (w = 0; w < ics->num_windows; w++) { |
1597 |
2/2✓ Branch 1 taken 7946 times.
✓ Branch 2 taken 3622 times.
|
11568 | if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) { |
1598 | 7946 | coef_res = get_bits1(gb); | |
1599 | |||
1600 |
2/2✓ Branch 0 taken 9407 times.
✓ Branch 1 taken 7946 times.
|
17353 | for (filt = 0; filt < tns->n_filt[w]; filt++) { |
1601 | int tmp2_idx; | ||
1602 | 9407 | tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); | |
1603 | |||
1604 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9407 times.
|
9407 | if (is_usac) |
1605 | ✗ | tns->order[w][filt] = get_bits(gb, 4 - is8); | |
1606 | else | ||
1607 | 9407 | tns->order[w][filt] = get_bits(gb, 5 - (2 * is8)); | |
1608 | |||
1609 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9407 times.
|
9407 | if (tns->order[w][filt] > tns_max_order) { |
1610 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1611 | "TNS filter order %d is greater than maximum %d.\n", | ||
1612 | tns->order[w][filt], tns_max_order); | ||
1613 | ✗ | tns->order[w][filt] = 0; | |
1614 | ✗ | return AVERROR_INVALIDDATA; | |
1615 | } | ||
1616 |
2/2✓ Branch 0 taken 8887 times.
✓ Branch 1 taken 520 times.
|
9407 | if (tns->order[w][filt]) { |
1617 | 8887 | tns->direction[w][filt] = get_bits1(gb); | |
1618 | 8887 | coef_compress = get_bits1(gb); | |
1619 | 8887 | coef_len = coef_res + 3 - coef_compress; | |
1620 | 8887 | tmp2_idx = 2 * coef_compress + coef_res; | |
1621 | |||
1622 |
2/2✓ Branch 0 taken 58548 times.
✓ Branch 1 taken 8887 times.
|
67435 | for (i = 0; i < tns->order[w][filt]; i++) { |
1623 |
2/2✓ Branch 0 taken 14113 times.
✓ Branch 1 taken 44435 times.
|
58548 | if (CONFIG_AAC_FIXED_DECODER && ac->is_fixed) |
1624 | 14113 | tns->coef_fixed[w][filt][i] = Q31(ff_tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)]); | |
1625 | else if (CONFIG_AAC_DECODER) | ||
1626 | 44435 | tns->coef[w][filt][i] = ff_tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)]; | |
1627 | } | ||
1628 | } | ||
1629 | } | ||
1630 | } | ||
1631 | } | ||
1632 | 6955 | return 0; | |
1633 | } | ||
1634 | |||
1635 | /** | ||
1636 | * Decode Mid/Side data; reference: table 4.54. | ||
1637 | * | ||
1638 | * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; | ||
1639 | * [1] mask is decoded from bitstream; [2] mask is all 1s; | ||
1640 | * [3] reserved for scalable AAC | ||
1641 | */ | ||
1642 | 27052 | static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, | |
1643 | int ms_present) | ||
1644 | { | ||
1645 | int idx; | ||
1646 | 27052 | int max_idx = cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb; | |
1647 | 27052 | cpe->max_sfb_ste = cpe->ch[0].ics.max_sfb; | |
1648 |
2/2✓ Branch 0 taken 12687 times.
✓ Branch 1 taken 14365 times.
|
27052 | if (ms_present == 1) { |
1649 |
2/2✓ Branch 0 taken 497864 times.
✓ Branch 1 taken 12687 times.
|
510551 | for (idx = 0; idx < max_idx; idx++) |
1650 | 497864 | cpe->ms_mask[idx] = get_bits1(gb); | |
1651 |
1/2✓ Branch 0 taken 14365 times.
✗ Branch 1 not taken.
|
14365 | } else if (ms_present == 2) { |
1652 | 14365 | memset(cpe->ms_mask, 1, max_idx * sizeof(cpe->ms_mask[0])); | |
1653 | } | ||
1654 | 27052 | } | |
1655 | |||
1656 | ✗ | static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb) | |
1657 | { | ||
1658 | // wd_num, wd_test, aloc_size | ||
1659 | static const uint8_t gain_mode[4][3] = { | ||
1660 | {1, 0, 5}, // ONLY_LONG_SEQUENCE = 0, | ||
1661 | {2, 1, 2}, // LONG_START_SEQUENCE, | ||
1662 | {8, 0, 2}, // EIGHT_SHORT_SEQUENCE, | ||
1663 | {2, 1, 5}, // LONG_STOP_SEQUENCE | ||
1664 | }; | ||
1665 | |||
1666 | ✗ | const int mode = sce->ics.window_sequence[0]; | |
1667 | uint8_t bd, wd, ad; | ||
1668 | |||
1669 | // FIXME: Store the gain control data on |sce| and do something with it. | ||
1670 | ✗ | uint8_t max_band = get_bits(gb, 2); | |
1671 | ✗ | for (bd = 0; bd < max_band; bd++) { | |
1672 | ✗ | for (wd = 0; wd < gain_mode[mode][0]; wd++) { | |
1673 | ✗ | uint8_t adjust_num = get_bits(gb, 3); | |
1674 | ✗ | for (ad = 0; ad < adjust_num; ad++) { | |
1675 | ✗ | skip_bits(gb, 4 + ((wd == 0 && gain_mode[mode][1]) | |
1676 | ? 4 | ||
1677 | ✗ | : gain_mode[mode][2])); | |
1678 | } | ||
1679 | } | ||
1680 | } | ||
1681 | ✗ | } | |
1682 | |||
1683 | /** | ||
1684 | * Decode an individual_channel_stream payload; reference: table 4.44. | ||
1685 | * | ||
1686 | * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. | ||
1687 | * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.) | ||
1688 | * | ||
1689 | * @return Returns error status. 0 - OK, !0 - error | ||
1690 | */ | ||
1691 | 93154 | int ff_aac_decode_ics(AACDecContext *ac, SingleChannelElement *sce, | |
1692 | GetBitContext *gb, int common_window, int scale_flag) | ||
1693 | { | ||
1694 | Pulse pulse; | ||
1695 | 93154 | TemporalNoiseShaping *tns = &sce->tns; | |
1696 | 93154 | IndividualChannelStream *ics = &sce->ics; | |
1697 | 93154 | int global_gain, eld_syntax, er_syntax, pulse_present = 0; | |
1698 | int ret; | ||
1699 | |||
1700 | 93154 | eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD; | |
1701 | 279462 | er_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_LC || | |
1702 |
1/2✓ Branch 0 taken 93154 times.
✗ Branch 1 not taken.
|
93154 | ac->oc[1].m4ac.object_type == AOT_ER_AAC_LTP || |
1703 |
3/4✓ Branch 0 taken 93154 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89518 times.
✓ Branch 3 taken 3636 times.
|
275826 | ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD || |
1704 |
2/2✓ Branch 0 taken 26598 times.
✓ Branch 1 taken 62920 times.
|
89518 | ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD; |
1705 | |||
1706 | /* This assignment is to silence a GCC warning about the variable being used | ||
1707 | * uninitialized when in fact it always is. | ||
1708 | */ | ||
1709 | 93154 | pulse.num_pulse = 0; | |
1710 | |||
1711 | 93154 | global_gain = get_bits(gb, 8); | |
1712 | |||
1713 |
3/4✓ Branch 0 taken 32768 times.
✓ Branch 1 taken 60386 times.
✓ Branch 2 taken 32768 times.
✗ Branch 3 not taken.
|
93154 | if (!common_window && !scale_flag) { |
1714 | 32768 | ret = decode_ics_info(ac, ics, gb); | |
1715 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32768 times.
|
32768 | if (ret < 0) |
1716 | ✗ | goto fail; | |
1717 | } | ||
1718 | |||
1719 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 93154 times.
|
93154 | if ((ret = decode_band_types(ac, sce, gb)) < 0) |
1720 | ✗ | goto fail; | |
1721 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 93154 times.
|
93154 | if ((ret = decode_scalefactors(ac, sce, gb, global_gain)) < 0) |
1722 | ✗ | goto fail; | |
1723 | |||
1724 | 93154 | ac->dsp.dequant_scalefactors(sce); | |
1725 | |||
1726 | 93154 | pulse_present = 0; | |
1727 |
1/2✓ Branch 0 taken 93154 times.
✗ Branch 1 not taken.
|
93154 | if (!scale_flag) { |
1728 |
4/4✓ Branch 0 taken 66556 times.
✓ Branch 1 taken 26598 times.
✓ Branch 3 taken 1098 times.
✓ Branch 4 taken 65458 times.
|
93154 | if (!eld_syntax && (pulse_present = get_bits1(gb))) { |
1729 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
|
1098 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
1730 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1731 | "Pulse tool not allowed in eight short sequence.\n"); | ||
1732 | ✗ | ret = AVERROR_INVALIDDATA; | |
1733 | ✗ | goto fail; | |
1734 | } | ||
1735 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1098 times.
|
1098 | if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) { |
1736 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1737 | "Pulse data corrupt or invalid.\n"); | ||
1738 | ✗ | ret = AVERROR_INVALIDDATA; | |
1739 | ✗ | goto fail; | |
1740 | } | ||
1741 | } | ||
1742 | 93154 | tns->present = get_bits1(gb); | |
1743 |
4/4✓ Branch 0 taken 6955 times.
✓ Branch 1 taken 86199 times.
✓ Branch 2 taken 5691 times.
✓ Branch 3 taken 1264 times.
|
93154 | if (tns->present && !er_syntax) { |
1744 | 5691 | ret = ff_aac_decode_tns(ac, tns, gb, ics); | |
1745 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5691 times.
|
5691 | if (ret < 0) |
1746 | ✗ | goto fail; | |
1747 | } | ||
1748 |
3/4✓ Branch 0 taken 66556 times.
✓ Branch 1 taken 26598 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 66556 times.
|
93154 | if (!eld_syntax && get_bits1(gb)) { |
1749 | ✗ | decode_gain_control(sce, gb); | |
1750 | ✗ | if (!ac->warned_gain_control) { | |
1751 | ✗ | avpriv_report_missing_feature(ac->avctx, "Gain control"); | |
1752 | ✗ | ac->warned_gain_control = 1; | |
1753 | } | ||
1754 | } | ||
1755 | // I see no textual basis in the spec for this occurring after SSR gain | ||
1756 | // control, but this is what both reference and real implementations do | ||
1757 |
4/4✓ Branch 0 taken 6955 times.
✓ Branch 1 taken 86199 times.
✓ Branch 2 taken 1264 times.
✓ Branch 3 taken 5691 times.
|
93154 | if (tns->present && er_syntax) { |
1758 | 1264 | ret = ff_aac_decode_tns(ac, tns, gb, ics); | |
1759 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1264 times.
|
1264 | if (ret < 0) |
1760 | ✗ | goto fail; | |
1761 | } | ||
1762 | } | ||
1763 | |||
1764 |
2/2✓ Branch 0 taken 1098 times.
✓ Branch 1 taken 92056 times.
|
93154 | ret = ac->proc.decode_spectrum_and_dequant(ac, gb, |
1765 | pulse_present ? &pulse : NULL, | ||
1766 | sce); | ||
1767 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93154 times.
|
93154 | if (ret < 0) |
1768 | ✗ | goto fail; | |
1769 | |||
1770 |
4/4✓ Branch 0 taken 6564 times.
✓ Branch 1 taken 86590 times.
✓ Branch 2 taken 6040 times.
✓ Branch 3 taken 524 times.
|
93154 | if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window) |
1771 | 6040 | ac->dsp.apply_prediction(ac, sce); | |
1772 | |||
1773 | 93154 | return 0; | |
1774 | ✗ | fail: | |
1775 | ✗ | memset(sce->sfo, 0, sizeof(sce->sfo)); | |
1776 | ✗ | tns->present = 0; | |
1777 | ✗ | return ret; | |
1778 | } | ||
1779 | |||
1780 | /** | ||
1781 | * Decode a channel_pair_element; reference: table 4.4. | ||
1782 | * | ||
1783 | * @return Returns error status. 0 - OK, !0 - error | ||
1784 | */ | ||
1785 | 30388 | static int decode_cpe(AACDecContext *ac, GetBitContext *gb, ChannelElement *cpe) | |
1786 | { | ||
1787 | 30388 | int i, ret, common_window, ms_present = 0; | |
1788 | 30388 | int eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD; | |
1789 | |||
1790 |
4/4✓ Branch 0 taken 20155 times.
✓ Branch 1 taken 10233 times.
✓ Branch 3 taken 19960 times.
✓ Branch 4 taken 195 times.
|
30388 | common_window = eld_syntax || get_bits1(gb); |
1791 |
2/2✓ Branch 0 taken 30193 times.
✓ Branch 1 taken 195 times.
|
30388 | if (common_window) { |
1792 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30193 times.
|
30193 | if (decode_ics_info(ac, &cpe->ch[0].ics, gb)) |
1793 | ✗ | return AVERROR_INVALIDDATA; | |
1794 | 30193 | i = cpe->ch[1].ics.use_kb_window[0]; | |
1795 | 30193 | cpe->ch[1].ics = cpe->ch[0].ics; | |
1796 | 30193 | cpe->ch[1].ics.use_kb_window[1] = i; | |
1797 |
2/2✓ Branch 0 taken 593 times.
✓ Branch 1 taken 29600 times.
|
30193 | if (cpe->ch[1].ics.predictor_present && |
1798 |
2/2✓ Branch 0 taken 538 times.
✓ Branch 1 taken 55 times.
|
593 | (ac->oc[1].m4ac.object_type != AOT_AAC_MAIN)) |
1799 |
2/2✓ Branch 1 taken 404 times.
✓ Branch 2 taken 134 times.
|
538 | if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1))) |
1800 | 404 | decode_ltp(ac, &cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb); | |
1801 | 30193 | ms_present = get_bits(gb, 2); | |
1802 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30193 times.
|
30193 | if (ms_present == 3) { |
1803 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n"); | |
1804 | ✗ | return AVERROR_INVALIDDATA; | |
1805 |
2/2✓ Branch 0 taken 27052 times.
✓ Branch 1 taken 3141 times.
|
30193 | } else if (ms_present) |
1806 | 27052 | decode_mid_side_stereo(cpe, gb, ms_present); | |
1807 | } | ||
1808 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30388 times.
|
30388 | if ((ret = ff_aac_decode_ics(ac, &cpe->ch[0], gb, common_window, 0))) |
1809 | ✗ | return ret; | |
1810 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30388 times.
|
30388 | if ((ret = ff_aac_decode_ics(ac, &cpe->ch[1], gb, common_window, 0))) |
1811 | ✗ | return ret; | |
1812 | |||
1813 |
2/2✓ Branch 0 taken 30193 times.
✓ Branch 1 taken 195 times.
|
30388 | if (common_window) { |
1814 |
2/2✓ Branch 0 taken 27052 times.
✓ Branch 1 taken 3141 times.
|
30193 | if (ms_present) |
1815 | 27052 | ac->dsp.apply_mid_side_stereo(ac, cpe); | |
1816 |
2/2✓ Branch 0 taken 262 times.
✓ Branch 1 taken 29931 times.
|
30193 | if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN) { |
1817 | 262 | ac->dsp.apply_prediction(ac, &cpe->ch[0]); | |
1818 | 262 | ac->dsp.apply_prediction(ac, &cpe->ch[1]); | |
1819 | } | ||
1820 | } | ||
1821 | |||
1822 | 30388 | ac->dsp.apply_intensity_stereo(ac, cpe, ms_present); | |
1823 | 30388 | return 0; | |
1824 | } | ||
1825 | |||
1826 | /** | ||
1827 | * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53. | ||
1828 | * | ||
1829 | * @return Returns number of bytes consumed. | ||
1830 | */ | ||
1831 | 4 | static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, | |
1832 | GetBitContext *gb) | ||
1833 | { | ||
1834 | int i; | ||
1835 | 4 | int num_excl_chan = 0; | |
1836 | |||
1837 | do { | ||
1838 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 4 times.
|
32 | for (i = 0; i < 7; i++) |
1839 | 28 | che_drc->exclude_mask[num_excl_chan++] = get_bits1(gb); | |
1840 |
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)); |
1841 | |||
1842 | 4 | return num_excl_chan / 7; | |
1843 | } | ||
1844 | |||
1845 | /** | ||
1846 | * Decode dynamic range information; reference: table 4.52. | ||
1847 | * | ||
1848 | * @return Returns number of bytes consumed. | ||
1849 | */ | ||
1850 | 880 | static int decode_dynamic_range(DynamicRangeControl *che_drc, | |
1851 | GetBitContext *gb) | ||
1852 | { | ||
1853 | 880 | int n = 1; | |
1854 | 880 | int drc_num_bands = 1; | |
1855 | int i; | ||
1856 | |||
1857 | /* pce_tag_present? */ | ||
1858 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 880 times.
|
880 | if (get_bits1(gb)) { |
1859 | ✗ | che_drc->pce_instance_tag = get_bits(gb, 4); | |
1860 | ✗ | skip_bits(gb, 4); // tag_reserved_bits | |
1861 | ✗ | n++; | |
1862 | } | ||
1863 | |||
1864 | /* excluded_chns_present? */ | ||
1865 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 876 times.
|
880 | if (get_bits1(gb)) { |
1866 | 4 | n += decode_drc_channel_exclusions(che_drc, gb); | |
1867 | } | ||
1868 | |||
1869 | /* drc_bands_present? */ | ||
1870 |
2/2✓ Branch 1 taken 35 times.
✓ Branch 2 taken 845 times.
|
880 | if (get_bits1(gb)) { |
1871 | 35 | che_drc->band_incr = get_bits(gb, 4); | |
1872 | 35 | che_drc->interpolation_scheme = get_bits(gb, 4); | |
1873 | 35 | n++; | |
1874 | 35 | drc_num_bands += che_drc->band_incr; | |
1875 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 35 times.
|
140 | for (i = 0; i < drc_num_bands; i++) { |
1876 | 105 | che_drc->band_top[i] = get_bits(gb, 8); | |
1877 | 105 | n++; | |
1878 | } | ||
1879 | } | ||
1880 | |||
1881 | /* prog_ref_level_present? */ | ||
1882 |
2/2✓ Branch 1 taken 878 times.
✓ Branch 2 taken 2 times.
|
880 | if (get_bits1(gb)) { |
1883 | 878 | che_drc->prog_ref_level = get_bits(gb, 7); | |
1884 | 878 | skip_bits1(gb); // prog_ref_level_reserved_bits | |
1885 | 878 | n++; | |
1886 | } | ||
1887 | |||
1888 |
2/2✓ Branch 0 taken 950 times.
✓ Branch 1 taken 880 times.
|
1830 | for (i = 0; i < drc_num_bands; i++) { |
1889 | 950 | che_drc->dyn_rng_sgn[i] = get_bits1(gb); | |
1890 | 950 | che_drc->dyn_rng_ctl[i] = get_bits(gb, 7); | |
1891 | 950 | n++; | |
1892 | } | ||
1893 | |||
1894 | 880 | return n; | |
1895 | } | ||
1896 | |||
1897 | 8959 | static int decode_fill(AACDecContext *ac, GetBitContext *gb, int len) { | |
1898 | uint8_t buf[256]; | ||
1899 | int i, major, minor; | ||
1900 | |||
1901 |
2/2✓ Branch 0 taken 380 times.
✓ Branch 1 taken 8579 times.
|
8959 | if (len < 13+7*8) |
1902 | 380 | goto unknown; | |
1903 | |||
1904 | 8579 | get_bits(gb, 13); len -= 13; | |
1905 | |||
1906 |
4/4✓ Branch 0 taken 1136929 times.
✓ Branch 1 taken 443 times.
✓ Branch 2 taken 1128793 times.
✓ Branch 3 taken 8136 times.
|
1137372 | for(i=0; i+1<sizeof(buf) && len>=8; i++, len-=8) |
1907 | 1128793 | buf[i] = get_bits(gb, 8); | |
1908 | |||
1909 | 8579 | buf[i] = 0; | |
1910 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8579 times.
|
8579 | if (ac->avctx->debug & FF_DEBUG_PICT_INFO) |
1911 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf); | |
1912 | |||
1913 |
2/2✓ Branch 0 taken 8560 times.
✓ Branch 1 taken 19 times.
|
8579 | if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){ |
1914 | 19 | ac->avctx->internal->skip_samples = 1024; | |
1915 | } | ||
1916 | |||
1917 | 8560 | unknown: | |
1918 | 8959 | skip_bits_long(gb, len); | |
1919 | |||
1920 | 8959 | return 0; | |
1921 | } | ||
1922 | |||
1923 | /** | ||
1924 | * Decode extension data (incomplete); reference: table 4.51. | ||
1925 | * | ||
1926 | * @param cnt length of TYPE_FIL syntactic element in bytes | ||
1927 | * | ||
1928 | * @return Returns number of bytes consumed | ||
1929 | */ | ||
1930 | 23694 | static int decode_extension_payload(AACDecContext *ac, GetBitContext *gb, int cnt, | |
1931 | ChannelElement *che, enum RawDataBlockType elem_type) | ||
1932 | { | ||
1933 | 23694 | int crc_flag = 0; | |
1934 | 23694 | int res = cnt; | |
1935 | 23694 | int type = get_bits(gb, 4); | |
1936 | |||
1937 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23694 times.
|
23694 | if (ac->avctx->debug & FF_DEBUG_STARTCODE) |
1938 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "extension type: %d len:%d\n", type, cnt); | |
1939 | |||
1940 |
4/5✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
✓ Branch 2 taken 880 times.
✓ Branch 3 taken 8959 times.
✓ Branch 4 taken 2954 times.
|
23694 | switch (type) { // extension type |
1941 | ✗ | case EXT_SBR_DATA_CRC: | |
1942 | ✗ | crc_flag++; | |
1943 | 10901 | case EXT_SBR_DATA: | |
1944 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
|
10901 | if (!che) { |
1945 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n"); | |
1946 | ✗ | return res; | |
1947 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
|
10901 | } else if (ac->oc[1].m4ac.frame_length_short) { |
1948 | ✗ | if (!ac->warned_960_sbr) | |
1949 | ✗ | avpriv_report_missing_feature(ac->avctx, | |
1950 | "SBR with 960 frame length"); | ||
1951 | ✗ | ac->warned_960_sbr = 1; | |
1952 | ✗ | skip_bits_long(gb, 8 * cnt - 4); | |
1953 | ✗ | return res; | |
1954 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
|
10901 | } else if (!ac->oc[1].m4ac.sbr) { |
1955 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n"); | |
1956 | ✗ | skip_bits_long(gb, 8 * cnt - 4); | |
1957 | ✗ | return res; | |
1958 |
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) { |
1959 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); | |
1960 | ✗ | skip_bits_long(gb, 8 * cnt - 4); | |
1961 | ✗ | return res; | |
1962 |
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 && |
1963 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 82 times.
|
94 | ac->avctx->ch_layout.nb_channels == 1) { |
1964 | 12 | ac->oc[1].m4ac.sbr = 1; | |
1965 | 12 | ac->oc[1].m4ac.ps = 1; | |
1966 | 12 | ac->avctx->profile = AV_PROFILE_AAC_HE_V2; | |
1967 | 12 | ff_aac_output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, | |
1968 | ac->oc[1].status, 1); | ||
1969 | } else { | ||
1970 | 10889 | ac->oc[1].m4ac.sbr = 1; | |
1971 | 10889 | ac->avctx->profile = AV_PROFILE_AAC_HE; | |
1972 | } | ||
1973 | |||
1974 | 10901 | ac->proc.sbr_decode_extension(ac, che, gb, crc_flag, cnt, elem_type); | |
1975 | |||
1976 |
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) { |
1977 | 22 | av_log(ac->avctx, AV_LOG_VERBOSE, "Treating HE-AAC mono as stereo.\n"); | |
1978 | 22 | ac->warned_he_aac_mono = 1; | |
1979 | } | ||
1980 | 10901 | break; | |
1981 | 880 | case EXT_DYNAMIC_RANGE: | |
1982 | 880 | res = decode_dynamic_range(&ac->che_drc, gb); | |
1983 | 880 | break; | |
1984 | 8959 | case EXT_FILL: | |
1985 | 8959 | decode_fill(ac, gb, 8 * cnt - 4); | |
1986 | 8959 | break; | |
1987 | 2954 | case EXT_FILL_DATA: | |
1988 | case EXT_DATA_ELEMENT: | ||
1989 | default: | ||
1990 | 2954 | skip_bits_long(gb, 8 * cnt - 4); | |
1991 | 2954 | break; | |
1992 | }; | ||
1993 | 23694 | return res; | |
1994 | } | ||
1995 | |||
1996 | /** | ||
1997 | * channel coupling transformation interface | ||
1998 | * | ||
1999 | * @param apply_coupling_method pointer to (in)dependent coupling function | ||
2000 | */ | ||
2001 | 175438 | static void apply_channel_coupling(AACDecContext *ac, ChannelElement *cc, | |
2002 | enum RawDataBlockType type, int elem_id, | ||
2003 | enum CouplingPoint coupling_point, | ||
2004 | void (*apply_coupling_method)(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)) | ||
2005 | { | ||
2006 | int i, c; | ||
2007 | |||
2008 |
2/2✓ Branch 0 taken 11228032 times.
✓ Branch 1 taken 175438 times.
|
11403470 | for (i = 0; i < MAX_ELEM_ID; i++) { |
2009 | 11228032 | ChannelElement *cce = ac->che[TYPE_CCE][i]; | |
2010 | 11228032 | int index = 0; | |
2011 | |||
2012 |
4/4✓ Branch 0 taken 11740 times.
✓ Branch 1 taken 11216292 times.
✓ Branch 2 taken 3915 times.
✓ Branch 3 taken 7825 times.
|
11228032 | if (cce && cce->coup.coupling_point == coupling_point) { |
2013 | 3915 | ChannelCoupling *coup = &cce->coup; | |
2014 | |||
2015 |
2/2✓ Branch 0 taken 9402 times.
✓ Branch 1 taken 3915 times.
|
13317 | for (c = 0; c <= coup->num_coupled; c++) { |
2016 |
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) { |
2017 |
2/2✓ Branch 0 taken 2561 times.
✓ Branch 1 taken 180 times.
|
2741 | if (coup->ch_select[c] != 1) { |
2018 | 2561 | apply_coupling_method(ac, &cc->ch[0], cce, index); | |
2019 |
1/2✓ Branch 0 taken 2561 times.
✗ Branch 1 not taken.
|
2561 | if (coup->ch_select[c] != 0) |
2020 | 2561 | index++; | |
2021 | } | ||
2022 |
2/2✓ Branch 0 taken 2147 times.
✓ Branch 1 taken 594 times.
|
2741 | if (coup->ch_select[c] != 2) |
2023 | 2147 | apply_coupling_method(ac, &cc->ch[1], cce, index++); | |
2024 | } else | ||
2025 |
2/2✓ Branch 0 taken 4720 times.
✓ Branch 1 taken 1941 times.
|
6661 | index += 1 + (coup->ch_select[c] == 3); |
2026 | } | ||
2027 | } | ||
2028 | } | ||
2029 | 175438 | } | |
2030 | |||
2031 | /** | ||
2032 | * Convert spectral data to samples, applying all supported tools as appropriate. | ||
2033 | */ | ||
2034 | 49700 | static void spectral_to_sample(AACDecContext *ac, int samples) | |
2035 | { | ||
2036 | int i, type; | ||
2037 | void (*imdct_and_window)(AACDecContext *ac, SingleChannelElement *sce); | ||
2038 |
3/3✓ Branch 0 taken 606 times.
✓ Branch 1 taken 16365 times.
✓ Branch 2 taken 32729 times.
|
49700 | switch (ac->oc[1].m4ac.object_type) { |
2039 | 606 | case AOT_ER_AAC_LD: | |
2040 | 606 | imdct_and_window = ac->dsp.imdct_and_windowing_ld; | |
2041 | 606 | break; | |
2042 | 16365 | case AOT_ER_AAC_ELD: | |
2043 | 16365 | imdct_and_window = ac->dsp.imdct_and_windowing_eld; | |
2044 | 16365 | break; | |
2045 | 32729 | default: | |
2046 |
2/2✓ Branch 0 taken 387 times.
✓ Branch 1 taken 32342 times.
|
32729 | if (ac->oc[1].m4ac.frame_length_short) |
2047 | 387 | imdct_and_window = ac->dsp.imdct_and_windowing_960; | |
2048 | else | ||
2049 | 32342 | imdct_and_window = ac->dsp.imdct_and_windowing; | |
2050 | } | ||
2051 |
2/2✓ Branch 0 taken 198800 times.
✓ Branch 1 taken 49700 times.
|
248500 | for (type = 3; type >= 0; type--) { |
2052 |
2/2✓ Branch 0 taken 12723200 times.
✓ Branch 1 taken 198800 times.
|
12922000 | for (i = 0; i < MAX_ELEM_ID; i++) { |
2053 | 12723200 | ChannelElement *che = ac->che[type][i]; | |
2054 |
4/4✓ Branch 0 taken 63095 times.
✓ Branch 1 taken 12660105 times.
✓ Branch 2 taken 62766 times.
✓ Branch 3 taken 329 times.
|
12723200 | if (che && che->present) { |
2055 |
2/2✓ Branch 0 taken 58088 times.
✓ Branch 1 taken 4678 times.
|
62766 | if (type <= TYPE_CPE) |
2056 | 58088 | apply_channel_coupling(ac, che, type, i, BEFORE_TNS, ac->dsp.apply_dependent_coupling); | |
2057 |
2/2✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 60982 times.
|
62766 | if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) { |
2058 |
2/2✓ Branch 0 taken 538 times.
✓ Branch 1 taken 1246 times.
|
1784 | if (che->ch[0].ics.predictor_present) { |
2059 |
2/2✓ Branch 0 taken 382 times.
✓ Branch 1 taken 156 times.
|
538 | if (che->ch[0].ics.ltp.present) |
2060 | 382 | ac->dsp.apply_ltp(ac, &che->ch[0]); | |
2061 |
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) |
2062 | 404 | ac->dsp.apply_ltp(ac, &che->ch[1]); | |
2063 | } | ||
2064 | } | ||
2065 |
2/2✓ Branch 0 taken 4647 times.
✓ Branch 1 taken 58119 times.
|
62766 | if (che->ch[0].tns.present) |
2066 | 4647 | ac->dsp.apply_tns(che->ch[0].coeffs, | |
2067 | &che->ch[0].tns, &che->ch[0].ics, 1); | ||
2068 |
2/2✓ Branch 0 taken 2308 times.
✓ Branch 1 taken 60458 times.
|
62766 | if (che->ch[1].tns.present) |
2069 | 2308 | ac->dsp.apply_tns(che->ch[1].coeffs, | |
2070 | &che->ch[1].tns, &che->ch[1].ics, 1); | ||
2071 |
2/2✓ Branch 0 taken 58088 times.
✓ Branch 1 taken 4678 times.
|
62766 | if (type <= TYPE_CPE) |
2072 | 58088 | apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, ac->dsp.apply_dependent_coupling); | |
2073 |
4/4✓ Branch 0 taken 1174 times.
✓ Branch 1 taken 61592 times.
✓ Branch 2 taken 393 times.
✓ Branch 3 taken 781 times.
|
62766 | if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { |
2074 | 61985 | imdct_and_window(ac, &che->ch[0]); | |
2075 |
2/2✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 60201 times.
|
61985 | if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) |
2076 | 1784 | ac->dsp.update_ltp(ac, &che->ch[0]); | |
2077 |
2/2✓ Branch 0 taken 30388 times.
✓ Branch 1 taken 31597 times.
|
61985 | if (type == TYPE_CPE) { |
2078 | 30388 | imdct_and_window(ac, &che->ch[1]); | |
2079 |
2/2✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 28604 times.
|
30388 | if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) |
2080 | 1784 | ac->dsp.update_ltp(ac, &che->ch[1]); | |
2081 | } | ||
2082 |
2/2✓ Branch 0 taken 12411 times.
✓ Branch 1 taken 49574 times.
|
61985 | if (ac->oc[1].m4ac.sbr > 0) { |
2083 | 12411 | ac->proc.sbr_apply(ac, che, type, | |
2084 | 12411 | che->ch[0].output, | |
2085 | 12411 | che->ch[1].output); | |
2086 | } | ||
2087 | } | ||
2088 |
2/2✓ Branch 0 taken 59262 times.
✓ Branch 1 taken 3504 times.
|
62766 | if (type <= TYPE_CCE) |
2089 | 59262 | apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, ac->dsp.apply_independent_coupling); | |
2090 | 62766 | ac->dsp.clip_output(ac, che, type, samples); | |
2091 | 62766 | che->present = 0; | |
2092 |
2/2✓ Branch 0 taken 329 times.
✓ Branch 1 taken 12660105 times.
|
12660434 | } else if (che) { |
2093 | 329 | av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i); | |
2094 | } | ||
2095 | } | ||
2096 | } | ||
2097 | 49700 | } | |
2098 | |||
2099 | 3702 | static int parse_adts_frame_header(AACDecContext *ac, GetBitContext *gb) | |
2100 | { | ||
2101 | int size; | ||
2102 | AACADTSHeaderInfo hdr_info; | ||
2103 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
2104 | int layout_map_tags, ret; | ||
2105 | |||
2106 | 3702 | size = ff_adts_header_parse(gb, &hdr_info); | |
2107 |
1/2✓ Branch 0 taken 3702 times.
✗ Branch 1 not taken.
|
3702 | if (size > 0) { |
2108 |
2/4✓ Branch 0 taken 3702 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3702 times.
|
3702 | if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) { |
2109 | // This is 2 for "VLB " audio in NSV files. | ||
2110 | // See samples/nsv/vlb_audio. | ||
2111 | ✗ | avpriv_report_missing_feature(ac->avctx, | |
2112 | "More than one AAC RDB per ADTS frame"); | ||
2113 | ✗ | ac->warned_num_aac_frames = 1; | |
2114 | } | ||
2115 | 3702 | push_output_configuration(ac); | |
2116 |
1/2✓ Branch 0 taken 3702 times.
✗ Branch 1 not taken.
|
3702 | if (hdr_info.chan_config) { |
2117 | 3702 | ac->oc[1].m4ac.chan_config = hdr_info.chan_config; | |
2118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3702 times.
|
3702 | if ((ret = ff_aac_set_default_channel_config(ac, ac->avctx, |
2119 | layout_map, | ||
2120 | &layout_map_tags, | ||
2121 | 3702 | hdr_info.chan_config)) < 0) | |
2122 | ✗ | return ret; | |
2123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3702 times.
|
3702 | if ((ret = ff_aac_output_configure(ac, layout_map, layout_map_tags, |
2124 | 3702 | FFMAX(ac->oc[1].status, | |
2125 | OC_TRIAL_FRAME), 0)) < 0) | ||
2126 | ✗ | return ret; | |
2127 | } else { | ||
2128 | ✗ | ac->oc[1].m4ac.chan_config = 0; | |
2129 | /** | ||
2130 | * dual mono frames in Japanese DTV can have chan_config 0 | ||
2131 | * WITHOUT specifying PCE. | ||
2132 | * thus, set dual mono as default. | ||
2133 | */ | ||
2134 | ✗ | if (ac->dmono_mode && ac->oc[0].status == OC_NONE) { | |
2135 | ✗ | layout_map_tags = 2; | |
2136 | ✗ | layout_map[0][0] = layout_map[1][0] = TYPE_SCE; | |
2137 | ✗ | layout_map[0][2] = layout_map[1][2] = AAC_CHANNEL_FRONT; | |
2138 | ✗ | layout_map[0][1] = 0; | |
2139 | ✗ | layout_map[1][1] = 1; | |
2140 | ✗ | if (ff_aac_output_configure(ac, layout_map, layout_map_tags, | |
2141 | OC_TRIAL_FRAME, 0)) | ||
2142 | ✗ | return -7; | |
2143 | } | ||
2144 | } | ||
2145 | 3702 | ac->oc[1].m4ac.sample_rate = hdr_info.sample_rate; | |
2146 | 3702 | ac->oc[1].m4ac.sampling_index = hdr_info.sampling_index; | |
2147 | 3702 | ac->oc[1].m4ac.object_type = hdr_info.object_type; | |
2148 | 3702 | ac->oc[1].m4ac.frame_length_short = 0; | |
2149 |
2/2✓ Branch 0 taken 3648 times.
✓ Branch 1 taken 54 times.
|
3702 | if (ac->oc[0].status != OC_LOCKED || |
2150 |
1/2✓ Branch 0 taken 3648 times.
✗ Branch 1 not taken.
|
3648 | ac->oc[0].m4ac.chan_config != hdr_info.chan_config || |
2151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3648 times.
|
3648 | ac->oc[0].m4ac.sample_rate != hdr_info.sample_rate) { |
2152 | 54 | ac->oc[1].m4ac.sbr = -1; | |
2153 | 54 | ac->oc[1].m4ac.ps = -1; | |
2154 | } | ||
2155 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3701 times.
|
3702 | if (!hdr_info.crc_absent) |
2156 | 1 | skip_bits(gb, 16); | |
2157 | } | ||
2158 | 3702 | return size; | |
2159 | } | ||
2160 | |||
2161 | 16971 | static int aac_decode_er_frame(AVCodecContext *avctx, AVFrame *frame, | |
2162 | int *got_frame_ptr, GetBitContext *gb) | ||
2163 | { | ||
2164 | 16971 | AACDecContext *ac = avctx->priv_data; | |
2165 | 16971 | const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac; | |
2166 | ChannelElement *che; | ||
2167 | int err, i; | ||
2168 |
2/2✓ Branch 0 taken 3559 times.
✓ Branch 1 taken 13412 times.
|
16971 | int samples = m4ac->frame_length_short ? 960 : 1024; |
2169 | 16971 | int chan_config = m4ac->chan_config; | |
2170 | 16971 | int aot = m4ac->object_type; | |
2171 | |||
2172 |
3/4✓ Branch 0 taken 16365 times.
✓ Branch 1 taken 606 times.
✓ Branch 2 taken 16365 times.
✗ Branch 3 not taken.
|
16971 | if (aot == AOT_ER_AAC_LD || aot == AOT_ER_AAC_ELD) |
2173 | 16971 | samples >>= 1; | |
2174 | |||
2175 | 16971 | ac->frame = frame; | |
2176 | |||
2177 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16971 times.
|
16971 | if ((err = frame_configure_elements(avctx)) < 0) |
2178 | ✗ | return err; | |
2179 | |||
2180 | // The AV_PROFILE_AAC_* defines are all object_type - 1 | ||
2181 | // This may lead to an undefined profile being signaled | ||
2182 | 16971 | ac->avctx->profile = aot - 1; | |
2183 | |||
2184 | 16971 | ac->tags_mapped = 0; | |
2185 | |||
2186 |
3/8✓ Branch 0 taken 16971 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16971 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 16971 times.
|
16971 | if (chan_config < 0 || (chan_config >= 8 && chan_config < 11) || chan_config >= 13) { |
2187 | ✗ | avpriv_request_sample(avctx, "Unknown ER channel configuration %d", | |
2188 | chan_config); | ||
2189 | ✗ | return AVERROR_INVALIDDATA; | |
2190 | } | ||
2191 |
2/2✓ Branch 0 taken 18789 times.
✓ Branch 1 taken 16971 times.
|
35760 | for (i = 0; i < ff_tags_per_config[chan_config]; i++) { |
2192 | 18789 | const int elem_type = ff_aac_channel_layout_map[chan_config-1][i][0]; | |
2193 | 18789 | const int elem_id = ff_aac_channel_layout_map[chan_config-1][i][1]; | |
2194 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18789 times.
|
18789 | if (!(che=ff_aac_get_che(ac, elem_type, elem_id))) { |
2195 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
2196 | "channel element %d.%d is not allocated\n", | ||
2197 | elem_type, elem_id); | ||
2198 | ✗ | return AVERROR_INVALIDDATA; | |
2199 | } | ||
2200 | 18789 | che->present = 1; | |
2201 |
2/2✓ Branch 0 taken 2424 times.
✓ Branch 1 taken 16365 times.
|
18789 | if (aot != AOT_ER_AAC_ELD) |
2202 | 2424 | skip_bits(gb, 4); | |
2203 |
3/4✓ Branch 0 taken 6738 times.
✓ Branch 1 taken 11445 times.
✓ Branch 2 taken 606 times.
✗ Branch 3 not taken.
|
18789 | switch (elem_type) { |
2204 | 6738 | case TYPE_SCE: | |
2205 | 6738 | err = ff_aac_decode_ics(ac, &che->ch[0], gb, 0, 0); | |
2206 | 6738 | break; | |
2207 | 11445 | case TYPE_CPE: | |
2208 | 11445 | err = decode_cpe(ac, gb, che); | |
2209 | 11445 | break; | |
2210 | 606 | case TYPE_LFE: | |
2211 | 606 | err = ff_aac_decode_ics(ac, &che->ch[0], gb, 0, 0); | |
2212 | 606 | break; | |
2213 | } | ||
2214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18789 times.
|
18789 | if (err < 0) |
2215 | ✗ | return err; | |
2216 | } | ||
2217 | |||
2218 | 16971 | spectral_to_sample(ac, samples); | |
2219 | |||
2220 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 16971 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
16971 | if (!ac->frame->data[0] && samples) { |
2221 | ✗ | av_log(avctx, AV_LOG_ERROR, "no frame data found\n"); | |
2222 | ✗ | return AVERROR_INVALIDDATA; | |
2223 | } | ||
2224 | |||
2225 | 16971 | ac->frame->nb_samples = samples; | |
2226 | 16971 | ac->frame->sample_rate = avctx->sample_rate; | |
2227 | 16971 | ac->frame->flags |= AV_FRAME_FLAG_KEY; | |
2228 | 16971 | *got_frame_ptr = 1; | |
2229 | |||
2230 | 16971 | skip_bits_long(gb, get_bits_left(gb)); | |
2231 | 16971 | return 0; | |
2232 | } | ||
2233 | |||
2234 | 32729 | static int decode_frame_ga(AVCodecContext *avctx, AACDecContext *ac, | |
2235 | GetBitContext *gb, int *got_frame_ptr) | ||
2236 | { | ||
2237 | int err; | ||
2238 | int is_dmono; | ||
2239 | int elem_id; | ||
2240 | 32729 | enum RawDataBlockType elem_type, che_prev_type = TYPE_END; | |
2241 | 32729 | uint8_t che_presence[4][MAX_ELEM_ID] = {{0}}; | |
2242 | 32729 | ChannelElement *che = NULL, *che_prev = NULL; | |
2243 | 32729 | int samples = 0, multiplier, audio_found = 0, pce_found = 0, sce_count = 0; | |
2244 | 32729 | AVFrame *frame = ac->frame; | |
2245 | |||
2246 | 32729 | int payload_alignment = get_bits_count(gb); | |
2247 | // parse | ||
2248 |
2/2✓ Branch 1 taken 72033 times.
✓ Branch 2 taken 32729 times.
|
104762 | while ((elem_type = get_bits(gb, 3)) != TYPE_END) { |
2249 | 72033 | elem_id = get_bits(gb, 4); | |
2250 | |||
2251 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72033 times.
|
72033 | if (avctx->debug & FF_DEBUG_STARTCODE) |
2252 | ✗ | av_log(avctx, AV_LOG_DEBUG, "Elem type:%x id:%x\n", elem_type, elem_id); | |
2253 | |||
2254 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 72033 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
72033 | if (!avctx->ch_layout.nb_channels && elem_type != TYPE_PCE) |
2255 | ✗ | return AVERROR_INVALIDDATA; | |
2256 | |||
2257 |
2/2✓ Branch 0 taken 43977 times.
✓ Branch 1 taken 28056 times.
|
72033 | if (elem_type < TYPE_DSE) { |
2258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43977 times.
|
43977 | if (che_presence[elem_type][elem_id]) { |
2259 | ✗ | int error = che_presence[elem_type][elem_id] > 1; | |
2260 | ✗ | av_log(ac->avctx, error ? AV_LOG_ERROR : AV_LOG_DEBUG, "channel element %d.%d duplicate\n", | |
2261 | elem_type, elem_id); | ||
2262 | ✗ | if (error) | |
2263 | ✗ | return AVERROR_INVALIDDATA; | |
2264 | } | ||
2265 | 43977 | che_presence[elem_type][elem_id]++; | |
2266 | |||
2267 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 43977 times.
|
43977 | if (!(che=ff_aac_get_che(ac, elem_type, elem_id))) { |
2268 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", | |
2269 | elem_type, elem_id); | ||
2270 | ✗ | return AVERROR_INVALIDDATA; | |
2271 | } | ||
2272 |
2/2✓ Branch 0 taken 387 times.
✓ Branch 1 taken 43590 times.
|
43977 | samples = ac->oc[1].m4ac.frame_length_short ? 960 : 1024; |
2273 | 43977 | che->present = 1; | |
2274 | } | ||
2275 | |||
2276 |
6/8✓ Branch 0 taken 20962 times.
✓ Branch 1 taken 18943 times.
✓ Branch 2 taken 1174 times.
✓ Branch 3 taken 2898 times.
✓ Branch 4 taken 2823 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 25233 times.
✗ Branch 7 not taken.
|
72033 | switch (elem_type) { |
2277 | |||
2278 | 20962 | case TYPE_SCE: | |
2279 | 20962 | err = ff_aac_decode_ics(ac, &che->ch[0], gb, 0, 0); | |
2280 | 20962 | audio_found = 1; | |
2281 | 20962 | sce_count++; | |
2282 | 20962 | break; | |
2283 | |||
2284 | 18943 | case TYPE_CPE: | |
2285 | 18943 | err = decode_cpe(ac, gb, che); | |
2286 | 18943 | audio_found = 1; | |
2287 | 18943 | break; | |
2288 | |||
2289 | 1174 | case TYPE_CCE: | |
2290 | 1174 | err = ac->proc.decode_cce(ac, gb, che); | |
2291 | 1174 | break; | |
2292 | |||
2293 | 2898 | case TYPE_LFE: | |
2294 | 2898 | err = ff_aac_decode_ics(ac, &che->ch[0], gb, 0, 0); | |
2295 | 2898 | audio_found = 1; | |
2296 | 2898 | break; | |
2297 | |||
2298 | 2823 | case TYPE_DSE: | |
2299 | 2823 | err = skip_data_stream_element(ac, gb); | |
2300 | 2823 | break; | |
2301 | |||
2302 | ✗ | case TYPE_PCE: { | |
2303 | ✗ | uint8_t layout_map[MAX_ELEM_ID*4][3] = {{0}}; | |
2304 | int tags; | ||
2305 | |||
2306 | ✗ | int pushed = push_output_configuration(ac); | |
2307 | ✗ | if (pce_found && !pushed) | |
2308 | ✗ | return AVERROR_INVALIDDATA; | |
2309 | |||
2310 | ✗ | tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb, | |
2311 | payload_alignment); | ||
2312 | ✗ | if (tags < 0) { | |
2313 | ✗ | err = tags; | |
2314 | ✗ | break; | |
2315 | } | ||
2316 | ✗ | if (pce_found) { | |
2317 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
2318 | "Not evaluating a further program_config_element as this construct is dubious at best.\n"); | ||
2319 | ✗ | pop_output_configuration(ac); | |
2320 | } else { | ||
2321 | ✗ | err = ff_aac_output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1); | |
2322 | ✗ | if (!err) | |
2323 | ✗ | ac->oc[1].m4ac.chan_config = 0; | |
2324 | ✗ | pce_found = 1; | |
2325 | } | ||
2326 | ✗ | break; | |
2327 | } | ||
2328 | |||
2329 | 25233 | case TYPE_FIL: | |
2330 |
2/2✓ Branch 0 taken 16451 times.
✓ Branch 1 taken 8782 times.
|
25233 | if (elem_id == 15) |
2331 | 16451 | elem_id += get_bits(gb, 8) - 1; | |
2332 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25233 times.
|
25233 | if (get_bits_left(gb) < 8 * elem_id) { |
2333 | ✗ | av_log(avctx, AV_LOG_ERROR, "TYPE_FIL: "overread_err); | |
2334 | ✗ | return AVERROR_INVALIDDATA; | |
2335 | } | ||
2336 | 25233 | err = 0; | |
2337 |
2/2✓ Branch 0 taken 23694 times.
✓ Branch 1 taken 25233 times.
|
48927 | while (elem_id > 0) { |
2338 | 23694 | int ret = decode_extension_payload(ac, gb, elem_id, che_prev, che_prev_type); | |
2339 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23694 times.
|
23694 | if (ret < 0) { |
2340 | ✗ | err = ret; | |
2341 | ✗ | break; | |
2342 | } | ||
2343 | 23694 | elem_id -= ret; | |
2344 | } | ||
2345 | 25233 | break; | |
2346 | |||
2347 | ✗ | default: | |
2348 | ✗ | err = AVERROR_BUG; /* should not happen, but keeps compiler happy */ | |
2349 | ✗ | break; | |
2350 | } | ||
2351 | |||
2352 |
2/2✓ Branch 0 taken 43977 times.
✓ Branch 1 taken 28056 times.
|
72033 | if (elem_type < TYPE_DSE) { |
2353 | 43977 | che_prev = che; | |
2354 | 43977 | che_prev_type = elem_type; | |
2355 | } | ||
2356 | |||
2357 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72033 times.
|
72033 | if (err) |
2358 | ✗ | return err; | |
2359 | |||
2360 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 72033 times.
|
72033 | if (get_bits_left(gb) < 3) { |
2361 | ✗ | av_log(avctx, AV_LOG_ERROR, overread_err); | |
2362 | ✗ | return AVERROR_INVALIDDATA; | |
2363 | } | ||
2364 | } | ||
2365 | |||
2366 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32729 times.
|
32729 | if (!avctx->ch_layout.nb_channels) |
2367 | ✗ | return 0; | |
2368 | |||
2369 |
4/4✓ Branch 0 taken 7881 times.
✓ Branch 1 taken 24848 times.
✓ Branch 2 taken 5583 times.
✓ Branch 3 taken 2298 times.
|
32729 | multiplier = (ac->oc[1].m4ac.sbr == 1) ? ac->oc[1].m4ac.ext_sample_rate > ac->oc[1].m4ac.sample_rate : 0; |
2370 | 32729 | samples <<= multiplier; | |
2371 | |||
2372 | 32729 | spectral_to_sample(ac, samples); | |
2373 | |||
2374 |
2/4✓ Branch 0 taken 32729 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32729 times.
✗ Branch 3 not taken.
|
32729 | if (ac->oc[1].status && audio_found) { |
2375 | 32729 | avctx->sample_rate = ac->oc[1].m4ac.sample_rate << multiplier; | |
2376 | 32729 | avctx->frame_size = samples; | |
2377 | 32729 | ac->oc[1].status = OC_LOCKED; | |
2378 | } | ||
2379 | |||
2380 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 32729 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
32729 | if (!ac->frame->data[0] && samples) { |
2381 | ✗ | av_log(avctx, AV_LOG_ERROR, "no frame data found\n"); | |
2382 | ✗ | return AVERROR_INVALIDDATA; | |
2383 | } | ||
2384 | |||
2385 |
1/2✓ Branch 0 taken 32729 times.
✗ Branch 1 not taken.
|
32729 | if (samples) { |
2386 | 32729 | ac->frame->nb_samples = samples; | |
2387 | 32729 | ac->frame->sample_rate = avctx->sample_rate; | |
2388 | 32729 | ac->frame->flags |= AV_FRAME_FLAG_KEY; | |
2389 | 32729 | *got_frame_ptr = 1; | |
2390 | } else { | ||
2391 | ✗ | av_frame_unref(ac->frame); | |
2392 | ✗ | *got_frame_ptr = 0; | |
2393 | } | ||
2394 | |||
2395 | /* for dual-mono audio (SCE + SCE) */ | ||
2396 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 32729 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
32729 | is_dmono = ac->dmono_mode && sce_count == 2 && |
2397 | ✗ | !av_channel_layout_compare(&ac->oc[1].ch_layout, | |
2398 | ✗ | &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); | |
2399 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32729 times.
|
32729 | if (is_dmono) { |
2400 | ✗ | if (ac->dmono_mode == 1) | |
2401 | ✗ | frame->data[1] = frame->data[0]; | |
2402 | ✗ | else if (ac->dmono_mode == 2) | |
2403 | ✗ | frame->data[0] = frame->data[1]; | |
2404 | } | ||
2405 | |||
2406 | 32729 | return 0; | |
2407 | } | ||
2408 | |||
2409 | 36613 | static int aac_decode_frame_int(AVCodecContext *avctx, AVFrame *frame, | |
2410 | int *got_frame_ptr, GetBitContext *gb, | ||
2411 | const AVPacket *avpkt) | ||
2412 | { | ||
2413 | int err; | ||
2414 | 36613 | AACDecContext *ac = avctx->priv_data; | |
2415 | |||
2416 | 36613 | ac->frame = frame; | |
2417 | 36613 | *got_frame_ptr = 0; | |
2418 | |||
2419 | // USAC can't be packed into ADTS due to field size limitations. | ||
2420 |
3/4✓ Branch 1 taken 3702 times.
✓ Branch 2 taken 32911 times.
✓ Branch 3 taken 3702 times.
✗ Branch 4 not taken.
|
36613 | if (show_bits(gb, 12) == 0xfff && ac->oc[1].m4ac.object_type != AOT_USAC) { |
2421 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3702 times.
|
3702 | if ((err = parse_adts_frame_header(ac, gb)) < 0) { |
2422 | ✗ | av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); | |
2423 | ✗ | goto fail; | |
2424 | } | ||
2425 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3702 times.
|
3702 | if (ac->oc[1].m4ac.sampling_index > 12) { |
2426 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->oc[1].m4ac.sampling_index); | |
2427 | ✗ | err = AVERROR_INVALIDDATA; | |
2428 | ✗ | goto fail; | |
2429 | } | ||
2430 | } | ||
2431 | |||
2432 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 36613 times.
|
36613 | if ((err = frame_configure_elements(avctx)) < 0) |
2433 | ✗ | goto fail; | |
2434 | |||
2435 | // The AV_PROFILE_AAC_* defines are all object_type - 1 | ||
2436 | // This may lead to an undefined profile being signaled | ||
2437 | 36613 | ac->avctx->profile = ac->oc[1].m4ac.object_type - 1; | |
2438 | |||
2439 | 36613 | ac->tags_mapped = 0; | |
2440 | |||
2441 |
2/2✓ Branch 0 taken 3884 times.
✓ Branch 1 taken 32729 times.
|
36613 | if (ac->oc[1].m4ac.object_type == AOT_USAC) { |
2442 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3884 times.
|
3884 | if (ac->is_fixed) { |
2443 | ✗ | avpriv_report_missing_feature(ac->avctx, | |
2444 | "AAC USAC fixed-point decoding"); | ||
2445 | ✗ | return AVERROR_PATCHWELCOME; | |
2446 | } | ||
2447 | #if CONFIG_AAC_DECODER | ||
2448 | 3884 | err = ff_aac_usac_decode_frame(avctx, ac, gb, got_frame_ptr); | |
2449 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3884 times.
|
3884 | if (err < 0) |
2450 | ✗ | goto fail; | |
2451 | #endif | ||
2452 | } else { | ||
2453 | 32729 | err = decode_frame_ga(avctx, ac, gb, got_frame_ptr); | |
2454 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32729 times.
|
32729 | if (err < 0) |
2455 | ✗ | goto fail; | |
2456 | } | ||
2457 | |||
2458 | 36613 | return err; | |
2459 | |||
2460 | ✗ | fail: | |
2461 | ✗ | pop_output_configuration(ac); | |
2462 | ✗ | return err; | |
2463 | } | ||
2464 | |||
2465 | 53069 | static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, | |
2466 | int *got_frame_ptr, AVPacket *avpkt) | ||
2467 | { | ||
2468 | 53069 | AACDecContext *ac = avctx->priv_data; | |
2469 | 53069 | const uint8_t *buf = avpkt->data; | |
2470 | 53069 | int buf_size = avpkt->size; | |
2471 | GetBitContext gb; | ||
2472 | int buf_consumed; | ||
2473 | int buf_offset; | ||
2474 | int err; | ||
2475 | size_t new_extradata_size; | ||
2476 | 53069 | const uint8_t *new_extradata = av_packet_get_side_data(avpkt, | |
2477 | AV_PKT_DATA_NEW_EXTRADATA, | ||
2478 | &new_extradata_size); | ||
2479 | size_t jp_dualmono_size; | ||
2480 | 53069 | const uint8_t *jp_dualmono = av_packet_get_side_data(avpkt, | |
2481 | AV_PKT_DATA_JP_DUALMONO, | ||
2482 | &jp_dualmono_size); | ||
2483 | |||
2484 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 53068 times.
|
53069 | if (new_extradata) { |
2485 | /* discard previous configuration */ | ||
2486 | 1 | ac->oc[1].status = OC_NONE; | |
2487 | 1 | err = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1], | |
2488 | new_extradata, | ||
2489 | 1 | new_extradata_size * 8LL, 1); | |
2490 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) { |
2491 | ✗ | return err; | |
2492 | } | ||
2493 | } | ||
2494 | |||
2495 | 53069 | ac->dmono_mode = 0; | |
2496 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 53069 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
53069 | if (jp_dualmono && jp_dualmono_size > 0) |
2497 | ✗ | ac->dmono_mode = 1 + *jp_dualmono; | |
2498 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53069 times.
|
53069 | if (ac->force_dmono_mode >= 0) |
2499 | ✗ | ac->dmono_mode = ac->force_dmono_mode; | |
2500 | |||
2501 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53069 times.
|
53069 | if (INT_MAX / 8 <= buf_size) |
2502 | ✗ | return AVERROR_INVALIDDATA; | |
2503 | |||
2504 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53069 times.
|
53069 | if ((err = init_get_bits8(&gb, buf, buf_size)) < 0) |
2505 | ✗ | return err; | |
2506 | |||
2507 |
2/2✓ Branch 0 taken 16971 times.
✓ Branch 1 taken 36098 times.
|
53069 | switch (ac->oc[1].m4ac.object_type) { |
2508 | 16971 | case AOT_ER_AAC_LC: | |
2509 | case AOT_ER_AAC_LTP: | ||
2510 | case AOT_ER_AAC_LD: | ||
2511 | case AOT_ER_AAC_ELD: | ||
2512 | 16971 | err = aac_decode_er_frame(avctx, frame, got_frame_ptr, &gb); | |
2513 | 16971 | break; | |
2514 | 36098 | default: | |
2515 | 36098 | err = aac_decode_frame_int(avctx, frame, got_frame_ptr, &gb, avpkt); | |
2516 | } | ||
2517 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53069 times.
|
53069 | if (err < 0) |
2518 | ✗ | return err; | |
2519 | |||
2520 | 53069 | buf_consumed = (get_bits_count(&gb) + 7) >> 3; | |
2521 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53069 times.
|
53069 | for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++) |
2522 | ✗ | if (buf[buf_offset]) | |
2523 | ✗ | break; | |
2524 | |||
2525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53069 times.
|
53069 | return buf_size > buf_offset ? buf_consumed : buf_size; |
2526 | } | ||
2527 | |||
2528 | #if CONFIG_AAC_LATM_DECODER | ||
2529 | #include "aacdec_latm.h" | ||
2530 | #endif | ||
2531 | |||
2532 | #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | ||
2533 | #define OFF(field) offsetof(AACDecContext, field) | ||
2534 | static const AVOption options[] = { | ||
2535 | /** | ||
2536 | * AVOptions for Japanese DTV specific extensions (ADTS only) | ||
2537 | */ | ||
2538 | {"dual_mono_mode", "Select the channel to decode for dual mono", | ||
2539 | OFF(force_dmono_mode), AV_OPT_TYPE_INT, {.i64=-1}, -1, 2, | ||
2540 | AACDEC_FLAGS, .unit = "dual_mono_mode"}, | ||
2541 | |||
2542 | {"auto", "autoselection", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, AACDEC_FLAGS, .unit = "dual_mono_mode"}, | ||
2543 | {"main", "Select Main/Left channel", 0, AV_OPT_TYPE_CONST, {.i64= 1}, INT_MIN, INT_MAX, AACDEC_FLAGS, .unit = "dual_mono_mode"}, | ||
2544 | {"sub" , "Select Sub/Right channel", 0, AV_OPT_TYPE_CONST, {.i64= 2}, INT_MIN, INT_MAX, AACDEC_FLAGS, .unit = "dual_mono_mode"}, | ||
2545 | {"both", "Select both channels", 0, AV_OPT_TYPE_CONST, {.i64= 0}, INT_MIN, INT_MAX, AACDEC_FLAGS, .unit = "dual_mono_mode"}, | ||
2546 | |||
2547 | { "channel_order", "Order in which the channels are to be exported", | ||
2548 | OFF(output_channel_order), AV_OPT_TYPE_INT, | ||
2549 | { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, AACDEC_FLAGS, .unit = "channel_order" }, | ||
2550 | { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST, | ||
2551 | { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = AACDEC_FLAGS, .unit = "channel_order" }, | ||
2552 | { "coded", "order in which the channels are coded in the bitstream", | ||
2553 | 0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = AACDEC_FLAGS, .unit = "channel_order" }, | ||
2554 | |||
2555 | {NULL}, | ||
2556 | }; | ||
2557 | |||
2558 | static const AVClass decoder_class = { | ||
2559 | .class_name = "AAC decoder", | ||
2560 | .item_name = av_default_item_name, | ||
2561 | .option = options, | ||
2562 | .version = LIBAVUTIL_VERSION_INT, | ||
2563 | }; | ||
2564 | |||
2565 | #if CONFIG_AAC_DECODER | ||
2566 | const FFCodec ff_aac_decoder = { | ||
2567 | .p.name = "aac", | ||
2568 | CODEC_LONG_NAME("AAC (Advanced Audio Coding)"), | ||
2569 | .p.type = AVMEDIA_TYPE_AUDIO, | ||
2570 | .p.id = AV_CODEC_ID_AAC, | ||
2571 | .p.priv_class = &decoder_class, | ||
2572 | .priv_data_size = sizeof(AACDecContext), | ||
2573 | .init = ff_aac_decode_init_float, | ||
2574 | .close = decode_close, | ||
2575 | FF_CODEC_DECODE_CB(aac_decode_frame), | ||
2576 | CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP), | ||
2577 | .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1, | ||
2578 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
2579 | CODEC_CH_LAYOUTS_ARRAY(ff_aac_ch_layout), | ||
2580 | .flush = flush, | ||
2581 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles), | ||
2582 | }; | ||
2583 | #endif | ||
2584 | |||
2585 | #if CONFIG_AAC_FIXED_DECODER | ||
2586 | const FFCodec ff_aac_fixed_decoder = { | ||
2587 | .p.name = "aac_fixed", | ||
2588 | CODEC_LONG_NAME("AAC (Advanced Audio Coding)"), | ||
2589 | .p.type = AVMEDIA_TYPE_AUDIO, | ||
2590 | .p.id = AV_CODEC_ID_AAC, | ||
2591 | .p.priv_class = &decoder_class, | ||
2592 | .priv_data_size = sizeof(AACDecContext), | ||
2593 | .init = ff_aac_decode_init_fixed, | ||
2594 | .close = decode_close, | ||
2595 | FF_CODEC_DECODE_CB(aac_decode_frame), | ||
2596 | CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_S32P), | ||
2597 | .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1, | ||
2598 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
2599 | CODEC_CH_LAYOUTS_ARRAY(ff_aac_ch_layout), | ||
2600 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles), | ||
2601 | .flush = flush, | ||
2602 | }; | ||
2603 | #endif | ||
2604 |