119 enum OCStatus oc_type,
int get_new_frame);
121 #define overread_err "Input buffer exhausted before END element found\n"
126 for (i = 0; i < tags; i++) {
127 int syn_ele =
layout[i][0];
129 sum += (1 + (syn_ele ==
TYPE_CPE)) *
149 int type,
int id,
int *channels)
154 if (!ac->
che[type][
id]) {
171 if (ac->
che[type][
id])
184 for (type = 0; type < 4; type++) {
201 for (ch = 0; ch < avctx->
channels; ch++) {
218 uint64_t right,
int pos)
220 if (layout_map[offset][0] ==
TYPE_CPE) {
222 .av_position = left | right,
224 .elem_id = layout_map[
offset][1],
232 .elem_id = layout_map[
offset][1],
236 .av_position = right,
238 .elem_id = layout_map[offset + 1][1],
248 int num_pos_channels = 0;
252 for (i = *current; i < tags; i++) {
253 if (layout_map[i][2] != pos)
263 num_pos_channels += 2;
274 return num_pos_channels;
279 int i,
n, total_non_cc_elements;
281 int num_front_channels, num_side_channels, num_back_channels;
290 if (num_front_channels < 0)
294 if (num_side_channels < 0)
298 if (num_back_channels < 0)
302 if (num_front_channels & 1) {
306 .elem_id = layout_map[i][1],
310 num_front_channels--;
312 if (num_front_channels >= 4) {
317 num_front_channels -= 2;
319 if (num_front_channels >= 2) {
324 num_front_channels -= 2;
326 while (num_front_channels >= 2) {
331 num_front_channels -= 2;
334 if (num_side_channels >= 2) {
339 num_side_channels -= 2;
341 while (num_side_channels >= 2) {
346 num_side_channels -= 2;
349 while (num_back_channels >= 4) {
354 num_back_channels -= 2;
356 if (num_back_channels >= 2) {
361 num_back_channels -= 2;
363 if (num_back_channels) {
367 .elem_id = layout_map[i][1],
378 .elem_id = layout_map[i][1],
387 .elem_id = layout_map[i][1],
394 total_non_cc_elements = n = i;
397 for (i = 1; i <
n; i++)
398 if (e2c_vec[i - 1].av_position > e2c_vec[i].av_position) {
406 for (i = 0; i < total_non_cc_elements; i++) {
407 layout_map[i][0] = e2c_vec[i].
syn_ele;
408 layout_map[i][1] = e2c_vec[i].
elem_id;
410 if (e2c_vec[i].av_position != UINT64_MAX) {
423 ac->
oc[0] = ac->
oc[1];
434 ac->
oc[1] = ac->
oc[0];
449 uint8_t layout_map[MAX_ELEM_ID * 4][3],
int tags,
450 enum OCStatus oc_type,
int get_new_frame)
453 int i, channels = 0,
ret;
457 memcpy(ac->
oc[1].
layout_map, layout_map, tags *
sizeof(layout_map[0]));
465 for (i = 0; i < tags; i++) {
466 int type = layout_map[i][0];
467 int id = layout_map[i][1];
468 int position = layout_map[i][2];
475 if (ac->
oc[1].
m4ac.
ps == 1 && channels == 2) {
502 for (type = 3; type >= 0; type--) {
506 for (j = 0; j <= 1; j++) {
525 if (channel_config < 1 || channel_config > 7) {
527 "invalid default channel configuration (%d)\n",
533 *tags *
sizeof(*layout_map));
547 uint8_t layout_map[MAX_ELEM_ID*4][3];
554 &layout_map_tags, 2) < 0)
566 uint8_t layout_map[MAX_ELEM_ID * 4][3];
573 &layout_map_tags, 1) < 0)
661 layout_map[0][0] = syn_ele;
663 layout_map[0][2] = type;
677 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
687 "Sample rate index in program config element does not "
688 "match the sample rate index configured by the container.\n");
705 if (
get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) {
748 int extension_flag,
ret;
749 uint8_t layout_map[MAX_ELEM_ID*4][3];
765 if (channel_config == 0) {
767 tags =
decode_pce(avctx, m4ac, layout_map, gb);
772 &tags, channel_config)))
778 }
else if (m4ac->
sbr == 1 && m4ac->
ps == -1)
784 if (extension_flag) {
826 av_dlog(avctx,
"audio specific config size %d\n", bit_size >> 3);
827 for (i = 0; i < bit_size >> 3; i++)
828 av_dlog(avctx,
"%02x ", data[i]);
835 sync_extension)) < 0)
839 "invalid sampling rate index %d\n",
856 "Audio object type %s%d is not supported.\n",
857 m4ac->
sbr == 1 ?
"SBR+" :
"",
863 "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
880 union {
unsigned u;
int s; }
v = { previous_val * 1664525
u + 1013904223 };
903 if (92017 <= rate)
return 0;
904 else if (75132 <= rate)
return 1;
905 else if (55426 <= rate)
return 2;
906 else if (46009 <= rate)
return 3;
907 else if (37566 <= rate)
return 4;
908 else if (27713 <= rate)
return 5;
909 else if (23004 <= rate)
return 6;
910 else if (18783 <= rate)
return 7;
911 else if (13856 <= rate)
return 8;
912 else if (11502 <= rate)
return 9;
913 else if (9391 <= rate)
return 10;
924 #define AAC_INIT_VLC_STATIC(num, size) \
925 INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \
926 ff_aac_spectral_bits[num], sizeof(ff_aac_spectral_bits[num][0]), \
927 sizeof(ff_aac_spectral_bits[num][0]), \
928 ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), \
929 sizeof(ff_aac_spectral_codes[num][0]), \
954 uint8_t layout_map[MAX_ELEM_ID*4][3];
1061 "Invalid Predictor Reset Group.\n");
1104 for (i = 0; i < 7; i++) {
1132 "Prediction is not allowed in AAC-LC.\n");
1143 "Number of scalefactor bands in group (%d) "
1144 "exceeds limit (%d).\n",
1171 while (k < ics->max_sfb) {
1174 int sect_band_type =
get_bits(gb, 4);
1175 if (sect_band_type == 12) {
1180 sect_len_incr =
get_bits(gb, bits);
1181 sect_end += sect_len_incr;
1186 if (sect_end > ics->
max_sfb) {
1188 "Number of bands (%d) exceeds limit (%d).\n",
1192 }
while (sect_len_incr == (1 << bits) - 1);
1193 for (; k < sect_end; k++) {
1194 band_type [idx] = sect_band_type;
1195 band_type_run_end[idx++] = sect_end;
1213 unsigned int global_gain,
1216 int band_type_run_end[120])
1219 int offset[3] = { global_gain, global_gain - 90, 0 };
1223 for (i = 0; i < ics->
max_sfb;) {
1224 int run_end = band_type_run_end[idx];
1225 if (band_type[idx] ==
ZERO_BT) {
1226 for (; i < run_end; i++, idx++)
1230 for (; i < run_end; i++, idx++) {
1231 offset[2] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1232 clipped_offset = av_clip(offset[2], -155, 100);
1233 if (offset[2] != clipped_offset) {
1235 "If you heard an audible artifact, there may be a bug in the decoder. "
1236 "Clipped intensity stereo position (%d -> %d)",
1237 offset[2], clipped_offset);
1241 }
else if (band_type[idx] ==
NOISE_BT) {
1242 for (; i < run_end; i++, idx++) {
1243 if (noise_flag-- > 0)
1244 offset[1] +=
get_bits(gb, 9) - 256;
1246 offset[1] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1247 clipped_offset = av_clip(offset[1], -100, 155);
1248 if (offset[1] != clipped_offset) {
1250 "If you heard an audible artifact, there may be a bug in the decoder. "
1251 "Clipped noise gain (%d -> %d)",
1252 offset[1], clipped_offset);
1257 for (; i < run_end; i++, idx++) {
1258 offset[0] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1259 if (offset[0] > 255
U) {
1261 "Scalefactor (%d) out of range.\n", offset[0]);
1276 const uint16_t *swb_offset,
int num_swb)
1281 if (pulse_swb >= num_swb)
1283 pulse->
pos[0] = swb_offset[pulse_swb];
1285 if (pulse->
pos[0] > 1023)
1288 for (i = 1; i < pulse->
num_pulse; i++) {
1290 if (pulse->
pos[i] > 1023)
1305 int w,
filt, i, coef_len, coef_res, coef_compress;
1312 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
1316 if ((tns->
order[w][filt] =
get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
1318 "TNS filter order %d is greater than maximum %d.\n",
1319 tns->
order[w][filt], tns_max_order);
1323 if (tns->
order[w][filt]) {
1326 coef_len = coef_res + 3 - coef_compress;
1327 tmp2_idx = 2 * coef_compress + coef_res;
1329 for (i = 0; i < tns->
order[w][
filt]; i++)
1349 if (ms_present == 1) {
1354 }
else if (ms_present == 2) {
1360 static inline float *
VMUL2(
float *dst,
const float *
v,
unsigned idx,
1364 *dst++ = v[idx & 15] *
s;
1365 *dst++ = v[idx>>4 & 15] *
s;
1371 static inline float *
VMUL4(
float *dst,
const float *
v,
unsigned idx,
1375 *dst++ = v[idx & 3] *
s;
1376 *dst++ = v[idx>>2 & 3] *
s;
1377 *dst++ = v[idx>>4 & 3] *
s;
1378 *dst++ = v[idx>>6 & 3] *
s;
1384 static inline float *
VMUL2S(
float *dst,
const float *
v,
unsigned idx,
1385 unsigned sign,
const float *
scale)
1390 s0.
i ^= sign >> 1 << 31;
1393 *dst++ = v[idx & 15] * s0.
f;
1394 *dst++ = v[idx>>4 & 15] * s1.
f;
1401 static inline float *
VMUL4S(
float *dst,
const float *
v,
unsigned idx,
1402 unsigned sign,
const float *
scale)
1404 unsigned nz = idx >> 12;
1408 t.
i = s.
i ^ (sign & 1
U<<31);
1409 *dst++ = v[idx & 3] * t.
f;
1411 sign <<= nz & 1; nz >>= 1;
1412 t.
i = s.
i ^ (sign & 1
U<<31);
1413 *dst++ = v[idx>>2 & 3] * t.
f;
1415 sign <<= nz & 1; nz >>= 1;
1416 t.
i = s.
i ^ (sign & 1
U<<31);
1417 *dst++ = v[idx>>4 & 3] * t.
f;
1420 t.
i = s.
i ^ (sign & 1
U<<31);
1421 *dst++ = v[idx>>6 & 3] * t.
f;
1441 int pulse_present,
const Pulse *pulse,
1445 int i, k,
g, idx = 0;
1448 float *coef_base = coef;
1451 memset(coef + g * 128 + offsets[ics->
max_sfb], 0,
1452 sizeof(
float) * (c - offsets[ics->
max_sfb]));
1457 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1458 const unsigned cbt_m1 = band_type[idx] - 1;
1459 float *cfo = coef + offsets[
i];
1460 int off_len = offsets[i + 1] - offsets[
i];
1464 for (group = 0; group < g_len; group++, cfo+=128) {
1465 memset(cfo, 0, off_len *
sizeof(
float));
1467 }
else if (cbt_m1 ==
NOISE_BT - 1) {
1468 for (group = 0; group < g_len; group++, cfo+=128) {
1472 for (k = 0; k < off_len; k++) {
1478 scale = sf[idx] / sqrtf(band_energy);
1487 switch (cbt_m1 >> 1) {
1489 for (group = 0; group < g_len; group++, cfo+=128) {
1499 cb_idx = cb_vector_idx[code];
1500 cf =
VMUL4(cf, vq, cb_idx, sf + idx);
1506 for (group = 0; group < g_len; group++, cfo+=128) {
1518 cb_idx = cb_vector_idx[code];
1519 nnz = cb_idx >> 8 & 15;
1522 cf =
VMUL4S(cf, vq, cb_idx, bits, sf + idx);
1528 for (group = 0; group < g_len; group++, cfo+=128) {
1538 cb_idx = cb_vector_idx[code];
1539 cf =
VMUL2(cf, vq, cb_idx, sf + idx);
1546 for (group = 0; group < g_len; group++, cfo+=128) {
1558 cb_idx = cb_vector_idx[code];
1559 nnz = cb_idx >> 8 & 15;
1560 sign = nnz ?
SHOW_UBITS(
re, gb, nnz) << (cb_idx >> 12) : 0;
1562 cf =
VMUL2S(cf, vq, cb_idx, sign, sf + idx);
1568 for (group = 0; group < g_len; group++, cfo+=128) {
1570 uint32_t *icf = (uint32_t *) cf;
1589 cb_idx = cb_vector_idx[code];
1595 for (j = 0; j < 2; j++) {
1617 unsigned v = ((
const uint32_t*)vq)[cb_idx & 15];
1618 *icf++ = (bits & 1
U<<31) | v;
1635 if (pulse_present) {
1637 for (i = 0; i < pulse->
num_pulse; i++) {
1638 float co = coef_base[ pulse->
pos[
i] ];
1639 while (offsets[idx + 1] <= pulse->
pos[i])
1641 if (band_type[idx] !=
NOISE_BT && sf[idx]) {
1642 float ico = -pulse->
amp[
i];
1645 ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
1647 coef_base[ pulse->
pos[
i] ] =
cbrtf(fabsf(ico)) * ico * sf[idx];
1658 tmp.
i = (tmp.
i + 0x00008000
U) & 0xFFFF0000U;
1666 tmp.
i = (tmp.
i + 0x00007FFF
U + (tmp.
i & 0x00010000
U >> 16)) & 0xFFFF0000
U;
1674 pun.
i &= 0xFFFF0000
U;
1681 const float a = 0.953125;
1682 const float alpha = 0.90625;
1686 float r0 = ps->
r0, r1 = ps->
r1;
1687 float cor0 = ps->
cor0, cor1 = ps->
cor1;
1688 float var0 = ps->
var0, var1 = ps->
var1;
1690 k1 = var0 > 1 ? cor0 *
flt16_even(a / var0) : 0;
1691 k2 = var1 > 1 ? cor1 *
flt16_even(a / var1) : 0;
1726 k < sce->ics.swb_offset[sfb + 1];
1755 int global_gain, pulse_present = 0;
1765 if (!common_window && !scale_flag) {
1782 "Pulse tool not allowed in eight short sequence.\n");
1787 "Pulse data corrupt or invalid.\n");
1817 int g,
i, group, idx = 0;
1820 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1824 for (group = 0; group < ics->
group_len[
g]; group++) {
1826 ch1 + group * 128 + offsets[i],
1827 offsets[i+1] - offsets[i]);
1850 int g, group,
i, idx = 0;
1854 for (i = 0; i < ics->
max_sfb;) {
1858 for (; i < bt_run_end; i++, idx++) {
1859 c = -1 + 2 * (sce1->
band_type[idx] - 14);
1861 c *= 1 - 2 * cpe->
ms_mask[idx];
1862 scale = c * sce1->
sf[idx];
1863 for (group = 0; group < ics->
group_len[
g]; group++)
1865 coef0 + group * 128 + offsets[i],
1867 offsets[i + 1] - offsets[i]);
1871 idx += bt_run_end -
i;
1887 int i,
ret, common_window, ms_present = 0;
1890 if (common_window) {
1901 if (ms_present == 3) {
1904 }
else if (ms_present)
1907 if ((ret =
decode_ics(ac, &cpe->
ch[0], gb, common_window, 0)))
1909 if ((ret =
decode_ics(ac, &cpe->
ch[1], gb, common_window, 0)))
1912 if (common_window) {
1926 1.09050773266525765921,
1927 1.18920711500272106672,
1962 scale = cce_scale[
get_bits(gb, 2)];
1967 for (c = 0; c < num_gain; c++) {
1971 float gain_cache = 1.;
1974 gain = cge ?
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60: 0;
1975 gain_cache =
powf(scale, -gain);
1978 coup->
gain[
c][0] = gain_cache;
1981 for (sfb = 0; sfb < sce->
ics.
max_sfb; sfb++, idx++) {
1992 gain_cache =
powf(scale, -t) *
s;
1995 coup->
gain[
c][idx] = gain_cache;
2013 int num_excl_chan = 0;
2016 for (i = 0; i < 7; i++)
2020 return num_excl_chan / 7;
2032 int drc_num_bands = 1;
2053 for (i = 0; i < drc_num_bands; i++) {
2066 for (i = 0; i < drc_num_bands; i++) {
2077 int i, major, minor;
2084 for(i=0; i+1<
sizeof(
buf) && len>=8; i++, len-=8)
2091 if (sscanf(buf,
"libfaac %d.%d", &major, &minor) == 2){
2170 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
2182 if ((size = end - start) <= 0)
2194 for (m = 0; m <
size; m++, start += inc)
2195 for (i = 1; i <=
FFMIN(m, order); i++)
2196 coef[start] -= coef[start - i * inc] * lpc[i - 1];
2199 for (m = 0; m <
size; m++, start += inc) {
2200 tmp[0] = coef[
start];
2201 for (i = 1; i <=
FFMIN(m, order); i++)
2202 coef[start] += tmp[i] * lpc[i - 1];
2203 for (i = order; i > 0; i--)
2204 tmp[i] = tmp[i - 1];
2226 memset(in, 0, 448 *
sizeof(
float));
2233 memset(in + 1024 + 576, 0, 448 *
sizeof(
float));
2248 float *predTime = sce->
ret;
2250 int16_t num_samples = 2048;
2252 if (ltp->
lag < 1024)
2253 num_samples = ltp->
lag + 1024;
2254 for (i = 0; i < num_samples; i++)
2256 memset(&predTime[i], 0, (2048 - i) *
sizeof(
float));
2265 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
2266 sce->
coeffs[i] += predFreq[i];
2276 float *saved = sce->
saved;
2277 float *saved_ltp = sce->
coeffs;
2283 memcpy(saved_ltp, saved, 512 *
sizeof(
float));
2284 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2286 for (i = 0; i < 64; i++)
2287 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2289 memcpy(saved_ltp, ac->
buf_mdct + 512, 448 *
sizeof(
float));
2290 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2292 for (i = 0; i < 64; i++)
2293 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2296 for (i = 0; i < 512; i++)
2297 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * lwindow[511 - i];
2313 float *saved = sce->
saved;
2323 for (i = 0; i < 1024; i += 128)
2338 memcpy( out, saved, 448 *
sizeof(
float));
2346 memcpy( out + 448 + 4*128, temp, 64 *
sizeof(
float));
2349 memcpy( out + 576, buf + 64, 448 *
sizeof(
float));
2355 memcpy( saved, temp + 64, 64 *
sizeof(
float));
2359 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2361 memcpy( saved, buf + 512, 448 *
sizeof(
float));
2362 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2364 memcpy( saved, buf + 512, 512 *
sizeof(
float));
2379 float *dest = target->
coeffs;
2381 int g,
i, group, k, idx = 0;
2384 "Dependent coupling is not supported together with LTP\n");
2388 for (i = 0; i < ics->
max_sfb; i++, idx++) {
2391 for (group = 0; group < ics->
group_len[
g]; group++) {
2392 for (k = offsets[i]; k < offsets[i + 1]; k++) {
2394 dest[group * 128 + k] += gain * src[group * 128 + k];
2416 float *dest = target->
ret;
2419 for (i = 0; i <
len; i++)
2420 dest[i] += gain * src[i];
2443 if (coup->
type[c] == type && coup->
id_select[c] == elem_id) {
2445 apply_coupling_method(ac, &cc->
ch[0], cce, index);
2450 apply_coupling_method(ac, &cc->
ch[1], cce, index++);
2464 for (type = 3; type >= 0; type--) {
2508 uint8_t layout_map[MAX_ELEM_ID*4][3];
2509 int layout_map_tags;
2517 "More than one AAC RDB per ADTS frame");
2537 layout_map_tags = 2;
2538 layout_map[0][0] = layout_map[1][0] =
TYPE_SCE;
2540 layout_map[0][1] = 0;
2541 layout_map[1][1] = 1;
2569 int samples = 0, multiplier, audio_found = 0, pce_found = 0;
2570 int is_dmono, sce_count = 0;
2598 if (!(che=
get_che(ac, elem_type, elem_id))) {
2600 elem_type, elem_id);
2607 switch (elem_type) {
2634 uint8_t layout_map[MAX_ELEM_ID*4][3];
2644 "Not evaluating a further program_config_element as this construct is dubious at best.\n");
2673 elem_type_prev = elem_type;
2688 samples <<= multiplier;
2690 is_dmono = ac->
dmono_mode && sce_count == 2 &&
2697 *got_frame_ptr = !!samples;
2706 if (ac->
oc[1].
status && audio_found) {
2715 if (side && side_size>=4)
2725 int *got_frame_ptr,
AVPacket *avpkt)
2729 int buf_size = avpkt->
size;
2734 int new_extradata_size;
2737 &new_extradata_size);
2738 int jp_dualmono_size;
2743 if (new_extradata && 0) {
2750 memcpy(avctx->
extradata, new_extradata, new_extradata_size);
2761 if (jp_dualmono && jp_dualmono_size > 0)
2766 if (INT_MAX / 8 <= buf_size)
2775 for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
2776 if (buf[buf_offset])
2779 return buf_size > buf_offset ? buf_consumed : buf_size;
2788 for (type = 0; type < 4; type++) {
2789 if (ac->
che[type][i])
2802 #define LOAS_SYNC_WORD 0x2b7
2828 int sync_extension = 0;
2829 int bits_consumed, esize;
2837 if (config_start_bit % 8) {
2839 "Non-byte-aligned audio-specific config");
2845 gb->
buffer + (config_start_bit / 8),
2846 asclen, sync_extension);
2848 if (bits_consumed < 0)
2862 esize = (bits_consumed+7) / 8;
2877 return bits_consumed;
2886 if (audio_mux_version)
2891 if (audio_mux_version)
2911 if (!audio_mux_version) {
2942 if (audio_mux_version) {
2965 int mux_slot_length = 0;
2968 mux_slot_length += tmp;
2969 }
while (tmp == 255);
2970 return mux_slot_length;
2986 if (!use_same_mux) {
2991 "no decoder config found\n");
2999 }
else if (mux_slot_length_bytes * 8 + 256 <
get_bits_left(gb)) {
3001 "frame length mismatch %d << %d\n",
3011 int *got_frame_ptr,
AVPacket *avpkt)
3026 if (muxlength > avpkt->
size)
3050 "ADTS header detected, probably as result of configuration "
3086 #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
3088 {
"dual_mono_mode",
"Select the channel to decode for dual mono",