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)
152 if (!ac->
che[type][
id]) {
169 if (ac->
che[type][
id])
179 int type,
id, ch, ret;
182 for (type = 0; type < 4; type++) {
200 for (ch = 0; ch < avctx->
channels; ch++) {
217 uint64_t right,
int pos)
219 if (layout_map[offset][0] ==
TYPE_CPE) {
221 .av_position = left | right, .syn_ele =
TYPE_CPE,
222 .elem_id = layout_map[
offset ][1], .aac_position = pos };
226 .av_position = left, .syn_ele =
TYPE_SCE,
227 .elem_id = layout_map[
offset ][1], .aac_position = pos };
229 .av_position = right, .syn_ele =
TYPE_SCE,
230 .elem_id = layout_map[offset + 1][1], .aac_position = pos };
236 int num_pos_channels = 0;
240 for (i = *current; i < tags; i++) {
241 if (layout_map[i][2] != pos)
251 num_pos_channels += 2;
262 return num_pos_channels;
267 int i, n, total_non_cc_elements;
269 int num_front_channels, num_side_channels, num_back_channels;
278 if (num_front_channels < 0)
282 if (num_side_channels < 0)
286 if (num_back_channels < 0)
290 if (num_front_channels & 1) {
295 num_front_channels--;
297 if (num_front_channels >= 4) {
302 num_front_channels -= 2;
304 if (num_front_channels >= 2) {
309 num_front_channels -= 2;
311 while (num_front_channels >= 2) {
316 num_front_channels -= 2;
319 if (num_side_channels >= 2) {
324 num_side_channels -= 2;
326 while (num_side_channels >= 2) {
331 num_side_channels -= 2;
334 while (num_back_channels >= 4) {
339 num_back_channels -= 2;
341 if (num_back_channels >= 2) {
346 num_back_channels -= 2;
348 if (num_back_channels) {
370 total_non_cc_elements = n = i;
373 for (i = 1; i < n; i++) {
374 if (e2c_vec[i-1].av_position > e2c_vec[i].av_position) {
383 for (i = 0; i < total_non_cc_elements; i++) {
384 layout_map[i][0] = e2c_vec[i].
syn_ele;
385 layout_map[i][1] = e2c_vec[i].
elem_id;
387 if (e2c_vec[i].av_position != UINT64_MAX) {
400 ac->
oc[0] = ac->
oc[1];
411 ac->
oc[1] = ac->
oc[0];
425 uint8_t layout_map[MAX_ELEM_ID*4][3],
int tags,
426 enum OCStatus oc_type,
int get_new_frame)
429 int i, channels = 0, ret;
433 memcpy(ac->
oc[1].
layout_map, layout_map, tags *
sizeof(layout_map[0]));
441 for (i = 0; i < tags; i++) {
442 int type = layout_map[i][0];
443 int id = layout_map[i][1];
444 int position = layout_map[i][2];
451 if (ac->
oc[1].
m4ac.
ps == 1 && channels == 2) {
478 for (type = 3; type >= 0; type--) {
482 for (j = 0; j <= 1; j++) {
501 if (channel_config < 1 || channel_config > 7) {
519 uint8_t layout_map[MAX_ELEM_ID*4][3];
537 uint8_t layout_map[MAX_ELEM_ID*4][3];
624 layout_map[0][0] = syn_ele;
626 layout_map[0][2] = type;
640 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index;
648 av_log(avctx,
AV_LOG_WARNING,
"Sample rate index in program config element does not match the sample rate index configured by the container.\n");
665 if (
get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) {
708 int extension_flag, ret;
709 uint8_t layout_map[MAX_ELEM_ID*4][3];
725 if (channel_config == 0) {
727 tags =
decode_pce(avctx, m4ac, layout_map, gb);
737 }
else if (m4ac->
sbr == 1 && m4ac->
ps == -1)
743 if (extension_flag) {
786 av_dlog(avctx,
"audio specific config size %d\n", bit_size >> 3);
787 for (i = 0; i < bit_size >> 3; i++)
788 av_dlog(avctx,
"%02x ", data[i]);
816 av_dlog(avctx,
"AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
832 union {
unsigned u;
int s; }
v = { previous_val * 1664525
u + 1013904223 };
855 if (92017 <= rate)
return 0;
856 else if (75132 <= rate)
return 1;
857 else if (55426 <= rate)
return 2;
858 else if (46009 <= rate)
return 3;
859 else if (37566 <= rate)
return 4;
860 else if (27713 <= rate)
return 5;
861 else if (23004 <= rate)
return 6;
862 else if (18783 <= rate)
return 7;
863 else if (13856 <= rate)
return 8;
864 else if (11502 <= rate)
return 9;
865 else if (9391 <= rate)
return 10;
876 #define AAC_INIT_VLC_STATIC(num, size) \
877 INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \
878 ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \
879 ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \
902 uint8_t layout_map[MAX_ELEM_ID*4][3];
1045 for (i = 0; i < 7; i++) {
1083 "Number of scalefactor bands in group (%d) exceeds limit (%d).\n",
1110 while (k < ics->max_sfb) {
1113 int sect_band_type =
get_bits(gb, 4);
1114 if (sect_band_type == 12) {
1119 sect_len_incr =
get_bits(gb, bits);
1120 sect_end += sect_len_incr;
1125 if (sect_end > ics->
max_sfb) {
1127 "Number of bands (%d) exceeds limit (%d).\n",
1131 }
while (sect_len_incr == (1 << bits) - 1);
1132 for (; k < sect_end; k++) {
1133 band_type [idx] = sect_band_type;
1134 band_type_run_end[idx++] = sect_end;
1152 unsigned int global_gain,
1155 int band_type_run_end[120])
1158 int offset[3] = { global_gain, global_gain - 90, 0 };
1162 for (i = 0; i < ics->
max_sfb;) {
1163 int run_end = band_type_run_end[idx];
1164 if (band_type[idx] ==
ZERO_BT) {
1165 for (; i < run_end; i++, idx++)
1168 for (; i < run_end; i++, idx++) {
1169 offset[2] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1170 clipped_offset = av_clip(offset[2], -155, 100);
1171 if (offset[2] != clipped_offset) {
1173 "position clipped (%d -> %d).\nIf you heard an "
1174 "audible artifact, there may be a bug in the "
1175 "decoder. ", offset[2], clipped_offset);
1179 }
else if (band_type[idx] ==
NOISE_BT) {
1180 for (; i < run_end; i++, idx++) {
1181 if (noise_flag-- > 0)
1182 offset[1] +=
get_bits(gb, 9) - 256;
1184 offset[1] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1185 clipped_offset = av_clip(offset[1], -100, 155);
1186 if (offset[1] != clipped_offset) {
1188 "(%d -> %d).\nIf you heard an audible "
1189 "artifact, there may be a bug in the decoder. ",
1190 offset[1], clipped_offset);
1195 for (; i < run_end; i++, idx++) {
1196 offset[0] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1197 if (offset[0] > 255
U) {
1199 "Scalefactor (%d) out of range.\n", offset[0]);
1214 const uint16_t *swb_offset,
int num_swb)
1219 if (pulse_swb >= num_swb)
1221 pulse->
pos[0] = swb_offset[pulse_swb];
1223 if (pulse->
pos[0] > 1023)
1226 for (i = 1; i < pulse->
num_pulse; i++) {
1228 if (pulse->
pos[i] > 1023)
1243 int w,
filt, i, coef_len, coef_res, coef_compress;
1250 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
1254 if ((tns->
order[w][filt] =
get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
1256 tns->
order[w][filt], tns_max_order);
1260 if (tns->
order[w][filt]) {
1263 coef_len = coef_res + 3 - coef_compress;
1264 tmp2_idx = 2 * coef_compress + coef_res;
1266 for (i = 0; i < tns->
order[w][
filt]; i++)
1286 if (ms_present == 1) {
1289 }
else if (ms_present == 2) {
1295 static inline float *
VMUL2(
float *
dst,
const float *
v,
unsigned idx,
1299 *dst++ = v[idx & 15] * s;
1300 *dst++ = v[idx>>4 & 15] * s;
1306 static inline float *
VMUL4(
float *
dst,
const float *
v,
unsigned idx,
1310 *dst++ = v[idx & 3] * s;
1311 *dst++ = v[idx>>2 & 3] * s;
1312 *dst++ = v[idx>>4 & 3] * s;
1313 *dst++ = v[idx>>6 & 3] * s;
1319 static inline float *
VMUL2S(
float *
dst,
const float *
v,
unsigned idx,
1320 unsigned sign,
const float *
scale)
1325 s0.
i ^= sign >> 1 << 31;
1328 *dst++ = v[idx & 15] * s0.
f;
1329 *dst++ = v[idx>>4 & 15] * s1.
f;
1336 static inline float *
VMUL4S(
float *
dst,
const float *
v,
unsigned idx,
1337 unsigned sign,
const float *
scale)
1339 unsigned nz = idx >> 12;
1343 t.
i = s.
i ^ (sign & 1
U<<31);
1344 *dst++ = v[idx & 3] * t.
f;
1346 sign <<= nz & 1; nz >>= 1;
1347 t.
i = s.
i ^ (sign & 1
U<<31);
1348 *dst++ = v[idx>>2 & 3] * t.
f;
1350 sign <<= nz & 1; nz >>= 1;
1351 t.
i = s.
i ^ (sign & 1
U<<31);
1352 *dst++ = v[idx>>4 & 3] * t.
f;
1355 t.
i = s.
i ^ (sign & 1
U<<31);
1356 *dst++ = v[idx>>6 & 3] * t.
f;
1376 int pulse_present,
const Pulse *pulse,
1380 int i, k,
g, idx = 0;
1383 float *coef_base = coef;
1386 memset(coef + g * 128 + offsets[ics->
max_sfb], 0,
sizeof(
float) * (c - offsets[ics->
max_sfb]));
1391 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1392 const unsigned cbt_m1 = band_type[idx] - 1;
1393 float *cfo = coef + offsets[
i];
1394 int off_len = offsets[i + 1] - offsets[
i];
1398 for (group = 0; group < g_len; group++, cfo+=128) {
1399 memset(cfo, 0, off_len *
sizeof(
float));
1401 }
else if (cbt_m1 ==
NOISE_BT - 1) {
1402 for (group = 0; group < g_len; group++, cfo+=128) {
1406 for (k = 0; k < off_len; k++) {
1412 scale = sf[idx] / sqrtf(band_energy);
1421 switch (cbt_m1 >> 1) {
1423 for (group = 0; group < g_len; group++, cfo+=128) {
1433 cb_idx = cb_vector_idx[code];
1434 cf =
VMUL4(cf, vq, cb_idx, sf + idx);
1440 for (group = 0; group < g_len; group++, cfo+=128) {
1452 cb_idx = cb_vector_idx[code];
1453 nnz = cb_idx >> 8 & 15;
1456 cf =
VMUL4S(cf, vq, cb_idx, bits, sf + idx);
1462 for (group = 0; group < g_len; group++, cfo+=128) {
1472 cb_idx = cb_vector_idx[code];
1473 cf =
VMUL2(cf, vq, cb_idx, sf + idx);
1480 for (group = 0; group < g_len; group++, cfo+=128) {
1492 cb_idx = cb_vector_idx[code];
1493 nnz = cb_idx >> 8 & 15;
1494 sign = nnz ?
SHOW_UBITS(
re, gb, nnz) << (cb_idx >> 12) : 0;
1496 cf =
VMUL2S(cf, vq, cb_idx, sign, sf + idx);
1502 for (group = 0; group < g_len; group++, cfo+=128) {
1504 uint32_t *icf = (uint32_t *) cf;
1523 cb_idx = cb_vector_idx[code];
1529 for (j = 0; j < 2; j++) {
1551 unsigned v = ((
const uint32_t*)vq)[cb_idx & 15];
1552 *icf++ = (bits & 1
U<<31) | v;
1569 if (pulse_present) {
1571 for (i = 0; i < pulse->
num_pulse; i++) {
1572 float co = coef_base[ pulse->
pos[
i] ];
1573 while (offsets[idx + 1] <= pulse->
pos[i])
1575 if (band_type[idx] !=
NOISE_BT && sf[idx]) {
1576 float ico = -pulse->
amp[
i];
1579 ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
1581 coef_base[ pulse->
pos[
i] ] =
cbrtf(fabsf(ico)) * ico * sf[idx];
1592 tmp.
i = (tmp.
i + 0x00008000
U) & 0xFFFF0000U;
1600 tmp.
i = (tmp.
i + 0x00007FFF
U + (tmp.
i & 0x00010000
U >> 16)) & 0xFFFF0000
U;
1608 pun.
i &= 0xFFFF0000
U;
1615 const float a = 0.953125;
1616 const float alpha = 0.90625;
1620 float r0 = ps->
r0, r1 = ps->
r1;
1621 float cor0 = ps->
cor0, cor1 = ps->
cor1;
1622 float var0 = ps->
var0, var1 = ps->
var1;
1624 k1 = var0 > 1 ? cor0 *
flt16_even(a / var0) : 0;
1625 k2 = var1 > 1 ? cor1 *
flt16_even(a / var1) : 0;
1657 for (k = sce->
ics.
swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) {
1683 int global_gain, pulse_present = 0;
1692 if (!common_window && !scale_flag) {
1739 int g,
i, group, idx = 0;
1742 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1745 for (group = 0; group < ics->
group_len[
g]; group++) {
1747 ch1 + group * 128 + offsets[i],
1748 offsets[i+1] - offsets[i]);
1770 int g, group,
i, idx = 0;
1774 for (i = 0; i < ics->
max_sfb;) {
1777 for (; i < bt_run_end; i++, idx++) {
1778 c = -1 + 2 * (sce1->
band_type[idx] - 14);
1780 c *= 1 - 2 * cpe->
ms_mask[idx];
1781 scale = c * sce1->
sf[idx];
1782 for (group = 0; group < ics->
group_len[
g]; group++)
1784 coef0 + group * 128 + offsets[i],
1786 offsets[i + 1] - offsets[i]);
1790 idx += bt_run_end -
i;
1806 int i, ret, common_window, ms_present = 0;
1809 if (common_window) {
1819 if (ms_present == 3) {
1822 }
else if (ms_present)
1825 if ((ret =
decode_ics(ac, &cpe->
ch[0], gb, common_window, 0)))
1827 if ((ret =
decode_ics(ac, &cpe->
ch[1], gb, common_window, 0)))
1830 if (common_window) {
1844 1.09050773266525765921,
1845 1.18920711500272106672,
1880 scale = cce_scale[
get_bits(gb, 2)];
1885 for (c = 0; c < num_gain; c++) {
1889 float gain_cache = 1.;
1892 gain = cge ?
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60: 0;
1893 gain_cache =
powf(scale, -gain);
1896 coup->
gain[
c][0] = gain_cache;
1899 for (sfb = 0; sfb < sce->
ics.
max_sfb; sfb++, idx++) {
1910 gain_cache =
powf(scale, -t) * s;
1913 coup->
gain[
c][idx] = gain_cache;
1931 int num_excl_chan = 0;
1934 for (i = 0; i < 7; i++)
1938 return num_excl_chan / 7;
1950 int drc_num_bands = 1;
1971 for (i = 0; i < drc_num_bands; i++) {
1984 for (i = 0; i < drc_num_bands; i++) {
1995 int i, major, minor;
2002 for(i=0; i+1<
sizeof(buf) && len>=8; i++, len-=8)
2009 if (sscanf(buf,
"libfaac %d.%d", &major, &minor) == 2){
2082 int bottom, top, order, start,
end,
size, inc;
2088 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
2100 if ((size = end - start) <= 0)
2112 for (m = 0; m <
size; m++, start += inc)
2113 for (i = 1; i <=
FFMIN(m, order); i++)
2114 coef[start] -= coef[start - i * inc] * lpc[i - 1];
2117 for (m = 0; m <
size; m++, start += inc) {
2118 tmp[0] = coef[start];
2119 for (i = 1; i <=
FFMIN(m, order); i++)
2120 coef[start] += tmp[i] * lpc[i - 1];
2121 for (i = order; i > 0; i--)
2122 tmp[i] = tmp[i - 1];
2144 memset(in, 0, 448 *
sizeof(
float));
2151 memset(in + 1024 + 576, 0, 448 *
sizeof(
float));
2166 float *predTime = sce->
ret;
2168 int16_t num_samples = 2048;
2170 if (ltp->
lag < 1024)
2171 num_samples = ltp->
lag + 1024;
2172 for (i = 0; i < num_samples; i++)
2174 memset(&predTime[i], 0, (2048 - i) *
sizeof(
float));
2183 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
2184 sce->
coeffs[i] += predFreq[i];
2194 float *saved = sce->
saved;
2195 float *saved_ltp = sce->
coeffs;
2201 memcpy(saved_ltp, saved, 512 *
sizeof(
float));
2202 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2204 for (i = 0; i < 64; i++)
2205 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2207 memcpy(saved_ltp, ac->
buf_mdct + 512, 448 *
sizeof(
float));
2208 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2210 for (i = 0; i < 64; i++)
2211 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2214 for (i = 0; i < 512; i++)
2215 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * lwindow[511 - i];
2231 float *saved = sce->
saved;
2241 for (i = 0; i < 1024; i += 128)
2256 memcpy( out, saved, 448 *
sizeof(
float));
2264 memcpy( out + 448 + 4*128, temp, 64 *
sizeof(
float));
2267 memcpy( out + 576, buf + 64, 448 *
sizeof(
float));
2273 memcpy( saved, temp + 64, 64 *
sizeof(
float));
2277 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2279 memcpy( saved, buf + 512, 448 *
sizeof(
float));
2280 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2282 memcpy( saved, buf + 512, 512 *
sizeof(
float));
2297 float *dest = target->
coeffs;
2298 const float *src = cce->
ch[0].
coeffs;
2299 int g,
i, group, k, idx = 0;
2302 "Dependent coupling is not supported together with LTP\n");
2306 for (i = 0; i < ics->
max_sfb; i++, idx++) {
2309 for (group = 0; group < ics->
group_len[
g]; group++) {
2310 for (k = offsets[i]; k < offsets[i + 1]; k++) {
2312 dest[group * 128 + k] += gain * src[group * 128 + k];
2333 const float *src = cce->
ch[0].
ret;
2334 float *dest = target->
ret;
2337 for (i = 0; i <
len; i++)
2338 dest[i] += gain * src[i];
2361 if (coup->
type[c] == type && coup->
id_select[c] == elem_id) {
2363 apply_coupling_method(ac, &cc->
ch[0], cce, index);
2368 apply_coupling_method(ac, &cc->
ch[1], cce, index++);
2382 for (type = 3; type >= 0; type--) {
2426 uint8_t layout_map[MAX_ELEM_ID*4][3];
2427 int layout_map_tags;
2454 layout_map_tags = 2;
2455 layout_map[0][0] = layout_map[1][0] =
TYPE_SCE;
2457 layout_map[0][1] = 0;
2458 layout_map[1][1] = 1;
2486 int samples = 0, multiplier, audio_found = 0, pce_found = 0;
2487 int is_dmono, sce_count = 0;
2515 if (!(che=
get_che(ac, elem_type, elem_id))) {
2517 elem_type, elem_id);
2524 switch (elem_type) {
2551 uint8_t layout_map[MAX_ELEM_ID*4][3];
2561 "Not evaluating a further program_config_element as this construct is dubious at best.\n");
2590 elem_type_prev = elem_type;
2605 samples <<= multiplier;
2607 is_dmono = ac->
dmono_mode && sce_count == 2 &&
2621 if (ac->
oc[1].
status && audio_found) {
2630 if (side && side_size>=4)
2640 int *got_frame_ptr,
AVPacket *avpkt)
2644 int buf_size = avpkt->
size;
2649 int new_extradata_size;
2652 &new_extradata_size);
2653 int jp_dualmono_size;
2658 if (new_extradata && 0) {
2665 memcpy(avctx->
extradata, new_extradata, new_extradata_size);
2676 if (jp_dualmono && jp_dualmono_size > 0)
2681 if (INT_MAX / 8 <= buf_size)
2690 for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
2691 if (buf[buf_offset])
2694 return buf_size > buf_offset ? buf_consumed : buf_size;
2703 for (type = 0; type < 4; type++) {
2704 if (ac->
che[type][i])
2717 #define LOAS_SYNC_WORD 0x2b7
2743 int sync_extension = 0;
2744 int bits_consumed, esize;
2752 if (config_start_bit % 8) {
2754 "Non-byte-aligned audio-specific config", 1);
2760 gb->
buffer + (config_start_bit / 8),
2761 asclen, sync_extension);
2763 if (bits_consumed < 0)
2777 esize = (bits_consumed+7) / 8;
2792 return bits_consumed;
2798 int ret, audio_mux_version =
get_bits(gb, 1);
2801 if (audio_mux_version)
2806 if (audio_mux_version)
2814 "Multiple programs", 1);
2823 "Multiple layers", 1);
2828 if (!audio_mux_version) {
2859 if (audio_mux_version) {
2882 int mux_slot_length = 0;
2885 mux_slot_length += tmp;
2886 }
while (tmp == 255);
2887 return mux_slot_length;
2903 if (!use_same_mux) {
2908 "no decoder config found\n");
2916 }
else if (mux_slot_length_bytes * 8 + 256 <
get_bits_left(gb)) {
2918 "frame length mismatch %d << %d\n",
2928 int *got_frame_ptr,
AVPacket *avpkt)
2943 if (muxlength > avpkt->
size)
2967 "ADTS header detected, probably as result of configuration "
3003 #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
3005 {
"dual_mono_mode",
"Select the channel to decode for dual mono",