55 #define DCA_PRIM_CHANNELS_MAX (7) 56 #define DCA_SUBBANDS (64) 57 #define DCA_ABITS_MAX (32) 58 #define DCA_SUBSUBFRAMES_MAX (4) 59 #define DCA_SUBFRAMES_MAX (16) 60 #define DCA_BLOCKS_MAX (16) 61 #define DCA_LFE_MAX (3) 62 #define DCA_CHSETS_MAX (4) 63 #define DCA_CHSET_CHANS_MAX (8) 187 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96) 236 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
240 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
241 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
242 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
243 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
244 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
245 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
246 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
247 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
248 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
249 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
250 { 3, 4, 0, 1, 5, 6, -1, -1, -1},
251 { 2, 0, 1, 4, 5, 6, -1, -1, -1},
252 { 0, 6, 4, 5, 2, 3, -1, -1, -1},
253 { 4, 2, 5, 0, 1, 6, 7, -1, -1},
254 { 5, 6, 0, 1, 7, 3, 8, 4, -1},
255 { 4, 2, 5, 0, 1, 6, 8, 7, -1},
259 { 0, 2, -1, -1, -1, -1, -1, -1, -1},
260 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
261 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
262 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
263 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
264 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
265 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
266 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
267 { 0, 1, 4, 5, 3, -1, -1, -1, -1},
268 { 2, 0, 1, 5, 6, 4, -1, -1, -1},
269 { 3, 4, 0, 1, 6, 7, 5, -1, -1},
270 { 2, 0, 1, 4, 5, 6, 7, -1, -1},
271 { 0, 6, 4, 5, 2, 3, 7, -1, -1},
272 { 4, 2, 5, 0, 1, 7, 8, 6, -1},
273 { 5, 6, 0, 1, 8, 3, 9, 4, 7},
274 { 4, 2, 5, 0, 1, 6, 9, 8, 7},
278 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
279 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
280 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
281 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
282 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
283 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
284 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
285 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
286 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
287 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
288 { 2, 3, 0, 1, 4, 5, -1, -1, -1},
289 { 2, 0, 1, 3, 4, 5, -1, -1, -1},
290 { 0, 5, 3, 4, 1, 2, -1, -1, -1},
291 { 3, 2, 4, 0, 1, 5, 6, -1, -1},
292 { 4, 5, 0, 1, 6, 2, 7, 3, -1},
293 { 3, 2, 4, 0, 1, 5, 7, 6, -1},
297 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
298 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
299 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
300 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
301 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
302 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
303 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
304 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
305 { 0, 1, 3, 4, 2, -1, -1, -1, -1},
306 { 2, 0, 1, 4, 5, 3, -1, -1, -1},
307 { 2, 3, 0, 1, 5, 6, 4, -1, -1},
308 { 2, 0, 1, 3, 4, 5, 6, -1, -1},
309 { 0, 5, 3, 4, 1, 2, 6, -1, -1},
310 { 3, 2, 4, 0, 1, 6, 7, 5, -1},
311 { 4, 5, 0, 1, 7, 2, 8, 3, 6},
312 { 3, 2, 4, 0, 1, 5, 8, 7, 6},
315 #define DCA_DOLBY 101 317 #define DCA_CHANNEL_BITS 6 318 #define DCA_CHANNEL_MASK 0x3F 322 #define HEADER_SIZE 14 324 #define DCA_MAX_FRAME_SIZE 16384 325 #define DCA_MAX_EXSS_HEADER_SIZE 4096 327 #define DCA_BUFFER_PADDING_SIZE 1024 424 uint8_t *extra_channels_buffer;
425 unsigned int extra_channels_buffer_size;
430 const int8_t *channel_order_tab;
433 int current_subframe;
434 int current_subsubframe;
440 int xch_base_channel;
444 int xxch_nbits_spk_mask;
445 uint32_t xxch_core_spkmask;
446 uint32_t xxch_spk_masks[4];
447 int xxch_chset_nch[4];
450 uint32_t xxch_dmix_embedded;
453 int8_t xxch_order_tab[32];
460 int mix_config_num_ch[4];
473 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
474 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
475 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
476 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
477 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
478 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
483 static int vlcs_initialized = 0;
485 static VLC_TYPE dca_table[23622][2];
487 if (vlcs_initialized)
490 dca_bitalloc_index.
offset = 1;
491 dca_bitalloc_index.
wrap = 2;
492 for (i = 0; i < 5; i++) {
499 dca_scalefactor.
offset = -64;
500 dca_scalefactor.
wrap = 2;
501 for (i = 0; i < 5; i++) {
510 for (i = 0; i < 4; i++) {
518 for (i = 0; i < 10; i++)
519 for (j = 0; j < 7; j++) {
523 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
533 vlcs_initialized = 1;
547 for (i = -1, base = 0, mask = (s->xxch_core_spkmask & ~
DCA_XXCH_LFE1);
548 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->xxch_spk_masks[++i])
549 base += av_popcount(mask);
551 return base + av_popcount(mask & (xxch_ch - 1));
558 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
559 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
560 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
561 int hdr_pos = 0, hdr_size = 0;
562 float sign,
mag, scale_factor;
563 int this_chans, acc_mask;
564 int embedded_downmix;
580 acc_mask = s->xxch_core_spkmask;
582 this_chans =
get_bits(&s->gb, s->xxch_nbits_spk_mask - 6) << 6;
583 s->xxch_spk_masks[s->xxch_chset] = this_chans;
584 s->xxch_chset_nch[s->xxch_chset] = nchans;
586 for (i = 0; i <= s->xxch_chset; i++)
587 acc_mask |= s->xxch_spk_masks[i];
595 s->xxch_dmix_sf[s->xxch_chset] = scale_factor;
598 mask[
i] =
get_bits(&s->gb, s->xxch_nbits_spk_mask);
602 memset(s->xxch_dmix_coeff[j], 0,
sizeof(s->xxch_dmix_coeff[0]));
603 s->xxch_dmix_embedded |= (embedded_downmix << j);
604 for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
605 if (mask[j] & (1 << i)) {
608 "DCA-XXCH: dmix to LFE1 not supported.\n");
613 sign = (coeff & 64) ? 1.0 : -1.0;
616 s->xxch_dmix_coeff[j][ichan] = sign *
mag;
645 for (j = 1; j < 11; j++)
650 for (j = 0; j < 11; j++)
654 for (j = 1; j < 11; j++)
667 if (hdr_pos + 8 * hdr_size > i)
671 s->current_subframe = 0;
672 s->current_subsubframe = 0;
691 for (j = 0; j < 11; j++)
695 for (j = 0; j < 11; j++)
706 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
758 s->output = s->
amode;
792 "source pcm resolution: %i (%i bits/sample)\n",
812 value = av_clip(value, 0, (1 << log2range) - 1);
813 }
else if (level < 8) {
814 if (level + 1 > log2range) {
861 "Invalid bit allocation index\n");
869 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
881 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
892 const uint32_t *scale_table;
893 int scale_sum, log_size;
945 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
950 if (!(s->debug_flag & 0x02)) {
952 "Joint stereo coding not supported\n");
953 s->debug_flag |= 0x02;
969 "Invalid channel mode %d\n", am);
999 if (!base_channel && s->
lfe) {
1002 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1003 int lfe_end_sample = 2 * s->
lfe * (4 + block_index + s->
subsubframes[s->current_subframe]);
1006 for (j = lfe_samples; j < lfe_end_sample; j++) {
1022 for (j = lfe_samples; j < lfe_end_sample; j++)
1041 "prediction coefs: %f, %f, %f, %f\n",
1073 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
1091 if (!base_channel && s->
lfe) {
1092 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1093 int lfe_end_sample = 2 * s->
lfe * (4 + block_index + s->
subsubframes[s->current_subframe]);
1096 for (j = lfe_samples; j < lfe_end_sample; j++)
1106 float samples_in[32][8],
float *samples_out,
1109 const float *prCoeff;
1115 scale *=
sqrt(1 / 8.0);
1119 prCoeff = fir_32bands_nonperfect;
1121 prCoeff = fir_32bands_perfect;
1123 for (i = sb_act; i < 32; i++)
1127 for (subindex = 0; subindex < 8; subindex++) {
1129 for (i = 0; i < sb_act; i++) {
1130 unsigned sign = (i - 1) & 2;
1131 uint32_t
v =
AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
1135 s->synth.synth_filter_float(&s->imdct,
1136 s->subband_fir_hist[chans],
1137 &s->hist_index[chans],
1138 s->subband_fir_noidea[chans], prCoeff,
1139 samples_out, s->raXin, scale);
1145 int num_deci_sample,
float *samples_in,
1146 float *samples_out,
float scale)
1157 const float *prCoeff;
1161 if (decimation_select == 1) {
1163 prCoeff = lfe_fir_128;
1166 prCoeff = lfe_fir_64;
1169 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1170 s->dcadsp.lfe_fir(samples_out, samples_in, prCoeff, decifactor, scale);
1172 samples_out += 2 * decifactor;
1177 #define MIX_REAR1(samples, s1, rs, coef) \ 1178 samples[0][i] += samples[s1][i] * coef[rs][0]; \ 1179 samples[1][i] += samples[s1][i] * coef[rs][1]; 1181 #define MIX_REAR2(samples, s1, s2, rs, coef) \ 1182 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \ 1183 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1]; 1185 #define MIX_FRONT3(samples, coef) \ 1186 t = samples[c][i]; \ 1187 u = samples[l][i]; \ 1188 v = samples[r][i]; \ 1189 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \ 1190 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1]; 1192 #define DOWNMIX_TO_STEREO(op1, op2) \ 1193 for (i = 0; i < 256; i++) { \ 1200 const int8_t *channel_mapping)
1202 int c, l,
r, sl, sr,
s;
1223 c = channel_mapping[0];
1224 l = channel_mapping[1];
1225 r = channel_mapping[2];
1229 s = channel_mapping[2];
1233 c = channel_mapping[0];
1234 l = channel_mapping[1];
1235 r = channel_mapping[2];
1236 s = channel_mapping[3];
1241 sl = channel_mapping[2];
1242 sr = channel_mapping[3];
1246 c = channel_mapping[0];
1247 l = channel_mapping[1];
1248 r = channel_mapping[2];
1249 sl = channel_mapping[3];
1250 sr = channel_mapping[4];
1258 #ifndef decode_blockcodes 1264 int offset = (levels - 1) >> 1;
1266 for (i = 0; i < 4; i++) {
1267 int div =
FASTDIV(code, levels);
1268 values[
i] = code - offset - div * levels;
1285 #ifndef int8x8_fmul_int32 1288 float fscale = scale / 16.0;
1290 for (i = 0; i < 8; i++)
1291 dst[i] = src[i] * fscale;
1298 int subsubframe = s->current_subsubframe;
1300 const float *quant_step_table;
1303 float (*subband_samples)[
DCA_SUBBANDS][8] = s->subband_samples[block_index];
1326 float quant_step_size = quant_step_table[abits];
1339 memset(subband_samples[k][l], 0, 8 *
sizeof(subband_samples[0][0][0]));
1343 float rscale = quant_step_size * s->
scale_factor[
k][l][sfi] *
1346 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
1349 int block_code1, block_code2,
size, levels, err;
1354 block_code1 =
get_bits(&s->gb, size);
1355 block_code2 =
get_bits(&s->gb, size);
1360 "ERROR: block code look-up failed\n");
1365 for (m = 0; m < 8; m++)
1366 block[m] =
get_sbits(&s->gb, abits - 3);
1370 for (m = 0; m < 8; m++)
1372 &dca_smpl_bitalloc[abits], sel);
1375 s->fmt_conv.int32_to_float_fmul_scalar(subband_samples[k][l],
1384 for (m = 0; m < 8; m++) {
1385 for (n = 1; n <= 4; n++)
1387 subband_samples[
k][l][
m] +=
1389 subband_samples[
k][l][m -
n] / 8192);
1391 subband_samples[
k][l][
m] +=
1393 s->subband_samples_hist[
k][l][m - n + 4] / 8192);
1406 if (!s->debug_flag & 0x01) {
1408 "Stream with high frequencies VQ coding\n");
1409 s->debug_flag |= 0x01;
1413 &high_freq_vq[hfvq][subsubframe * 8],
1420 if (0xFFFF ==
get_bits(&s->gb, 16)) {
1432 memcpy(s->subband_samples_hist[k][l],
1433 &subband_samples[k][l][4],
1434 4 *
sizeof(subband_samples[0][0][0]));
1441 float (*subband_samples)[
DCA_SUBBANDS][8] = s->subband_samples[block_index];
1463 s->samples_chanptr[s->lfe_index],
1464 1.0 / (256.0 * 32768.0));
1474 int aux_data_count = 0,
i;
1481 if (!base_channel) {
1486 aux_data_count =
get_bits(&s->gb, 6);
1488 for (
i = 0;
i < aux_data_count;
i++)
1509 if (s->current_subframe >= s->
subframes) {
1515 if (!s->current_subsubframe) {
1532 s->current_subsubframe++;
1533 if (s->current_subsubframe >= s->
subsubframes[s->current_subframe]) {
1534 s->current_subsubframe = 0;
1535 s->current_subframe++;
1537 if (s->current_subframe >= s->
subframes) {
1555 return av_popcount(mask) +
1574 for (i = 0; i < channels; i++) {
1575 int mix_map_mask =
get_bits(gb, out_ch);
1576 int num_coeffs = av_popcount(mix_map_mask);
1589 int embedded_stereo = 0;
1590 int embedded_6ch = 0;
1591 int drc_code_present;
1601 header_size =
get_bits(&s->gb, 9) + 1;
1604 if (s->static_fields) {
1613 int text_length =
get_bits(&s->gb, 10) + 1;
1621 channels =
get_bits(&s->gb, 8) + 1;
1624 int spkr_remap_sets;
1625 int spkr_mask_size = 16;
1634 spkr_mask_size = (
get_bits(&s->gb, 2) + 1) << 2;
1638 spkr_remap_sets =
get_bits(&s->gb, 3);
1640 for (i = 0; i < spkr_remap_sets; i++) {
1645 for (i = 0; i < spkr_remap_sets; i++) {
1646 int num_dec_ch_remaps =
get_bits(&s->gb, 5) + 1;
1650 for (j = 0; j < num_spkrs[
i]; j++) {
1651 int remap_dec_ch_mask =
get_bits_long(&s->gb, num_dec_ch_remaps);
1652 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1663 if (drc_code_present)
1669 if (drc_code_present && embedded_stereo)
1672 if (s->mix_metadata &&
get_bits1(&s->gb)) {
1682 for (i = 0; i < s->num_mix_configs; i++)
1687 for (i = 0; i < s->num_mix_configs; i++) {
1693 if (embedded_stereo)
1699 case 0: extensions_mask =
get_bits(&s->gb, 12);
break;
1702 case 3: extensions_mask = 0;
break;
1726 "DTS extensions detection mismatch (%d, %d)\n",
1727 extensions_mask & DCA_CORE_EXTS, s->core_ext_mask);
1740 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1741 int i, j,
k, l, chset, chan_base;
1748 hdr_size =
get_bits(&s->gb, 6) + 1;
1749 num_chsets =
get_bits(&s->gb, 2) + 1;
1751 for(i = 0; i < num_chsets; i++)
1752 chset_fsize[i] =
get_bits(&s->gb, 14) + 1;
1756 for(i = 0; i < num_chsets; i++) {
1759 for(j = 0; j < n_xbr_ch[
i]; j++)
1760 active_bands[i][j] =
get_bits(&s->gb, k) + 1;
1765 if(hdr_pos + hdr_size * 8 > i)
1770 for(chset = 0, chan_base = 0;
1771 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1772 chan_base += n_xbr_ch[chset++]) {
1774 int subsubframe = 0;
1780 if(subsubframe == 0) {
1782 for(i = 0; i < n_xbr_ch[chset]; i++) {
1786 for(i = 0; i < n_xbr_ch[chset]; i++) {
1787 get_array(&s->gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1790 for(i = 0; i < n_xbr_ch[chset]; i++) {
1792 if(anctemp[i] < 1) {
1799 for(i = 0; i < n_xbr_ch[chset]; i++) {
1800 const uint32_t *scale_table;
1811 for(j = 0; j < active_bands[chset][
i]; j++) {
1812 if(abits_high[i][j] > 0) {
1813 scale_table_high[
i][j][0] =
1814 scale_table[
get_bits(&s->gb, nbits)];
1817 scale_table_high[
i][j][1] =
1818 scale_table[
get_bits(&s->gb, nbits)];
1826 for(i = 0; i < n_xbr_ch[chset]; i++) {
1827 for(j = 0; j < active_bands[chset][
i]; j++) {
1828 const int xbr_abits = abits_high[
i][j];
1831 const float rscale = quant_step_size * scale_table_high[
i][j][sfi];
1832 float *subband_samples = s->subband_samples[
k][chan_base+
i][j];
1839 get_array(&s->gb, block, 8, xbr_abits - 3);
1841 int block_code1, block_code2,
size, levels, err;
1846 block_code1 =
get_bits(&s->gb, size);
1847 block_code2 =
get_bits(&s->gb, size);
1852 "ERROR: DTS-XBR: block code look-up failed\n");
1858 for(l = 0; l < 8; l++)
1859 subband_samples[l] += (
float)block[l] * rscale;
1865 if(
get_bits(&s->gb, 16) != 0xffff) {
1880 if(start_posn + chset_fsize[chset] * 8 != i) {
1881 j = start_posn + chset_fsize[chset] * 8 -
i;
1884 " skipping further than expected (%d bits)\n", j);
1895 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1896 int i, chset, base_channel, chstart, fsize[8];
1900 hdr_size =
get_bits(&s->gb, 6) + 1;
1902 spkmsk_bits =
get_bits(&s->gb, 5) + 1;
1903 num_chsets =
get_bits(&s->gb, 2) + 1;
1905 for (i = 0; i < num_chsets; i++)
1906 fsize[i] =
get_bits(&s->gb, 14) + 1;
1908 core_spk =
get_bits(&s->gb, spkmsk_bits);
1909 s->xxch_core_spkmask = core_spk;
1910 s->xxch_nbits_spk_mask = spkmsk_bits;
1911 s->xxch_dmix_embedded = 0;
1915 if (hdr_pos + hdr_size * 8 > i)
1918 for (chset = 0; chset < num_chsets; chset++) {
1921 s->xxch_chset = chset;
1931 "Error decoding DTS-XXCH extension\n");
1938 if (chstart + fsize[chset] * 8 > i)
1941 s->xxch_chset = num_chsets;
1956 int active_ss_mask[8];
1971 hdrsize =
get_bits(&s->gb, 8 + 4 * blownup) + 1;
1975 if (s->static_fields) {
1985 num_audiop =
get_bits(&s->gb, 3) + 1;
1986 if (num_audiop > 1) {
1988 "Multiple DTS-HD audio presentations");
1993 num_assets =
get_bits(&s->gb, 3) + 1;
1994 if (num_assets > 1) {
2000 for (i = 0; i < num_audiop; i++)
2001 active_ss_mask[i] =
get_bits(&s->gb, ss_index + 1);
2003 for (i = 0; i < num_audiop; i++)
2004 for (j = 0; j <= ss_index; j++)
2005 if (active_ss_mask[i] & (1 << j))
2009 if (s->mix_metadata) {
2010 int mix_out_mask_size;
2013 mix_out_mask_size = (
get_bits(&s->gb, 2) + 1) << 2;
2014 s->num_mix_configs =
get_bits(&s->gb, 2) + 1;
2016 for (i = 0; i < s->num_mix_configs; i++) {
2017 int mix_out_mask =
get_bits(&s->gb, mix_out_mask_size);
2023 for (i = 0; i < num_assets; i++)
2026 for (i = 0; i < num_assets; i++) {
2034 if (num_assets > 0) {
2036 if (start_posn + hdrsize * 8 > j)
2039 for (i = 0; i < num_assets; i++) {
2044 if (mkr == 0x655e315e) {
2046 }
else if (mkr == 0x47004a03) {
2051 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
2056 if (start_posn + asset_size[i] * 8 > j)
2067 int *got_frame_ptr,
AVPacket *avpkt)
2071 int buf_size = avpkt->
size;
2075 int num_core_channels = 0;
2077 float **samples_flt;
2082 int channels, full_channels;
2101 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
2125 s->core_ext_mask = 0;
2135 s->core_ext_mask =
FFMAX(s->core_ext_mask, 0);
2145 int ext_amode, xch_fsize;
2162 if ((ext_amode =
get_bits(&s->gb, 4)) != 1) {
2164 " supported!\n", ext_amode);
2168 if (s->xch_base_channel < 2) {
2194 int fsize96 =
show_bits(&s->gb, 12) + 1;
2222 if (s->dca_buffer_size - s->
frame_size > 32 &&
2233 || (s->core_ext_mask &
DCA_EXT_XXCH && avctx->request_channels > 0
2234 && avctx->request_channels
2235 < num_core_channels + !!s->
lfe + s->xxch_chset_nch[0]))
2237 if (s->
amode < 16) {
2240 if (s->xch_present && (!avctx->request_channels ||
2241 avctx->request_channels
2242 > num_core_channels + !!s->
lfe)) {
2253 channels = num_core_channels + !!s->
lfe;
2262 if (channels > !!s->
lfe &&
2277 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
2283 "Non standard configuration %d !\n", s->
amode);
2287 s->xxch_dmix_embedded = 0;
2290 channel_mask = s->xxch_core_spkmask;
2292 if (avctx->request_channels > 0
2294 channels = num_core_channels + !!s->
lfe;
2295 for (i = 0; i < s->xxch_chset && channels + s->xxch_chset_nch[
i]
2296 <= avctx->request_channels; i++) {
2297 channels += s->xxch_chset_nch[
i];
2298 channel_mask |= s->xxch_spk_masks[
i];
2302 for (i = 0; i < s->xxch_chset; i++) {
2303 channel_mask |= s->xxch_spk_masks[
i];
2309 for (i = 0; i < s->xxch_nbits_spk_mask; ++
i) {
2310 if (channel_mask & (1 << i)) {
2317 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
2319 "DTS-XXCH: Inconsistant avcodec/dts channel layouts\n");
2327 for (chset = -1, j = 0; chset < s->xxch_chset; ++chset) {
2328 mask = chset >= 0 ? s->xxch_spk_masks[chset]
2329 : s->xxch_core_spkmask;
2330 for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
2333 posn = av_popcount(channel_layout & (lavc - 1));
2334 s->xxch_order_tab[j++] = posn;
2341 for (i = 0; i < channels; i++)
2342 s->xxch_order_tab[i] = i;
2344 s->lfe_index = channels - 1;
2371 &s->extra_channels_buffer_size, ret);
2372 if (!s->extra_channels_buffer)
2376 s->extra_channels_buffer,
2377 full_channels - channels,
2387 for (ch = 0; ch < channels; ch++)
2388 s->samples_chanptr[ch] = samples_flt[ch] + i * 256;
2389 for (; ch < full_channels; ch++)
2390 s->samples_chanptr[ch] = s->extra_channels[ch - channels] + i * 256;
2397 float *back_chan = s->samples_chanptr[s->
channel_order_tab[s->xch_base_channel]];
2398 float *lt_chan = s->samples_chanptr[s->
channel_order_tab[s->xch_base_channel - 2]];
2399 float *rt_chan = s->samples_chanptr[s->
channel_order_tab[s->xch_base_channel - 1]];
2400 s->fdsp.vector_fmac_scalar(lt_chan, back_chan, -
M_SQRT1_2, 256);
2401 s->fdsp.vector_fmac_scalar(rt_chan, back_chan, -
M_SQRT1_2, 256);
2405 if (s->xxch_dmix_embedded) {
2407 ch = num_core_channels;
2408 for (chset = 0; chset < s->xxch_chset; chset++) {
2409 endch = ch + s->xxch_chset_nch[chset];
2410 mask = s->xxch_dmix_embedded;
2413 for (j = ch; j < endch; j++) {
2414 if (mask & (1 << j)) {
2416 for (k = 0; k < endch; k++) {
2418 scale = s->xxch_dmix_coeff[j][
k];
2420 dst_chan = s->samples_chanptr[achan];
2421 s->fdsp.vector_fmac_scalar(dst_chan, src_chan,
2429 if ((mask & (1 << ch)) && s->xxch_dmix_sf[chset] != 1.0f) {
2430 scale = s->xxch_dmix_sf[chset];
2432 for (j = 0; j < ch; j++) {
2434 for (k = 0; k < 256; k++)
2435 src_chan[k] *= scale;
2440 src_chan = s->samples_chanptr[s->lfe_index];
2441 for (k = 0; k < 256; k++)
2442 src_chan[k] *= scale;
2454 for (i = 0; i < 2 * s->
lfe * 4; i++)
2487 avctx->request_channels == 2) {
2488 avctx->
channels = avctx->request_channels;
2498 av_freep(&s->extra_channels_buffer);
int wrap
wrap for get_vlc2()
int ext_descr
extension audio descriptor flag
static const int8_t bitalloc_offsets[10]
int downmix
embedded downmix enabled
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]
quantization index codebook select
int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]
bit allocation quantizer select
int crc_present
crc is present in the bitstream
#define DCA_CHSET_CHANS_MAX
This structure describes decoded (raw) audio or video data.
low bitrate component in ExSS
#define AV_CH_TOP_FRONT_RIGHT
int timestamp
embedded time stamp flag
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
int amode
audio channels arrangement
static const AVProfile profiles[]
static const uint16_t tmode_codes[TMODE_COUNT][4]
int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]
stereo downmix coefficients
int transient_huffman[DCA_PRIM_CHANNELS_MAX]
transient mode code book
int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]
scale factors (2 if transient)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static const uint32_t scale_factor_quant6[64]
static void skip_bits_long(GetBitContext *s, int n)
static av_cold int init(AVCodecContext *avctx)
static int dca_parse_frame_header(DCAContext *s)
static int dca_exss_parse_asset_header(DCAContext *s)
Parse extension substream asset header (HD)
#define AV_LOG_WARNING
Something somehow does not look correct.
static void dca_exss_skip_mix_coeffs(GetBitContext *gb, int channels, int out_ch)
Skip mixing coefficients of a single mix out configuration (HD)
#define AV_CH_TOP_FRONT_LEFT
int vq_start_subband[DCA_PRIM_CHANNELS_MAX]
high frequency vq start subband
XXCh channels extension in core substream.
#define AV_CH_TOP_FRONT_CENTER
void ff_dcadsp_init(DCADSPContext *s)
int samples_deficit
deficit sample count
#define DECLARE_ALIGNED(n, t, v)
static const float lossless_quant_d[32]
int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, int max_size)
Convert bitstream to one representation based on sync marker.
int dynrange
embedded dynamic range flag
int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
joint subband scale factors
int version
encoder software revision
static const int8_t dca_channel_reorder_lfe_xch[][9]
#define FF_ARRAY_ELEMS(a)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
#define AV_CH_LAYOUT_STEREO
static BitAlloc dca_scalefactor
scalefactor VLCs
#define DCA_BUFFER_PADDING_SIZE
static int get_sbits(GetBitContext *s, int n)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define DCA_HD_MARKER
DCA-HD specific block starts with this marker.
static int dca_subframe_footer(DCAContext *s, int base_channel)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static BitAlloc dca_tmode
transition mode VLCs
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill plane data pointers and linesize for samples with sample format sample_fmt.
#define MIX_FRONT3(samples, coef)
#define FF_PROFILE_DTS_ES
static int dca_exss_mask2count(int mask)
Return the number of channels in an ExSS speaker mask (HD)
static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]
scale factor code book
static int dca_decode_block(DCAContext *s, int base_channel, int block_index)
Decode a dca frame block.
static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)
enum AVSampleFormat sample_fmt
audio sample format
static const uint16_t dca_vlc_offs[]
#define AV_CH_TOP_BACK_LEFT
static int dca_parse_audio_coding_header(DCAContext *s, int base_channel, int xxch)
static const uint32_t scale_factor_quant7[128]
#define MIX_REAR2(samples, s1, s2, rs, coef)
static void get_array(GetBitContext *gb, int *dst, int len, int bits)
#define AV_CH_TOP_BACK_CENTER
#define FF_PROFILE_UNKNOWN
static av_cold int dca_decode_end(AVCodecContext *avctx)
#define AV_CH_LOW_FREQUENCY
int header_crc
header crc check bytes
#define FF_PROFILE_DTS_96_24
int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
transition mode (transients)
static int dca_xxch2index(DCAContext *s, int xxch_ch)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int get_bits_count(const GetBitContext *s)
int sample_rate
audio sampling rate
bitstream reader API header.
XCh channel extension in core substream.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static BitAlloc dca_bitalloc_index
indexes for samples VLC select
int lfe
low frequency effects flag
static BitAlloc dca_smpl_bitalloc[11]
samples VLCs
XXCh channels extension in ExSS.
static const uint8_t bitalloc_sizes[10]
int predictor_history
predictor history flag
static int dca_xbr_parse_frame(DCAContext *s)
int dynrange_coef
dynamic range coefficient
int joint_huff[DCA_PRIM_CHANNELS_MAX]
joint subband scale factors codebook
static int get_bits_left(GetBitContext *gb)
static const uint16_t mask[17]
#define MIX_REAR1(samples, s1, rs, coef)
#define DCA_PRIM_CHANNELS_MAX
static const uint16_t bitalloc_12_codes[BITALLOC_12_COUNT][12]
static const struct endianess table[]
int hdcd
source material is mastered in HDCD
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
void av_log(void *avcl, int level, const char *fmt,...)
static const uint8_t bitalloc_12_bits[BITALLOC_12_COUNT][12]
const char * name
Name of the codec implementation.
int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
bit allocation index
static int dca_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Main frame decoding function FIXME add arguments.
static const uint8_t offset[127][2]
uint64_t channel_layout
Audio channel layout.
static const int8_t dca_lfe_index[]
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
float lfe_data[2 *DCA_LFE_MAX *(DCA_BLOCKS_MAX+4)]
Low frequency effect data.
common internal API header
static const uint8_t tmode_bits[TMODE_COUNT][4]
static void qmf_32_subbands(DCAContext *s, int chans, float samples_in[32][8], float *samples_out, float scale)
int front_sum
front sum/difference flag
static const float dca_downmix_coeffs[65]
int source_pcm_res
source pcm resolution
static int dca_xxch_decode_frame(DCAContext *s)
static const uint32_t map_xxch_to_native[28]
#define FF_PROFILE_DTS_HD_HRA
int bit_rate
the average bitrate
audio channel layout utility functions
static const int8_t dca_channel_reorder_lfe[][9]
static const int8_t dca_channel_reorder_nolfe[][9]
int surround_sum
surround sum/difference flag
static av_cold void dca_init_vlcs(void)
static const float dca_downmix_scale_factors[241]
av_cold void ff_synth_filter_init(SynthFilterContext *c)
static const uint8_t scales_bits[SCALES_COUNT][129]
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
int joint_intensity[DCA_PRIM_CHANNELS_MAX]
joint intensity coding index
static const int16_t adpcm_vb[4096][4]
static const uint16_t *const bitalloc_codes[10][8]
int multirate_inter
multirate interpolator switch
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static const uint8_t dca_channels[16]
#define AV_CH_FRONT_LEFT_OF_CENTER
lossless extension in ExSS
#define AV_CH_FRONT_CENTER
const uint32_t avpriv_dca_sample_rates[16]
FIXME Range Coding of cr are level
int bit_rate
transmission bit rate
static const uint8_t *const bitalloc_bits[10][8]
#define INIT_VLC_USE_NEW_STATIC
int offset
code values offset
static const uint8_t abits_levels[7]
#define AV_CH_FRONT_RIGHT_OF_CENTER
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
VQ encoded high frequency subbands.
or the Software in violation of any applicable export control laws in any jurisdiction Except as provided by mandatorily applicable UPF has no obligation to provide you with source code to the Software In the event Software contains any source code
#define DCA_MAX_FRAME_SIZE
int aux_data
auxiliary data flag
int sample_rate
samples per second
int ext_coding
extended coding flag
#define AV_CH_LAYOUT_NATIVE
Channel mask value used for AVCodecContext.request_channel_layout to indicate that the user requests ...
int subband_activity[DCA_PRIM_CHANNELS_MAX]
subband activity count
main external API structure.
static void close(AVCodecParserContext *s)
float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]
scale factor adjustment
int copy_history
copy history
static void dca_exss_parse_header(DCAContext *s)
Parse extension substream header (HD)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void int8x8_fmul_int32(float *dst, const int8_t *src, int scale)
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
#define AV_CH_TOP_BACK_RIGHT
core in ExSS (extension substream)
static void skip_bits(GetBitContext *s, int n)
synthesis window for stochastic i
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static const uint64_t dca_core_channel_layout[]
static void dca_downmix(float **samples, int srcfmt, int downmix_coef[DCA_PRIM_CHANNELS_MAX][2], const int8_t *channel_mapping)
static int decode_blockcodes(int code1, int code2, int levels, int *values)
static const float lossy_quant_d[32]
extended bitrate extension in ExSS
static int decode_blockcode(int code, int levels, int *values)
int sample_blocks
number of PCM sample blocks
static const double coeff[2][5]
static const uint8_t abits_sizes[7]
static const int8_t dca_channel_reorder_nolfe_xch[][9]
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define AV_CH_BACK_CENTER
int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
prediction mode (ADPCM used or not)
static av_cold int dca_decode_init(AVCodecContext *avctx)
DCA initialization.
static const uint8_t dca_default_coeffs[10][5][2]
96/24 extension in core substream
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
common internal and external API header
static void lfe_interpolation_fir(DCAContext *s, int decimation_select, int num_deci_sample, float *samples_in, float *samples_out, float scale)
#define CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
int total_channels
number of channels including extensions
static const uint16_t scales_codes[SCALES_COUNT][129]
static int dca_filter_channels(DCAContext *s, int block_index)
int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
prediction VQ coefs
int dialog_norm
dialog normalisation parameter
AVSampleFormat
Audio Sample Formats.
these buffered frames must be flushed immediately if a new input produces new output(Example:frame rate-doubling filter:filter_frame must(1) flush the second copy of the previous frame, if it is still there,(2) push the first copy of the incoming frame,(3) keep the second copy for later.) If the input frame is not enough to produce output
#define FF_PROFILE_DTS_HD_MA
int bit_rate_index
transmission bit rate index
static const uint8_t bitalloc_maxbits[10][7]
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
int channels
number of audio channels
static const uint32_t dca_bit_rates[32]
else dst[i][x+y *dst_stride[i]]
VLC_TYPE(* table)[2]
code, bits
int subsubframes[DCA_SUBFRAMES_MAX]
number of subsubframes
#define DCA_MAX_EXSS_HEADER_SIZE
static const int dca_ext_audio_descr_mask[]
#define DOWNMIX_TO_STEREO(op1, op2)
int frame_size
primary frame byte size
#define DCA_SUBFRAMES_MAX
#define AV_CH_FRONT_RIGHT
int aspf
audio sync word insertion flag
Filter the word “frame” indicates either a video frame or a group of audio samples
#define LOCAL_ALIGNED_16(t, v,...)
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int prim_channels
number of primary audio channels
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
static const uint8_t bitalloc_12_vlc_bits[BITALLOC_12_COUNT]
static int get_scale(GetBitContext *gb, int level, int value, int log2range)
uint8_t ** extended_data
pointers to the data planes/channels.
uint64_t request_channel_layout
Request decoder to use this channel layout if it can (0 for default)
int partial_samples[DCA_SUBFRAMES_MAX]
partial subsubframe samples count
This structure stores compressed data.
int subframes
number of subframes
int nb_samples
number of audio samples (per channel) described by this frame
static const uint8_t tmode_vlc_bits[TMODE_COUNT]
static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
int frame_type
type of the current frame
static const uint8_t dca_bits_per_sample[7]