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