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