Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/aacdec_template.c |
Date: | 2022-07-07 01:21:54 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 1485 | 1892 | 78.5% |
Branches: | 940 | 1316 | 71.4% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * AAC decoder | ||
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 | /** | ||
33 | * @file | ||
34 | * AAC decoder | ||
35 | * @author Oded Shimon ( ods15 ods15 dyndns org ) | ||
36 | * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) | ||
37 | * | ||
38 | * AAC decoder fixed-point implementation | ||
39 | * @author Stanislav Ocovaj ( stanislav.ocovaj imgtec com ) | ||
40 | * @author Nedeljko Babic ( nedeljko.babic imgtec com ) | ||
41 | */ | ||
42 | |||
43 | /* | ||
44 | * supported tools | ||
45 | * | ||
46 | * Support? Name | ||
47 | * N (code in SoC repo) gain control | ||
48 | * Y block switching | ||
49 | * Y window shapes - standard | ||
50 | * N window shapes - Low Delay | ||
51 | * Y filterbank - standard | ||
52 | * N (code in SoC repo) filterbank - Scalable Sample Rate | ||
53 | * Y Temporal Noise Shaping | ||
54 | * Y Long Term Prediction | ||
55 | * Y intensity stereo | ||
56 | * Y channel coupling | ||
57 | * Y frequency domain prediction | ||
58 | * Y Perceptual Noise Substitution | ||
59 | * Y Mid/Side stereo | ||
60 | * N Scalable Inverse AAC Quantization | ||
61 | * N Frequency Selective Switch | ||
62 | * N upsampling filter | ||
63 | * Y quantization & coding - AAC | ||
64 | * N quantization & coding - TwinVQ | ||
65 | * N quantization & coding - BSAC | ||
66 | * N AAC Error Resilience tools | ||
67 | * N Error Resilience payload syntax | ||
68 | * N Error Protection tool | ||
69 | * N CELP | ||
70 | * N Silence Compression | ||
71 | * N HVXC | ||
72 | * N HVXC 4kbits/s VR | ||
73 | * N Structured Audio tools | ||
74 | * N Structured Audio Sample Bank Format | ||
75 | * N MIDI | ||
76 | * N Harmonic and Individual Lines plus Noise | ||
77 | * N Text-To-Speech Interface | ||
78 | * Y Spectral Band Replication | ||
79 | * Y (not in this code) Layer-1 | ||
80 | * Y (not in this code) Layer-2 | ||
81 | * Y (not in this code) Layer-3 | ||
82 | * N SinuSoidal Coding (Transient, Sinusoid, Noise) | ||
83 | * Y Parametric Stereo | ||
84 | * N Direct Stream Transfer | ||
85 | * Y (not in fixed point code) Enhanced AAC Low Delay (ER AAC ELD) | ||
86 | * | ||
87 | * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. | ||
88 | * - HE AAC v2 comprises LC AAC with Spectral Band Replication and | ||
89 | Parametric Stereo. | ||
90 | */ | ||
91 | |||
92 | #include "libavutil/channel_layout.h" | ||
93 | #include "libavutil/thread.h" | ||
94 | #include "internal.h" | ||
95 | |||
96 | static VLC vlc_scalefactors; | ||
97 | static VLC vlc_spectral[11]; | ||
98 | |||
99 | static int output_configure(AACContext *ac, | ||
100 | uint8_t layout_map[MAX_ELEM_ID*4][3], int tags, | ||
101 | enum OCStatus oc_type, int get_new_frame); | ||
102 | |||
103 | #define overread_err "Input buffer exhausted before END element found\n" | ||
104 | |||
105 | 541 | static int count_channels(uint8_t (*layout)[3], int tags) | |
106 | { | ||
107 | 541 | int i, sum = 0; | |
108 |
2/2✓ Branch 0 taken 1103 times.
✓ Branch 1 taken 541 times.
|
1644 | for (i = 0; i < tags; i++) { |
109 | 1103 | int syn_ele = layout[i][0]; | |
110 | 1103 | int pos = layout[i][2]; | |
111 |
2/2✓ Branch 0 taken 627 times.
✓ Branch 1 taken 476 times.
|
2206 | sum += (1 + (syn_ele == TYPE_CPE)) * |
112 |
3/4✓ Branch 0 taken 1103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1095 times.
✓ Branch 3 taken 8 times.
|
1103 | (pos != AAC_CHANNEL_OFF && pos != AAC_CHANNEL_CC); |
113 | } | ||
114 | 541 | return sum; | |
115 | } | ||
116 | |||
117 | /** | ||
118 | * Check for the channel element in the current channel position configuration. | ||
119 | * If it exists, make sure the appropriate element is allocated and map the | ||
120 | * channel order to match the internal FFmpeg channel layout. | ||
121 | * | ||
122 | * @param che_pos current channel position configuration | ||
123 | * @param type channel element type | ||
124 | * @param id channel element id | ||
125 | * @param channels count of the number of channels in the configuration | ||
126 | * | ||
127 | * @return Returns error status. 0 - OK, !0 - error | ||
128 | */ | ||
129 | 4595 | static av_cold int che_configure(AACContext *ac, | |
130 | enum ChannelPosition che_pos, | ||
131 | int type, int id, int *channels) | ||
132 | { | ||
133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4595 times.
|
4595 | if (*channels >= MAX_CHANNELS) |
134 | ✗ | return AVERROR_INVALIDDATA; | |
135 |
1/2✓ Branch 0 taken 4595 times.
✗ Branch 1 not taken.
|
4595 | if (che_pos) { |
136 |
2/2✓ Branch 0 taken 360 times.
✓ Branch 1 taken 4235 times.
|
4595 | if (!ac->che[type][id]) { |
137 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 360 times.
|
360 | if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) |
138 | ✗ | return AVERROR(ENOMEM); | |
139 | 360 | AAC_RENAME(ff_aac_sbr_ctx_init)(ac, &ac->che[type][id]->sbr, type); | |
140 | } | ||
141 |
2/2✓ Branch 0 taken 4587 times.
✓ Branch 1 taken 8 times.
|
4595 | if (type != TYPE_CCE) { |
142 |
7/8✓ Branch 0 taken 842 times.
✓ Branch 1 taken 3745 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 4587 times.
|
4587 | if (*channels >= MAX_CHANNELS - (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))) { |
143 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "Too many channels\n"); | |
144 | ✗ | return AVERROR_INVALIDDATA; | |
145 | } | ||
146 | 4587 | ac->output_element[(*channels)++] = &ac->che[type][id]->ch[0]; | |
147 |
4/4✓ Branch 0 taken 842 times.
✓ Branch 1 taken 3745 times.
✓ Branch 2 taken 775 times.
✓ Branch 3 taken 67 times.
|
4587 | if (type == TYPE_CPE || |
148 |
2/2✓ Branch 0 taken 366 times.
✓ Branch 1 taken 409 times.
|
775 | (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1)) { |
149 | 4111 | ac->output_element[(*channels)++] = &ac->che[type][id]->ch[1]; | |
150 | } | ||
151 | } | ||
152 | } else { | ||
153 | ✗ | if (ac->che[type][id]) | |
154 | ✗ | AAC_RENAME(ff_aac_sbr_ctx_close)(&ac->che[type][id]->sbr); | |
155 | ✗ | av_freep(&ac->che[type][id]); | |
156 | } | ||
157 | 4595 | return 0; | |
158 | } | ||
159 | |||
160 | 50016 | static int frame_configure_elements(AVCodecContext *avctx) | |
161 | { | ||
162 | 50016 | AACContext *ac = avctx->priv_data; | |
163 | int type, id, ch, ret; | ||
164 | |||
165 | /* set channel pointers to internal buffers by default */ | ||
166 |
2/2✓ Branch 0 taken 200064 times.
✓ Branch 1 taken 50016 times.
|
250080 | for (type = 0; type < 4; type++) { |
167 |
2/2✓ Branch 0 taken 3201024 times.
✓ Branch 1 taken 200064 times.
|
3401088 | for (id = 0; id < MAX_ELEM_ID; id++) { |
168 | 3201024 | ChannelElement *che = ac->che[type][id]; | |
169 |
2/2✓ Branch 0 taken 63396 times.
✓ Branch 1 taken 3137628 times.
|
3201024 | if (che) { |
170 | 63396 | che->ch[0].ret = che->ch[0].ret_buf; | |
171 | 63396 | che->ch[1].ret = che->ch[1].ret_buf; | |
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
176 | /* get output buffer */ | ||
177 | 50016 | av_frame_unref(ac->frame); | |
178 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50016 times.
|
50016 | if (!avctx->ch_layout.nb_channels) |
179 | ✗ | return 1; | |
180 | |||
181 | 50016 | ac->frame->nb_samples = 2048; | |
182 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 50016 times.
|
50016 | if ((ret = ff_get_buffer(avctx, ac->frame, 0)) < 0) |
183 | ✗ | return ret; | |
184 | |||
185 | /* map output channel pointers to AVFrame data */ | ||
186 |
2/2✓ Branch 0 taken 94573 times.
✓ Branch 1 taken 50016 times.
|
144589 | for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { |
187 |
1/2✓ Branch 0 taken 94573 times.
✗ Branch 1 not taken.
|
94573 | if (ac->output_element[ch]) |
188 | 94573 | ac->output_element[ch]->ret = (INTFLOAT *)ac->frame->extended_data[ch]; | |
189 | } | ||
190 | |||
191 | 50016 | return 0; | |
192 | } | ||
193 | |||
194 | struct elem_to_channel { | ||
195 | uint64_t av_position; | ||
196 | uint8_t syn_ele; | ||
197 | uint8_t elem_id; | ||
198 | uint8_t aac_position; | ||
199 | }; | ||
200 | |||
201 | 3749 | static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID], | |
202 | uint8_t (*layout_map)[3], int offset, uint64_t left, | ||
203 | uint64_t right, int pos, uint64_t *layout) | ||
204 | { | ||
205 |
2/2✓ Branch 0 taken 3745 times.
✓ Branch 1 taken 4 times.
|
3749 | if (layout_map[offset][0] == TYPE_CPE) { |
206 | 3745 | e2c_vec[offset] = (struct elem_to_channel) { | |
207 | 3745 | .av_position = left | right, | |
208 | .syn_ele = TYPE_CPE, | ||
209 | 3745 | .elem_id = layout_map[offset][1], | |
210 | .aac_position = pos | ||
211 | }; | ||
212 |
1/2✓ Branch 0 taken 3745 times.
✗ Branch 1 not taken.
|
3745 | if (e2c_vec[offset].av_position != UINT64_MAX) |
213 | 3745 | *layout |= e2c_vec[offset].av_position; | |
214 | |||
215 | 3745 | return 1; | |
216 | } else { | ||
217 | 4 | e2c_vec[offset] = (struct elem_to_channel) { | |
218 | .av_position = left, | ||
219 | .syn_ele = TYPE_SCE, | ||
220 | 4 | .elem_id = layout_map[offset][1], | |
221 | .aac_position = pos | ||
222 | }; | ||
223 | 4 | e2c_vec[offset + 1] = (struct elem_to_channel) { | |
224 | .av_position = right, | ||
225 | .syn_ele = TYPE_SCE, | ||
226 | 4 | .elem_id = layout_map[offset + 1][1], | |
227 | .aac_position = pos | ||
228 | }; | ||
229 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (left != UINT64_MAX) |
230 | 4 | *layout |= left; | |
231 | |||
232 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (right != UINT64_MAX) |
233 | 4 | *layout |= right; | |
234 | |||
235 | 4 | return 2; | |
236 | } | ||
237 | } | ||
238 | |||
239 | 13134 | static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, | |
240 | int *current) | ||
241 | { | ||
242 | 13134 | int num_pos_channels = 0; | |
243 | 13134 | int first_cpe = 0; | |
244 | 13134 | int sce_parity = 0; | |
245 | int i; | ||
246 |
2/2✓ Branch 0 taken 4721 times.
✓ Branch 1 taken 12933 times.
|
17654 | for (i = *current; i < tags; i++) { |
247 |
2/2✓ Branch 0 taken 201 times.
✓ Branch 1 taken 4520 times.
|
4721 | if (layout_map[i][2] != pos) |
248 | 201 | break; | |
249 |
2/2✓ Branch 0 taken 3745 times.
✓ Branch 1 taken 775 times.
|
4520 | if (layout_map[i][0] == TYPE_CPE) { |
250 |
2/2✓ Branch 0 taken 71 times.
✓ Branch 1 taken 3674 times.
|
3745 | if (sce_parity) { |
251 |
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) { |
252 | 71 | sce_parity = 0; | |
253 | } else { | ||
254 | ✗ | return -1; | |
255 | } | ||
256 | } | ||
257 | 3745 | num_pos_channels += 2; | |
258 | 3745 | first_cpe = 1; | |
259 | } else { | ||
260 | 775 | num_pos_channels++; | |
261 | 775 | sce_parity ^= 1; | |
262 | } | ||
263 | } | ||
264 |
3/4✓ Branch 0 taken 696 times.
✓ Branch 1 taken 12438 times.
✓ Branch 2 taken 696 times.
✗ Branch 3 not taken.
|
13134 | if (sce_parity && |
265 |
2/4✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 696 times.
|
696 | ((pos == AAC_CHANNEL_FRONT && first_cpe) || pos == AAC_CHANNEL_SIDE)) |
266 | ✗ | return -1; | |
267 | 13134 | *current = i; | |
268 | 13134 | return num_pos_channels; | |
269 | } | ||
270 | |||
271 | #define PREFIX_FOR_22POINT2 (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_LOW_FREQUENCY_2) | ||
272 | 4378 | static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) | |
273 | { | ||
274 | int i, n, total_non_cc_elements; | ||
275 | 4378 | struct elem_to_channel e2c_vec[4 * MAX_ELEM_ID] = { { 0 } }; | |
276 | int num_front_channels, num_side_channels, num_back_channels; | ||
277 | 4378 | uint64_t layout = 0; | |
278 | |||
279 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (FF_ARRAY_ELEMS(e2c_vec) < tags) |
280 | ✗ | return 0; | |
281 | |||
282 | 4378 | i = 0; | |
283 | num_front_channels = | ||
284 | 4378 | count_paired_channels(layout_map, tags, AAC_CHANNEL_FRONT, &i); | |
285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (num_front_channels < 0) |
286 | ✗ | return 0; | |
287 | num_side_channels = | ||
288 | 4378 | count_paired_channels(layout_map, tags, AAC_CHANNEL_SIDE, &i); | |
289 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (num_side_channels < 0) |
290 | ✗ | return 0; | |
291 | num_back_channels = | ||
292 | 4378 | count_paired_channels(layout_map, tags, AAC_CHANNEL_BACK, &i); | |
293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (num_back_channels < 0) |
294 | ✗ | return 0; | |
295 | |||
296 |
2/4✓ Branch 0 taken 4378 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4378 times.
|
4378 | if (num_side_channels == 0 && num_back_channels >= 4) { |
297 | ✗ | num_side_channels = 2; | |
298 | ✗ | num_back_channels -= 2; | |
299 | } | ||
300 | |||
301 | 4378 | i = 0; | |
302 |
2/2✓ Branch 0 taken 767 times.
✓ Branch 1 taken 3611 times.
|
4378 | if (num_front_channels & 1) { |
303 | 767 | e2c_vec[i] = (struct elem_to_channel) { | |
304 | .av_position = AV_CH_FRONT_CENTER, | ||
305 | .syn_ele = TYPE_SCE, | ||
306 | 767 | .elem_id = layout_map[i][1], | |
307 | .aac_position = AAC_CHANNEL_FRONT | ||
308 | }; | ||
309 | 767 | layout |= e2c_vec[i].av_position; | |
310 | 767 | i++; | |
311 | 767 | num_front_channels--; | |
312 | } | ||
313 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4370 times.
|
4378 | if (num_front_channels >= 4) { |
314 | 8 | i += assign_pair(e2c_vec, layout_map, i, | |
315 | AV_CH_FRONT_LEFT_OF_CENTER, | ||
316 | AV_CH_FRONT_RIGHT_OF_CENTER, | ||
317 | AAC_CHANNEL_FRONT, &layout); | ||
318 | 8 | num_front_channels -= 2; | |
319 | } | ||
320 |
2/2✓ Branch 0 taken 3682 times.
✓ Branch 1 taken 696 times.
|
4378 | if (num_front_channels >= 2) { |
321 | 3682 | i += assign_pair(e2c_vec, layout_map, i, | |
322 | AV_CH_FRONT_LEFT, | ||
323 | AV_CH_FRONT_RIGHT, | ||
324 | AAC_CHANNEL_FRONT, &layout); | ||
325 | 3682 | num_front_channels -= 2; | |
326 | } | ||
327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | while (num_front_channels >= 2) { |
328 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
329 | UINT64_MAX, | ||
330 | UINT64_MAX, | ||
331 | AAC_CHANNEL_FRONT, &layout); | ||
332 | ✗ | num_front_channels -= 2; | |
333 | } | ||
334 | |||
335 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (num_side_channels >= 2) { |
336 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
337 | AV_CH_SIDE_LEFT, | ||
338 | AV_CH_SIDE_RIGHT, | ||
339 | AAC_CHANNEL_FRONT, &layout); | ||
340 | ✗ | num_side_channels -= 2; | |
341 | } | ||
342 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | while (num_side_channels >= 2) { |
343 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
344 | UINT64_MAX, | ||
345 | UINT64_MAX, | ||
346 | AAC_CHANNEL_SIDE, &layout); | ||
347 | ✗ | num_side_channels -= 2; | |
348 | } | ||
349 | |||
350 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | while (num_back_channels >= 4) { |
351 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
352 | UINT64_MAX, | ||
353 | UINT64_MAX, | ||
354 | AAC_CHANNEL_BACK, &layout); | ||
355 | ✗ | num_back_channels -= 2; | |
356 | } | ||
357 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 4319 times.
|
4378 | if (num_back_channels >= 2) { |
358 | 59 | i += assign_pair(e2c_vec, layout_map, i, | |
359 | AV_CH_BACK_LEFT, | ||
360 | AV_CH_BACK_RIGHT, | ||
361 | AAC_CHANNEL_BACK, &layout); | ||
362 | 59 | num_back_channels -= 2; | |
363 | } | ||
364 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (num_back_channels) { |
365 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
366 | .av_position = AV_CH_BACK_CENTER, | ||
367 | .syn_ele = TYPE_SCE, | ||
368 | ✗ | .elem_id = layout_map[i][1], | |
369 | .aac_position = AAC_CHANNEL_BACK | ||
370 | }; | ||
371 | ✗ | layout |= e2c_vec[i].av_position; | |
372 | ✗ | i++; | |
373 | ✗ | num_back_channels--; | |
374 | } | ||
375 | |||
376 |
3/4✓ Branch 0 taken 67 times.
✓ Branch 1 taken 4311 times.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
|
4378 | if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { |
377 | 67 | e2c_vec[i] = (struct elem_to_channel) { | |
378 | .av_position = AV_CH_LOW_FREQUENCY, | ||
379 | .syn_ele = TYPE_LFE, | ||
380 | 67 | .elem_id = layout_map[i][1], | |
381 | .aac_position = AAC_CHANNEL_LFE | ||
382 | }; | ||
383 | 67 | layout |= e2c_vec[i].av_position; | |
384 | 67 | i++; | |
385 | } | ||
386 |
3/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
4378 | if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { |
387 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
388 | .av_position = AV_CH_LOW_FREQUENCY_2, | ||
389 | .syn_ele = TYPE_LFE, | ||
390 | ✗ | .elem_id = layout_map[i][1], | |
391 | .aac_position = AAC_CHANNEL_LFE | ||
392 | }; | ||
393 | ✗ | layout |= e2c_vec[i].av_position; | |
394 | ✗ | i++; | |
395 | } | ||
396 |
3/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
4378 | while (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { |
397 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
398 | .av_position = UINT64_MAX, | ||
399 | .syn_ele = TYPE_LFE, | ||
400 | ✗ | .elem_id = layout_map[i][1], | |
401 | .aac_position = AAC_CHANNEL_LFE | ||
402 | }; | ||
403 | ✗ | i++; | |
404 | } | ||
405 | |||
406 | // The previous checks would end up at 8 at this point for 22.2 | ||
407 |
1/6✓ Branch 0 taken 4378 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
4378 | if (layout == PREFIX_FOR_22POINT2 && tags == 16 && i == 8) { |
408 | ✗ | const uint8_t (*reference_layout_map)[3] = aac_channel_layout_map[12]; | |
409 | ✗ | for (int j = 0; j < tags; j++) { | |
410 | ✗ | if (layout_map[j][0] != reference_layout_map[j][0] || | |
411 | ✗ | layout_map[j][2] != reference_layout_map[j][2]) | |
412 | ✗ | goto end_of_layout_definition; | |
413 | } | ||
414 | |||
415 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
416 | .av_position = AV_CH_TOP_FRONT_CENTER, | ||
417 | ✗ | .syn_ele = layout_map[i][0], | |
418 | ✗ | .elem_id = layout_map[i][1], | |
419 | ✗ | .aac_position = layout_map[i][2] | |
420 | ✗ | }; layout |= e2c_vec[i].av_position; i++; | |
421 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
422 | AV_CH_TOP_FRONT_LEFT, | ||
423 | AV_CH_TOP_FRONT_RIGHT, | ||
424 | AAC_CHANNEL_FRONT, | ||
425 | &layout); | ||
426 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
427 | AV_CH_TOP_SIDE_LEFT, | ||
428 | AV_CH_TOP_SIDE_RIGHT, | ||
429 | AAC_CHANNEL_SIDE, | ||
430 | &layout); | ||
431 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
432 | .av_position = AV_CH_TOP_CENTER, | ||
433 | ✗ | .syn_ele = layout_map[i][0], | |
434 | ✗ | .elem_id = layout_map[i][1], | |
435 | ✗ | .aac_position = layout_map[i][2] | |
436 | ✗ | }; layout |= e2c_vec[i].av_position; i++; | |
437 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
438 | AV_CH_TOP_BACK_LEFT, | ||
439 | AV_CH_TOP_BACK_RIGHT, | ||
440 | AAC_CHANNEL_BACK, | ||
441 | &layout); | ||
442 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
443 | .av_position = AV_CH_TOP_BACK_CENTER, | ||
444 | ✗ | .syn_ele = layout_map[i][0], | |
445 | ✗ | .elem_id = layout_map[i][1], | |
446 | ✗ | .aac_position = layout_map[i][2] | |
447 | ✗ | }; layout |= e2c_vec[i].av_position; i++; | |
448 | ✗ | e2c_vec[i] = (struct elem_to_channel) { | |
449 | .av_position = AV_CH_BOTTOM_FRONT_CENTER, | ||
450 | ✗ | .syn_ele = layout_map[i][0], | |
451 | ✗ | .elem_id = layout_map[i][1], | |
452 | ✗ | .aac_position = layout_map[i][2] | |
453 | ✗ | }; layout |= e2c_vec[i].av_position; i++; | |
454 | ✗ | i += assign_pair(e2c_vec, layout_map, i, | |
455 | AV_CH_BOTTOM_FRONT_LEFT, | ||
456 | AV_CH_BOTTOM_FRONT_RIGHT, | ||
457 | AAC_CHANNEL_FRONT, | ||
458 | &layout); | ||
459 | } | ||
460 | |||
461 | 4378 | end_of_layout_definition: | |
462 | |||
463 | 4378 | total_non_cc_elements = n = i; | |
464 | |||
465 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (layout == AV_CH_LAYOUT_22POINT2) { |
466 | // For 22.2 reorder the result as needed | ||
467 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[0]); // FL & FR first (final), FC third | |
468 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[1]); // FC second (final), FLc & FRc third | |
469 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[2]); // LFE1 third (final), FLc & FRc seventh | |
470 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[4], e2c_vec[3]); // BL & BR fourth (final), SiL & SiR fifth | |
471 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[4]); // FLc & FRc fifth (final), SiL & SiR seventh | |
472 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[7], e2c_vec[6]); // LFE2 seventh (final), SiL & SiR eight (final) | |
473 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[9], e2c_vec[8]); // TpFL & TpFR ninth (final), TFC tenth (final) | |
474 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[11], e2c_vec[10]); // TC eleventh (final), TpSiL & TpSiR twelth | |
475 | ✗ | FFSWAP(struct elem_to_channel, e2c_vec[12], e2c_vec[11]); // TpBL & TpBR twelth (final), TpSiL & TpSiR thirteenth (final) | |
476 | } else { | ||
477 | // For everything else, utilize the AV channel position define as a | ||
478 | // stable sort. | ||
479 | do { | ||
480 | 4457 | int next_n = 0; | |
481 |
2/2✓ Branch 0 taken 343 times.
✓ Branch 1 taken 4457 times.
|
4800 | for (i = 1; i < n; i++) |
482 |
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) { |
483 | 146 | FFSWAP(struct elem_to_channel, e2c_vec[i - 1], e2c_vec[i]); | |
484 | 146 | next_n = i; | |
485 | } | ||
486 | 4457 | n = next_n; | |
487 |
2/2✓ Branch 0 taken 79 times.
✓ Branch 1 taken 4378 times.
|
4457 | } while (n > 0); |
488 | |||
489 | } | ||
490 | |||
491 |
2/2✓ Branch 0 taken 4587 times.
✓ Branch 1 taken 4378 times.
|
8965 | for (i = 0; i < total_non_cc_elements; i++) { |
492 | 4587 | layout_map[i][0] = e2c_vec[i].syn_ele; | |
493 | 4587 | layout_map[i][1] = e2c_vec[i].elem_id; | |
494 | 4587 | layout_map[i][2] = e2c_vec[i].aac_position; | |
495 | } | ||
496 | |||
497 | 4378 | return layout; | |
498 | } | ||
499 | |||
500 | /** | ||
501 | * Save current output configuration if and only if it has been locked. | ||
502 | */ | ||
503 | 4118 | static int push_output_configuration(AACContext *ac) { | |
504 | 4118 | int pushed = 0; | |
505 | |||
506 |
3/4✓ Branch 0 taken 59 times.
✓ Branch 1 taken 4059 times.
✓ Branch 2 taken 59 times.
✗ Branch 3 not taken.
|
4118 | if (ac->oc[1].status == OC_LOCKED || ac->oc[0].status == OC_NONE) { |
507 | 4118 | ac->oc[0] = ac->oc[1]; | |
508 | 4118 | pushed = 1; | |
509 | } | ||
510 | 4118 | ac->oc[1].status = OC_NONE; | |
511 | 4118 | return pushed; | |
512 | } | ||
513 | |||
514 | /** | ||
515 | * Restore the previous output configuration if and only if the current | ||
516 | * configuration is unlocked. | ||
517 | */ | ||
518 | ✗ | static void pop_output_configuration(AACContext *ac) { | |
519 | ✗ | if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) { | |
520 | ✗ | ac->oc[1] = ac->oc[0]; | |
521 | ✗ | ac->avctx->ch_layout = ac->oc[1].ch_layout; | |
522 | ✗ | output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, | |
523 | ac->oc[1].status, 0); | ||
524 | } | ||
525 | } | ||
526 | |||
527 | /** | ||
528 | * Configure output channel order based on the current program | ||
529 | * configuration element. | ||
530 | * | ||
531 | * @return Returns error status. 0 - OK, !0 - error | ||
532 | */ | ||
533 | 4378 | static int output_configure(AACContext *ac, | |
534 | uint8_t layout_map[MAX_ELEM_ID * 4][3], int tags, | ||
535 | enum OCStatus oc_type, int get_new_frame) | ||
536 | { | ||
537 | 4378 | AVCodecContext *avctx = ac->avctx; | |
538 | 4378 | int i, channels = 0, ret; | |
539 | 4378 | uint64_t layout = 0; | |
540 | 4378 | uint8_t id_map[TYPE_END][MAX_ELEM_ID] = {{ 0 }}; | |
541 | 4378 | uint8_t type_counts[TYPE_END] = { 0 }; | |
542 | |||
543 |
2/2✓ Branch 0 taken 4366 times.
✓ Branch 1 taken 12 times.
|
4378 | if (ac->oc[1].layout_map != layout_map) { |
544 | 4366 | memcpy(ac->oc[1].layout_map, layout_map, tags * sizeof(layout_map[0])); | |
545 | 4366 | ac->oc[1].layout_map_tags = tags; | |
546 | } | ||
547 |
2/2✓ Branch 0 taken 4595 times.
✓ Branch 1 taken 4378 times.
|
8973 | for (i = 0; i < tags; i++) { |
548 | 4595 | int type = layout_map[i][0]; | |
549 | 4595 | int id = layout_map[i][1]; | |
550 | 4595 | id_map[type][id] = type_counts[type]++; | |
551 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4595 times.
|
4595 | if (id_map[type][id] >= MAX_ELEM_ID) { |
552 | ✗ | avpriv_request_sample(ac->avctx, "Too large remapped id"); | |
553 | ✗ | return AVERROR_PATCHWELCOME; | |
554 | } | ||
555 | } | ||
556 | // Try to sniff a reasonable channel order, otherwise output the | ||
557 | // channels in the order the PCE declared them. | ||
558 | #if FF_API_OLD_CHANNEL_LAYOUT | ||
559 | FF_DISABLE_DEPRECATION_WARNINGS | ||
560 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4378 times.
|
4378 | if (avctx->request_channel_layout == AV_CH_LAYOUT_NATIVE) |
561 | ✗ | ac->output_channel_order = CHANNEL_ORDER_CODED; | |
562 | FF_ENABLE_DEPRECATION_WARNINGS | ||
563 | #endif | ||
564 | |||
565 |
1/2✓ Branch 0 taken 4378 times.
✗ Branch 1 not taken.
|
4378 | if (ac->output_channel_order == CHANNEL_ORDER_DEFAULT) |
566 | 4378 | layout = sniff_channel_order(layout_map, tags); | |
567 |
2/2✓ Branch 0 taken 4595 times.
✓ Branch 1 taken 4378 times.
|
8973 | for (i = 0; i < tags; i++) { |
568 | 4595 | int type = layout_map[i][0]; | |
569 | 4595 | int id = layout_map[i][1]; | |
570 | 4595 | int iid = id_map[type][id]; | |
571 | 4595 | int position = layout_map[i][2]; | |
572 | // Allocate or free elements depending on if they are in the | ||
573 | // current program configuration. | ||
574 | 4595 | ret = che_configure(ac, position, type, iid, &channels); | |
575 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4595 times.
|
4595 | if (ret < 0) |
576 | ✗ | return ret; | |
577 | 4595 | ac->tag_che_map[type][id] = ac->che[type][iid]; | |
578 | } | ||
579 |
3/4✓ Branch 0 taken 366 times.
✓ Branch 1 taken 4012 times.
✓ Branch 2 taken 366 times.
✗ Branch 3 not taken.
|
4378 | if (ac->oc[1].m4ac.ps == 1 && channels == 2) { |
580 |
1/2✓ Branch 0 taken 366 times.
✗ Branch 1 not taken.
|
366 | if (layout == AV_CH_FRONT_CENTER) { |
581 | 366 | layout = AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT; | |
582 | } else { | ||
583 | ✗ | layout = 0; | |
584 | } | ||
585 | } | ||
586 | |||
587 | 4378 | av_channel_layout_uninit(&ac->oc[1].ch_layout); | |
588 |
1/2✓ Branch 0 taken 4378 times.
✗ Branch 1 not taken.
|
4378 | if (layout) |
589 | 4378 | av_channel_layout_from_mask(&ac->oc[1].ch_layout, layout); | |
590 | else { | ||
591 | ✗ | ac->oc[1].ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; | |
592 | ✗ | ac->oc[1].ch_layout.nb_channels = channels; | |
593 | } | ||
594 | |||
595 | 4378 | av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout); | |
596 | 4378 | ac->oc[1].status = oc_type; | |
597 | |||
598 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4366 times.
|
4378 | if (get_new_frame) { |
599 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if ((ret = frame_configure_elements(ac->avctx)) < 0) |
600 | ✗ | return ret; | |
601 | } | ||
602 | |||
603 | 4378 | return 0; | |
604 | } | ||
605 | |||
606 | 5 | static void flush(AVCodecContext *avctx) | |
607 | { | ||
608 | 5 | AACContext *ac= avctx->priv_data; | |
609 | int type, i, j; | ||
610 | |||
611 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5 times.
|
25 | for (type = 3; type >= 0; type--) { |
612 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 20 times.
|
340 | for (i = 0; i < MAX_ELEM_ID; i++) { |
613 | 320 | ChannelElement *che = ac->che[type][i]; | |
614 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 315 times.
|
320 | if (che) { |
615 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5 times.
|
15 | for (j = 0; j <= 1; j++) { |
616 | 10 | memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved)); | |
617 | } | ||
618 | } | ||
619 | } | ||
620 | } | ||
621 | 5 | } | |
622 | |||
623 | /** | ||
624 | * Set up channel positions based on a default channel configuration | ||
625 | * as specified in table 1.17. | ||
626 | * | ||
627 | * @return Returns error status. 0 - OK, !0 - error | ||
628 | */ | ||
629 | 4644 | static int set_default_channel_config(AACContext *ac, AVCodecContext *avctx, | |
630 | uint8_t (*layout_map)[3], | ||
631 | int *tags, | ||
632 | int channel_config) | ||
633 | { | ||
634 |
3/8✓ Branch 0 taken 4644 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4644 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4644 times.
|
4644 | if (channel_config < 1 || (channel_config > 7 && channel_config < 11) || |
635 | channel_config > 13) { | ||
636 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
637 | "invalid default channel configuration (%d)\n", | ||
638 | channel_config); | ||
639 | ✗ | return AVERROR_INVALIDDATA; | |
640 | } | ||
641 | 4644 | *tags = tags_per_config[channel_config]; | |
642 | 4644 | memcpy(layout_map, aac_channel_layout_map[channel_config - 1], | |
643 | 4644 | *tags * sizeof(*layout_map)); | |
644 | |||
645 | /* | ||
646 | * AAC specification has 7.1(wide) as a default layout for 8-channel streams. | ||
647 | * However, at least Nero AAC encoder encodes 7.1 streams using the default | ||
648 | * channel config 7, mapping the side channels of the original audio stream | ||
649 | * to the second AAC_CHANNEL_FRONT pair in the AAC stream. Similarly, e.g. FAAD | ||
650 | * decodes the second AAC_CHANNEL_FRONT pair as side channels, therefore decoding | ||
651 | * the incorrect streams as if they were correct (and as the encoder intended). | ||
652 | * | ||
653 | * As actual intended 7.1(wide) streams are very rare, default to assuming a | ||
654 | * 7.1 layout was intended. | ||
655 | */ | ||
656 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4644 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4644 | if (channel_config == 7 && avctx->strict_std_compliance < FF_COMPLIANCE_STRICT) { |
657 | ✗ | layout_map[2][2] = AAC_CHANNEL_SIDE; | |
658 | |||
659 | ✗ | if (!ac || !ac->warned_71_wide++) { | |
660 | ✗ | av_log(avctx, AV_LOG_INFO, "Assuming an incorrectly encoded 7.1 channel layout" | |
661 | " instead of a spec-compliant 7.1(wide) layout, use -strict %d to decode" | ||
662 | " according to the specification instead.\n", FF_COMPLIANCE_STRICT); | ||
663 | } | ||
664 | } | ||
665 | |||
666 | 4644 | return 0; | |
667 | } | ||
668 | |||
669 | 63050 | static ChannelElement *get_che(AACContext *ac, int type, int elem_id) | |
670 | { | ||
671 | /* For PCE based channel configurations map the channels solely based | ||
672 | * on tags. */ | ||
673 |
2/2✓ Branch 0 taken 24124 times.
✓ Branch 1 taken 38926 times.
|
63050 | if (!ac->oc[1].m4ac.chan_config) { |
674 | 24124 | return ac->tag_che_map[type][elem_id]; | |
675 | } | ||
676 | // Allow single CPE stereo files to be signalled with mono configuration. | ||
677 |
4/4✓ Branch 0 taken 36466 times.
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 20540 times.
✓ Branch 3 taken 15926 times.
|
38926 | if (!ac->tags_mapped && type == TYPE_CPE && |
678 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20540 times.
|
20540 | ac->oc[1].m4ac.chan_config == 1) { |
679 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
680 | int layout_map_tags; | ||
681 | ✗ | push_output_configuration(ac); | |
682 | |||
683 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "mono with CPE\n"); | |
684 | |||
685 | ✗ | if (set_default_channel_config(ac, ac->avctx, layout_map, | |
686 | &layout_map_tags, 2) < 0) | ||
687 | ✗ | return NULL; | |
688 | ✗ | if (output_configure(ac, layout_map, layout_map_tags, | |
689 | OC_TRIAL_FRAME, 1) < 0) | ||
690 | ✗ | return NULL; | |
691 | |||
692 | ✗ | ac->oc[1].m4ac.chan_config = 2; | |
693 | ✗ | ac->oc[1].m4ac.ps = 0; | |
694 | } | ||
695 | // And vice-versa | ||
696 |
4/4✓ Branch 0 taken 36466 times.
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 15926 times.
✓ Branch 3 taken 20540 times.
|
38926 | if (!ac->tags_mapped && type == TYPE_SCE && |
697 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15926 times.
|
15926 | ac->oc[1].m4ac.chan_config == 2) { |
698 | uint8_t layout_map[MAX_ELEM_ID * 4][3]; | ||
699 | int layout_map_tags; | ||
700 | ✗ | push_output_configuration(ac); | |
701 | |||
702 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "stereo with SCE\n"); | |
703 | |||
704 | ✗ | if (set_default_channel_config(ac, ac->avctx, layout_map, | |
705 | &layout_map_tags, 1) < 0) | ||
706 | ✗ | return NULL; | |
707 | ✗ | if (output_configure(ac, layout_map, layout_map_tags, | |
708 | OC_TRIAL_FRAME, 1) < 0) | ||
709 | ✗ | return NULL; | |
710 | |||
711 | ✗ | ac->oc[1].m4ac.chan_config = 1; | |
712 | ✗ | if (ac->oc[1].m4ac.sbr) | |
713 | ✗ | ac->oc[1].m4ac.ps = -1; | |
714 | } | ||
715 | /* For indexed channel configurations map the channels solely based | ||
716 | * on position. */ | ||
717 |
3/9✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3280 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 20540 times.
✓ Branch 7 taken 15106 times.
✗ Branch 8 not taken.
|
38926 | switch (ac->oc[1].m4ac.chan_config) { |
718 | ✗ | case 13: | |
719 | ✗ | if (ac->tags_mapped > 3 && ((type == TYPE_CPE && elem_id < 8) || | |
720 | ✗ | (type == TYPE_SCE && elem_id < 6) || | |
721 | ✗ | (type == TYPE_LFE && elem_id < 2))) { | |
722 | ✗ | ac->tags_mapped++; | |
723 | ✗ | return ac->tag_che_map[type][elem_id] = ac->che[type][elem_id]; | |
724 | } | ||
725 | case 12: | ||
726 | case 7: | ||
727 | ✗ | if (ac->tags_mapped == 3 && type == TYPE_CPE) { | |
728 | ✗ | ac->tags_mapped++; | |
729 | ✗ | return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2]; | |
730 | } | ||
731 | case 11: | ||
732 | ✗ | if (ac->tags_mapped == 2 && | |
733 | ✗ | ac->oc[1].m4ac.chan_config == 11 && | |
734 | type == TYPE_SCE) { | ||
735 | ✗ | ac->tags_mapped++; | |
736 | ✗ | return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; | |
737 | } | ||
738 | case 6: | ||
739 | /* Some streams incorrectly code 5.1 audio as | ||
740 | * SCE[0] CPE[0] CPE[1] SCE[1] | ||
741 | * instead of | ||
742 | * SCE[0] CPE[0] CPE[1] LFE[0]. | ||
743 | * If we seem to have encountered such a stream, transfer | ||
744 | * the LFE[0] element to the SCE[1]'s mapping */ | ||
745 |
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 == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) { |
746 |
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)) { |
747 | ✗ | av_log(ac->avctx, AV_LOG_WARNING, | |
748 | "This stream seems to incorrectly report its last channel as %s[%d], mapping to LFE[0]\n", | ||
749 | type == TYPE_SCE ? "SCE" : "LFE", elem_id); | ||
750 | ✗ | ac->warned_remapping_once++; | |
751 | } | ||
752 | 820 | ac->tags_mapped++; | |
753 | 820 | return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0]; | |
754 | } | ||
755 | case 5: | ||
756 |
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) { |
757 | 820 | ac->tags_mapped++; | |
758 | 820 | return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1]; | |
759 | } | ||
760 | case 4: | ||
761 | /* Some streams incorrectly code 4.0 audio as | ||
762 | * SCE[0] CPE[0] LFE[0] | ||
763 | * instead of | ||
764 | * SCE[0] CPE[0] SCE[1]. | ||
765 | * If we seem to have encountered such a stream, transfer | ||
766 | * the SCE[1] element to the LFE[0]'s mapping */ | ||
767 |
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 == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) { |
768 | ✗ | if (!ac->warned_remapping_once && (type != TYPE_SCE || elem_id != 1)) { | |
769 | ✗ | av_log(ac->avctx, AV_LOG_WARNING, | |
770 | "This stream seems to incorrectly report its last channel as %s[%d], mapping to SCE[1]\n", | ||
771 | type == TYPE_SCE ? "SCE" : "LFE", elem_id); | ||
772 | ✗ | ac->warned_remapping_once++; | |
773 | } | ||
774 | ✗ | ac->tags_mapped++; | |
775 | ✗ | return ac->tag_che_map[type][elem_id] = ac->che[TYPE_SCE][1]; | |
776 | } | ||
777 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1640 times.
|
1640 | if (ac->tags_mapped == 2 && |
778 | ✗ | ac->oc[1].m4ac.chan_config == 4 && | |
779 | type == TYPE_SCE) { | ||
780 | ✗ | ac->tags_mapped++; | |
781 | ✗ | return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; | |
782 | } | ||
783 | case 3: | ||
784 | case 2: | ||
785 |
3/4✓ Branch 0 taken 21360 times.
✓ Branch 1 taken 820 times.
✓ Branch 2 taken 21360 times.
✗ Branch 3 not taken.
|
22180 | if (ac->tags_mapped == (ac->oc[1].m4ac.chan_config != 2) && |
786 | type == TYPE_CPE) { | ||
787 | 21360 | ac->tags_mapped++; | |
788 | 21360 | return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0]; | |
789 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 820 times.
|
820 | } else if (ac->oc[1].m4ac.chan_config == 2) { |
790 | ✗ | return NULL; | |
791 | } | ||
792 | case 1: | ||
793 |
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) { |
794 | 15926 | ac->tags_mapped++; | |
795 | 15926 | return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0]; | |
796 | } | ||
797 | default: | ||
798 | ✗ | return NULL; | |
799 | } | ||
800 | } | ||
801 | |||
802 | /** | ||
803 | * Decode an array of 4 bit element IDs, optionally interleaved with a | ||
804 | * stereo/mono switching bit. | ||
805 | * | ||
806 | * @param type speaker type/position for these channels | ||
807 | */ | ||
808 | 215 | static void decode_channel_map(uint8_t layout_map[][3], | |
809 | enum ChannelPosition type, | ||
810 | GetBitContext *gb, int n) | ||
811 | { | ||
812 |
2/2✓ Branch 0 taken 95 times.
✓ Branch 1 taken 215 times.
|
310 | while (n--) { |
813 | enum RawDataBlockType syn_ele; | ||
814 |
3/4✓ Branch 0 taken 75 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
95 | switch (type) { |
815 | 75 | case AAC_CHANNEL_FRONT: | |
816 | case AAC_CHANNEL_BACK: | ||
817 | case AAC_CHANNEL_SIDE: | ||
818 | 75 | syn_ele = get_bits1(gb); | |
819 | 75 | break; | |
820 | 8 | case AAC_CHANNEL_CC: | |
821 | 8 | skip_bits1(gb); | |
822 | 8 | syn_ele = TYPE_CCE; | |
823 | 8 | break; | |
824 | 12 | case AAC_CHANNEL_LFE: | |
825 | 12 | syn_ele = TYPE_LFE; | |
826 | 12 | break; | |
827 | ✗ | default: | |
828 | // AAC_CHANNEL_OFF has no channel map | ||
829 | ✗ | av_assert0(0); | |
830 | } | ||
831 | 95 | layout_map[0][0] = syn_ele; | |
832 | 95 | layout_map[0][1] = get_bits(gb, 4); | |
833 | 95 | layout_map[0][2] = type; | |
834 | 95 | layout_map++; | |
835 | } | ||
836 | 215 | } | |
837 | |||
838 | 43 | static inline void relative_align_get_bits(GetBitContext *gb, | |
839 | int reference_position) { | ||
840 | 43 | int n = (reference_position - get_bits_count(gb) & 7); | |
841 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 4 times.
|
43 | if (n) |
842 | 39 | skip_bits(gb, n); | |
843 | 43 | } | |
844 | |||
845 | /** | ||
846 | * Decode program configuration element; reference: table 4.2. | ||
847 | * | ||
848 | * @return Returns error status. 0 - OK, !0 - error | ||
849 | */ | ||
850 | 43 | static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, | |
851 | uint8_t (*layout_map)[3], | ||
852 | GetBitContext *gb, int byte_align_ref) | ||
853 | { | ||
854 | int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc; | ||
855 | int sampling_index; | ||
856 | int comment_len; | ||
857 | int tags; | ||
858 | |||
859 | 43 | skip_bits(gb, 2); // object_type | |
860 | |||
861 | 43 | sampling_index = get_bits(gb, 4); | |
862 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if (m4ac->sampling_index != sampling_index) |
863 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
864 | "Sample rate index in program config element does not " | ||
865 | "match the sample rate index configured by the container.\n"); | ||
866 | |||
867 | 43 | num_front = get_bits(gb, 4); | |
868 | 43 | num_side = get_bits(gb, 4); | |
869 | 43 | num_back = get_bits(gb, 4); | |
870 | 43 | num_lfe = get_bits(gb, 2); | |
871 | 43 | num_assoc_data = get_bits(gb, 3); | |
872 | 43 | num_cc = get_bits(gb, 4); | |
873 | |||
874 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
|
43 | if (get_bits1(gb)) |
875 | ✗ | skip_bits(gb, 4); // mono_mixdown_tag | |
876 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
|
43 | if (get_bits1(gb)) |
877 | ✗ | skip_bits(gb, 4); // stereo_mixdown_tag | |
878 | |||
879 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
|
43 | if (get_bits1(gb)) |
880 | ✗ | skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround | |
881 | |||
882 |
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)) { |
883 | ✗ | av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err); | |
884 | ✗ | return -1; | |
885 | } | ||
886 | 43 | decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front); | |
887 | 43 | tags = num_front; | |
888 | 43 | decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side); | |
889 | 43 | tags += num_side; | |
890 | 43 | decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back); | |
891 | 43 | tags += num_back; | |
892 | 43 | decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe); | |
893 | 43 | tags += num_lfe; | |
894 | |||
895 | 43 | skip_bits_long(gb, 4 * num_assoc_data); | |
896 | |||
897 | 43 | decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc); | |
898 | 43 | tags += num_cc; | |
899 | |||
900 | 43 | relative_align_get_bits(gb, byte_align_ref); | |
901 | |||
902 | /* comment field, first byte is length */ | ||
903 | 43 | comment_len = get_bits(gb, 8) * 8; | |
904 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
|
43 | if (get_bits_left(gb) < comment_len) { |
905 | ✗ | av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err); | |
906 | ✗ | return AVERROR_INVALIDDATA; | |
907 | } | ||
908 | 43 | skip_bits_long(gb, comment_len); | |
909 | 43 | return tags; | |
910 | } | ||
911 | |||
912 | /** | ||
913 | * Decode GA "General Audio" specific configuration; reference: table 4.1. | ||
914 | * | ||
915 | * @param ac pointer to AACContext, may be null | ||
916 | * @param avctx pointer to AVCCodecContext, used for logging | ||
917 | * | ||
918 | * @return Returns error status. 0 - OK, !0 - error | ||
919 | */ | ||
920 | 541 | static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, | |
921 | GetBitContext *gb, | ||
922 | int get_bit_alignment, | ||
923 | MPEG4AudioConfig *m4ac, | ||
924 | int channel_config) | ||
925 | { | ||
926 | int extension_flag, ret, ep_config, res_flags; | ||
927 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
928 | 541 | int tags = 0; | |
929 | |||
930 | #if USE_FIXED | ||
931 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
|
19 | if (get_bits1(gb)) { // frameLengthFlag |
932 | ✗ | avpriv_report_missing_feature(avctx, "Fixed point 960/120 MDCT window"); | |
933 | ✗ | return AVERROR_PATCHWELCOME; | |
934 | } | ||
935 | 19 | m4ac->frame_length_short = 0; | |
936 | #else | ||
937 | 522 | m4ac->frame_length_short = get_bits1(gb); | |
938 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 520 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
522 | if (m4ac->frame_length_short && m4ac->sbr == 1) { |
939 | ✗ | avpriv_report_missing_feature(avctx, "SBR with 960 frame length"); | |
940 | ✗ | if (ac) ac->warned_960_sbr = 1; | |
941 | ✗ | m4ac->sbr = 0; | |
942 | ✗ | m4ac->ps = 0; | |
943 | } | ||
944 | #endif | ||
945 | |||
946 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 541 times.
|
541 | if (get_bits1(gb)) // dependsOnCoreCoder |
947 | ✗ | skip_bits(gb, 14); // coreCoderDelay | |
948 | 541 | extension_flag = get_bits1(gb); | |
949 | |||
950 |
1/2✓ Branch 0 taken 541 times.
✗ Branch 1 not taken.
|
541 | if (m4ac->object_type == AOT_AAC_SCALABLE || |
951 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 541 times.
|
541 | m4ac->object_type == AOT_ER_AAC_SCALABLE) |
952 | ✗ | skip_bits(gb, 3); // layerNr | |
953 | |||
954 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 498 times.
|
541 | if (channel_config == 0) { |
955 | 43 | skip_bits(gb, 4); // element_instance_tag | |
956 | 43 | tags = decode_pce(avctx, m4ac, layout_map, gb, get_bit_alignment); | |
957 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if (tags < 0) |
958 | ✗ | return tags; | |
959 | } else { | ||
960 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 498 times.
|
498 | if ((ret = set_default_channel_config(ac, avctx, layout_map, |
961 | &tags, channel_config))) | ||
962 | ✗ | return ret; | |
963 | } | ||
964 | |||
965 |
2/2✓ Branch 1 taken 449 times.
✓ Branch 2 taken 92 times.
|
541 | if (count_channels(layout_map, tags) > 1) { |
966 | 449 | m4ac->ps = 0; | |
967 |
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) |
968 | 18 | m4ac->ps = 1; | |
969 | |||
970 |
3/4✓ Branch 0 taken 220 times.
✓ Branch 1 taken 321 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 220 times.
|
541 | if (ac && (ret = output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0))) |
971 | ✗ | return ret; | |
972 | |||
973 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 537 times.
|
541 | if (extension_flag) { |
974 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | switch (m4ac->object_type) { |
975 | ✗ | case AOT_ER_BSAC: | |
976 | ✗ | skip_bits(gb, 5); // numOfSubFrame | |
977 | ✗ | skip_bits(gb, 11); // layer_length | |
978 | ✗ | break; | |
979 | 4 | case AOT_ER_AAC_LC: | |
980 | case AOT_ER_AAC_LTP: | ||
981 | case AOT_ER_AAC_SCALABLE: | ||
982 | case AOT_ER_AAC_LD: | ||
983 | 4 | res_flags = get_bits(gb, 3); | |
984 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (res_flags) { |
985 | ✗ | avpriv_report_missing_feature(avctx, | |
986 | "AAC data resilience (flags %x)", | ||
987 | res_flags); | ||
988 | ✗ | return AVERROR_PATCHWELCOME; | |
989 | } | ||
990 | 4 | break; | |
991 | } | ||
992 | 4 | skip_bits1(gb); // extensionFlag3 (TBD in version 3) | |
993 | } | ||
994 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 537 times.
|
541 | switch (m4ac->object_type) { |
995 | 4 | case AOT_ER_AAC_LC: | |
996 | case AOT_ER_AAC_LTP: | ||
997 | case AOT_ER_AAC_SCALABLE: | ||
998 | case AOT_ER_AAC_LD: | ||
999 | 4 | ep_config = get_bits(gb, 2); | |
1000 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ep_config) { |
1001 | ✗ | avpriv_report_missing_feature(avctx, | |
1002 | "epConfig %d", ep_config); | ||
1003 | ✗ | return AVERROR_PATCHWELCOME; | |
1004 | } | ||
1005 | } | ||
1006 | 541 | return 0; | |
1007 | } | ||
1008 | |||
1009 | 10 | static int decode_eld_specific_config(AACContext *ac, AVCodecContext *avctx, | |
1010 | GetBitContext *gb, | ||
1011 | MPEG4AudioConfig *m4ac, | ||
1012 | int channel_config) | ||
1013 | { | ||
1014 | int ret, ep_config, res_flags; | ||
1015 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
1016 | 10 | int tags = 0; | |
1017 | 10 | const int ELDEXT_TERM = 0; | |
1018 | |||
1019 | 10 | m4ac->ps = 0; | |
1020 | 10 | m4ac->sbr = 0; | |
1021 | #if USE_FIXED | ||
1022 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (get_bits1(gb)) { // frameLengthFlag |
1023 | ✗ | avpriv_request_sample(avctx, "960/120 MDCT window"); | |
1024 | ✗ | return AVERROR_PATCHWELCOME; | |
1025 | } | ||
1026 | #else | ||
1027 | 8 | m4ac->frame_length_short = get_bits1(gb); | |
1028 | #endif | ||
1029 | 10 | res_flags = get_bits(gb, 3); | |
1030 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (res_flags) { |
1031 | ✗ | avpriv_report_missing_feature(avctx, | |
1032 | "AAC data resilience (flags %x)", | ||
1033 | res_flags); | ||
1034 | ✗ | return AVERROR_PATCHWELCOME; | |
1035 | } | ||
1036 | |||
1037 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (get_bits1(gb)) { // ldSbrPresentFlag |
1038 | ✗ | avpriv_report_missing_feature(avctx, | |
1039 | "Low Delay SBR"); | ||
1040 | ✗ | return AVERROR_PATCHWELCOME; | |
1041 | } | ||
1042 | |||
1043 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | while (get_bits(gb, 4) != ELDEXT_TERM) { |
1044 | ✗ | int len = get_bits(gb, 4); | |
1045 | ✗ | if (len == 15) | |
1046 | ✗ | len += get_bits(gb, 8); | |
1047 | ✗ | if (len == 15 + 255) | |
1048 | ✗ | len += get_bits(gb, 16); | |
1049 | ✗ | if (get_bits_left(gb) < len * 8 + 4) { | |
1050 | ✗ | av_log(avctx, AV_LOG_ERROR, overread_err); | |
1051 | ✗ | return AVERROR_INVALIDDATA; | |
1052 | } | ||
1053 | ✗ | skip_bits_long(gb, 8 * len); | |
1054 | } | ||
1055 | |||
1056 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = set_default_channel_config(ac, avctx, layout_map, |
1057 | &tags, channel_config))) | ||
1058 | ✗ | return ret; | |
1059 | |||
1060 |
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))) |
1061 | ✗ | return ret; | |
1062 | |||
1063 | 10 | ep_config = get_bits(gb, 2); | |
1064 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ep_config) { |
1065 | ✗ | avpriv_report_missing_feature(avctx, | |
1066 | "epConfig %d", ep_config); | ||
1067 | ✗ | return AVERROR_PATCHWELCOME; | |
1068 | } | ||
1069 | 10 | return 0; | |
1070 | } | ||
1071 | |||
1072 | /** | ||
1073 | * Decode audio specific configuration; reference: table 1.13. | ||
1074 | * | ||
1075 | * @param ac pointer to AACContext, may be null | ||
1076 | * @param avctx pointer to AVCCodecContext, used for logging | ||
1077 | * @param m4ac pointer to MPEG4AudioConfig, used for parsing | ||
1078 | * @param gb buffer holding an audio specific config | ||
1079 | * @param get_bit_alignment relative alignment for byte align operations | ||
1080 | * @param sync_extension look for an appended sync extension | ||
1081 | * | ||
1082 | * @return Returns error status or number of consumed bits. <0 - error | ||
1083 | */ | ||
1084 | 551 | static int decode_audio_specific_config_gb(AACContext *ac, | |
1085 | AVCodecContext *avctx, | ||
1086 | MPEG4AudioConfig *m4ac, | ||
1087 | GetBitContext *gb, | ||
1088 | int get_bit_alignment, | ||
1089 | int sync_extension) | ||
1090 | { | ||
1091 | int i, ret; | ||
1092 | 551 | GetBitContext gbc = *gb; | |
1093 | 551 | MPEG4AudioConfig m4ac_bak = *m4ac; | |
1094 | |||
1095 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 551 times.
|
551 | if ((i = ff_mpeg4audio_get_config_gb(m4ac, &gbc, sync_extension, avctx)) < 0) { |
1096 | ✗ | *m4ac = m4ac_bak; | |
1097 | ✗ | return AVERROR_INVALIDDATA; | |
1098 | } | ||
1099 | |||
1100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 551 times.
|
551 | if (m4ac->sampling_index > 12) { |
1101 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1102 | "invalid sampling rate index %d\n", | ||
1103 | m4ac->sampling_index); | ||
1104 | ✗ | *m4ac = m4ac_bak; | |
1105 | ✗ | return AVERROR_INVALIDDATA; | |
1106 | } | ||
1107 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 547 times.
|
551 | if (m4ac->object_type == AOT_ER_AAC_LD && |
1108 |
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)) { |
1109 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1110 | "invalid low delay sampling rate index %d\n", | ||
1111 | m4ac->sampling_index); | ||
1112 | ✗ | *m4ac = m4ac_bak; | |
1113 | ✗ | return AVERROR_INVALIDDATA; | |
1114 | } | ||
1115 | |||
1116 | 551 | skip_bits_long(gb, i); | |
1117 | |||
1118 |
2/3✓ Branch 0 taken 541 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
551 | switch (m4ac->object_type) { |
1119 | 541 | case AOT_AAC_MAIN: | |
1120 | case AOT_AAC_LC: | ||
1121 | case AOT_AAC_SSR: | ||
1122 | case AOT_AAC_LTP: | ||
1123 | case AOT_ER_AAC_LC: | ||
1124 | case AOT_ER_AAC_LD: | ||
1125 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 541 times.
|
541 | if ((ret = decode_ga_specific_config(ac, avctx, gb, get_bit_alignment, |
1126 | m4ac, m4ac->chan_config)) < 0) | ||
1127 | ✗ | return ret; | |
1128 | 541 | break; | |
1129 | 10 | case AOT_ER_AAC_ELD: | |
1130 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = decode_eld_specific_config(ac, avctx, gb, |
1131 | m4ac, m4ac->chan_config)) < 0) | ||
1132 | ✗ | return ret; | |
1133 | 10 | break; | |
1134 | ✗ | default: | |
1135 | ✗ | avpriv_report_missing_feature(avctx, | |
1136 | "Audio object type %s%d", | ||
1137 | ✗ | m4ac->sbr == 1 ? "SBR+" : "", | |
1138 | m4ac->object_type); | ||
1139 | ✗ | return AVERROR(ENOSYS); | |
1140 | } | ||
1141 | |||
1142 | ff_dlog(avctx, | ||
1143 | "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n", | ||
1144 | m4ac->object_type, m4ac->chan_config, m4ac->sampling_index, | ||
1145 | m4ac->sample_rate, m4ac->sbr, | ||
1146 | m4ac->ps); | ||
1147 | |||
1148 | 551 | return get_bits_count(gb); | |
1149 | } | ||
1150 | |||
1151 | 230 | static int decode_audio_specific_config(AACContext *ac, | |
1152 | AVCodecContext *avctx, | ||
1153 | MPEG4AudioConfig *m4ac, | ||
1154 | const uint8_t *data, int64_t bit_size, | ||
1155 | int sync_extension) | ||
1156 | { | ||
1157 | int i, ret; | ||
1158 | GetBitContext gb; | ||
1159 | |||
1160 |
2/4✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 230 times.
|
230 | if (bit_size < 0 || bit_size > INT_MAX) { |
1161 | ✗ | av_log(avctx, AV_LOG_ERROR, "Audio specific config size is invalid\n"); | |
1162 | ✗ | return AVERROR_INVALIDDATA; | |
1163 | } | ||
1164 | |||
1165 | ff_dlog(avctx, "audio specific config size %d\n", (int)bit_size >> 3); | ||
1166 |
2/2✓ Branch 0 taken 1365 times.
✓ Branch 1 taken 230 times.
|
1595 | for (i = 0; i < bit_size >> 3; i++) |
1167 | ff_dlog(avctx, "%02x ", data[i]); | ||
1168 | ff_dlog(avctx, "\n"); | ||
1169 | |||
1170 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 230 times.
|
230 | if ((ret = init_get_bits(&gb, data, bit_size)) < 0) |
1171 | ✗ | return ret; | |
1172 | |||
1173 | 230 | return decode_audio_specific_config_gb(ac, avctx, m4ac, &gb, 0, | |
1174 | sync_extension); | ||
1175 | } | ||
1176 | |||
1177 | /** | ||
1178 | * linear congruential pseudorandom number generator | ||
1179 | * | ||
1180 | * @param previous_val pointer to the current state of the generator | ||
1181 | * | ||
1182 | * @return Returns a 32-bit pseudorandom integer | ||
1183 | */ | ||
1184 | 5944200 | static av_always_inline int lcg_random(unsigned previous_val) | |
1185 | { | ||
1186 | 5944200 | union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 }; | |
1187 | 5944200 | return v.s; | |
1188 | } | ||
1189 | |||
1190 | 40 | static void reset_all_predictors(PredictorState *ps) | |
1191 | { | ||
1192 | int i; | ||
1193 |
2/2✓ Branch 0 taken 26880 times.
✓ Branch 1 taken 40 times.
|
26920 | for (i = 0; i < MAX_PREDICTORS; i++) |
1194 | 26880 | reset_predict_state(&ps[i]); | |
1195 | 40 | } | |
1196 | |||
1197 | 59 | static int sample_rate_idx (int rate) | |
1198 | { | ||
1199 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
|
59 | if (92017 <= rate) return 0; |
1200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
|
59 | else if (75132 <= rate) return 1; |
1201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
|
59 | else if (55426 <= rate) return 2; |
1202 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 58 times.
|
59 | else if (46009 <= rate) return 3; |
1203 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 42 times.
|
58 | else if (37566 <= rate) return 4; |
1204 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 39 times.
|
42 | else if (27713 <= rate) return 5; |
1205 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
|
39 | else if (23004 <= rate) return 6; |
1206 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
|
39 | else if (18783 <= rate) return 7; |
1207 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 35 times.
|
39 | else if (13856 <= rate) return 8; |
1208 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | else if (11502 <= rate) return 9; |
1209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | else if (9391 <= rate) return 10; |
1210 | 35 | else return 11; | |
1211 | } | ||
1212 | |||
1213 | 518 | static void reset_predictor_group(PredictorState *ps, int group_num) | |
1214 | { | ||
1215 | int i; | ||
1216 |
2/2✓ Branch 0 taken 11662 times.
✓ Branch 1 taken 518 times.
|
12180 | for (i = group_num - 1; i < MAX_PREDICTORS; i += 30) |
1217 | 11662 | reset_predict_state(&ps[i]); | |
1218 | 518 | } | |
1219 | |||
1220 | static void aacdec_init(AACContext *ac); | ||
1221 | |||
1222 | 172 | static av_cold void aac_static_table_init(void) | |
1223 | { | ||
1224 | static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 + | ||
1225 | 294 + 306 + 268 + 510 + 366 + 462]; | ||
1226 |
2/2✓ Branch 0 taken 1892 times.
✓ Branch 1 taken 172 times.
|
2064 | for (unsigned i = 0, offset = 0; i < 11; i++) { |
1227 | 1892 | vlc_spectral[i].table = &vlc_buf[offset]; | |
1228 | 1892 | vlc_spectral[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset; | |
1229 | 1892 | ff_init_vlc_sparse(&vlc_spectral[i], 8, ff_aac_spectral_sizes[i], | |
1230 | 1892 | ff_aac_spectral_bits[i], sizeof(ff_aac_spectral_bits[i][0]), | |
1231 | sizeof(ff_aac_spectral_bits[i][0]), | ||
1232 | 1892 | ff_aac_spectral_codes[i], sizeof(ff_aac_spectral_codes[i][0]), | |
1233 | sizeof(ff_aac_spectral_codes[i][0]), | ||
1234 | 1892 | ff_aac_codebook_vector_idx[i], sizeof(ff_aac_codebook_vector_idx[i][0]), | |
1235 | sizeof(ff_aac_codebook_vector_idx[i][0]), | ||
1236 | INIT_VLC_STATIC_OVERLONG); | ||
1237 | 1892 | offset += vlc_spectral[i].table_size; | |
1238 | } | ||
1239 | |||
1240 | 172 | AAC_RENAME(ff_aac_sbr_init)(); | |
1241 | |||
1242 | 172 | ff_aac_tableinit(); | |
1243 | |||
1244 | 172 | INIT_VLC_STATIC(&vlc_scalefactors, 7, | |
1245 | FF_ARRAY_ELEMS(ff_aac_scalefactor_code), | ||
1246 | ff_aac_scalefactor_bits, | ||
1247 | sizeof(ff_aac_scalefactor_bits[0]), | ||
1248 | sizeof(ff_aac_scalefactor_bits[0]), | ||
1249 | ff_aac_scalefactor_code, | ||
1250 | sizeof(ff_aac_scalefactor_code[0]), | ||
1251 | sizeof(ff_aac_scalefactor_code[0]), | ||
1252 | 352); | ||
1253 | |||
1254 | // window initialization | ||
1255 | #if !USE_FIXED | ||
1256 | 155 | AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960); | |
1257 | 155 | AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_short_120), 6.0, 120); | |
1258 | 155 | AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_960), 960); | |
1259 | 155 | AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_120), 120); | |
1260 | 155 | AAC_RENAME(ff_init_ff_sine_windows)(9); | |
1261 | 155 | ff_aac_float_common_init(); | |
1262 | #else | ||
1263 | 17 | AAC_RENAME(ff_kbd_window_init)(AAC_RENAME2(aac_kbd_long_1024), 4.0, 1024); | |
1264 | 17 | AAC_RENAME(ff_kbd_window_init)(AAC_RENAME2(aac_kbd_short_128), 6.0, 128); | |
1265 | 17 | init_sine_windows_fixed(); | |
1266 | #endif | ||
1267 | |||
1268 | 172 | AAC_RENAME(ff_cbrt_tableinit)(); | |
1269 | 172 | } | |
1270 | |||
1271 | static AVOnce aac_table_init = AV_ONCE_INIT; | ||
1272 | |||
1273 | 282 | static av_cold int aac_decode_init(AVCodecContext *avctx) | |
1274 | { | ||
1275 | 282 | AACContext *ac = avctx->priv_data; | |
1276 | int ret; | ||
1277 | |||
1278 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 282 times.
|
282 | if (avctx->sample_rate > 96000) |
1279 | ✗ | return AVERROR_INVALIDDATA; | |
1280 | |||
1281 | 282 | ret = ff_thread_once(&aac_table_init, &aac_static_table_init); | |
1282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 282 times.
|
282 | if (ret != 0) |
1283 | ✗ | return AVERROR_UNKNOWN; | |
1284 | |||
1285 | 282 | ac->avctx = avctx; | |
1286 | 282 | ac->oc[1].m4ac.sample_rate = avctx->sample_rate; | |
1287 | |||
1288 | 282 | aacdec_init(ac); | |
1289 | #if USE_FIXED | ||
1290 | 21 | avctx->sample_fmt = AV_SAMPLE_FMT_S32P; | |
1291 | #else | ||
1292 | 261 | avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; | |
1293 | #endif /* USE_FIXED */ | ||
1294 | |||
1295 |
2/2✓ Branch 0 taken 223 times.
✓ Branch 1 taken 59 times.
|
282 | if (avctx->extradata_size > 0) { |
1296 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 223 times.
|
223 | if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac, |
1297 | 223 | avctx->extradata, | |
1298 | 223 | avctx->extradata_size * 8LL, | |
1299 | 1)) < 0) | ||
1300 | ✗ | return ret; | |
1301 | } else { | ||
1302 | int sr, i; | ||
1303 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
1304 | int layout_map_tags; | ||
1305 | |||
1306 | 59 | sr = sample_rate_idx(avctx->sample_rate); | |
1307 | 59 | ac->oc[1].m4ac.sampling_index = sr; | |
1308 | 59 | ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels; | |
1309 | 59 | ac->oc[1].m4ac.sbr = -1; | |
1310 | 59 | ac->oc[1].m4ac.ps = -1; | |
1311 | |||
1312 |
1/2✓ Branch 0 taken 107 times.
✗ Branch 1 not taken.
|
107 | for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) |
1313 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 48 times.
|
107 | if (ff_mpeg4audio_channels[i] == avctx->ch_layout.nb_channels) |
1314 | 59 | break; | |
1315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
|
59 | if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { |
1316 | ✗ | i = 0; | |
1317 | } | ||
1318 | 59 | ac->oc[1].m4ac.chan_config = i; | |
1319 | |||
1320 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 35 times.
|
59 | if (ac->oc[1].m4ac.chan_config) { |
1321 | 24 | int ret = set_default_channel_config(ac, avctx, layout_map, | |
1322 | &layout_map_tags, ac->oc[1].m4ac.chan_config); | ||
1323 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (!ret) |
1324 | 24 | output_configure(ac, layout_map, layout_map_tags, | |
1325 | OC_GLOBAL_HDR, 0); | ||
1326 | ✗ | else if (avctx->err_recognition & AV_EF_EXPLODE) | |
1327 | ✗ | return AVERROR_INVALIDDATA; | |
1328 | } | ||
1329 | } | ||
1330 | |||
1331 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 282 times.
|
282 | if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { |
1332 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); | |
1333 | ✗ | return AVERROR_INVALIDDATA; | |
1334 | } | ||
1335 | |||
1336 | #if USE_FIXED | ||
1337 | 21 | ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT); | |
1338 | #else | ||
1339 | 261 | ac->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); | |
1340 | #endif /* USE_FIXED */ | ||
1341 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 282 times.
|
282 | if (!ac->fdsp) { |
1342 | ✗ | return AVERROR(ENOMEM); | |
1343 | } | ||
1344 | |||
1345 | 282 | ac->random_state = 0x1f2e3d4c; | |
1346 | |||
1347 | 282 | AAC_RENAME_32(ff_mdct_init)(&ac->mdct, 11, 1, 1.0 / RANGE15(1024.0)); | |
1348 | 282 | AAC_RENAME_32(ff_mdct_init)(&ac->mdct_ld, 10, 1, 1.0 / RANGE15(512.0)); | |
1349 | 282 | AAC_RENAME_32(ff_mdct_init)(&ac->mdct_small, 8, 1, 1.0 / RANGE15(128.0)); | |
1350 | 282 | AAC_RENAME_32(ff_mdct_init)(&ac->mdct_ltp, 11, 0, RANGE15(-2.0)); | |
1351 | #if !USE_FIXED | ||
1352 | 261 | ret = ff_mdct15_init(&ac->mdct120, 1, 3, 1.0f/(16*1024*120*2)); | |
1353 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 261 times.
|
261 | if (ret < 0) |
1354 | ✗ | return ret; | |
1355 | 261 | ret = ff_mdct15_init(&ac->mdct480, 1, 5, 1.0f/(16*1024*960)); | |
1356 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 261 times.
|
261 | if (ret < 0) |
1357 | ✗ | return ret; | |
1358 | 261 | ret = ff_mdct15_init(&ac->mdct960, 1, 6, 1.0f/(16*1024*960*2)); | |
1359 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 261 times.
|
261 | if (ret < 0) |
1360 | ✗ | return ret; | |
1361 | #endif | ||
1362 | |||
1363 | 282 | return 0; | |
1364 | } | ||
1365 | |||
1366 | /** | ||
1367 | * Skip data_stream_element; reference: table 4.10. | ||
1368 | */ | ||
1369 | 2821 | static int skip_data_stream_element(AACContext *ac, GetBitContext *gb) | |
1370 | { | ||
1371 | 2821 | int byte_align = get_bits1(gb); | |
1372 | 2821 | int count = get_bits(gb, 8); | |
1373 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2821 times.
|
2821 | if (count == 255) |
1374 | ✗ | count += get_bits(gb, 8); | |
1375 |
2/2✓ Branch 0 taken 2454 times.
✓ Branch 1 taken 367 times.
|
2821 | if (byte_align) |
1376 | 2454 | align_get_bits(gb); | |
1377 | |||
1378 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2821 times.
|
2821 | if (get_bits_left(gb) < 8 * count) { |
1379 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "skip_data_stream_element: "overread_err); | |
1380 | ✗ | return AVERROR_INVALIDDATA; | |
1381 | } | ||
1382 | 2821 | skip_bits_long(gb, 8 * count); | |
1383 | 2821 | return 0; | |
1384 | } | ||
1385 | |||
1386 | 1426 | static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, | |
1387 | GetBitContext *gb) | ||
1388 | { | ||
1389 | int sfb; | ||
1390 |
2/2✓ Branch 1 taken 359 times.
✓ Branch 2 taken 1067 times.
|
1426 | if (get_bits1(gb)) { |
1391 | 359 | ics->predictor_reset_group = get_bits(gb, 5); | |
1392 |
1/2✓ Branch 0 taken 359 times.
✗ Branch 1 not taken.
|
359 | if (ics->predictor_reset_group == 0 || |
1393 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
|
359 | ics->predictor_reset_group > 30) { |
1394 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1395 | "Invalid Predictor Reset Group.\n"); | ||
1396 | ✗ | return AVERROR_INVALIDDATA; | |
1397 | } | ||
1398 | } | ||
1399 |
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++) { |
1400 | 46375 | ics->prediction_used[sfb] = get_bits1(gb); | |
1401 | } | ||
1402 | 1426 | return 0; | |
1403 | } | ||
1404 | |||
1405 | /** | ||
1406 | * Decode Long Term Prediction data; reference: table 4.xx. | ||
1407 | */ | ||
1408 | 786 | static void decode_ltp(LongTermPrediction *ltp, | |
1409 | GetBitContext *gb, uint8_t max_sfb) | ||
1410 | { | ||
1411 | int sfb; | ||
1412 | |||
1413 | 786 | ltp->lag = get_bits(gb, 11); | |
1414 | 786 | ltp->coef = ltp_coef[get_bits(gb, 3)]; | |
1415 |
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++) |
1416 | 31440 | ltp->used[sfb] = get_bits1(gb); | |
1417 | 786 | } | |
1418 | |||
1419 | /** | ||
1420 | * Decode Individual Channel Stream info; reference: table 4.6. | ||
1421 | */ | ||
1422 | 63272 | static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, | |
1423 | GetBitContext *gb) | ||
1424 | { | ||
1425 | 63272 | const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac; | |
1426 | 63272 | const int aot = m4ac->object_type; | |
1427 | 63272 | const int sampling_index = m4ac->sampling_index; | |
1428 | 63272 | int ret_fail = AVERROR_INVALIDDATA; | |
1429 | |||
1430 |
2/2✓ Branch 0 taken 46907 times.
✓ Branch 1 taken 16365 times.
|
63272 | if (aot != AOT_ER_AAC_ELD) { |
1431 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 46907 times.
|
46907 | if (get_bits1(gb)) { |
1432 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n"); | |
1433 | ✗ | if (ac->avctx->err_recognition & AV_EF_BITSTREAM) | |
1434 | ✗ | return AVERROR_INVALIDDATA; | |
1435 | } | ||
1436 | 46907 | ics->window_sequence[1] = ics->window_sequence[0]; | |
1437 | 46907 | ics->window_sequence[0] = get_bits(gb, 2); | |
1438 |
2/2✓ Branch 0 taken 2424 times.
✓ Branch 1 taken 44483 times.
|
46907 | if (aot == AOT_ER_AAC_LD && |
1439 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
|
2424 | ics->window_sequence[0] != ONLY_LONG_SEQUENCE) { |
1440 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1441 | "AAC LD is only defined for ONLY_LONG_SEQUENCE but " | ||
1442 | ✗ | "window sequence %d found.\n", ics->window_sequence[0]); | |
1443 | ✗ | ics->window_sequence[0] = ONLY_LONG_SEQUENCE; | |
1444 | ✗ | return AVERROR_INVALIDDATA; | |
1445 | } | ||
1446 | 46907 | ics->use_kb_window[1] = ics->use_kb_window[0]; | |
1447 | 46907 | ics->use_kb_window[0] = get_bits1(gb); | |
1448 | } | ||
1449 | 63272 | ics->num_window_groups = 1; | |
1450 | 63272 | ics->group_len[0] = 1; | |
1451 |
2/2✓ Branch 0 taken 1331 times.
✓ Branch 1 taken 61941 times.
|
63272 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
1452 | int i; | ||
1453 | 1331 | ics->max_sfb = get_bits(gb, 4); | |
1454 |
2/2✓ Branch 0 taken 9317 times.
✓ Branch 1 taken 1331 times.
|
10648 | for (i = 0; i < 7; i++) { |
1455 |
2/2✓ Branch 1 taken 5889 times.
✓ Branch 2 taken 3428 times.
|
9317 | if (get_bits1(gb)) { |
1456 | 5889 | ics->group_len[ics->num_window_groups - 1]++; | |
1457 | } else { | ||
1458 | 3428 | ics->num_window_groups++; | |
1459 | 3428 | ics->group_len[ics->num_window_groups - 1] = 1; | |
1460 | } | ||
1461 | } | ||
1462 | 1331 | ics->num_windows = 8; | |
1463 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1330 times.
|
1331 | if (m4ac->frame_length_short) { |
1464 | 1 | ics->swb_offset = ff_swb_offset_120[sampling_index]; | |
1465 | 1 | ics->num_swb = ff_aac_num_swb_120[sampling_index]; | |
1466 | } else { | ||
1467 | 1330 | ics->swb_offset = ff_swb_offset_128[sampling_index]; | |
1468 | 1330 | ics->num_swb = ff_aac_num_swb_128[sampling_index]; | |
1469 | } | ||
1470 | 1331 | ics->tns_max_bands = ff_tns_max_bands_128[sampling_index]; | |
1471 | 1331 | ics->predictor_present = 0; | |
1472 | } else { | ||
1473 | 61941 | ics->max_sfb = get_bits(gb, 6); | |
1474 | 61941 | ics->num_windows = 1; | |
1475 |
4/4✓ Branch 0 taken 59517 times.
✓ Branch 1 taken 2424 times.
✓ Branch 2 taken 16365 times.
✓ Branch 3 taken 43152 times.
|
61941 | if (aot == AOT_ER_AAC_LD || aot == AOT_ER_AAC_ELD) { |
1476 |
2/2✓ Branch 0 taken 3559 times.
✓ Branch 1 taken 15230 times.
|
18789 | if (m4ac->frame_length_short) { |
1477 | 3559 | ics->swb_offset = ff_swb_offset_480[sampling_index]; | |
1478 | 3559 | ics->num_swb = ff_aac_num_swb_480[sampling_index]; | |
1479 | 3559 | ics->tns_max_bands = ff_tns_max_bands_480[sampling_index]; | |
1480 | } else { | ||
1481 | 15230 | ics->swb_offset = ff_swb_offset_512[sampling_index]; | |
1482 | 15230 | ics->num_swb = ff_aac_num_swb_512[sampling_index]; | |
1483 | 15230 | ics->tns_max_bands = ff_tns_max_bands_512[sampling_index]; | |
1484 | } | ||
1485 |
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) { |
1486 | ✗ | ret_fail = AVERROR_BUG; | |
1487 | ✗ | goto fail; | |
1488 | } | ||
1489 | } else { | ||
1490 |
2/2✓ Branch 0 taken 386 times.
✓ Branch 1 taken 42766 times.
|
43152 | if (m4ac->frame_length_short) { |
1491 | 386 | ics->num_swb = ff_aac_num_swb_960[sampling_index]; | |
1492 | 386 | ics->swb_offset = ff_swb_offset_960[sampling_index]; | |
1493 | } else { | ||
1494 | 42766 | ics->num_swb = ff_aac_num_swb_1024[sampling_index]; | |
1495 | 42766 | ics->swb_offset = ff_swb_offset_1024[sampling_index]; | |
1496 | } | ||
1497 | 43152 | ics->tns_max_bands = ff_tns_max_bands_1024[sampling_index]; | |
1498 | } | ||
1499 |
2/2✓ Branch 0 taken 45576 times.
✓ Branch 1 taken 16365 times.
|
61941 | if (aot != AOT_ER_AAC_ELD) { |
1500 | 45576 | ics->predictor_present = get_bits1(gb); | |
1501 | 45576 | ics->predictor_reset_group = 0; | |
1502 | } | ||
1503 |
2/2✓ Branch 0 taken 1964 times.
✓ Branch 1 taken 59977 times.
|
61941 | if (ics->predictor_present) { |
1504 |
2/2✓ Branch 0 taken 1426 times.
✓ Branch 1 taken 538 times.
|
1964 | if (aot == AOT_AAC_MAIN) { |
1505 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1426 times.
|
1426 | if (decode_prediction(ac, ics, gb)) { |
1506 | ✗ | goto fail; | |
1507 | } | ||
1508 |
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 || |
1509 | aot == AOT_ER_AAC_LC) { | ||
1510 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1511 | "Prediction is not allowed in AAC-LC.\n"); | ||
1512 | ✗ | goto fail; | |
1513 | } else { | ||
1514 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
|
538 | if (aot == AOT_ER_AAC_LD) { |
1515 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1516 | "LTP in ER AAC LD not yet implemented.\n"); | ||
1517 | ✗ | ret_fail = AVERROR_PATCHWELCOME; | |
1518 | ✗ | goto fail; | |
1519 | } | ||
1520 |
2/2✓ Branch 1 taken 382 times.
✓ Branch 2 taken 156 times.
|
538 | if ((ics->ltp.present = get_bits(gb, 1))) |
1521 | 382 | decode_ltp(&ics->ltp, gb, ics->max_sfb); | |
1522 | } | ||
1523 | } | ||
1524 | } | ||
1525 | |||
1526 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 63272 times.
|
63272 | if (ics->max_sfb > ics->num_swb) { |
1527 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1528 | "Number of scalefactor bands in group (%d) " | ||
1529 | "exceeds limit (%d).\n", | ||
1530 | ✗ | ics->max_sfb, ics->num_swb); | |
1531 | ✗ | goto fail; | |
1532 | } | ||
1533 | |||
1534 | 63272 | return 0; | |
1535 | ✗ | fail: | |
1536 | ✗ | ics->max_sfb = 0; | |
1537 | ✗ | return ret_fail; | |
1538 | } | ||
1539 | |||
1540 | /** | ||
1541 | * Decode band types (section_data payload); reference: table 4.46. | ||
1542 | * | ||
1543 | * @param band_type array of the used band type | ||
1544 | * @param band_type_run_end array of the last scalefactor band of a band type run | ||
1545 | * | ||
1546 | * @return Returns error status. 0 - OK, !0 - error | ||
1547 | */ | ||
1548 | 93736 | static int decode_band_types(AACContext *ac, enum BandType band_type[120], | |
1549 | int band_type_run_end[120], GetBitContext *gb, | ||
1550 | IndividualChannelStream *ics) | ||
1551 | { | ||
1552 | 93736 | int g, idx = 0; | |
1553 |
2/2✓ Branch 0 taken 2089 times.
✓ Branch 1 taken 91647 times.
|
93736 | const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5; |
1554 |
2/2✓ Branch 0 taken 98974 times.
✓ Branch 1 taken 93736 times.
|
192710 | for (g = 0; g < ics->num_window_groups; g++) { |
1555 | 98974 | int k = 0; | |
1556 |
2/2✓ Branch 0 taken 463697 times.
✓ Branch 1 taken 98974 times.
|
562671 | while (k < ics->max_sfb) { |
1557 | 463697 | uint8_t sect_end = k; | |
1558 | int sect_len_incr; | ||
1559 | 463697 | int sect_band_type = get_bits(gb, 4); | |
1560 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 463697 times.
|
463697 | if (sect_band_type == 12) { |
1561 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n"); | |
1562 | ✗ | return AVERROR_INVALIDDATA; | |
1563 | } | ||
1564 | do { | ||
1565 | 482410 | sect_len_incr = get_bits(gb, bits); | |
1566 | 482410 | sect_end += sect_len_incr; | |
1567 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 482410 times.
|
482410 | if (get_bits_left(gb) < 0) { |
1568 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "decode_band_types: "overread_err); | |
1569 | ✗ | return AVERROR_INVALIDDATA; | |
1570 | } | ||
1571 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 482410 times.
|
482410 | if (sect_end > ics->max_sfb) { |
1572 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1573 | "Number of bands (%d) exceeds limit (%d).\n", | ||
1574 | ✗ | sect_end, ics->max_sfb); | |
1575 | ✗ | return AVERROR_INVALIDDATA; | |
1576 | } | ||
1577 |
2/2✓ Branch 0 taken 18713 times.
✓ Branch 1 taken 463697 times.
|
482410 | } while (sect_len_incr == (1 << bits) - 1); |
1578 |
2/2✓ Branch 0 taken 3471310 times.
✓ Branch 1 taken 463697 times.
|
3935007 | for (; k < sect_end; k++) { |
1579 | 3471310 | band_type [idx] = sect_band_type; | |
1580 | 3471310 | band_type_run_end[idx++] = sect_end; | |
1581 | } | ||
1582 | } | ||
1583 | } | ||
1584 | 93736 | return 0; | |
1585 | } | ||
1586 | |||
1587 | /** | ||
1588 | * Decode scalefactors; reference: table 4.47. | ||
1589 | * | ||
1590 | * @param global_gain first scalefactor value as scalefactors are differentially coded | ||
1591 | * @param band_type array of the used band type | ||
1592 | * @param band_type_run_end array of the last scalefactor band of a band type run | ||
1593 | * @param sf array of scalefactors or intensity stereo positions | ||
1594 | * | ||
1595 | * @return Returns error status. 0 - OK, !0 - error | ||
1596 | */ | ||
1597 | 93736 | static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *gb, | |
1598 | unsigned int global_gain, | ||
1599 | IndividualChannelStream *ics, | ||
1600 | enum BandType band_type[120], | ||
1601 | int band_type_run_end[120]) | ||
1602 | { | ||
1603 | 93736 | int g, i, idx = 0; | |
1604 | 93736 | int offset[3] = { global_gain, global_gain - NOISE_OFFSET, 0 }; | |
1605 | int clipped_offset; | ||
1606 | 93736 | int noise_flag = 1; | |
1607 |
2/2✓ Branch 0 taken 98974 times.
✓ Branch 1 taken 93736 times.
|
192710 | for (g = 0; g < ics->num_window_groups; g++) { |
1608 |
2/2✓ Branch 0 taken 463697 times.
✓ Branch 1 taken 98974 times.
|
562671 | for (i = 0; i < ics->max_sfb;) { |
1609 | 463697 | int run_end = band_type_run_end[idx]; | |
1610 |
2/2✓ Branch 0 taken 63204 times.
✓ Branch 1 taken 400493 times.
|
463697 | if (band_type[idx] == ZERO_BT) { |
1611 |
2/2✓ Branch 0 taken 533534 times.
✓ Branch 1 taken 63204 times.
|
596738 | for (; i < run_end; i++, idx++) |
1612 | 533534 | sf[idx] = FIXR(0.); | |
1613 |
2/2✓ Branch 0 taken 391021 times.
✓ Branch 1 taken 9472 times.
|
400493 | } else if ((band_type[idx] == INTENSITY_BT) || |
1614 |
2/2✓ Branch 0 taken 111 times.
✓ Branch 1 taken 390910 times.
|
391021 | (band_type[idx] == INTENSITY_BT2)) { |
1615 |
2/2✓ Branch 0 taken 66207 times.
✓ Branch 1 taken 9583 times.
|
75790 | for (; i < run_end; i++, idx++) { |
1616 | 66207 | offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO; | |
1617 | 66207 | clipped_offset = av_clip(offset[2], -155, 100); | |
1618 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66207 times.
|
66207 | if (offset[2] != clipped_offset) { |
1619 | ✗ | avpriv_request_sample(ac->avctx, | |
1620 | "If you heard an audible artifact, there may be a bug in the decoder. " | ||
1621 | "Clipped intensity stereo position (%d -> %d)", | ||
1622 | offset[2], clipped_offset); | ||
1623 | } | ||
1624 | #if USE_FIXED | ||
1625 | 17856 | sf[idx] = 100 - clipped_offset; | |
1626 | #else | ||
1627 | 48351 | sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO]; | |
1628 | #endif /* USE_FIXED */ | ||
1629 | } | ||
1630 |
2/2✓ Branch 0 taken 7825 times.
✓ Branch 1 taken 383085 times.
|
390910 | } else if (band_type[idx] == NOISE_BT) { |
1631 |
2/2✓ Branch 0 taken 281615 times.
✓ Branch 1 taken 7825 times.
|
289440 | for (; i < run_end; i++, idx++) { |
1632 |
2/2✓ Branch 0 taken 6715 times.
✓ Branch 1 taken 274900 times.
|
281615 | if (noise_flag-- > 0) |
1633 | 6715 | offset[1] += get_bits(gb, NOISE_PRE_BITS) - NOISE_PRE; | |
1634 | else | ||
1635 | 274900 | offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO; | |
1636 | 281615 | clipped_offset = av_clip(offset[1], -100, 155); | |
1637 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 281615 times.
|
281615 | if (offset[1] != clipped_offset) { |
1638 | ✗ | avpriv_request_sample(ac->avctx, | |
1639 | "If you heard an audible artifact, there may be a bug in the decoder. " | ||
1640 | "Clipped noise gain (%d -> %d)", | ||
1641 | offset[1], clipped_offset); | ||
1642 | } | ||
1643 | #if USE_FIXED | ||
1644 | 137931 | sf[idx] = -(100 + clipped_offset); | |
1645 | #else | ||
1646 | 143684 | sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO]; | |
1647 | #endif /* USE_FIXED */ | ||
1648 | } | ||
1649 | } else { | ||
1650 |
2/2✓ Branch 0 taken 2589954 times.
✓ Branch 1 taken 383085 times.
|
2973039 | for (; i < run_end; i++, idx++) { |
1651 | 2589954 | offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO; | |
1652 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2589954 times.
|
2589954 | if (offset[0] > 255U) { |
1653 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1654 | "Scalefactor (%d) out of range.\n", offset[0]); | ||
1655 | ✗ | return AVERROR_INVALIDDATA; | |
1656 | } | ||
1657 | #if USE_FIXED | ||
1658 | 779531 | sf[idx] = -offset[0]; | |
1659 | #else | ||
1660 | 1810423 | sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO]; | |
1661 | #endif /* USE_FIXED */ | ||
1662 | } | ||
1663 | } | ||
1664 | } | ||
1665 | } | ||
1666 | 93736 | return 0; | |
1667 | } | ||
1668 | |||
1669 | /** | ||
1670 | * Decode pulse data; reference: table 4.7. | ||
1671 | */ | ||
1672 | 1098 | static int decode_pulses(Pulse *pulse, GetBitContext *gb, | |
1673 | const uint16_t *swb_offset, int num_swb) | ||
1674 | { | ||
1675 | int i, pulse_swb; | ||
1676 | 1098 | pulse->num_pulse = get_bits(gb, 2) + 1; | |
1677 | 1098 | pulse_swb = get_bits(gb, 6); | |
1678 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
|
1098 | if (pulse_swb >= num_swb) |
1679 | ✗ | return -1; | |
1680 | 1098 | pulse->pos[0] = swb_offset[pulse_swb]; | |
1681 | 1098 | pulse->pos[0] += get_bits(gb, 5); | |
1682 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
|
1098 | if (pulse->pos[0] >= swb_offset[num_swb]) |
1683 | ✗ | return -1; | |
1684 | 1098 | pulse->amp[0] = get_bits(gb, 4); | |
1685 |
2/2✓ Branch 0 taken 1646 times.
✓ Branch 1 taken 1098 times.
|
2744 | for (i = 1; i < pulse->num_pulse; i++) { |
1686 | 1646 | pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i - 1]; | |
1687 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1646 times.
|
1646 | if (pulse->pos[i] >= swb_offset[num_swb]) |
1688 | ✗ | return -1; | |
1689 | 1646 | pulse->amp[i] = get_bits(gb, 4); | |
1690 | } | ||
1691 | 1098 | return 0; | |
1692 | } | ||
1693 | |||
1694 | /** | ||
1695 | * Decode Temporal Noise Shaping data; reference: table 4.48. | ||
1696 | * | ||
1697 | * @return Returns error status. 0 - OK, !0 - error | ||
1698 | */ | ||
1699 | 6927 | static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns, | |
1700 | GetBitContext *gb, const IndividualChannelStream *ics) | ||
1701 | { | ||
1702 | int w, filt, i, coef_len, coef_res, coef_compress; | ||
1703 | 6927 | const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE; | |
1704 |
4/4✓ Branch 0 taken 6268 times.
✓ Branch 1 taken 659 times.
✓ Branch 2 taken 163 times.
✓ Branch 3 taken 6105 times.
|
6927 | const int tns_max_order = is8 ? 7 : ac->oc[1].m4ac.object_type == AOT_AAC_MAIN ? 20 : 12; |
1705 |
2/2✓ Branch 0 taken 11540 times.
✓ Branch 1 taken 6927 times.
|
18467 | for (w = 0; w < ics->num_windows; w++) { |
1706 |
2/2✓ Branch 1 taken 7918 times.
✓ Branch 2 taken 3622 times.
|
11540 | if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) { |
1707 | 7918 | coef_res = get_bits1(gb); | |
1708 | |||
1709 |
2/2✓ Branch 0 taken 9379 times.
✓ Branch 1 taken 7918 times.
|
17297 | for (filt = 0; filt < tns->n_filt[w]; filt++) { |
1710 | int tmp2_idx; | ||
1711 | 9379 | tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); | |
1712 | |||
1713 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9379 times.
|
9379 | if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) { |
1714 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
1715 | "TNS filter order %d is greater than maximum %d.\n", | ||
1716 | tns->order[w][filt], tns_max_order); | ||
1717 | ✗ | tns->order[w][filt] = 0; | |
1718 | ✗ | return AVERROR_INVALIDDATA; | |
1719 | } | ||
1720 |
2/2✓ Branch 0 taken 8859 times.
✓ Branch 1 taken 520 times.
|
9379 | if (tns->order[w][filt]) { |
1721 | 8859 | tns->direction[w][filt] = get_bits1(gb); | |
1722 | 8859 | coef_compress = get_bits1(gb); | |
1723 | 8859 | coef_len = coef_res + 3 - coef_compress; | |
1724 | 8859 | tmp2_idx = 2 * coef_compress + coef_res; | |
1725 | |||
1726 |
2/2✓ Branch 0 taken 58308 times.
✓ Branch 1 taken 8859 times.
|
67167 | for (i = 0; i < tns->order[w][filt]; i++) |
1727 | 58308 | tns->coef[w][filt][i] = tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)]; | |
1728 | } | ||
1729 | } | ||
1730 | } | ||
1731 | } | ||
1732 | 6927 | return 0; | |
1733 | } | ||
1734 | |||
1735 | /** | ||
1736 | * Decode Mid/Side data; reference: table 4.54. | ||
1737 | * | ||
1738 | * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; | ||
1739 | * [1] mask is decoded from bitstream; [2] mask is all 1s; | ||
1740 | * [3] reserved for scalable AAC | ||
1741 | */ | ||
1742 | 26972 | static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, | |
1743 | int ms_present) | ||
1744 | { | ||
1745 | int idx; | ||
1746 | 26972 | int max_idx = cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb; | |
1747 |
2/2✓ Branch 0 taken 12685 times.
✓ Branch 1 taken 14287 times.
|
26972 | if (ms_present == 1) { |
1748 |
2/2✓ Branch 0 taken 497780 times.
✓ Branch 1 taken 12685 times.
|
510465 | for (idx = 0; idx < max_idx; idx++) |
1749 | 497780 | cpe->ms_mask[idx] = get_bits1(gb); | |
1750 |
1/2✓ Branch 0 taken 14287 times.
✗ Branch 1 not taken.
|
14287 | } else if (ms_present == 2) { |
1751 | 14287 | memset(cpe->ms_mask, 1, max_idx * sizeof(cpe->ms_mask[0])); | |
1752 | } | ||
1753 | 26972 | } | |
1754 | |||
1755 | /** | ||
1756 | * Decode spectral data; reference: table 4.50. | ||
1757 | * Dequantize and scale spectral data; reference: 4.6.3.3. | ||
1758 | * | ||
1759 | * @param coef array of dequantized, scaled spectral data | ||
1760 | * @param sf array of scalefactors or intensity stereo positions | ||
1761 | * @param pulse_present set if pulses are present | ||
1762 | * @param pulse pointer to pulse data struct | ||
1763 | * @param band_type array of the used band type | ||
1764 | * | ||
1765 | * @return Returns error status. 0 - OK, !0 - error | ||
1766 | */ | ||
1767 | 93736 | static int decode_spectrum_and_dequant(AACContext *ac, INTFLOAT coef[1024], | |
1768 | GetBitContext *gb, const INTFLOAT sf[120], | ||
1769 | int pulse_present, const Pulse *pulse, | ||
1770 | const IndividualChannelStream *ics, | ||
1771 | enum BandType band_type[120]) | ||
1772 | { | ||
1773 | 93736 | int i, k, g, idx = 0; | |
1774 | 93736 | const int c = 1024 / ics->num_windows; | |
1775 | 93736 | const uint16_t *offsets = ics->swb_offset; | |
1776 | 93736 | INTFLOAT *coef_base = coef; | |
1777 | |||
1778 |
2/2✓ Branch 0 taken 108359 times.
✓ Branch 1 taken 93736 times.
|
202095 | for (g = 0; g < ics->num_windows; g++) |
1779 | 108359 | memset(coef + g * 128 + offsets[ics->max_sfb], 0, | |
1780 | 108359 | sizeof(INTFLOAT) * (c - offsets[ics->max_sfb])); | |
1781 | |||
1782 |
2/2✓ Branch 0 taken 98974 times.
✓ Branch 1 taken 93736 times.
|
192710 | for (g = 0; g < ics->num_window_groups; g++) { |
1783 | 98974 | unsigned g_len = ics->group_len[g]; | |
1784 | |||
1785 |
2/2✓ Branch 0 taken 3471310 times.
✓ Branch 1 taken 98974 times.
|
3570284 | for (i = 0; i < ics->max_sfb; i++, idx++) { |
1786 | 3471310 | const unsigned cbt_m1 = band_type[idx] - 1; | |
1787 | 3471310 | INTFLOAT *cfo = coef + offsets[i]; | |
1788 | 3471310 | int off_len = offsets[i + 1] - offsets[i]; | |
1789 | int group; | ||
1790 | |||
1791 |
2/2✓ Branch 0 taken 599741 times.
✓ Branch 1 taken 2871569 times.
|
3471310 | if (cbt_m1 >= INTENSITY_BT2 - 1) { |
1792 |
2/2✓ Branch 0 taken 637814 times.
✓ Branch 1 taken 599741 times.
|
1237555 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
1793 | 637814 | memset(cfo, 0, off_len * sizeof(*cfo)); | |
1794 | } | ||
1795 |
2/2✓ Branch 0 taken 281615 times.
✓ Branch 1 taken 2589954 times.
|
2871569 | } else if (cbt_m1 == NOISE_BT - 1) { |
1796 |
2/2✓ Branch 0 taken 281642 times.
✓ Branch 1 taken 281615 times.
|
563257 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
1797 | INTFLOAT band_energy; | ||
1798 | #if USE_FIXED | ||
1799 |
2/2✓ Branch 0 taken 2883476 times.
✓ Branch 1 taken 137931 times.
|
3021407 | for (k = 0; k < off_len; k++) { |
1800 | 2883476 | ac->random_state = lcg_random(ac->random_state); | |
1801 | 2883476 | cfo[k] = ac->random_state >> 3; | |
1802 | } | ||
1803 | |||
1804 | 137931 | band_energy = ac->fdsp->scalarproduct_fixed(cfo, cfo, off_len); | |
1805 | 137931 | band_energy = fixed_sqrt(band_energy, 31); | |
1806 | 137931 | noise_scale(cfo, sf[idx], band_energy, off_len); | |
1807 | #else | ||
1808 | float scale; | ||
1809 | |||
1810 |
2/2✓ Branch 0 taken 3060724 times.
✓ Branch 1 taken 143711 times.
|
3204435 | for (k = 0; k < off_len; k++) { |
1811 | 3060724 | ac->random_state = lcg_random(ac->random_state); | |
1812 | 3060724 | cfo[k] = ac->random_state; | |
1813 | } | ||
1814 | |||
1815 | 143711 | band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len); | |
1816 | 143711 | scale = sf[idx] / sqrtf(band_energy); | |
1817 | 143711 | ac->fdsp->vector_fmul_scalar(cfo, cfo, scale, off_len); | |
1818 | #endif /* USE_FIXED */ | ||
1819 | } | ||
1820 | } else { | ||
1821 | #if !USE_FIXED | ||
1822 | 1810423 | const float *vq = ff_aac_codebook_vector_vals[cbt_m1]; | |
1823 | #endif /* !USE_FIXED */ | ||
1824 | 2589954 | const VLCElem *vlc_tab = vlc_spectral[cbt_m1].table; | |
1825 | 2589954 | OPEN_READER(re, gb); | |
1826 | |||
1827 |
5/5✓ Branch 0 taken 628826 times.
✓ Branch 1 taken 578848 times.
✓ Branch 2 taken 399520 times.
✓ Branch 3 taken 543934 times.
✓ Branch 4 taken 438826 times.
|
2589954 | switch (cbt_m1 >> 1) { |
1828 | 628826 | case 0: | |
1829 |
2/2✓ Branch 0 taken 656190 times.
✓ Branch 1 taken 628826 times.
|
1285016 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
1830 | 656190 | INTFLOAT *cf = cfo; | |
1831 | 656190 | int len = off_len; | |
1832 | |||
1833 | do { | ||
1834 | int code; | ||
1835 | unsigned cb_idx; | ||
1836 | |||
1837 | 3268639 | UPDATE_CACHE(re, gb); | |
1838 |
2/2✓ Branch 1 taken 111173 times.
✓ Branch 2 taken 3157466 times.
|
3268639 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
1839 | 3268639 | cb_idx = code; | |
1840 | #if USE_FIXED | ||
1841 | 995694 | cf = DEC_SQUAD(cf, cb_idx); | |
1842 | #else | ||
1843 | 2272945 | cf = VMUL4(cf, vq, cb_idx, sf + idx); | |
1844 | #endif /* USE_FIXED */ | ||
1845 |
2/2✓ Branch 0 taken 2612449 times.
✓ Branch 1 taken 656190 times.
|
3268639 | } while (len -= 4); |
1846 | } | ||
1847 | 628826 | break; | |
1848 | |||
1849 | 578848 | case 1: | |
1850 |
2/2✓ Branch 0 taken 591305 times.
✓ Branch 1 taken 578848 times.
|
1170153 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
1851 | 591305 | INTFLOAT *cf = cfo; | |
1852 | 591305 | int len = off_len; | |
1853 | |||
1854 | do { | ||
1855 | int code; | ||
1856 | unsigned nnz; | ||
1857 | unsigned cb_idx; | ||
1858 | uint32_t bits; | ||
1859 | |||
1860 | 2635089 | UPDATE_CACHE(re, gb); | |
1861 |
2/2✓ Branch 1 taken 94141 times.
✓ Branch 2 taken 2540948 times.
|
2635089 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
1862 | 2635089 | cb_idx = code; | |
1863 | 2635089 | nnz = cb_idx >> 8 & 15; | |
1864 |
2/2✓ Branch 0 taken 1733779 times.
✓ Branch 1 taken 901310 times.
|
2635089 | bits = nnz ? GET_CACHE(re, gb) : 0; |
1865 | 2635089 | LAST_SKIP_BITS(re, gb, nnz); | |
1866 | #if USE_FIXED | ||
1867 | 825340 | cf = DEC_UQUAD(cf, cb_idx, bits); | |
1868 | #else | ||
1869 | 1809749 | cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx); | |
1870 | #endif /* USE_FIXED */ | ||
1871 |
2/2✓ Branch 0 taken 2043784 times.
✓ Branch 1 taken 591305 times.
|
2635089 | } while (len -= 4); |
1872 | } | ||
1873 | 578848 | break; | |
1874 | |||
1875 | 399520 | case 2: | |
1876 |
2/2✓ Branch 0 taken 412245 times.
✓ Branch 1 taken 399520 times.
|
811765 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
1877 | 412245 | INTFLOAT *cf = cfo; | |
1878 | 412245 | int len = off_len; | |
1879 | |||
1880 | do { | ||
1881 | int code; | ||
1882 | unsigned cb_idx; | ||
1883 | |||
1884 | 2497594 | UPDATE_CACHE(re, gb); | |
1885 |
2/2✓ Branch 1 taken 87434 times.
✓ Branch 2 taken 2410160 times.
|
2497594 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
1886 | 2497594 | cb_idx = code; | |
1887 | #if USE_FIXED | ||
1888 | 682784 | cf = DEC_SPAIR(cf, cb_idx); | |
1889 | #else | ||
1890 | 1814810 | cf = VMUL2(cf, vq, cb_idx, sf + idx); | |
1891 | #endif /* USE_FIXED */ | ||
1892 |
2/2✓ Branch 0 taken 2085349 times.
✓ Branch 1 taken 412245 times.
|
2497594 | } while (len -= 2); |
1893 | } | ||
1894 | 399520 | break; | |
1895 | |||
1896 | 543934 | case 3: | |
1897 | case 4: | ||
1898 |
2/2✓ Branch 0 taken 562533 times.
✓ Branch 1 taken 543934 times.
|
1106467 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
1899 | 562533 | INTFLOAT *cf = cfo; | |
1900 | 562533 | int len = off_len; | |
1901 | |||
1902 | do { | ||
1903 | int code; | ||
1904 | unsigned nnz; | ||
1905 | unsigned cb_idx; | ||
1906 | unsigned sign; | ||
1907 | |||
1908 | 2981574 | UPDATE_CACHE(re, gb); | |
1909 |
2/2✓ Branch 1 taken 212207 times.
✓ Branch 2 taken 2769367 times.
|
2981574 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
1910 | 2981574 | cb_idx = code; | |
1911 | 2981574 | nnz = cb_idx >> 8 & 15; | |
1912 |
2/2✓ Branch 0 taken 2374558 times.
✓ Branch 1 taken 607016 times.
|
2981574 | sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0; |
1913 | 2981574 | LAST_SKIP_BITS(re, gb, nnz); | |
1914 | #if USE_FIXED | ||
1915 | 707574 | cf = DEC_UPAIR(cf, cb_idx, sign); | |
1916 | #else | ||
1917 | 2274000 | cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx); | |
1918 | #endif /* USE_FIXED */ | ||
1919 |
2/2✓ Branch 0 taken 2419041 times.
✓ Branch 1 taken 562533 times.
|
2981574 | } while (len -= 2); |
1920 | } | ||
1921 | 543934 | break; | |
1922 | |||
1923 | 438826 | default: | |
1924 |
2/2✓ Branch 0 taken 448746 times.
✓ Branch 1 taken 438826 times.
|
887572 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
1925 | #if USE_FIXED | ||
1926 | 119421 | int *icf = cfo; | |
1927 | int v; | ||
1928 | #else | ||
1929 | 329325 | float *cf = cfo; | |
1930 | 329325 | uint32_t *icf = (uint32_t *) cf; | |
1931 | #endif /* USE_FIXED */ | ||
1932 | 448746 | int len = off_len; | |
1933 | |||
1934 | do { | ||
1935 | int code; | ||
1936 | unsigned nzt, nnz; | ||
1937 | unsigned cb_idx; | ||
1938 | uint32_t bits; | ||
1939 | int j; | ||
1940 | |||
1941 | 1486272 | UPDATE_CACHE(re, gb); | |
1942 |
2/2✓ Branch 1 taken 424481 times.
✓ Branch 2 taken 1061791 times.
|
1486272 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
1943 | 1486272 | cb_idx = code; | |
1944 | |||
1945 |
2/2✓ Branch 0 taken 70723 times.
✓ Branch 1 taken 1415549 times.
|
1486272 | if (cb_idx == 0x0000) { |
1946 | 70723 | *icf++ = 0; | |
1947 | 70723 | *icf++ = 0; | |
1948 | 70723 | continue; | |
1949 | } | ||
1950 | |||
1951 | 1415549 | nnz = cb_idx >> 12; | |
1952 | 1415549 | nzt = cb_idx >> 8; | |
1953 | 1415549 | bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); | |
1954 | 1415549 | LAST_SKIP_BITS(re, gb, nnz); | |
1955 | |||
1956 |
2/2✓ Branch 0 taken 2831098 times.
✓ Branch 1 taken 1415549 times.
|
4246647 | for (j = 0; j < 2; j++) { |
1957 |
2/2✓ Branch 0 taken 365049 times.
✓ Branch 1 taken 2466049 times.
|
2831098 | if (nzt & 1<<j) { |
1958 | uint32_t b; | ||
1959 | int n; | ||
1960 | /* The total length of escape_sequence must be < 22 bits according | ||
1961 | to the specification (i.e. max is 111111110xxxxxxxxxxxx). */ | ||
1962 | 365049 | UPDATE_CACHE(re, gb); | |
1963 | 365049 | b = GET_CACHE(re, gb); | |
1964 | 365049 | b = 31 - av_log2(~b); | |
1965 | |||
1966 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 365049 times.
|
365049 | if (b > 8) { |
1967 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); | |
1968 | ✗ | return AVERROR_INVALIDDATA; | |
1969 | } | ||
1970 | |||
1971 | 365049 | SKIP_BITS(re, gb, b + 1); | |
1972 | 365049 | b += 4; | |
1973 | 365049 | n = (1 << b) + SHOW_UBITS(re, gb, b); | |
1974 | 365049 | LAST_SKIP_BITS(re, gb, b); | |
1975 | #if USE_FIXED | ||
1976 | 64965 | v = n; | |
1977 |
2/2✓ Branch 0 taken 32342 times.
✓ Branch 1 taken 32623 times.
|
64965 | if (bits & 1U<<31) |
1978 | 32342 | v = -v; | |
1979 | 64965 | *icf++ = v; | |
1980 | #else | ||
1981 | 300084 | *icf++ = ff_cbrt_tab[n] | (bits & 1U<<31); | |
1982 | #endif /* USE_FIXED */ | ||
1983 | 365049 | bits <<= 1; | |
1984 | } else { | ||
1985 | #if USE_FIXED | ||
1986 | 539931 | v = cb_idx & 15; | |
1987 |
2/2✓ Branch 0 taken 256615 times.
✓ Branch 1 taken 283316 times.
|
539931 | if (bits & 1U<<31) |
1988 | 256615 | v = -v; | |
1989 | 539931 | *icf++ = v; | |
1990 | #else | ||
1991 | 1926118 | unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; | |
1992 | 1926118 | *icf++ = (bits & 1U<<31) | v; | |
1993 | #endif /* USE_FIXED */ | ||
1994 | 2466049 | bits <<= !!v; | |
1995 | } | ||
1996 | 2831098 | cb_idx >>= 4; | |
1997 | } | ||
1998 |
2/2✓ Branch 0 taken 1037526 times.
✓ Branch 1 taken 448746 times.
|
1486272 | } while (len -= 2); |
1999 | #if !USE_FIXED | ||
2000 | 329325 | ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len); | |
2001 | #endif /* !USE_FIXED */ | ||
2002 | } | ||
2003 | } | ||
2004 | |||
2005 | 2589954 | CLOSE_READER(re, gb); | |
2006 | } | ||
2007 | } | ||
2008 | 98974 | coef += g_len << 7; | |
2009 | } | ||
2010 | |||
2011 |
2/2✓ Branch 0 taken 1098 times.
✓ Branch 1 taken 92638 times.
|
93736 | if (pulse_present) { |
2012 | 1098 | idx = 0; | |
2013 |
2/2✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 1098 times.
|
3842 | for (i = 0; i < pulse->num_pulse; i++) { |
2014 | 2744 | INTFLOAT co = coef_base[ pulse->pos[i] ]; | |
2015 |
2/2✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 2744 times.
|
6840 | while (offsets[idx + 1] <= pulse->pos[i]) |
2016 | 4096 | idx++; | |
2017 |
3/4✓ Branch 0 taken 2744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2668 times.
✓ Branch 3 taken 76 times.
|
2744 | if (band_type[idx] != NOISE_BT && sf[idx]) { |
2018 | 2668 | INTFLOAT ico = -pulse->amp[i]; | |
2019 | #if USE_FIXED | ||
2020 |
2/2✓ Branch 0 taken 730 times.
✓ Branch 1 taken 134 times.
|
864 | if (co) { |
2021 |
2/2✓ Branch 0 taken 379 times.
✓ Branch 1 taken 351 times.
|
730 | ico = co + (co > 0 ? -ico : ico); |
2022 | } | ||
2023 | 864 | coef_base[ pulse->pos[i] ] = ico; | |
2024 | #else | ||
2025 |
2/2✓ Branch 0 taken 1564 times.
✓ Branch 1 taken 240 times.
|
1804 | if (co) { |
2026 | 1564 | co /= sf[idx]; | |
2027 |
2/2✓ Branch 0 taken 799 times.
✓ Branch 1 taken 765 times.
|
1564 | ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico); |
2028 | } | ||
2029 | 1804 | coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx]; | |
2030 | #endif /* USE_FIXED */ | ||
2031 | } | ||
2032 | } | ||
2033 | } | ||
2034 | #if USE_FIXED | ||
2035 | 28862 | coef = coef_base; | |
2036 | 28862 | idx = 0; | |
2037 |
2/2✓ Branch 0 taken 31194 times.
✓ Branch 1 taken 28862 times.
|
60056 | for (g = 0; g < ics->num_window_groups; g++) { |
2038 | 31194 | unsigned g_len = ics->group_len[g]; | |
2039 | |||
2040 |
2/2✓ Branch 0 taken 1046993 times.
✓ Branch 1 taken 31194 times.
|
1078187 | for (i = 0; i < ics->max_sfb; i++, idx++) { |
2041 | 1046993 | const unsigned cbt_m1 = band_type[idx] - 1; | |
2042 | 1046993 | int *cfo = coef + offsets[i]; | |
2043 | 1046993 | int off_len = offsets[i + 1] - offsets[i]; | |
2044 | int group; | ||
2045 | |||
2046 |
2/2✓ Branch 0 taken 779531 times.
✓ Branch 1 taken 267462 times.
|
1046993 | if (cbt_m1 < NOISE_BT - 1) { |
2047 |
2/2✓ Branch 0 taken 795075 times.
✓ Branch 1 taken 779531 times.
|
1574606 | for (group = 0; group < (int)g_len; group++, cfo+=128) { |
2048 | 795075 | ac->vector_pow43(cfo, off_len); | |
2049 | 795075 | ac->subband_scale(cfo, cfo, sf[idx], 34, off_len, ac->avctx); | |
2050 | } | ||
2051 | } | ||
2052 | } | ||
2053 | 31194 | coef += g_len << 7; | |
2054 | } | ||
2055 | #endif /* USE_FIXED */ | ||
2056 | 93736 | return 0; | |
2057 | } | ||
2058 | |||
2059 | /** | ||
2060 | * Apply AAC-Main style frequency domain prediction. | ||
2061 | */ | ||
2062 | 7388 | static void apply_prediction(AACContext *ac, SingleChannelElement *sce) | |
2063 | { | ||
2064 | int sfb, k; | ||
2065 | |||
2066 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 7368 times.
|
7388 | if (!sce->ics.predictor_initialized) { |
2067 | 20 | reset_all_predictors(sce->predictor_state); | |
2068 | 20 | sce->ics.predictor_initialized = 1; | |
2069 | } | ||
2070 | |||
2071 |
2/2✓ Branch 0 taken 7368 times.
✓ Branch 1 taken 20 times.
|
7388 | if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { |
2072 | 7368 | for (sfb = 0; | |
2073 |
2/2✓ Branch 0 taken 255198 times.
✓ Branch 1 taken 7368 times.
|
262566 | sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]; |
2074 | 255198 | sfb++) { | |
2075 | 255198 | for (k = sce->ics.swb_offset[sfb]; | |
2076 |
2/2✓ Branch 0 taken 4047936 times.
✓ Branch 1 taken 255198 times.
|
4303134 | k < sce->ics.swb_offset[sfb + 1]; |
2077 | 4047936 | k++) { | |
2078 | 4047936 | predict(&sce->predictor_state[k], &sce->coeffs[k], | |
2079 |
2/2✓ Branch 0 taken 892992 times.
✓ Branch 1 taken 3154944 times.
|
4047936 | sce->ics.predictor_present && |
2080 |
2/2✓ Branch 0 taken 271896 times.
✓ Branch 1 taken 621096 times.
|
892992 | sce->ics.prediction_used[sfb]); |
2081 | } | ||
2082 | } | ||
2083 |
2/2✓ Branch 0 taken 518 times.
✓ Branch 1 taken 6850 times.
|
7368 | if (sce->ics.predictor_reset_group) |
2084 | 518 | reset_predictor_group(sce->predictor_state, | |
2085 | sce->ics.predictor_reset_group); | ||
2086 | } else | ||
2087 | 20 | reset_all_predictors(sce->predictor_state); | |
2088 | 7388 | } | |
2089 | |||
2090 | ✗ | static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb) | |
2091 | { | ||
2092 | // wd_num, wd_test, aloc_size | ||
2093 | static const uint8_t gain_mode[4][3] = { | ||
2094 | {1, 0, 5}, // ONLY_LONG_SEQUENCE = 0, | ||
2095 | {2, 1, 2}, // LONG_START_SEQUENCE, | ||
2096 | {8, 0, 2}, // EIGHT_SHORT_SEQUENCE, | ||
2097 | {2, 1, 5}, // LONG_STOP_SEQUENCE | ||
2098 | }; | ||
2099 | |||
2100 | ✗ | const int mode = sce->ics.window_sequence[0]; | |
2101 | uint8_t bd, wd, ad; | ||
2102 | |||
2103 | // FIXME: Store the gain control data on |sce| and do something with it. | ||
2104 | ✗ | uint8_t max_band = get_bits(gb, 2); | |
2105 | ✗ | for (bd = 0; bd < max_band; bd++) { | |
2106 | ✗ | for (wd = 0; wd < gain_mode[mode][0]; wd++) { | |
2107 | ✗ | uint8_t adjust_num = get_bits(gb, 3); | |
2108 | ✗ | for (ad = 0; ad < adjust_num; ad++) { | |
2109 | ✗ | skip_bits(gb, 4 + ((wd == 0 && gain_mode[mode][1]) | |
2110 | ? 4 | ||
2111 | ✗ | : gain_mode[mode][2])); | |
2112 | } | ||
2113 | } | ||
2114 | } | ||
2115 | } | ||
2116 | |||
2117 | /** | ||
2118 | * Decode an individual_channel_stream payload; reference: table 4.44. | ||
2119 | * | ||
2120 | * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. | ||
2121 | * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.) | ||
2122 | * | ||
2123 | * @return Returns error status. 0 - OK, !0 - error | ||
2124 | */ | ||
2125 | 93736 | static int decode_ics(AACContext *ac, SingleChannelElement *sce, | |
2126 | GetBitContext *gb, int common_window, int scale_flag) | ||
2127 | { | ||
2128 | Pulse pulse; | ||
2129 | 93736 | TemporalNoiseShaping *tns = &sce->tns; | |
2130 | 93736 | IndividualChannelStream *ics = &sce->ics; | |
2131 | 93736 | INTFLOAT *out = sce->coeffs; | |
2132 | 93736 | int global_gain, eld_syntax, er_syntax, pulse_present = 0; | |
2133 | int ret; | ||
2134 | |||
2135 | 93736 | eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD; | |
2136 | 281208 | er_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_LC || | |
2137 |
1/2✓ Branch 0 taken 93736 times.
✗ Branch 1 not taken.
|
93736 | ac->oc[1].m4ac.object_type == AOT_ER_AAC_LTP || |
2138 |
3/4✓ Branch 0 taken 93736 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90100 times.
✓ Branch 3 taken 3636 times.
|
277572 | ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD || |
2139 |
2/2✓ Branch 0 taken 26598 times.
✓ Branch 1 taken 63502 times.
|
90100 | ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD; |
2140 | |||
2141 | /* This assignment is to silence a GCC warning about the variable being used | ||
2142 | * uninitialized when in fact it always is. | ||
2143 | */ | ||
2144 | 93736 | pulse.num_pulse = 0; | |
2145 | |||
2146 | 93736 | global_gain = get_bits(gb, 8); | |
2147 | |||
2148 |
3/4✓ Branch 0 taken 32808 times.
✓ Branch 1 taken 60928 times.
✓ Branch 2 taken 32808 times.
✗ Branch 3 not taken.
|
93736 | if (!common_window && !scale_flag) { |
2149 | 32808 | ret = decode_ics_info(ac, ics, gb); | |
2150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32808 times.
|
32808 | if (ret < 0) |
2151 | ✗ | goto fail; | |
2152 | } | ||
2153 | |||
2154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93736 times.
|
93736 | if ((ret = decode_band_types(ac, sce->band_type, |
2155 | 93736 | sce->band_type_run_end, gb, ics)) < 0) | |
2156 | ✗ | goto fail; | |
2157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93736 times.
|
93736 | if ((ret = decode_scalefactors(ac, sce->sf, gb, global_gain, ics, |
2158 | 93736 | sce->band_type, sce->band_type_run_end)) < 0) | |
2159 | ✗ | goto fail; | |
2160 | |||
2161 | 93736 | pulse_present = 0; | |
2162 |
1/2✓ Branch 0 taken 93736 times.
✗ Branch 1 not taken.
|
93736 | if (!scale_flag) { |
2163 |
4/4✓ Branch 0 taken 67138 times.
✓ Branch 1 taken 26598 times.
✓ Branch 3 taken 1098 times.
✓ Branch 4 taken 66040 times.
|
93736 | if (!eld_syntax && (pulse_present = get_bits1(gb))) { |
2164 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
|
1098 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2165 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
2166 | "Pulse tool not allowed in eight short sequence.\n"); | ||
2167 | ✗ | ret = AVERROR_INVALIDDATA; | |
2168 | ✗ | goto fail; | |
2169 | } | ||
2170 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1098 times.
|
1098 | if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) { |
2171 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
2172 | "Pulse data corrupt or invalid.\n"); | ||
2173 | ✗ | ret = AVERROR_INVALIDDATA; | |
2174 | ✗ | goto fail; | |
2175 | } | ||
2176 | } | ||
2177 | 93736 | tns->present = get_bits1(gb); | |
2178 |
4/4✓ Branch 0 taken 6927 times.
✓ Branch 1 taken 86809 times.
✓ Branch 2 taken 5663 times.
✓ Branch 3 taken 1264 times.
|
93736 | if (tns->present && !er_syntax) { |
2179 | 5663 | ret = decode_tns(ac, tns, gb, ics); | |
2180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5663 times.
|
5663 | if (ret < 0) |
2181 | ✗ | goto fail; | |
2182 | } | ||
2183 |
3/4✓ Branch 0 taken 67138 times.
✓ Branch 1 taken 26598 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 67138 times.
|
93736 | if (!eld_syntax && get_bits1(gb)) { |
2184 | ✗ | decode_gain_control(sce, gb); | |
2185 | ✗ | if (!ac->warned_gain_control) { | |
2186 | ✗ | avpriv_report_missing_feature(ac->avctx, "Gain control"); | |
2187 | ✗ | ac->warned_gain_control = 1; | |
2188 | } | ||
2189 | } | ||
2190 | // I see no textual basis in the spec for this occurring after SSR gain | ||
2191 | // control, but this is what both reference and real implmentations do | ||
2192 |
4/4✓ Branch 0 taken 6927 times.
✓ Branch 1 taken 86809 times.
✓ Branch 2 taken 1264 times.
✓ Branch 3 taken 5663 times.
|
93736 | if (tns->present && er_syntax) { |
2193 | 1264 | ret = decode_tns(ac, tns, gb, ics); | |
2194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1264 times.
|
1264 | if (ret < 0) |
2195 | ✗ | goto fail; | |
2196 | } | ||
2197 | } | ||
2198 | |||
2199 | 93736 | ret = decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, | |
2200 | 93736 | &pulse, ics, sce->band_type); | |
2201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93736 times.
|
93736 | if (ret < 0) |
2202 | ✗ | goto fail; | |
2203 | |||
2204 |
4/4✓ Branch 0 taken 7388 times.
✓ Branch 1 taken 86348 times.
✓ Branch 2 taken 6094 times.
✓ Branch 3 taken 1294 times.
|
93736 | if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window) |
2205 | 6094 | apply_prediction(ac, sce); | |
2206 | |||
2207 | 93736 | return 0; | |
2208 | ✗ | fail: | |
2209 | ✗ | tns->present = 0; | |
2210 | ✗ | return ret; | |
2211 | } | ||
2212 | |||
2213 | /** | ||
2214 | * Mid/Side stereo decoding; reference: 4.6.8.1.3. | ||
2215 | */ | ||
2216 | 26972 | static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe) | |
2217 | { | ||
2218 | 26972 | const IndividualChannelStream *ics = &cpe->ch[0].ics; | |
2219 | 26972 | INTFLOAT *ch0 = cpe->ch[0].coeffs; | |
2220 | 26972 | INTFLOAT *ch1 = cpe->ch[1].coeffs; | |
2221 | 26972 | int g, i, group, idx = 0; | |
2222 | 26972 | const uint16_t *offsets = ics->swb_offset; | |
2223 |
2/2✓ Branch 0 taken 28677 times.
✓ Branch 1 taken 26972 times.
|
55649 | for (g = 0; g < ics->num_window_groups; g++) { |
2224 |
2/2✓ Branch 0 taken 1012976 times.
✓ Branch 1 taken 28677 times.
|
1041653 | for (i = 0; i < ics->max_sfb; i++, idx++) { |
2225 |
2/2✓ Branch 0 taken 795390 times.
✓ Branch 1 taken 217586 times.
|
1012976 | if (cpe->ms_mask[idx] && |
2226 |
1/2✓ Branch 0 taken 795390 times.
✗ Branch 1 not taken.
|
795390 | cpe->ch[0].band_type[idx] < NOISE_BT && |
2227 |
2/2✓ Branch 0 taken 793014 times.
✓ Branch 1 taken 2376 times.
|
795390 | cpe->ch[1].band_type[idx] < NOISE_BT) { |
2228 | #if USE_FIXED | ||
2229 |
2/2✓ Branch 0 taken 253158 times.
✓ Branch 1 taken 247459 times.
|
500617 | for (group = 0; group < ics->group_len[g]; group++) { |
2230 | 253158 | ac->fdsp->butterflies_fixed(ch0 + group * 128 + offsets[i], | |
2231 | 253158 | ch1 + group * 128 + offsets[i], | |
2232 | 253158 | offsets[i+1] - offsets[i]); | |
2233 | #else | ||
2234 |
2/2✓ Branch 0 taken 570043 times.
✓ Branch 1 taken 545555 times.
|
1115598 | for (group = 0; group < ics->group_len[g]; group++) { |
2235 | 570043 | ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[i], | |
2236 | 570043 | ch1 + group * 128 + offsets[i], | |
2237 | 570043 | offsets[i+1] - offsets[i]); | |
2238 | #endif /* USE_FIXED */ | ||
2239 | } | ||
2240 | } | ||
2241 | } | ||
2242 | 28677 | ch0 += ics->group_len[g] * 128; | |
2243 | 28677 | ch1 += ics->group_len[g] * 128; | |
2244 | } | ||
2245 | 26972 | } | |
2246 | |||
2247 | /** | ||
2248 | * intensity stereo decoding; reference: 4.6.8.2.3 | ||
2249 | * | ||
2250 | * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; | ||
2251 | * [1] mask is decoded from bitstream; [2] mask is all 1s; | ||
2252 | * [3] reserved for scalable AAC | ||
2253 | */ | ||
2254 | 30686 | static void apply_intensity_stereo(AACContext *ac, | |
2255 | ChannelElement *cpe, int ms_present) | ||
2256 | { | ||
2257 | 30686 | const IndividualChannelStream *ics = &cpe->ch[1].ics; | |
2258 | 30686 | SingleChannelElement *sce1 = &cpe->ch[1]; | |
2259 | 30686 | INTFLOAT *coef0 = cpe->ch[0].coeffs, *coef1 = cpe->ch[1].coeffs; | |
2260 | 30686 | const uint16_t *offsets = ics->swb_offset; | |
2261 | 30686 | int g, group, i, idx = 0; | |
2262 | int c; | ||
2263 | INTFLOAT scale; | ||
2264 |
2/2✓ Branch 0 taken 32614 times.
✓ Branch 1 taken 30686 times.
|
63300 | for (g = 0; g < ics->num_window_groups; g++) { |
2265 |
2/2✓ Branch 0 taken 160764 times.
✓ Branch 1 taken 32614 times.
|
193378 | for (i = 0; i < ics->max_sfb;) { |
2266 |
2/2✓ Branch 0 taken 151292 times.
✓ Branch 1 taken 9472 times.
|
160764 | if (sce1->band_type[idx] == INTENSITY_BT || |
2267 |
2/2✓ Branch 0 taken 111 times.
✓ Branch 1 taken 151181 times.
|
160875 | sce1->band_type[idx] == INTENSITY_BT2) { |
2268 | 9583 | const int bt_run_end = sce1->band_type_run_end[idx]; | |
2269 |
2/2✓ Branch 0 taken 66207 times.
✓ Branch 1 taken 9583 times.
|
75790 | for (; i < bt_run_end; i++, idx++) { |
2270 | 66207 | c = -1 + 2 * (sce1->band_type[idx] - 14); | |
2271 |
2/2✓ Branch 0 taken 61324 times.
✓ Branch 1 taken 4883 times.
|
66207 | if (ms_present) |
2272 | 61324 | c *= 1 - 2 * cpe->ms_mask[idx]; | |
2273 | 66207 | scale = c * sce1->sf[idx]; | |
2274 |
2/2✓ Branch 0 taken 66538 times.
✓ Branch 1 taken 66207 times.
|
132745 | for (group = 0; group < ics->group_len[g]; group++) |
2275 | #if USE_FIXED | ||
2276 | 17955 | ac->subband_scale(coef1 + group * 128 + offsets[i], | |
2277 | 17955 | coef0 + group * 128 + offsets[i], | |
2278 | scale, | ||
2279 | 23, | ||
2280 | 17955 | offsets[i + 1] - offsets[i] ,ac->avctx); | |
2281 | #else | ||
2282 | 48583 | ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[i], | |
2283 | 48583 | coef0 + group * 128 + offsets[i], | |
2284 | scale, | ||
2285 | 48583 | offsets[i + 1] - offsets[i]); | |
2286 | #endif /* USE_FIXED */ | ||
2287 | } | ||
2288 | } else { | ||
2289 | 151181 | int bt_run_end = sce1->band_type_run_end[idx]; | |
2290 | 151181 | idx += bt_run_end - i; | |
2291 | 151181 | i = bt_run_end; | |
2292 | } | ||
2293 | } | ||
2294 | 32614 | coef0 += ics->group_len[g] * 128; | |
2295 | 32614 | coef1 += ics->group_len[g] * 128; | |
2296 | } | ||
2297 | 30686 | } | |
2298 | |||
2299 | /** | ||
2300 | * Decode a channel_pair_element; reference: table 4.4. | ||
2301 | * | ||
2302 | * @return Returns error status. 0 - OK, !0 - error | ||
2303 | */ | ||
2304 | 30686 | static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) | |
2305 | { | ||
2306 | 30686 | int i, ret, common_window, ms_present = 0; | |
2307 | 30686 | int eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD; | |
2308 | |||
2309 |
4/4✓ Branch 0 taken 20453 times.
✓ Branch 1 taken 10233 times.
✓ Branch 3 taken 20231 times.
✓ Branch 4 taken 222 times.
|
30686 | common_window = eld_syntax || get_bits1(gb); |
2310 |
2/2✓ Branch 0 taken 30464 times.
✓ Branch 1 taken 222 times.
|
30686 | if (common_window) { |
2311 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30464 times.
|
30464 | if (decode_ics_info(ac, &cpe->ch[0].ics, gb)) |
2312 | ✗ | return AVERROR_INVALIDDATA; | |
2313 | 30464 | i = cpe->ch[1].ics.use_kb_window[0]; | |
2314 | 30464 | cpe->ch[1].ics = cpe->ch[0].ics; | |
2315 | 30464 | cpe->ch[1].ics.use_kb_window[1] = i; | |
2316 |
2/2✓ Branch 0 taken 723 times.
✓ Branch 1 taken 29741 times.
|
30464 | if (cpe->ch[1].ics.predictor_present && |
2317 |
2/2✓ Branch 0 taken 538 times.
✓ Branch 1 taken 185 times.
|
723 | (ac->oc[1].m4ac.object_type != AOT_AAC_MAIN)) |
2318 |
2/2✓ Branch 1 taken 404 times.
✓ Branch 2 taken 134 times.
|
538 | if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1))) |
2319 | 404 | decode_ltp(&cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb); | |
2320 | 30464 | ms_present = get_bits(gb, 2); | |
2321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30464 times.
|
30464 | if (ms_present == 3) { |
2322 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n"); | |
2323 | ✗ | return AVERROR_INVALIDDATA; | |
2324 |
2/2✓ Branch 0 taken 26972 times.
✓ Branch 1 taken 3492 times.
|
30464 | } else if (ms_present) |
2325 | 26972 | decode_mid_side_stereo(cpe, gb, ms_present); | |
2326 | } | ||
2327 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30686 times.
|
30686 | if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0))) |
2328 | ✗ | return ret; | |
2329 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30686 times.
|
30686 | if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0))) |
2330 | ✗ | return ret; | |
2331 | |||
2332 |
2/2✓ Branch 0 taken 30464 times.
✓ Branch 1 taken 222 times.
|
30686 | if (common_window) { |
2333 |
2/2✓ Branch 0 taken 26972 times.
✓ Branch 1 taken 3492 times.
|
30464 | if (ms_present) |
2334 | 26972 | apply_mid_side_stereo(ac, cpe); | |
2335 |
2/2✓ Branch 0 taken 647 times.
✓ Branch 1 taken 29817 times.
|
30464 | if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN) { |
2336 | 647 | apply_prediction(ac, &cpe->ch[0]); | |
2337 | 647 | apply_prediction(ac, &cpe->ch[1]); | |
2338 | } | ||
2339 | } | ||
2340 | |||
2341 | 30686 | apply_intensity_stereo(ac, cpe, ms_present); | |
2342 | 30686 | return 0; | |
2343 | } | ||
2344 | |||
2345 | static const float cce_scale[] = { | ||
2346 | 1.09050773266525765921, //2^(1/8) | ||
2347 | 1.18920711500272106672, //2^(1/4) | ||
2348 | M_SQRT2, | ||
2349 | 2, | ||
2350 | }; | ||
2351 | |||
2352 | /** | ||
2353 | * Decode coupling_channel_element; reference: table 4.8. | ||
2354 | * | ||
2355 | * @return Returns error status. 0 - OK, !0 - error | ||
2356 | */ | ||
2357 | 1174 | static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) | |
2358 | { | ||
2359 | 1174 | int num_gain = 0; | |
2360 | int c, g, sfb, ret; | ||
2361 | int sign; | ||
2362 | INTFLOAT scale; | ||
2363 | 1174 | SingleChannelElement *sce = &che->ch[0]; | |
2364 | 1174 | ChannelCoupling *coup = &che->coup; | |
2365 | |||
2366 | 1174 | coup->coupling_point = 2 * get_bits1(gb); | |
2367 | 1174 | coup->num_coupled = get_bits(gb, 3); | |
2368 |
2/2✓ Branch 0 taken 2741 times.
✓ Branch 1 taken 1174 times.
|
3915 | for (c = 0; c <= coup->num_coupled; c++) { |
2369 | 2741 | num_gain++; | |
2370 | 2741 | coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE; | |
2371 | 2741 | coup->id_select[c] = get_bits(gb, 4); | |
2372 |
2/2✓ Branch 0 taken 2348 times.
✓ Branch 1 taken 393 times.
|
2741 | if (coup->type[c] == TYPE_CPE) { |
2373 | 2348 | coup->ch_select[c] = get_bits(gb, 2); | |
2374 |
2/2✓ Branch 0 taken 1967 times.
✓ Branch 1 taken 381 times.
|
2348 | if (coup->ch_select[c] == 3) |
2375 | 1967 | num_gain++; | |
2376 | } else | ||
2377 | 393 | coup->ch_select[c] = 2; | |
2378 | } | ||
2379 |
4/4✓ Branch 1 taken 602 times.
✓ Branch 2 taken 572 times.
✓ Branch 3 taken 152 times.
✓ Branch 4 taken 450 times.
|
1174 | coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1); |
2380 | |||
2381 | 1174 | sign = get_bits(gb, 1); | |
2382 | #if USE_FIXED | ||
2383 | 130 | scale = get_bits(gb, 2); | |
2384 | #else | ||
2385 | 1044 | scale = cce_scale[get_bits(gb, 2)]; | |
2386 | #endif | ||
2387 | |||
2388 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1174 times.
|
1174 | if ((ret = decode_ics(ac, sce, gb, 0, 0))) |
2389 | ✗ | return ret; | |
2390 | |||
2391 |
2/2✓ Branch 0 taken 4708 times.
✓ Branch 1 taken 1174 times.
|
5882 | for (c = 0; c < num_gain; c++) { |
2392 | 4708 | int idx = 0; | |
2393 | 4708 | int cge = 1; | |
2394 | 4708 | int gain = 0; | |
2395 | 4708 | INTFLOAT gain_cache = FIXR10(1.); | |
2396 |
2/2✓ Branch 0 taken 3534 times.
✓ Branch 1 taken 1174 times.
|
4708 | if (c) { |
2397 |
2/2✓ Branch 0 taken 1962 times.
✓ Branch 1 taken 1572 times.
|
3534 | cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); |
2398 |
2/2✓ Branch 0 taken 1973 times.
✓ Branch 1 taken 1561 times.
|
3534 | gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0; |
2399 | 3534 | gain_cache = GET_GAIN(scale, gain); | |
2400 | #if USE_FIXED | ||
2401 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 520 times.
|
520 | if ((abs(gain_cache)-1024) >> 3 > 30) |
2402 | ✗ | return AVERROR(ERANGE); | |
2403 | #endif | ||
2404 | } | ||
2405 |
2/2✓ Branch 0 taken 1965 times.
✓ Branch 1 taken 2743 times.
|
4708 | if (coup->coupling_point == AFTER_IMDCT) { |
2406 | 1965 | coup->gain[c][0] = gain_cache; | |
2407 | } else { | ||
2408 |
2/2✓ Branch 0 taken 2743 times.
✓ Branch 1 taken 2743 times.
|
5486 | for (g = 0; g < sce->ics.num_window_groups; g++) { |
2409 |
2/2✓ Branch 0 taken 109720 times.
✓ Branch 1 taken 2743 times.
|
112463 | for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) { |
2410 |
2/2✓ Branch 0 taken 5196 times.
✓ Branch 1 taken 104524 times.
|
109720 | if (sce->band_type[idx] != ZERO_BT) { |
2411 |
2/2✓ Branch 0 taken 2879 times.
✓ Branch 1 taken 2317 times.
|
5196 | if (!cge) { |
2412 | 2879 | int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; | |
2413 |
2/2✓ Branch 0 taken 2724 times.
✓ Branch 1 taken 155 times.
|
2879 | if (t) { |
2414 | 2724 | int s = 1; | |
2415 | 2724 | t = gain += t; | |
2416 |
2/2✓ Branch 0 taken 1666 times.
✓ Branch 1 taken 1058 times.
|
2724 | if (sign) { |
2417 | 1666 | s -= 2 * (t & 0x1); | |
2418 | 1666 | t >>= 1; | |
2419 | } | ||
2420 | 2724 | gain_cache = GET_GAIN(scale, t) * s; | |
2421 | #if USE_FIXED | ||
2422 | ✗ | if ((abs(gain_cache)-1024) >> 3 > 30) | |
2423 | ✗ | return AVERROR(ERANGE); | |
2424 | #endif | ||
2425 | } | ||
2426 | } | ||
2427 | 5196 | coup->gain[c][idx] = gain_cache; | |
2428 | } | ||
2429 | } | ||
2430 | } | ||
2431 | } | ||
2432 | } | ||
2433 | 1174 | return 0; | |
2434 | } | ||
2435 | |||
2436 | /** | ||
2437 | * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53. | ||
2438 | * | ||
2439 | * @return Returns number of bytes consumed. | ||
2440 | */ | ||
2441 | 4 | static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, | |
2442 | GetBitContext *gb) | ||
2443 | { | ||
2444 | int i; | ||
2445 | 4 | int num_excl_chan = 0; | |
2446 | |||
2447 | do { | ||
2448 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 4 times.
|
32 | for (i = 0; i < 7; i++) |
2449 | 28 | che_drc->exclude_mask[num_excl_chan++] = get_bits1(gb); | |
2450 |
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)); |
2451 | |||
2452 | 4 | return num_excl_chan / 7; | |
2453 | } | ||
2454 | |||
2455 | /** | ||
2456 | * Decode dynamic range information; reference: table 4.52. | ||
2457 | * | ||
2458 | * @return Returns number of bytes consumed. | ||
2459 | */ | ||
2460 | 880 | static int decode_dynamic_range(DynamicRangeControl *che_drc, | |
2461 | GetBitContext *gb) | ||
2462 | { | ||
2463 | 880 | int n = 1; | |
2464 | 880 | int drc_num_bands = 1; | |
2465 | int i; | ||
2466 | |||
2467 | /* pce_tag_present? */ | ||
2468 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 880 times.
|
880 | if (get_bits1(gb)) { |
2469 | ✗ | che_drc->pce_instance_tag = get_bits(gb, 4); | |
2470 | ✗ | skip_bits(gb, 4); // tag_reserved_bits | |
2471 | ✗ | n++; | |
2472 | } | ||
2473 | |||
2474 | /* excluded_chns_present? */ | ||
2475 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 876 times.
|
880 | if (get_bits1(gb)) { |
2476 | 4 | n += decode_drc_channel_exclusions(che_drc, gb); | |
2477 | } | ||
2478 | |||
2479 | /* drc_bands_present? */ | ||
2480 |
2/2✓ Branch 1 taken 35 times.
✓ Branch 2 taken 845 times.
|
880 | if (get_bits1(gb)) { |
2481 | 35 | che_drc->band_incr = get_bits(gb, 4); | |
2482 | 35 | che_drc->interpolation_scheme = get_bits(gb, 4); | |
2483 | 35 | n++; | |
2484 | 35 | drc_num_bands += che_drc->band_incr; | |
2485 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 35 times.
|
140 | for (i = 0; i < drc_num_bands; i++) { |
2486 | 105 | che_drc->band_top[i] = get_bits(gb, 8); | |
2487 | 105 | n++; | |
2488 | } | ||
2489 | } | ||
2490 | |||
2491 | /* prog_ref_level_present? */ | ||
2492 |
2/2✓ Branch 1 taken 878 times.
✓ Branch 2 taken 2 times.
|
880 | if (get_bits1(gb)) { |
2493 | 878 | che_drc->prog_ref_level = get_bits(gb, 7); | |
2494 | 878 | skip_bits1(gb); // prog_ref_level_reserved_bits | |
2495 | 878 | n++; | |
2496 | } | ||
2497 | |||
2498 |
2/2✓ Branch 0 taken 950 times.
✓ Branch 1 taken 880 times.
|
1830 | for (i = 0; i < drc_num_bands; i++) { |
2499 | 950 | che_drc->dyn_rng_sgn[i] = get_bits1(gb); | |
2500 | 950 | che_drc->dyn_rng_ctl[i] = get_bits(gb, 7); | |
2501 | 950 | n++; | |
2502 | } | ||
2503 | |||
2504 | 880 | return n; | |
2505 | } | ||
2506 | |||
2507 | 8949 | static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { | |
2508 | uint8_t buf[256]; | ||
2509 | int i, major, minor; | ||
2510 | |||
2511 |
2/2✓ Branch 0 taken 380 times.
✓ Branch 1 taken 8569 times.
|
8949 | if (len < 13+7*8) |
2512 | 380 | goto unknown; | |
2513 | |||
2514 | 8569 | get_bits(gb, 13); len -= 13; | |
2515 | |||
2516 |
4/4✓ Branch 0 taken 1136273 times.
✓ Branch 1 taken 441 times.
✓ Branch 2 taken 1128145 times.
✓ Branch 3 taken 8128 times.
|
1136714 | for(i=0; i+1<sizeof(buf) && len>=8; i++, len-=8) |
2517 | 1128145 | buf[i] = get_bits(gb, 8); | |
2518 | |||
2519 | 8569 | buf[i] = 0; | |
2520 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8569 times.
|
8569 | if (ac->avctx->debug & FF_DEBUG_PICT_INFO) |
2521 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf); | |
2522 | |||
2523 |
2/2✓ Branch 0 taken 8550 times.
✓ Branch 1 taken 19 times.
|
8569 | if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){ |
2524 | 19 | ac->avctx->internal->skip_samples = 1024; | |
2525 | } | ||
2526 | |||
2527 | 8550 | unknown: | |
2528 | 8949 | skip_bits_long(gb, len); | |
2529 | |||
2530 | 8949 | return 0; | |
2531 | } | ||
2532 | |||
2533 | /** | ||
2534 | * Decode extension data (incomplete); reference: table 4.51. | ||
2535 | * | ||
2536 | * @param cnt length of TYPE_FIL syntactic element in bytes | ||
2537 | * | ||
2538 | * @return Returns number of bytes consumed | ||
2539 | */ | ||
2540 | 23680 | static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, | |
2541 | ChannelElement *che, enum RawDataBlockType elem_type) | ||
2542 | { | ||
2543 | 23680 | int crc_flag = 0; | |
2544 | 23680 | int res = cnt; | |
2545 | 23680 | int type = get_bits(gb, 4); | |
2546 | |||
2547 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23680 times.
|
23680 | if (ac->avctx->debug & FF_DEBUG_STARTCODE) |
2548 | ✗ | av_log(ac->avctx, AV_LOG_DEBUG, "extension type: %d len:%d\n", type, cnt); | |
2549 | |||
2550 |
4/5✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
✓ Branch 2 taken 880 times.
✓ Branch 3 taken 8949 times.
✓ Branch 4 taken 2950 times.
|
23680 | switch (type) { // extension type |
2551 | ✗ | case EXT_SBR_DATA_CRC: | |
2552 | ✗ | crc_flag++; | |
2553 | 10901 | case EXT_SBR_DATA: | |
2554 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
|
10901 | if (!che) { |
2555 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n"); | |
2556 | ✗ | return res; | |
2557 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
|
10901 | } else if (ac->oc[1].m4ac.frame_length_short) { |
2558 | ✗ | if (!ac->warned_960_sbr) | |
2559 | ✗ | avpriv_report_missing_feature(ac->avctx, | |
2560 | "SBR with 960 frame length"); | ||
2561 | ✗ | ac->warned_960_sbr = 1; | |
2562 | ✗ | skip_bits_long(gb, 8 * cnt - 4); | |
2563 | ✗ | return res; | |
2564 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10901 times.
|
10901 | } else if (!ac->oc[1].m4ac.sbr) { |
2565 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n"); | |
2566 | ✗ | skip_bits_long(gb, 8 * cnt - 4); | |
2567 | ✗ | return res; | |
2568 |
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) { |
2569 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); | |
2570 | ✗ | skip_bits_long(gb, 8 * cnt - 4); | |
2571 | ✗ | return res; | |
2572 |
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 && |
2573 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 82 times.
|
94 | ac->avctx->ch_layout.nb_channels == 1) { |
2574 | 12 | ac->oc[1].m4ac.sbr = 1; | |
2575 | 12 | ac->oc[1].m4ac.ps = 1; | |
2576 | 12 | ac->avctx->profile = FF_PROFILE_AAC_HE_V2; | |
2577 | 12 | output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, | |
2578 | ac->oc[1].status, 1); | ||
2579 | } else { | ||
2580 | 10889 | ac->oc[1].m4ac.sbr = 1; | |
2581 | 10889 | ac->avctx->profile = FF_PROFILE_AAC_HE; | |
2582 | } | ||
2583 | 10901 | res = AAC_RENAME(ff_decode_sbr_extension)(ac, &che->sbr, gb, crc_flag, cnt, elem_type); | |
2584 | 10901 | break; | |
2585 | 880 | case EXT_DYNAMIC_RANGE: | |
2586 | 880 | res = decode_dynamic_range(&ac->che_drc, gb); | |
2587 | 880 | break; | |
2588 | 8949 | case EXT_FILL: | |
2589 | 8949 | decode_fill(ac, gb, 8 * cnt - 4); | |
2590 | 8949 | break; | |
2591 | 2950 | case EXT_FILL_DATA: | |
2592 | case EXT_DATA_ELEMENT: | ||
2593 | default: | ||
2594 | 2950 | skip_bits_long(gb, 8 * cnt - 4); | |
2595 | 2950 | break; | |
2596 | }; | ||
2597 | 23680 | return res; | |
2598 | } | ||
2599 | |||
2600 | /** | ||
2601 | * Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4.6.9.3. | ||
2602 | * | ||
2603 | * @param decode 1 if tool is used normally, 0 if tool is used in LTP. | ||
2604 | * @param coef spectral coefficients | ||
2605 | */ | ||
2606 | 6933 | static void apply_tns(INTFLOAT coef_param[1024], TemporalNoiseShaping *tns, | |
2607 | IndividualChannelStream *ics, int decode) | ||
2608 | { | ||
2609 | 6933 | const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb); | |
2610 | int w, filt, m, i; | ||
2611 | int bottom, top, order, start, end, size, inc; | ||
2612 | INTFLOAT lpc[TNS_MAX_ORDER]; | ||
2613 | INTFLOAT tmp[TNS_MAX_ORDER+1]; | ||
2614 | 6933 | UINTFLOAT *coef = coef_param; | |
2615 | |||
2616 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6927 times.
|
6933 | if(!mmm) |
2617 | 6 | return; | |
2618 | |||
2619 |
2/2✓ Branch 0 taken 11540 times.
✓ Branch 1 taken 6927 times.
|
18467 | for (w = 0; w < ics->num_windows; w++) { |
2620 | 11540 | bottom = ics->num_swb; | |
2621 |
2/2✓ Branch 0 taken 9379 times.
✓ Branch 1 taken 11540 times.
|
20919 | for (filt = 0; filt < tns->n_filt[w]; filt++) { |
2622 | 9379 | top = bottom; | |
2623 | 9379 | bottom = FFMAX(0, top - tns->length[w][filt]); | |
2624 | 9379 | order = tns->order[w][filt]; | |
2625 |
2/2✓ Branch 0 taken 520 times.
✓ Branch 1 taken 8859 times.
|
9379 | if (order == 0) |
2626 | 520 | continue; | |
2627 | |||
2628 | // tns_decode_coef | ||
2629 | 8859 | AAC_RENAME(compute_lpc_coefs)(tns->coef[w][filt], order, lpc, 0, 0, 0); | |
2630 | |||
2631 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8853 times.
|
8859 | start = ics->swb_offset[FFMIN(bottom, mmm)]; |
2632 |
2/2✓ Branch 0 taken 7061 times.
✓ Branch 1 taken 1798 times.
|
8859 | end = ics->swb_offset[FFMIN( top, mmm)]; |
2633 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8851 times.
|
8859 | if ((size = end - start) <= 0) |
2634 | 8 | continue; | |
2635 |
2/2✓ Branch 0 taken 3590 times.
✓ Branch 1 taken 5261 times.
|
8851 | if (tns->direction[w][filt]) { |
2636 | 3590 | inc = -1; | |
2637 | 3590 | start = end - 1; | |
2638 | } else { | ||
2639 | 5261 | inc = 1; | |
2640 | } | ||
2641 | 8851 | start += w * 128; | |
2642 | |||
2643 |
2/2✓ Branch 0 taken 8845 times.
✓ Branch 1 taken 6 times.
|
8851 | if (decode) { |
2644 | // ar filter | ||
2645 |
2/2✓ Branch 0 taken 2730044 times.
✓ Branch 1 taken 8845 times.
|
2738889 | for (m = 0; m < size; m++, start += inc) |
2646 |
2/2✓ Branch 0 taken 21153425 times.
✓ Branch 1 taken 2730044 times.
|
23883469 | for (i = 1; i <= FFMIN(m, order); i++) |
2647 | 21153425 | coef[start] -= AAC_MUL26((INTFLOAT)coef[start - i * inc], lpc[i - 1]); | |
2648 | } else { | ||
2649 | // ma filter | ||
2650 |
2/2✓ Branch 0 taken 3696 times.
✓ Branch 1 taken 6 times.
|
3702 | for (m = 0; m < size; m++, start += inc) { |
2651 | 3696 | tmp[0] = coef[start]; | |
2652 |
2/2✓ Branch 0 taken 35416 times.
✓ Branch 1 taken 3696 times.
|
39112 | for (i = 1; i <= FFMIN(m, order); i++) |
2653 | 35416 | coef[start] += AAC_MUL26(tmp[i], lpc[i - 1]); | |
2654 |
2/2✓ Branch 0 taken 35728 times.
✓ Branch 1 taken 3696 times.
|
39424 | for (i = order; i > 0; i--) |
2655 | 35728 | tmp[i] = tmp[i - 1]; | |
2656 | } | ||
2657 | } | ||
2658 | } | ||
2659 | } | ||
2660 | } | ||
2661 | |||
2662 | /** | ||
2663 | * Apply windowing and MDCT to obtain the spectral | ||
2664 | * coefficient from the predicted sample by LTP. | ||
2665 | */ | ||
2666 | 786 | static void windowing_and_mdct_ltp(AACContext *ac, INTFLOAT *out, | |
2667 | INTFLOAT *in, IndividualChannelStream *ics) | ||
2668 | { | ||
2669 |
1/2✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
|
786 | const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024); |
2670 |
1/2✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
|
786 | const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128); |
2671 |
2/2✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2 times.
|
786 | const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024); |
2672 |
2/2✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2 times.
|
786 | const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128); |
2673 | |||
2674 |
2/2✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2 times.
|
786 | if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) { |
2675 | 784 | ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024); | |
2676 | } else { | ||
2677 | 2 | memset(in, 0, 448 * sizeof(*in)); | |
2678 | 2 | ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128); | |
2679 | } | ||
2680 |
1/2✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
|
786 | if (ics->window_sequence[0] != LONG_START_SEQUENCE) { |
2681 | 786 | ac->fdsp->vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024); | |
2682 | } else { | ||
2683 | ✗ | ac->fdsp->vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128); | |
2684 | ✗ | memset(in + 1024 + 576, 0, 448 * sizeof(*in)); | |
2685 | } | ||
2686 | 786 | ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in); | |
2687 | 786 | } | |
2688 | |||
2689 | /** | ||
2690 | * Apply the long term prediction | ||
2691 | */ | ||
2692 | 786 | static void apply_ltp(AACContext *ac, SingleChannelElement *sce) | |
2693 | { | ||
2694 | 786 | const LongTermPrediction *ltp = &sce->ics.ltp; | |
2695 | 786 | const uint16_t *offsets = sce->ics.swb_offset; | |
2696 | int i, sfb; | ||
2697 | |||
2698 |
1/2✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
|
786 | if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { |
2699 | 786 | INTFLOAT *predTime = sce->ret; | |
2700 | 786 | INTFLOAT *predFreq = ac->buf_mdct; | |
2701 | 786 | int16_t num_samples = 2048; | |
2702 | |||
2703 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
|
786 | if (ltp->lag < 1024) |
2704 | ✗ | num_samples = ltp->lag + 1024; | |
2705 |
2/2✓ Branch 0 taken 1609728 times.
✓ Branch 1 taken 786 times.
|
1610514 | for (i = 0; i < num_samples; i++) |
2706 | 1609728 | predTime[i] = AAC_MUL30(sce->ltp_state[i + 2048 - ltp->lag], ltp->coef); | |
2707 | 786 | memset(&predTime[i], 0, (2048 - i) * sizeof(*predTime)); | |
2708 | |||
2709 | 786 | ac->windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics); | |
2710 | |||
2711 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 780 times.
|
786 | if (sce->tns.present) |
2712 | 6 | ac->apply_tns(predFreq, &sce->tns, &sce->ics, 0); | |
2713 | |||
2714 |
2/2✓ Branch 0 taken 31440 times.
✓ Branch 1 taken 786 times.
|
32226 | for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++) |
2715 |
2/2✓ Branch 0 taken 22868 times.
✓ Branch 1 taken 8572 times.
|
31440 | if (ltp->used[sfb]) |
2716 |
2/2✓ Branch 0 taken 347544 times.
✓ Branch 1 taken 22868 times.
|
370412 | for (i = offsets[sfb]; i < offsets[sfb + 1]; i++) |
2717 | 347544 | sce->coeffs[i] += (UINTFLOAT)predFreq[i]; | |
2718 | } | ||
2719 | 786 | } | |
2720 | |||
2721 | /** | ||
2722 | * Update the LTP buffer for next frame | ||
2723 | */ | ||
2724 | 3568 | static void update_ltp(AACContext *ac, SingleChannelElement *sce) | |
2725 | { | ||
2726 | 3568 | IndividualChannelStream *ics = &sce->ics; | |
2727 | 3568 | INTFLOAT *saved = sce->saved; | |
2728 | 3568 | INTFLOAT *saved_ltp = sce->coeffs; | |
2729 |
2/2✓ Branch 0 taken 3560 times.
✓ Branch 1 taken 8 times.
|
3568 | const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024); |
2730 |
2/2✓ Branch 0 taken 3560 times.
✓ Branch 1 taken 8 times.
|
3568 | const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128); |
2731 | int i; | ||
2732 | |||
2733 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3564 times.
|
3568 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2734 | 4 | memcpy(saved_ltp, saved, 512 * sizeof(*saved_ltp)); | |
2735 | 4 | memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp)); | |
2736 | 4 | ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); | |
2737 | |||
2738 |
2/2✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
|
260 | for (i = 0; i < 64; i++) |
2739 | 256 | saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], swindow[63 - i]); | |
2740 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3560 times.
|
3564 | } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { |
2741 | 4 | memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(*saved_ltp)); | |
2742 | 4 | memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp)); | |
2743 | 4 | ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); | |
2744 | |||
2745 |
2/2✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
|
260 | for (i = 0; i < 64; i++) |
2746 | 256 | saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], swindow[63 - i]); | |
2747 | } else { // LONG_STOP or ONLY_LONG | ||
2748 | 3560 | ac->fdsp->vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512); | |
2749 | |||
2750 |
2/2✓ Branch 0 taken 1822720 times.
✓ Branch 1 taken 3560 times.
|
1826280 | for (i = 0; i < 512; i++) |
2751 | 1822720 | saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], lwindow[511 - i]); | |
2752 | } | ||
2753 | |||
2754 | 3568 | memcpy(sce->ltp_state, sce->ltp_state+1024, 1024 * sizeof(*sce->ltp_state)); | |
2755 | 3568 | memcpy(sce->ltp_state+1024, sce->ret, 1024 * sizeof(*sce->ltp_state)); | |
2756 | 3568 | memcpy(sce->ltp_state+2048, saved_ltp, 1024 * sizeof(*sce->ltp_state)); | |
2757 | 3568 | } | |
2758 | |||
2759 | /** | ||
2760 | * Conduct IMDCT and windowing. | ||
2761 | */ | ||
2762 | 62334 | static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) | |
2763 | { | ||
2764 | 62334 | IndividualChannelStream *ics = &sce->ics; | |
2765 | 62334 | INTFLOAT *in = sce->coeffs; | |
2766 | 62334 | INTFLOAT *out = sce->ret; | |
2767 | 62334 | INTFLOAT *saved = sce->saved; | |
2768 |
2/2✓ Branch 0 taken 40464 times.
✓ Branch 1 taken 21870 times.
|
62334 | const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128); |
2769 |
2/2✓ Branch 0 taken 40317 times.
✓ Branch 1 taken 22017 times.
|
62334 | const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024); |
2770 |
2/2✓ Branch 0 taken 40317 times.
✓ Branch 1 taken 22017 times.
|
62334 | const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128); |
2771 | 62334 | INTFLOAT *buf = ac->buf_mdct; | |
2772 | 62334 | INTFLOAT *temp = ac->temp; | |
2773 | int i; | ||
2774 | |||
2775 | // imdct | ||
2776 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 60246 times.
|
62334 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2777 |
2/2✓ Branch 0 taken 16704 times.
✓ Branch 1 taken 2088 times.
|
18792 | for (i = 0; i < 1024; i += 128) |
2778 | 16704 | ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i); | |
2779 | } else { | ||
2780 | 60246 | ac->mdct.imdct_half(&ac->mdct, buf, in); | |
2781 | #if USE_FIXED | ||
2782 |
2/2✓ Branch 0 taken 16951296 times.
✓ Branch 1 taken 16554 times.
|
16967850 | for (i=0; i<1024; i++) |
2783 | 16951296 | buf[i] = (buf[i] + 4LL) >> 3; | |
2784 | #endif /* USE_FIXED */ | ||
2785 | } | ||
2786 | |||
2787 | /* window overlapping | ||
2788 | * NOTE: To simplify the overlapping code, all 'meaningless' short to long | ||
2789 | * and long to short transitions are considered to be short to short | ||
2790 | * transitions. This leaves just two cases (long to long and short to short) | ||
2791 | * with a little special sauce for EIGHT_SHORT_SEQUENCE. | ||
2792 | */ | ||
2793 |
4/4✓ Branch 0 taken 4249 times.
✓ Branch 1 taken 58085 times.
✓ Branch 2 taken 1079 times.
✓ Branch 3 taken 3170 times.
|
62334 | if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && |
2794 |
4/4✓ Branch 0 taken 1219 times.
✓ Branch 1 taken 57945 times.
✓ Branch 2 taken 1217 times.
✓ Branch 3 taken 2 times.
|
59164 | (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { |
2795 | 59162 | ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512); | |
2796 | } else { | ||
2797 | 3172 | memcpy( out, saved, 448 * sizeof(*out)); | |
2798 | |||
2799 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 1084 times.
|
3172 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2800 | 2088 | ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64); | |
2801 | 2088 | ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64); | |
2802 | 2088 | ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64); | |
2803 | 2088 | ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64); | |
2804 | 2088 | ac->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64); | |
2805 | 2088 | memcpy( out + 448 + 4*128, temp, 64 * sizeof(*out)); | |
2806 | } else { | ||
2807 | 1084 | ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64); | |
2808 | 1084 | memcpy( out + 576, buf + 64, 448 * sizeof(*out)); | |
2809 | } | ||
2810 | } | ||
2811 | |||
2812 | // buffer update | ||
2813 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 60246 times.
|
62334 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2814 | 2088 | memcpy( saved, temp + 64, 64 * sizeof(*saved)); | |
2815 | 2088 | ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64); | |
2816 | 2088 | ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64); | |
2817 | 2088 | ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64); | |
2818 | 2088 | memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved)); | |
2819 |
2/2✓ Branch 0 taken 1217 times.
✓ Branch 1 taken 59029 times.
|
60246 | } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { |
2820 | 1217 | memcpy( saved, buf + 512, 448 * sizeof(*saved)); | |
2821 | 1217 | memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved)); | |
2822 | } else { // LONG_STOP or ONLY_LONG | ||
2823 | 59029 | memcpy( saved, buf + 512, 512 * sizeof(*saved)); | |
2824 | } | ||
2825 | 62334 | } | |
2826 | |||
2827 | /** | ||
2828 | * Conduct IMDCT and windowing. | ||
2829 | */ | ||
2830 | 387 | static void imdct_and_windowing_960(AACContext *ac, SingleChannelElement *sce) | |
2831 | { | ||
2832 | #if !USE_FIXED | ||
2833 | 387 | IndividualChannelStream *ics = &sce->ics; | |
2834 | 387 | INTFLOAT *in = sce->coeffs; | |
2835 | 387 | INTFLOAT *out = sce->ret; | |
2836 | 387 | INTFLOAT *saved = sce->saved; | |
2837 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 373 times.
|
387 | const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120); |
2838 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 373 times.
|
387 | const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_long_960) : AAC_RENAME(sine_960); |
2839 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 373 times.
|
387 | const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120); |
2840 | 387 | INTFLOAT *buf = ac->buf_mdct; | |
2841 | 387 | INTFLOAT *temp = ac->temp; | |
2842 | int i; | ||
2843 | |||
2844 | // imdct | ||
2845 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 386 times.
|
387 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2846 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for (i = 0; i < 8; i++) |
2847 | 8 | ac->mdct120->imdct_half(ac->mdct120, buf + i * 120, in + i * 128, 1); | |
2848 | } else { | ||
2849 | 386 | ac->mdct960->imdct_half(ac->mdct960, buf, in, 1); | |
2850 | } | ||
2851 | |||
2852 | /* window overlapping | ||
2853 | * NOTE: To simplify the overlapping code, all 'meaningless' short to long | ||
2854 | * and long to short transitions are considered to be short to short | ||
2855 | * transitions. This leaves just two cases (long to long and short to short) | ||
2856 | * with a little special sauce for EIGHT_SHORT_SEQUENCE. | ||
2857 | */ | ||
2858 | |||
2859 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
387 | if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && |
2860 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 383 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
385 | (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { |
2861 | 385 | ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 480); | |
2862 | } else { | ||
2863 | 2 | memcpy( out, saved, 420 * sizeof(*out)); | |
2864 | |||
2865 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2866 | 1 | ac->fdsp->vector_fmul_window(out + 420 + 0*120, saved + 420, buf + 0*120, swindow_prev, 60); | |
2867 | 1 | ac->fdsp->vector_fmul_window(out + 420 + 1*120, buf + 0*120 + 60, buf + 1*120, swindow, 60); | |
2868 | 1 | ac->fdsp->vector_fmul_window(out + 420 + 2*120, buf + 1*120 + 60, buf + 2*120, swindow, 60); | |
2869 | 1 | ac->fdsp->vector_fmul_window(out + 420 + 3*120, buf + 2*120 + 60, buf + 3*120, swindow, 60); | |
2870 | 1 | ac->fdsp->vector_fmul_window(temp, buf + 3*120 + 60, buf + 4*120, swindow, 60); | |
2871 | 1 | memcpy( out + 420 + 4*120, temp, 60 * sizeof(*out)); | |
2872 | } else { | ||
2873 | 1 | ac->fdsp->vector_fmul_window(out + 420, saved + 420, buf, swindow_prev, 60); | |
2874 | 1 | memcpy( out + 540, buf + 60, 420 * sizeof(*out)); | |
2875 | } | ||
2876 | } | ||
2877 | |||
2878 | // buffer update | ||
2879 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 386 times.
|
387 | if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
2880 | 1 | memcpy( saved, temp + 60, 60 * sizeof(*saved)); | |
2881 | 1 | ac->fdsp->vector_fmul_window(saved + 60, buf + 4*120 + 60, buf + 5*120, swindow, 60); | |
2882 | 1 | ac->fdsp->vector_fmul_window(saved + 180, buf + 5*120 + 60, buf + 6*120, swindow, 60); | |
2883 | 1 | ac->fdsp->vector_fmul_window(saved + 300, buf + 6*120 + 60, buf + 7*120, swindow, 60); | |
2884 | 1 | memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved)); | |
2885 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 384 times.
|
386 | } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { |
2886 | 2 | memcpy( saved, buf + 480, 420 * sizeof(*saved)); | |
2887 | 2 | memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved)); | |
2888 | } else { // LONG_STOP or ONLY_LONG | ||
2889 | 384 | memcpy( saved, buf + 480, 480 * sizeof(*saved)); | |
2890 | } | ||
2891 | #endif | ||
2892 | 387 | } | |
2893 | 3636 | static void imdct_and_windowing_ld(AACContext *ac, SingleChannelElement *sce) | |
2894 | { | ||
2895 | 3636 | IndividualChannelStream *ics = &sce->ics; | |
2896 | 3636 | INTFLOAT *in = sce->coeffs; | |
2897 | 3636 | INTFLOAT *out = sce->ret; | |
2898 | 3636 | INTFLOAT *saved = sce->saved; | |
2899 | 3636 | INTFLOAT *buf = ac->buf_mdct; | |
2900 | #if USE_FIXED | ||
2901 | int i; | ||
2902 | #endif /* USE_FIXED */ | ||
2903 | |||
2904 | // imdct | ||
2905 | 3636 | ac->mdct.imdct_half(&ac->mdct_ld, buf, in); | |
2906 | |||
2907 | #if USE_FIXED | ||
2908 |
2/2✓ Branch 0 taken 1855488 times.
✓ Branch 1 taken 1812 times.
|
1857300 | for (i = 0; i < 1024; i++) |
2909 | 1855488 | buf[i] = (buf[i] + 2) >> 2; | |
2910 | #endif /* USE_FIXED */ | ||
2911 | |||
2912 | // window overlapping | ||
2913 |
2/2✓ Branch 0 taken 62 times.
✓ Branch 1 taken 3574 times.
|
3636 | if (ics->use_kb_window[1]) { |
2914 | // AAC LD uses a low overlap sine window instead of a KBD window | ||
2915 | 62 | memcpy(out, saved, 192 * sizeof(*out)); | |
2916 | 62 | ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, AAC_RENAME2(sine_128), 64); | |
2917 | 62 | memcpy( out + 320, buf + 64, 192 * sizeof(*out)); | |
2918 | } else { | ||
2919 | 3574 | ac->fdsp->vector_fmul_window(out, saved, buf, AAC_RENAME2(sine_512), 256); | |
2920 | } | ||
2921 | |||
2922 | // buffer update | ||
2923 | 3636 | memcpy(saved, buf + 256, 256 * sizeof(*saved)); | |
2924 | 3636 | } | |
2925 | |||
2926 | 26598 | static void imdct_and_windowing_eld(AACContext *ac, SingleChannelElement *sce) | |
2927 | { | ||
2928 | 26598 | UINTFLOAT *in = sce->coeffs; | |
2929 | 26598 | INTFLOAT *out = sce->ret; | |
2930 | 26598 | INTFLOAT *saved = sce->saved; | |
2931 | 26598 | INTFLOAT *buf = ac->buf_mdct; | |
2932 | int i; | ||
2933 |
2/2✓ Branch 0 taken 7118 times.
✓ Branch 1 taken 19480 times.
|
26598 | const int n = ac->oc[1].m4ac.frame_length_short ? 480 : 512; |
2934 | 26598 | const int n2 = n >> 1; | |
2935 | 26598 | const int n4 = n >> 2; | |
2936 |
2/2✓ Branch 0 taken 7118 times.
✓ Branch 1 taken 19480 times.
|
26598 | const INTFLOAT *const window = n == 480 ? AAC_RENAME(ff_aac_eld_window_480) : |
2937 | AAC_RENAME(ff_aac_eld_window_512); | ||
2938 | |||
2939 | // Inverse transform, mapped to the conventional IMDCT by | ||
2940 | // Chivukula, R.K.; Reznik, Y.A.; Devarajan, V., | ||
2941 | // "Efficient algorithms for MPEG-4 AAC-ELD, AAC-LD and AAC-LC filterbanks," | ||
2942 | // International Conference on Audio, Language and Image Processing, ICALIP 2008. | ||
2943 | // URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4590245&isnumber=4589950 | ||
2944 |
2/2✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
|
3374198 | for (i = 0; i < n2; i+=2) { |
2945 | INTFLOAT temp; | ||
2946 | 3347600 | temp = in[i ]; in[i ] = -in[n - 1 - i]; in[n - 1 - i] = temp; | |
2947 | 3347600 | temp = -in[i + 1]; in[i + 1] = in[n - 2 - i]; in[n - 2 - i] = temp; | |
2948 | } | ||
2949 | #if !USE_FIXED | ||
2950 |
2/2✓ Branch 0 taken 7118 times.
✓ Branch 1 taken 9743 times.
|
16861 | if (n == 480) |
2951 | 7118 | ac->mdct480->imdct_half(ac->mdct480, buf, in, 1); | |
2952 | else | ||
2953 | #endif | ||
2954 | 19480 | ac->mdct.imdct_half(&ac->mdct_ld, buf, in); | |
2955 | |||
2956 | #if USE_FIXED | ||
2957 |
2/2✓ Branch 0 taken 9970688 times.
✓ Branch 1 taken 9737 times.
|
9980425 | for (i = 0; i < 1024; i++) |
2958 | 9970688 | buf[i] = (buf[i] + 1) >> 1; | |
2959 | #endif /* USE_FIXED */ | ||
2960 | |||
2961 |
2/2✓ Branch 0 taken 6695200 times.
✓ Branch 1 taken 26598 times.
|
6721798 | for (i = 0; i < n; i+=2) { |
2962 | 6695200 | buf[i] = -buf[i]; | |
2963 | } | ||
2964 | // Like with the regular IMDCT at this point we still have the middle half | ||
2965 | // of a transform but with even symmetry on the left and odd symmetry on | ||
2966 | // the right | ||
2967 | |||
2968 | // window overlapping | ||
2969 | // The spec says to use samples [0..511] but the reference decoder uses | ||
2970 | // samples [128..639]. | ||
2971 |
2/2✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
|
3374198 | for (i = n4; i < n2; i ++) { |
2972 | 3347600 | out[i - n4] = AAC_MUL31( buf[ n2 - 1 - i] , window[i - n4]) + | |
2973 | 3347600 | AAC_MUL31( saved[ i + n2] , window[i + n - n4]) + | |
2974 | 3347600 | AAC_MUL31(-saved[n + n2 - 1 - i] , window[i + 2*n - n4]) + | |
2975 | 3347600 | AAC_MUL31(-saved[ 2*n + n2 + i] , window[i + 3*n - n4]); | |
2976 | } | ||
2977 |
2/2✓ Branch 0 taken 6695200 times.
✓ Branch 1 taken 26598 times.
|
6721798 | for (i = 0; i < n2; i ++) { |
2978 | 6695200 | out[n4 + i] = AAC_MUL31( buf[ i] , window[i + n2 - n4]) + | |
2979 | 6695200 | AAC_MUL31(-saved[ n - 1 - i] , window[i + n2 + n - n4]) + | |
2980 | 6695200 | AAC_MUL31(-saved[ n + i] , window[i + n2 + 2*n - n4]) + | |
2981 | 6695200 | AAC_MUL31( saved[2*n + n - 1 - i] , window[i + n2 + 3*n - n4]); | |
2982 | } | ||
2983 |
2/2✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
|
3374198 | for (i = 0; i < n4; i ++) { |
2984 | 3347600 | out[n2 + n4 + i] = AAC_MUL31( buf[ i + n2] , window[i + n - n4]) + | |
2985 | 3347600 | AAC_MUL31(-saved[n2 - 1 - i] , window[i + 2*n - n4]) + | |
2986 | 3347600 | AAC_MUL31(-saved[n + n2 + i] , window[i + 3*n - n4]); | |
2987 | } | ||
2988 | |||
2989 | // buffer update | ||
2990 | 26598 | memmove(saved + n, saved, 2 * n * sizeof(*saved)); | |
2991 | 26598 | memcpy( saved, buf, n * sizeof(*saved)); | |
2992 | 26598 | } | |
2993 | |||
2994 | /** | ||
2995 | * channel coupling transformation interface | ||
2996 | * | ||
2997 | * @param apply_coupling_method pointer to (in)dependent coupling function | ||
2998 | */ | ||
2999 | 176290 | static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, | |
3000 | enum RawDataBlockType type, int elem_id, | ||
3001 | enum CouplingPoint coupling_point, | ||
3002 | void (*apply_coupling_method)(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)) | ||
3003 | { | ||
3004 | int i, c; | ||
3005 | |||
3006 |
2/2✓ Branch 0 taken 2820640 times.
✓ Branch 1 taken 176290 times.
|
2996930 | for (i = 0; i < MAX_ELEM_ID; i++) { |
3007 | 2820640 | ChannelElement *cce = ac->che[TYPE_CCE][i]; | |
3008 | 2820640 | int index = 0; | |
3009 | |||
3010 |
4/4✓ Branch 0 taken 11740 times.
✓ Branch 1 taken 2808900 times.
✓ Branch 2 taken 3915 times.
✓ Branch 3 taken 7825 times.
|
2820640 | if (cce && cce->coup.coupling_point == coupling_point) { |
3011 | 3915 | ChannelCoupling *coup = &cce->coup; | |
3012 | |||
3013 |
2/2✓ Branch 0 taken 9402 times.
✓ Branch 1 taken 3915 times.
|
13317 | for (c = 0; c <= coup->num_coupled; c++) { |
3014 |
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) { |
3015 |
2/2✓ Branch 0 taken 2561 times.
✓ Branch 1 taken 180 times.
|
2741 | if (coup->ch_select[c] != 1) { |
3016 | 2561 | apply_coupling_method(ac, &cc->ch[0], cce, index); | |
3017 |
1/2✓ Branch 0 taken 2561 times.
✗ Branch 1 not taken.
|
2561 | if (coup->ch_select[c] != 0) |
3018 | 2561 | index++; | |
3019 | } | ||
3020 |
2/2✓ Branch 0 taken 2147 times.
✓ Branch 1 taken 594 times.
|
2741 | if (coup->ch_select[c] != 2) |
3021 | 2147 | apply_coupling_method(ac, &cc->ch[1], cce, index++); | |
3022 | } else | ||
3023 |
2/2✓ Branch 0 taken 4720 times.
✓ Branch 1 taken 1941 times.
|
6661 | index += 1 + (coup->ch_select[c] == 3); |
3024 | } | ||
3025 | } | ||
3026 | } | ||
3027 | 176290 | } | |
3028 | |||
3029 | /** | ||
3030 | * Convert spectral data to samples, applying all supported tools as appropriate. | ||
3031 | */ | ||
3032 | 50004 | static void spectral_to_sample(AACContext *ac, int samples) | |
3033 | { | ||
3034 | int i, type; | ||
3035 | void (*imdct_and_window)(AACContext *ac, SingleChannelElement *sce); | ||
3036 |
3/3✓ Branch 0 taken 606 times.
✓ Branch 1 taken 16365 times.
✓ Branch 2 taken 33033 times.
|
50004 | switch (ac->oc[1].m4ac.object_type) { |
3037 | 606 | case AOT_ER_AAC_LD: | |
3038 | 606 | imdct_and_window = imdct_and_windowing_ld; | |
3039 | 606 | break; | |
3040 | 16365 | case AOT_ER_AAC_ELD: | |
3041 | 16365 | imdct_and_window = imdct_and_windowing_eld; | |
3042 | 16365 | break; | |
3043 | 33033 | default: | |
3044 |
2/2✓ Branch 0 taken 387 times.
✓ Branch 1 taken 32646 times.
|
33033 | if (ac->oc[1].m4ac.frame_length_short) |
3045 | 387 | imdct_and_window = imdct_and_windowing_960; | |
3046 | else | ||
3047 | 32646 | imdct_and_window = ac->imdct_and_windowing; | |
3048 | } | ||
3049 |
2/2✓ Branch 0 taken 200016 times.
✓ Branch 1 taken 50004 times.
|
250020 | for (type = 3; type >= 0; type--) { |
3050 |
2/2✓ Branch 0 taken 3200256 times.
✓ Branch 1 taken 200016 times.
|
3400272 | for (i = 0; i < MAX_ELEM_ID; i++) { |
3051 | 3200256 | ChannelElement *che = ac->che[type][i]; | |
3052 |
4/4✓ Branch 0 taken 63379 times.
✓ Branch 1 taken 3136877 times.
✓ Branch 2 taken 63050 times.
✓ Branch 3 taken 329 times.
|
3200256 | if (che && che->present) { |
3053 |
2/2✓ Branch 0 taken 58372 times.
✓ Branch 1 taken 4678 times.
|
63050 | if (type <= TYPE_CPE) |
3054 | 58372 | apply_channel_coupling(ac, che, type, i, BEFORE_TNS, AAC_RENAME(apply_dependent_coupling)); | |
3055 |
2/2✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 61266 times.
|
63050 | if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) { |
3056 |
2/2✓ Branch 0 taken 538 times.
✓ Branch 1 taken 1246 times.
|
1784 | if (che->ch[0].ics.predictor_present) { |
3057 |
2/2✓ Branch 0 taken 382 times.
✓ Branch 1 taken 156 times.
|
538 | if (che->ch[0].ics.ltp.present) |
3058 | 382 | ac->apply_ltp(ac, &che->ch[0]); | |
3059 |
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) |
3060 | 404 | ac->apply_ltp(ac, &che->ch[1]); | |
3061 | } | ||
3062 | } | ||
3063 |
2/2✓ Branch 0 taken 4633 times.
✓ Branch 1 taken 58417 times.
|
63050 | if (che->ch[0].tns.present) |
3064 | 4633 | ac->apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); | |
3065 |
2/2✓ Branch 0 taken 2294 times.
✓ Branch 1 taken 60756 times.
|
63050 | if (che->ch[1].tns.present) |
3066 | 2294 | ac->apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); | |
3067 |
2/2✓ Branch 0 taken 58372 times.
✓ Branch 1 taken 4678 times.
|
63050 | if (type <= TYPE_CPE) |
3068 | 58372 | apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, AAC_RENAME(apply_dependent_coupling)); | |
3069 |
4/4✓ Branch 0 taken 1174 times.
✓ Branch 1 taken 61876 times.
✓ Branch 2 taken 393 times.
✓ Branch 3 taken 781 times.
|
63050 | if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { |
3070 | 62269 | imdct_and_window(ac, &che->ch[0]); | |
3071 |
2/2✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 60485 times.
|
62269 | if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) |
3072 | 1784 | ac->update_ltp(ac, &che->ch[0]); | |
3073 |
2/2✓ Branch 0 taken 30686 times.
✓ Branch 1 taken 31583 times.
|
62269 | if (type == TYPE_CPE) { |
3074 | 30686 | imdct_and_window(ac, &che->ch[1]); | |
3075 |
2/2✓ Branch 0 taken 1784 times.
✓ Branch 1 taken 28902 times.
|
30686 | if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) |
3076 | 1784 | ac->update_ltp(ac, &che->ch[1]); | |
3077 | } | ||
3078 |
2/2✓ Branch 0 taken 12411 times.
✓ Branch 1 taken 49858 times.
|
62269 | if (ac->oc[1].m4ac.sbr > 0) { |
3079 | 12411 | AAC_RENAME(ff_sbr_apply)(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret); | |
3080 | } | ||
3081 | } | ||
3082 |
2/2✓ Branch 0 taken 59546 times.
✓ Branch 1 taken 3504 times.
|
63050 | if (type <= TYPE_CCE) |
3083 | 59546 | apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, AAC_RENAME(apply_independent_coupling)); | |
3084 | |||
3085 | #if USE_FIXED | ||
3086 | { | ||
3087 | int j; | ||
3088 | /* preparation for resampler */ | ||
3089 |
2/2✓ Branch 0 taken 19882496 times.
✓ Branch 1 taken 19451 times.
|
19901947 | for(j = 0; j<samples; j++){ |
3090 | 19882496 | che->ch[0].ret[j] = (int32_t)av_clip64((int64_t)che->ch[0].ret[j]*128, INT32_MIN, INT32_MAX-0x8000)+0x8000; | |
3091 |
2/2✓ Branch 0 taken 9935872 times.
✓ Branch 1 taken 9946624 times.
|
19882496 | if(type == TYPE_CPE) |
3092 | 9935872 | che->ch[1].ret[j] = (int32_t)av_clip64((int64_t)che->ch[1].ret[j]*128, INT32_MIN, INT32_MAX-0x8000)+0x8000; | |
3093 | } | ||
3094 | } | ||
3095 | #endif /* USE_FIXED */ | ||
3096 | 63050 | che->present = 0; | |
3097 |
2/2✓ Branch 0 taken 329 times.
✓ Branch 1 taken 3136877 times.
|
3137206 | } else if (che) { |
3098 | 329 | av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i); | |
3099 | } | ||
3100 | } | ||
3101 | } | ||
3102 | 50004 | } | |
3103 | |||
3104 | 4112 | static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) | |
3105 | { | ||
3106 | int size; | ||
3107 | AACADTSHeaderInfo hdr_info; | ||
3108 | uint8_t layout_map[MAX_ELEM_ID*4][3]; | ||
3109 | int layout_map_tags, ret; | ||
3110 | |||
3111 | 4112 | size = ff_adts_header_parse(gb, &hdr_info); | |
3112 |
1/2✓ Branch 0 taken 4112 times.
✗ Branch 1 not taken.
|
4112 | if (size > 0) { |
3113 |
2/4✓ Branch 0 taken 4112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4112 times.
|
4112 | if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) { |
3114 | // This is 2 for "VLB " audio in NSV files. | ||
3115 | // See samples/nsv/vlb_audio. | ||
3116 | ✗ | avpriv_report_missing_feature(ac->avctx, | |
3117 | "More than one AAC RDB per ADTS frame"); | ||
3118 | ✗ | ac->warned_num_aac_frames = 1; | |
3119 | } | ||
3120 | 4112 | push_output_configuration(ac); | |
3121 |
1/2✓ Branch 0 taken 4112 times.
✗ Branch 1 not taken.
|
4112 | if (hdr_info.chan_config) { |
3122 | 4112 | ac->oc[1].m4ac.chan_config = hdr_info.chan_config; | |
3123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4112 times.
|
4112 | if ((ret = set_default_channel_config(ac, ac->avctx, |
3124 | layout_map, | ||
3125 | &layout_map_tags, | ||
3126 | 4112 | hdr_info.chan_config)) < 0) | |
3127 | ✗ | return ret; | |
3128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4112 times.
|
4112 | if ((ret = output_configure(ac, layout_map, layout_map_tags, |
3129 | 4112 | FFMAX(ac->oc[1].status, | |
3130 | OC_TRIAL_FRAME), 0)) < 0) | ||
3131 | ✗ | return ret; | |
3132 | } else { | ||
3133 | ✗ | ac->oc[1].m4ac.chan_config = 0; | |
3134 | /** | ||
3135 | * dual mono frames in Japanese DTV can have chan_config 0 | ||
3136 | * WITHOUT specifying PCE. | ||
3137 | * thus, set dual mono as default. | ||
3138 | */ | ||
3139 | ✗ | if (ac->dmono_mode && ac->oc[0].status == OC_NONE) { | |
3140 | ✗ | layout_map_tags = 2; | |
3141 | ✗ | layout_map[0][0] = layout_map[1][0] = TYPE_SCE; | |
3142 | ✗ | layout_map[0][2] = layout_map[1][2] = AAC_CHANNEL_FRONT; | |
3143 | ✗ | layout_map[0][1] = 0; | |
3144 | ✗ | layout_map[1][1] = 1; | |
3145 | ✗ | if (output_configure(ac, layout_map, layout_map_tags, | |
3146 | OC_TRIAL_FRAME, 0)) | ||
3147 | ✗ | return -7; | |
3148 | } | ||
3149 | } | ||
3150 | 4112 | ac->oc[1].m4ac.sample_rate = hdr_info.sample_rate; | |
3151 | 4112 | ac->oc[1].m4ac.sampling_index = hdr_info.sampling_index; | |
3152 | 4112 | ac->oc[1].m4ac.object_type = hdr_info.object_type; | |
3153 | 4112 | ac->oc[1].m4ac.frame_length_short = 0; | |
3154 |
2/2✓ Branch 0 taken 4058 times.
✓ Branch 1 taken 54 times.
|
4112 | if (ac->oc[0].status != OC_LOCKED || |
3155 |
1/2✓ Branch 0 taken 4058 times.
✗ Branch 1 not taken.
|
4058 | ac->oc[0].m4ac.chan_config != hdr_info.chan_config || |
3156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4058 times.
|
4058 | ac->oc[0].m4ac.sample_rate != hdr_info.sample_rate) { |
3157 | 54 | ac->oc[1].m4ac.sbr = -1; | |
3158 | 54 | ac->oc[1].m4ac.ps = -1; | |
3159 | } | ||
3160 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4111 times.
|
4112 | if (!hdr_info.crc_absent) |
3161 | 1 | skip_bits(gb, 16); | |
3162 | } | ||
3163 | 4112 | return size; | |
3164 | } | ||
3165 | |||
3166 | 16971 | static int aac_decode_er_frame(AVCodecContext *avctx, void *data, | |
3167 | int *got_frame_ptr, GetBitContext *gb) | ||
3168 | { | ||
3169 | 16971 | AACContext *ac = avctx->priv_data; | |
3170 | 16971 | const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac; | |
3171 | ChannelElement *che; | ||
3172 | int err, i; | ||
3173 |
2/2✓ Branch 0 taken 3559 times.
✓ Branch 1 taken 13412 times.
|
16971 | int samples = m4ac->frame_length_short ? 960 : 1024; |
3174 | 16971 | int chan_config = m4ac->chan_config; | |
3175 | 16971 | int aot = m4ac->object_type; | |
3176 | |||
3177 |
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) |
3178 | 16971 | samples >>= 1; | |
3179 | |||
3180 | 16971 | ac->frame = data; | |
3181 | |||
3182 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16971 times.
|
16971 | if ((err = frame_configure_elements(avctx)) < 0) |
3183 | ✗ | return err; | |
3184 | |||
3185 | // The FF_PROFILE_AAC_* defines are all object_type - 1 | ||
3186 | // This may lead to an undefined profile being signaled | ||
3187 | 16971 | ac->avctx->profile = aot - 1; | |
3188 | |||
3189 | 16971 | ac->tags_mapped = 0; | |
3190 | |||
3191 |
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) { |
3192 | ✗ | avpriv_request_sample(avctx, "Unknown ER channel configuration %d", | |
3193 | chan_config); | ||
3194 | ✗ | return AVERROR_INVALIDDATA; | |
3195 | } | ||
3196 |
2/2✓ Branch 0 taken 18789 times.
✓ Branch 1 taken 16971 times.
|
35760 | for (i = 0; i < tags_per_config[chan_config]; i++) { |
3197 | 18789 | const int elem_type = aac_channel_layout_map[chan_config-1][i][0]; | |
3198 | 18789 | const int elem_id = aac_channel_layout_map[chan_config-1][i][1]; | |
3199 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18789 times.
|
18789 | if (!(che=get_che(ac, elem_type, elem_id))) { |
3200 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, | |
3201 | "channel element %d.%d is not allocated\n", | ||
3202 | elem_type, elem_id); | ||
3203 | ✗ | return AVERROR_INVALIDDATA; | |
3204 | } | ||
3205 | 18789 | che->present = 1; | |
3206 |
2/2✓ Branch 0 taken 2424 times.
✓ Branch 1 taken 16365 times.
|
18789 | if (aot != AOT_ER_AAC_ELD) |
3207 | 2424 | skip_bits(gb, 4); | |
3208 |
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) { |
3209 | 6738 | case TYPE_SCE: | |
3210 | 6738 | err = decode_ics(ac, &che->ch[0], gb, 0, 0); | |
3211 | 6738 | break; | |
3212 | 11445 | case TYPE_CPE: | |
3213 | 11445 | err = decode_cpe(ac, gb, che); | |
3214 | 11445 | break; | |
3215 | 606 | case TYPE_LFE: | |
3216 | 606 | err = decode_ics(ac, &che->ch[0], gb, 0, 0); | |
3217 | 606 | break; | |
3218 | } | ||
3219 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18789 times.
|
18789 | if (err < 0) |
3220 | ✗ | return err; | |
3221 | } | ||
3222 | |||
3223 | 16971 | spectral_to_sample(ac, samples); | |
3224 | |||
3225 |
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) { |
3226 | ✗ | av_log(avctx, AV_LOG_ERROR, "no frame data found\n"); | |
3227 | ✗ | return AVERROR_INVALIDDATA; | |
3228 | } | ||
3229 | |||
3230 | 16971 | ac->frame->nb_samples = samples; | |
3231 | 16971 | ac->frame->sample_rate = avctx->sample_rate; | |
3232 | 16971 | *got_frame_ptr = 1; | |
3233 | |||
3234 | 16971 | skip_bits_long(gb, get_bits_left(gb)); | |
3235 | 16971 | return 0; | |
3236 | } | ||
3237 | |||
3238 | 33033 | static int aac_decode_frame_int(AVCodecContext *avctx, AVFrame *frame, | |
3239 | int *got_frame_ptr, GetBitContext *gb, | ||
3240 | const AVPacket *avpkt) | ||
3241 | { | ||
3242 | 33033 | AACContext *ac = avctx->priv_data; | |
3243 | 33033 | ChannelElement *che = NULL, *che_prev = NULL; | |
3244 | 33033 | enum RawDataBlockType elem_type, che_prev_type = TYPE_END; | |
3245 | int err, elem_id; | ||
3246 | 33033 | int samples = 0, multiplier, audio_found = 0, pce_found = 0; | |
3247 | 33033 | int is_dmono, sce_count = 0; | |
3248 | int payload_alignment; | ||
3249 | 33033 | uint8_t che_presence[4][MAX_ELEM_ID] = {{0}}; | |
3250 | |||
3251 | 33033 | ac->frame = frame; | |
3252 | |||
3253 |
2/2✓ Branch 1 taken 4112 times.
✓ Branch 2 taken 28921 times.
|
33033 | if (show_bits(gb, 12) == 0xfff) { |
3254 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4112 times.
|
4112 | if ((err = parse_adts_frame_header(ac, gb)) < 0) { |
3255 | ✗ | av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); | |
3256 | ✗ | goto fail; | |
3257 | } | ||
3258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4112 times.
|
4112 | if (ac->oc[1].m4ac.sampling_index > 12) { |
3259 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->oc[1].m4ac.sampling_index); | |
3260 | ✗ | err = AVERROR_INVALIDDATA; | |
3261 | ✗ | goto fail; | |
3262 | } | ||
3263 | } | ||
3264 | |||
3265 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 33033 times.
|
33033 | if ((err = frame_configure_elements(avctx)) < 0) |
3266 | ✗ | goto fail; | |
3267 | |||
3268 | // The FF_PROFILE_AAC_* defines are all object_type - 1 | ||
3269 | // This may lead to an undefined profile being signaled | ||
3270 | 33033 | ac->avctx->profile = ac->oc[1].m4ac.object_type - 1; | |
3271 | |||
3272 | 33033 | payload_alignment = get_bits_count(gb); | |
3273 | 33033 | ac->tags_mapped = 0; | |
3274 | // parse | ||
3275 |
2/2✓ Branch 1 taken 72301 times.
✓ Branch 2 taken 33033 times.
|
105334 | while ((elem_type = get_bits(gb, 3)) != TYPE_END) { |
3276 | 72301 | elem_id = get_bits(gb, 4); | |
3277 | |||
3278 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72301 times.
|
72301 | if (avctx->debug & FF_DEBUG_STARTCODE) |
3279 | ✗ | av_log(avctx, AV_LOG_DEBUG, "Elem type:%x id:%x\n", elem_type, elem_id); | |
3280 | |||
3281 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 72301 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
72301 | if (!avctx->ch_layout.nb_channels && elem_type != TYPE_PCE) { |
3282 | ✗ | err = AVERROR_INVALIDDATA; | |
3283 | ✗ | goto fail; | |
3284 | } | ||
3285 | |||
3286 |
2/2✓ Branch 0 taken 44261 times.
✓ Branch 1 taken 28040 times.
|
72301 | if (elem_type < TYPE_DSE) { |
3287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44261 times.
|
44261 | if (che_presence[elem_type][elem_id]) { |
3288 | ✗ | int error = che_presence[elem_type][elem_id] > 1; | |
3289 | ✗ | av_log(ac->avctx, error ? AV_LOG_ERROR : AV_LOG_DEBUG, "channel element %d.%d duplicate\n", | |
3290 | elem_type, elem_id); | ||
3291 | ✗ | if (error) { | |
3292 | ✗ | err = AVERROR_INVALIDDATA; | |
3293 | ✗ | goto fail; | |
3294 | } | ||
3295 | } | ||
3296 | 44261 | che_presence[elem_type][elem_id]++; | |
3297 | |||
3298 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 44261 times.
|
44261 | if (!(che=get_che(ac, elem_type, elem_id))) { |
3299 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", | |
3300 | elem_type, elem_id); | ||
3301 | ✗ | err = AVERROR_INVALIDDATA; | |
3302 | ✗ | goto fail; | |
3303 | } | ||
3304 |
2/2✓ Branch 0 taken 387 times.
✓ Branch 1 taken 43874 times.
|
44261 | samples = ac->oc[1].m4ac.frame_length_short ? 960 : 1024; |
3305 | 44261 | che->present = 1; | |
3306 | } | ||
3307 | |||
3308 |
6/8✓ Branch 0 taken 20948 times.
✓ Branch 1 taken 19241 times.
✓ Branch 2 taken 1174 times.
✓ Branch 3 taken 2898 times.
✓ Branch 4 taken 2821 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 25219 times.
✗ Branch 7 not taken.
|
72301 | switch (elem_type) { |
3309 | |||
3310 | 20948 | case TYPE_SCE: | |
3311 | 20948 | err = decode_ics(ac, &che->ch[0], gb, 0, 0); | |
3312 | 20948 | audio_found = 1; | |
3313 | 20948 | sce_count++; | |
3314 | 20948 | break; | |
3315 | |||
3316 | 19241 | case TYPE_CPE: | |
3317 | 19241 | err = decode_cpe(ac, gb, che); | |
3318 | 19241 |