| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * AAC decoder | ||
| 3 | * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) | ||
| 4 | * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) | ||
| 5 | * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com> | ||
| 6 | * | ||
| 7 | * AAC LATM decoder | ||
| 8 | * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz> | ||
| 9 | * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net> | ||
| 10 | * | ||
| 11 | * AAC decoder fixed-point implementation | ||
| 12 | * Copyright (c) 2013 | ||
| 13 | * MIPS Technologies, Inc., California. | ||
| 14 | * | ||
| 15 | * This file is part of FFmpeg. | ||
| 16 | * | ||
| 17 | * FFmpeg is free software; you can redistribute it and/or | ||
| 18 | * modify it under the terms of the GNU Lesser General Public | ||
| 19 | * License as published by the Free Software Foundation; either | ||
| 20 | * version 2.1 of the License, or (at your option) any later version. | ||
| 21 | * | ||
| 22 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 25 | * Lesser General Public License for more details. | ||
| 26 | * | ||
| 27 | * You should have received a copy of the GNU Lesser General Public | ||
| 28 | * License along with FFmpeg; if not, write to the Free Software | ||
| 29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 30 | */ | ||
| 31 | |||
| 32 | /** | ||
| 33 | * linear congruential pseudorandom number generator | ||
| 34 | * | ||
| 35 | * @param previous_val pointer to the current state of the generator | ||
| 36 | * | ||
| 37 | * @return Returns a 32-bit pseudorandom integer | ||
| 38 | */ | ||
| 39 | 5952828 | static av_always_inline int lcg_random(unsigned previous_val) | |
| 40 | { | ||
| 41 | 5952828 | union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 }; | |
| 42 | 5952828 | return v.s; | |
| 43 | } | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Decode spectral data; reference: table 4.50. | ||
| 47 | * Dequantize and scale spectral data; reference: 4.6.3.3. | ||
| 48 | * | ||
| 49 | * @param coef array of dequantized, scaled spectral data | ||
| 50 | * @param sf array of scalefactors or intensity stereo positions | ||
| 51 | * @param pulse_present set if pulses are present | ||
| 52 | * @param pulse pointer to pulse data struct | ||
| 53 | * @param band_type array of the used band type | ||
| 54 | * | ||
| 55 | * @return Returns error status. 0 - OK, !0 - error | ||
| 56 | */ | ||
| 57 | 93155 | static int AAC_RENAME(decode_spectrum_and_dequant)(AACDecContext *ac, | |
| 58 | GetBitContext *gb, | ||
| 59 | const Pulse *pulse, | ||
| 60 | SingleChannelElement *sce) | ||
| 61 | { | ||
| 62 | 93155 | int i, k, g, idx = 0; | |
| 63 | 93155 | INTFLOAT *coef = sce->AAC_RENAME(coeffs); | |
| 64 | 93155 | IndividualChannelStream *ics = &sce->ics; | |
| 65 | 93155 | const int c = 1024 / ics->num_windows; | |
| 66 | 93155 | const uint16_t *offsets = ics->swb_offset; | |
| 67 | 93155 | const INTFLOAT *sf = sce->AAC_RENAME(sf); | |
| 68 | 93155 | const enum BandType *band_type = sce->band_type; | |
| 69 | 93155 | INTFLOAT *coef_base = coef; | |
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 107470 times.
✓ Branch 1 taken 93155 times.
|
200625 | for (g = 0; g < ics->num_windows; g++) |
| 72 | 107470 | memset(coef + g * 128 + offsets[ics->max_sfb], 0, | |
| 73 | 107470 | sizeof(INTFLOAT) * (c - offsets[ics->max_sfb])); | |
| 74 | |||
| 75 |
2/2✓ Branch 0 taken 98252 times.
✓ Branch 1 taken 93155 times.
|
191407 | for (g = 0; g < ics->num_window_groups; g++) { |
| 76 | 98252 | unsigned g_len = ics->group_len[g]; | |
| 77 | |||
| 78 |
2/2✓ Branch 0 taken 3438229 times.
✓ Branch 1 taken 98252 times.
|
3536481 | for (i = 0; i < ics->max_sfb; i++, idx++) { |
| 79 | 3438229 | const unsigned cbt_m1 = band_type[idx] - 1; | |
| 80 | 3438229 | INTFLOAT *cfo = coef + offsets[i]; | |
| 81 | 3438229 | int off_len = offsets[i + 1] - offsets[i]; | |
| 82 | int group; | ||
| 83 | |||
| 84 |
2/2✓ Branch 0 taken 602039 times.
✓ Branch 1 taken 2836190 times.
|
3438229 | if (cbt_m1 >= INTENSITY_BT2 - 1) { |
| 85 |
2/2✓ Branch 0 taken 639809 times.
✓ Branch 1 taken 602039 times.
|
1241848 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
| 86 | 639809 | memset(cfo, 0, off_len * sizeof(*cfo)); | |
| 87 | } | ||
| 88 |
2/2✓ Branch 0 taken 281913 times.
✓ Branch 1 taken 2554277 times.
|
2836190 | } else if (cbt_m1 == NOISE_BT - 1) { |
| 89 |
2/2✓ Branch 0 taken 281932 times.
✓ Branch 1 taken 281913 times.
|
563845 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
| 90 | INTFLOAT band_energy; | ||
| 91 | #if USE_FIXED | ||
| 92 |
2/2✓ Branch 0 taken 2883476 times.
✓ Branch 1 taken 137931 times.
|
3021407 | for (k = 0; k < off_len; k++) { |
| 93 | 2883476 | ac->random_state = lcg_random(ac->random_state); | |
| 94 | 2883476 | cfo[k] = ac->random_state >> 3; | |
| 95 | } | ||
| 96 | |||
| 97 | 137931 | band_energy = ac->fdsp->scalarproduct_fixed(cfo, cfo, off_len); | |
| 98 | 137931 | band_energy = fixed_sqrt(band_energy, 31); | |
| 99 | 137931 | noise_scale(cfo, sf[idx], band_energy, off_len); | |
| 100 | #else | ||
| 101 | float scale; | ||
| 102 | |||
| 103 |
2/2✓ Branch 0 taken 3069352 times.
✓ Branch 1 taken 144001 times.
|
3213353 | for (k = 0; k < off_len; k++) { |
| 104 | 3069352 | ac->random_state = lcg_random(ac->random_state); | |
| 105 | 3069352 | cfo[k] = ac->random_state; | |
| 106 | } | ||
| 107 | |||
| 108 | 144001 | band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len); | |
| 109 | 144001 | scale = sf[idx] / sqrtf(band_energy); | |
| 110 | 144001 | ac->fdsp->vector_fmul_scalar(cfo, cfo, scale, off_len); | |
| 111 | #endif /* USE_FIXED */ | ||
| 112 | } | ||
| 113 | } else { | ||
| 114 | #if !USE_FIXED | ||
| 115 | 1771050 | const float *vq = ff_aac_codebook_vector_vals[cbt_m1]; | |
| 116 | #endif /* !USE_FIXED */ | ||
| 117 | 2554277 | const VLCElem *vlc_tab = ff_vlc_spectral[cbt_m1]; | |
| 118 | 2554277 | OPEN_READER(re, gb); | |
| 119 | |||
| 120 |
5/5✓ Branch 0 taken 613148 times.
✓ Branch 1 taken 569290 times.
✓ Branch 2 taken 395290 times.
✓ Branch 3 taken 540080 times.
✓ Branch 4 taken 436469 times.
|
2554277 | switch (cbt_m1 >> 1) { |
| 121 | 613148 | case 0: | |
| 122 |
2/2✓ Branch 0 taken 640052 times.
✓ Branch 1 taken 613148 times.
|
1253200 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
| 123 | 640052 | INTFLOAT *cf = cfo; | |
| 124 | 640052 | int len = off_len; | |
| 125 | |||
| 126 | do { | ||
| 127 | int code; | ||
| 128 | unsigned cb_idx; | ||
| 129 | |||
| 130 | 3152657 | UPDATE_CACHE(re, gb); | |
| 131 |
2/2✓ Branch 1 taken 107433 times.
✓ Branch 2 taken 3045224 times.
|
3152657 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
| 132 | 3152657 | cb_idx = code; | |
| 133 | #if USE_FIXED | ||
| 134 | 996762 | cf = DEC_SQUAD(cf, cb_idx); | |
| 135 | #else | ||
| 136 | 2155895 | cf = VMUL4(cf, vq, cb_idx, sf + idx); | |
| 137 | #endif /* USE_FIXED */ | ||
| 138 |
2/2✓ Branch 0 taken 2512605 times.
✓ Branch 1 taken 640052 times.
|
3152657 | } while (len -= 4); |
| 139 | } | ||
| 140 | 613148 | break; | |
| 141 | |||
| 142 | 569290 | case 1: | |
| 143 |
2/2✓ Branch 0 taken 581527 times.
✓ Branch 1 taken 569290 times.
|
1150817 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
| 144 | 581527 | INTFLOAT *cf = cfo; | |
| 145 | 581527 | int len = off_len; | |
| 146 | |||
| 147 | do { | ||
| 148 | int code; | ||
| 149 | unsigned nnz; | ||
| 150 | unsigned cb_idx; | ||
| 151 | uint32_t bits; | ||
| 152 | |||
| 153 | 2579921 | UPDATE_CACHE(re, gb); | |
| 154 |
2/2✓ Branch 1 taken 92855 times.
✓ Branch 2 taken 2487066 times.
|
2579921 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
| 155 | 2579921 | cb_idx = code; | |
| 156 | 2579921 | nnz = cb_idx >> 8 & 15; | |
| 157 |
2/2✓ Branch 0 taken 1689511 times.
✓ Branch 1 taken 890410 times.
|
2579921 | bits = nnz ? GET_CACHE(re, gb) : 0; |
| 158 | 2579921 | LAST_SKIP_BITS(re, gb, nnz); | |
| 159 | #if USE_FIXED | ||
| 160 | 826740 | cf = DEC_UQUAD(cf, cb_idx, bits); | |
| 161 | #else | ||
| 162 | 1753181 | cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx); | |
| 163 | #endif /* USE_FIXED */ | ||
| 164 |
2/2✓ Branch 0 taken 1998394 times.
✓ Branch 1 taken 581527 times.
|
2579921 | } while (len -= 4); |
| 165 | } | ||
| 166 | 569290 | break; | |
| 167 | |||
| 168 | 395290 | case 2: | |
| 169 |
2/2✓ Branch 0 taken 407778 times.
✓ Branch 1 taken 395290 times.
|
803068 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
| 170 | 407778 | INTFLOAT *cf = cfo; | |
| 171 | 407778 | int len = off_len; | |
| 172 | |||
| 173 | do { | ||
| 174 | int code; | ||
| 175 | unsigned cb_idx; | ||
| 176 | |||
| 177 | 2480128 | UPDATE_CACHE(re, gb); | |
| 178 |
2/2✓ Branch 1 taken 86688 times.
✓ Branch 2 taken 2393440 times.
|
2480128 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
| 179 | 2480128 | cb_idx = code; | |
| 180 | #if USE_FIXED | ||
| 181 | 690688 | cf = DEC_SPAIR(cf, cb_idx); | |
| 182 | #else | ||
| 183 | 1789440 | cf = VMUL2(cf, vq, cb_idx, sf + idx); | |
| 184 | #endif /* USE_FIXED */ | ||
| 185 |
2/2✓ Branch 0 taken 2072350 times.
✓ Branch 1 taken 407778 times.
|
2480128 | } while (len -= 2); |
| 186 | } | ||
| 187 | 395290 | break; | |
| 188 | |||
| 189 | 540080 | case 3: | |
| 190 | case 4: | ||
| 191 |
2/2✓ Branch 0 taken 558311 times.
✓ Branch 1 taken 540080 times.
|
1098391 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
| 192 | 558311 | INTFLOAT *cf = cfo; | |
| 193 | 558311 | int len = off_len; | |
| 194 | |||
| 195 | do { | ||
| 196 | int code; | ||
| 197 | unsigned nnz; | ||
| 198 | unsigned cb_idx; | ||
| 199 | unsigned sign; | ||
| 200 | |||
| 201 | 2973438 | UPDATE_CACHE(re, gb); | |
| 202 |
2/2✓ Branch 1 taken 211316 times.
✓ Branch 2 taken 2762122 times.
|
2973438 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
| 203 | 2973438 | cb_idx = code; | |
| 204 | 2973438 | nnz = cb_idx >> 8 & 15; | |
| 205 |
2/2✓ Branch 0 taken 2368780 times.
✓ Branch 1 taken 604658 times.
|
2973438 | sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0; |
| 206 | 2973438 | LAST_SKIP_BITS(re, gb, nnz); | |
| 207 | #if USE_FIXED | ||
| 208 | 718254 | cf = DEC_UPAIR(cf, cb_idx, sign); | |
| 209 | #else | ||
| 210 | 2255184 | cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx); | |
| 211 | #endif /* USE_FIXED */ | ||
| 212 |
2/2✓ Branch 0 taken 2415127 times.
✓ Branch 1 taken 558311 times.
|
2973438 | } while (len -= 2); |
| 213 | } | ||
| 214 | 540080 | break; | |
| 215 | |||
| 216 | 436469 | default: | |
| 217 |
2/2✓ Branch 0 taken 445865 times.
✓ Branch 1 taken 436469 times.
|
882334 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { |
| 218 | #if USE_FIXED | ||
| 219 | 120281 | int *icf = cfo; | |
| 220 | int v; | ||
| 221 | #else | ||
| 222 | 325584 | float *cf = cfo; | |
| 223 | 325584 | uint32_t *icf = (uint32_t *) cf; | |
| 224 | #endif /* USE_FIXED */ | ||
| 225 | 445865 | int len = off_len; | |
| 226 | |||
| 227 | do { | ||
| 228 | int code; | ||
| 229 | unsigned nzt, nnz; | ||
| 230 | unsigned cb_idx; | ||
| 231 | uint32_t bits; | ||
| 232 | int j; | ||
| 233 | |||
| 234 | 1480140 | UPDATE_CACHE(re, gb); | |
| 235 |
2/2✓ Branch 1 taken 423191 times.
✓ Branch 2 taken 1056949 times.
|
1480140 | GET_VLC(code, re, gb, vlc_tab, 8, 2); |
| 236 | 1480140 | cb_idx = code; | |
| 237 | |||
| 238 |
2/2✓ Branch 0 taken 70684 times.
✓ Branch 1 taken 1409456 times.
|
1480140 | if (cb_idx == 0x0000) { |
| 239 | 70684 | *icf++ = 0; | |
| 240 | 70684 | *icf++ = 0; | |
| 241 | 70684 | continue; | |
| 242 | } | ||
| 243 | |||
| 244 | 1409456 | nnz = cb_idx >> 12; | |
| 245 | 1409456 | nzt = cb_idx >> 8; | |
| 246 | 1409456 | bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); | |
| 247 | 1409456 | LAST_SKIP_BITS(re, gb, nnz); | |
| 248 | |||
| 249 |
2/2✓ Branch 0 taken 2818912 times.
✓ Branch 1 taken 1409456 times.
|
4228368 | for (j = 0; j < 2; j++) { |
| 250 |
2/2✓ Branch 0 taken 364664 times.
✓ Branch 1 taken 2454248 times.
|
2818912 | if (nzt & 1<<j) { |
| 251 | uint32_t b; | ||
| 252 | int n; | ||
| 253 | /* The total length of escape_sequence must be < 22 bits according | ||
| 254 | to the specification (i.e. max is 111111110xxxxxxxxxxxx). */ | ||
| 255 | 364664 | UPDATE_CACHE(re, gb); | |
| 256 | 364664 | b = GET_CACHE(re, gb); | |
| 257 | 364664 | b = 31 - av_log2(~b); | |
| 258 | |||
| 259 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 364664 times.
|
364664 | if (b > 8) { |
| 260 | ✗ | av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); | |
| 261 | ✗ | return AVERROR_INVALIDDATA; | |
| 262 | } | ||
| 263 | |||
| 264 | 364664 | SKIP_BITS(re, gb, b + 1); | |
| 265 | 364664 | b += 4; | |
| 266 | 364664 | n = (1 << b) + SHOW_UBITS(re, gb, b); | |
| 267 | 364664 | LAST_SKIP_BITS(re, gb, b); | |
| 268 | #if USE_FIXED | ||
| 269 | 67153 | v = n; | |
| 270 |
2/2✓ Branch 0 taken 33454 times.
✓ Branch 1 taken 33699 times.
|
67153 | if (bits & 1U<<31) |
| 271 | 33454 | v = -v; | |
| 272 | 67153 | *icf++ = v; | |
| 273 | #else | ||
| 274 | 297511 | *icf++ = ff_cbrt_tab[n] | (bits & 1U<<31); | |
| 275 | #endif /* USE_FIXED */ | ||
| 276 | 364664 | bits <<= 1; | |
| 277 | } else { | ||
| 278 | #if USE_FIXED | ||
| 279 | 544503 | v = cb_idx & 15; | |
| 280 |
2/2✓ Branch 0 taken 258827 times.
✓ Branch 1 taken 285676 times.
|
544503 | if (bits & 1U<<31) |
| 281 | 258827 | v = -v; | |
| 282 | 544503 | *icf++ = v; | |
| 283 | #else | ||
| 284 | 1909745 | unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; | |
| 285 | 1909745 | *icf++ = (bits & 1U<<31) | v; | |
| 286 | #endif /* USE_FIXED */ | ||
| 287 | 2454248 | bits <<= !!v; | |
| 288 | } | ||
| 289 | 2818912 | cb_idx >>= 4; | |
| 290 | } | ||
| 291 |
2/2✓ Branch 0 taken 1034275 times.
✓ Branch 1 taken 445865 times.
|
1480140 | } while (len -= 2); |
| 292 | #if !USE_FIXED | ||
| 293 | 325584 | ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len); | |
| 294 | #endif /* !USE_FIXED */ | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | 2554277 | CLOSE_READER(re, gb); | |
| 299 | } | ||
| 300 | } | ||
| 301 | 98252 | coef += g_len << 7; | |
| 302 | } | ||
| 303 | |||
| 304 |
2/2✓ Branch 0 taken 1098 times.
✓ Branch 1 taken 92057 times.
|
93155 | if (pulse) { |
| 305 | 1098 | idx = 0; | |
| 306 |
2/2✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 1098 times.
|
3842 | for (i = 0; i < pulse->num_pulse; i++) { |
| 307 | 2744 | INTFLOAT co = coef_base[ pulse->pos[i] ]; | |
| 308 |
2/2✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 2744 times.
|
6840 | while (offsets[idx + 1] <= pulse->pos[i]) |
| 309 | 4096 | idx++; | |
| 310 |
3/4✓ Branch 0 taken 2744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2668 times.
✓ Branch 3 taken 76 times.
|
2744 | if (band_type[idx] != NOISE_BT && sf[idx]) { |
| 311 | 2668 | INTFLOAT ico = -pulse->amp[i]; | |
| 312 | #if USE_FIXED | ||
| 313 |
2/2✓ Branch 0 taken 730 times.
✓ Branch 1 taken 134 times.
|
864 | if (co) { |
| 314 |
2/2✓ Branch 0 taken 379 times.
✓ Branch 1 taken 351 times.
|
730 | ico = co + (co > 0 ? -ico : ico); |
| 315 | } | ||
| 316 | 864 | coef_base[ pulse->pos[i] ] = ico; | |
| 317 | #else | ||
| 318 |
2/2✓ Branch 0 taken 1564 times.
✓ Branch 1 taken 240 times.
|
1804 | if (co) { |
| 319 | 1564 | co /= sf[idx]; | |
| 320 |
2/2✓ Branch 0 taken 799 times.
✓ Branch 1 taken 765 times.
|
1564 | ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico); |
| 321 | } | ||
| 322 | 1804 | coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx]; | |
| 323 | #endif /* USE_FIXED */ | ||
| 324 | } | ||
| 325 | } | ||
| 326 | } | ||
| 327 | #if USE_FIXED | ||
| 328 | 29050 | coef = coef_base; | |
| 329 | 29050 | idx = 0; | |
| 330 |
2/2✓ Branch 0 taken 31382 times.
✓ Branch 1 taken 29050 times.
|
60432 | for (g = 0; g < ics->num_window_groups; g++) { |
| 331 | 31382 | unsigned g_len = ics->group_len[g]; | |
| 332 | |||
| 333 |
2/2✓ Branch 0 taken 1053985 times.
✓ Branch 1 taken 31382 times.
|
1085367 | for (i = 0; i < ics->max_sfb; i++, idx++) { |
| 334 | 1053985 | const unsigned cbt_m1 = band_type[idx] - 1; | |
| 335 | 1053985 | int *cfo = coef + offsets[i]; | |
| 336 | 1053985 | int off_len = offsets[i + 1] - offsets[i]; | |
| 337 | int group; | ||
| 338 | |||
| 339 |
2/2✓ Branch 0 taken 783227 times.
✓ Branch 1 taken 270758 times.
|
1053985 | if (cbt_m1 < NOISE_BT - 1) { |
| 340 |
2/2✓ Branch 0 taken 798771 times.
✓ Branch 1 taken 783227 times.
|
1581998 | for (group = 0; group < (int)g_len; group++, cfo+=128) { |
| 341 | 798771 | vector_pow43(cfo, off_len); | |
| 342 | 798771 | subband_scale(cfo, cfo, sf[idx], 34, off_len, ac->avctx); | |
| 343 | } | ||
| 344 | } | ||
| 345 | } | ||
| 346 | 31382 | coef += g_len << 7; | |
| 347 | } | ||
| 348 | #endif /* USE_FIXED */ | ||
| 349 | 93155 | return 0; | |
| 350 | } | ||
| 351 | |||
| 352 | /** | ||
| 353 | * Decode coupling_channel_element; reference: table 4.8. | ||
| 354 | * | ||
| 355 | * @return Returns error status. 0 - OK, !0 - error | ||
| 356 | */ | ||
| 357 | 1174 | static int AAC_RENAME(decode_cce)(AACDecContext *ac, GetBitContext *gb, ChannelElement *che) | |
| 358 | { | ||
| 359 | 1174 | int num_gain = 0; | |
| 360 | int c, g, sfb, ret; | ||
| 361 | int sign; | ||
| 362 | INTFLOAT scale; | ||
| 363 | 1174 | SingleChannelElement *sce = &che->ch[0]; | |
| 364 | 1174 | ChannelCoupling *coup = &che->coup; | |
| 365 | |||
| 366 | 1174 | coup->coupling_point = 2 * get_bits1(gb); | |
| 367 | 1174 | coup->num_coupled = get_bits(gb, 3); | |
| 368 |
2/2✓ Branch 0 taken 2741 times.
✓ Branch 1 taken 1174 times.
|
3915 | for (c = 0; c <= coup->num_coupled; c++) { |
| 369 | 2741 | num_gain++; | |
| 370 | 2741 | coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE; | |
| 371 | 2741 | coup->id_select[c] = get_bits(gb, 4); | |
| 372 |
2/2✓ Branch 0 taken 2348 times.
✓ Branch 1 taken 393 times.
|
2741 | if (coup->type[c] == TYPE_CPE) { |
| 373 | 2348 | coup->ch_select[c] = get_bits(gb, 2); | |
| 374 |
2/2✓ Branch 0 taken 1967 times.
✓ Branch 1 taken 381 times.
|
2348 | if (coup->ch_select[c] == 3) |
| 375 | 1967 | num_gain++; | |
| 376 | } else | ||
| 377 | 393 | coup->ch_select[c] = 2; | |
| 378 | } | ||
| 379 |
4/4✓ Branch 1 taken 602 times.
✓ Branch 2 taken 572 times.
✓ Branch 3 taken 152 times.
✓ Branch 4 taken 450 times.
|
1174 | coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1); |
| 380 | |||
| 381 | 1174 | sign = get_bits(gb, 1); | |
| 382 | #if USE_FIXED | ||
| 383 | 130 | scale = get_bits(gb, 2); | |
| 384 | #else | ||
| 385 | 1044 | scale = cce_scale[get_bits(gb, 2)]; | |
| 386 | #endif | ||
| 387 | |||
| 388 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1174 times.
|
1174 | if ((ret = ff_aac_decode_ics(ac, sce, gb, 0, 0))) |
| 389 | ✗ | return ret; | |
| 390 | |||
| 391 |
2/2✓ Branch 0 taken 4708 times.
✓ Branch 1 taken 1174 times.
|
5882 | for (c = 0; c < num_gain; c++) { |
| 392 | 4708 | int idx = 0; | |
| 393 | 4708 | int cge = 1; | |
| 394 | 4708 | int gain = 0; | |
| 395 | 4708 | INTFLOAT gain_cache = FIXR10(1.); | |
| 396 |
2/2✓ Branch 0 taken 3534 times.
✓ Branch 1 taken 1174 times.
|
4708 | if (c) { |
| 397 |
2/2✓ Branch 0 taken 1962 times.
✓ Branch 1 taken 1572 times.
|
3534 | cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); |
| 398 |
2/2✓ Branch 0 taken 1973 times.
✓ Branch 1 taken 1561 times.
|
3534 | gain = cge ? get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - 60: 0; |
| 399 | 3534 | gain_cache = GET_GAIN(scale, gain); | |
| 400 | #if USE_FIXED | ||
| 401 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 520 times.
|
520 | if ((abs(gain_cache)-1024) >> 3 > 30) |
| 402 | ✗ | return AVERROR(ERANGE); | |
| 403 | #endif | ||
| 404 | } | ||
| 405 |
2/2✓ Branch 0 taken 1965 times.
✓ Branch 1 taken 2743 times.
|
4708 | if (coup->coupling_point == AFTER_IMDCT) { |
| 406 | 1965 | coup->gain[c][0] = gain_cache; | |
| 407 | } else { | ||
| 408 |
2/2✓ Branch 0 taken 2743 times.
✓ Branch 1 taken 2743 times.
|
5486 | for (g = 0; g < sce->ics.num_window_groups; g++) { |
| 409 |
2/2✓ Branch 0 taken 109720 times.
✓ Branch 1 taken 2743 times.
|
112463 | for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) { |
| 410 |
2/2✓ Branch 0 taken 5196 times.
✓ Branch 1 taken 104524 times.
|
109720 | if (sce->band_type[idx] != ZERO_BT) { |
| 411 |
2/2✓ Branch 0 taken 2879 times.
✓ Branch 1 taken 2317 times.
|
5196 | if (!cge) { |
| 412 | 2879 | int t = get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - 60; | |
| 413 |
2/2✓ Branch 0 taken 2724 times.
✓ Branch 1 taken 155 times.
|
2879 | if (t) { |
| 414 | 2724 | int s = 1; | |
| 415 | 2724 | t = gain += t; | |
| 416 |
2/2✓ Branch 0 taken 1666 times.
✓ Branch 1 taken 1058 times.
|
2724 | if (sign) { |
| 417 | 1666 | s -= 2 * (t & 0x1); | |
| 418 | 1666 | t >>= 1; | |
| 419 | } | ||
| 420 | 2724 | gain_cache = GET_GAIN(scale, t) * s; | |
| 421 | #if USE_FIXED | ||
| 422 | ✗ | if ((abs(gain_cache)-1024) >> 3 > 30) | |
| 423 | ✗ | return AVERROR(ERANGE); | |
| 424 | #endif | ||
| 425 | } | ||
| 426 | } | ||
| 427 | 5196 | coup->gain[c][idx] = gain_cache; | |
| 428 | } | ||
| 429 | } | ||
| 430 | } | ||
| 431 | } | ||
| 432 | } | ||
| 433 | 1174 | return 0; | |
| 434 | } | ||
| 435 | |||
| 436 | 308 | static av_cold void AAC_RENAME(aac_proc_init)(AACDecProc *aac_proc) | |
| 437 | { | ||
| 438 | #define SET(member) aac_proc->member = AAC_RENAME(member) | ||
| 439 | 308 | SET(decode_spectrum_and_dequant); | |
| 440 | 308 | SET(decode_cce); | |
| 441 | #undef SET | ||
| 442 | #define SET(member) aac_proc->member = AV_JOIN(ff_aac_, AAC_RENAME(member)); | ||
| 443 | 308 | SET(sbr_ctx_alloc_init); | |
| 444 | 308 | SET(sbr_decode_extension); | |
| 445 | 308 | SET(sbr_apply); | |
| 446 | 308 | SET(sbr_ctx_close); | |
| 447 | #undef SET | ||
| 448 | 308 | } | |
| 449 |