Reviewed-by: Benjamin Larsson <benjamin@southpole.se>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -376,6 +376,10 @@ typedef struct { |
376 | 376 |
int xch_present; ///< XCh extension present and valid |
377 | 377 |
int xch_base_channel; ///< index of first (only) channel containing XCH data |
378 | 378 |
|
379 |
+ /* XXCH extension information */ |
|
380 |
+ int xxch_spk_layout; |
|
381 |
+ int xxch_nbits_spk_mask; |
|
382 |
+ |
|
379 | 383 |
/* ExSS header parser */ |
380 | 384 |
int static_fields; ///< static fields present |
381 | 385 |
int mix_metadata; ///< mixing metadata present |
... | ... |
@@ -462,16 +466,44 @@ static inline void get_array(GetBitContext *gb, int *dst, int len, int bits) |
462 | 462 |
*dst++ = get_bits(gb, bits); |
463 | 463 |
} |
464 | 464 |
|
465 |
-static int dca_parse_audio_coding_header(DCAContext *s, int base_channel) |
|
465 |
+static int dca_parse_audio_coding_header(DCAContext *s, int base_channel, |
|
466 |
+ int xxch) |
|
466 | 467 |
{ |
467 | 468 |
int i, j; |
468 | 469 |
static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 }; |
469 | 470 |
static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; |
470 | 471 |
static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; |
472 |
+ int hdr_pos = 0, hdr_size = 0; |
|
473 |
+ int mask[8]; |
|
474 |
+ |
|
475 |
+ /* xxch has arbitrary sized audio coding headers */ |
|
476 |
+ if (xxch) { |
|
477 |
+ hdr_pos = get_bits_count(&s->gb); |
|
478 |
+ hdr_size = get_bits(&s->gb, 7) + 1; |
|
479 |
+ } |
|
471 | 480 |
|
472 | 481 |
s->total_channels = get_bits(&s->gb, 3) + 1 + base_channel; |
473 | 482 |
s->prim_channels = s->total_channels; |
474 | 483 |
|
484 |
+ /* obtain speaker layout mask & mixdown coefficients if applicable */ |
|
485 |
+ if (xxch) { |
|
486 |
+ s->xxch_spk_layout |= get_bits(&s->gb, s->xxch_nbits_spk_mask - 6); |
|
487 |
+ if (get_bits1(&s->gb)) { |
|
488 |
+ get_bits1(&s->gb); |
|
489 |
+ skip_bits(&s->gb, 6); |
|
490 |
+ for (i = base_channel; i < s->prim_channels; i++) { |
|
491 |
+ mask[i] = get_bits(&s->gb, s->xxch_nbits_spk_mask); |
|
492 |
+ } |
|
493 |
+ for (j = base_channel; j < s->prim_channels; j++) { |
|
494 |
+ for (i = 0; i < s->xxch_nbits_spk_mask; i++) { |
|
495 |
+ if (mask[j] & (1 << i)) { |
|
496 |
+ int coeff = get_bits(&s->gb, 7); |
|
497 |
+ } |
|
498 |
+ } |
|
499 |
+ } |
|
500 |
+ } |
|
501 |
+ } |
|
502 |
+ |
|
475 | 503 |
if (s->prim_channels > DCA_PRIM_CHANNELS_MAX) |
476 | 504 |
s->prim_channels = DCA_PRIM_CHANNELS_MAX; |
477 | 505 |
|
... | ... |
@@ -508,9 +540,16 @@ static int dca_parse_audio_coding_header(DCAContext *s, int base_channel) |
508 | 508 |
if (s->quant_index_huffman[i][j] < thr[j]) |
509 | 509 |
s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)]; |
510 | 510 |
|
511 |
- if (s->crc_present) { |
|
512 |
- /* Audio header CRC check */ |
|
513 |
- get_bits(&s->gb, 16); |
|
511 |
+ if (!xxch) { |
|
512 |
+ if (s->crc_present) { |
|
513 |
+ /* Audio header CRC check */ |
|
514 |
+ get_bits(&s->gb, 16); |
|
515 |
+ } |
|
516 |
+ } else { |
|
517 |
+ /* Skip to the end of the header, also ignore CRC if present */ |
|
518 |
+ i = get_bits_count(&s->gb); |
|
519 |
+ if (hdr_pos + 8 * hdr_size > i) |
|
520 |
+ skip_bits_long(&s->gb, hdr_pos + 8 * hdr_size - i); |
|
514 | 521 |
} |
515 | 522 |
|
516 | 523 |
s->current_subframe = 0; |
... | ... |
@@ -639,7 +678,7 @@ static int dca_parse_frame_header(DCAContext *s) |
639 | 639 |
/* Primary audio coding header */ |
640 | 640 |
s->subframes = get_bits(&s->gb, 4) + 1; |
641 | 641 |
|
642 |
- return dca_parse_audio_coding_header(s, 0); |
|
642 |
+ return dca_parse_audio_coding_header(s, 0, 0); |
|
643 | 643 |
} |
644 | 644 |
|
645 | 645 |
|
... | ... |
@@ -1727,6 +1766,58 @@ static int dca_xbr_parse_frame(DCAContext *s) |
1727 | 1727 |
return 0; |
1728 | 1728 |
} |
1729 | 1729 |
|
1730 |
+/* parse initial header for XXCH and dump details */ |
|
1731 |
+static int dca_xxch_decode_frame(DCAContext *s) |
|
1732 |
+{ |
|
1733 |
+ int hdr_size, chhdr_crc, spkmsk_bits, num_chsets, core_spk, hdr_pos; |
|
1734 |
+ int i, chset, base_channel, chstart, fsize[8]; |
|
1735 |
+ |
|
1736 |
+ /* assume header word has already been parsed */ |
|
1737 |
+ hdr_pos = get_bits_count(&s->gb) - 32; |
|
1738 |
+ hdr_size = get_bits(&s->gb, 6) + 1; |
|
1739 |
+ chhdr_crc = get_bits1(&s->gb); |
|
1740 |
+ spkmsk_bits = get_bits(&s->gb, 5) + 1; |
|
1741 |
+ num_chsets = get_bits(&s->gb, 2) + 1; |
|
1742 |
+ |
|
1743 |
+ for (i = 0; i < num_chsets; i++) |
|
1744 |
+ fsize[i] = get_bits(&s->gb, 14) + 1; |
|
1745 |
+ |
|
1746 |
+ core_spk = get_bits(&s->gb, spkmsk_bits); |
|
1747 |
+ |
|
1748 |
+ s->xxch_spk_layout = core_spk; |
|
1749 |
+ s->xxch_nbits_spk_mask = spkmsk_bits; |
|
1750 |
+ |
|
1751 |
+ /* skip to the end of the header */ |
|
1752 |
+ i = get_bits_count(&s->gb); |
|
1753 |
+ if (hdr_pos + hdr_size * 8 > i) |
|
1754 |
+ skip_bits_long(&s->gb, hdr_pos + hdr_size * 8 - i); |
|
1755 |
+ |
|
1756 |
+ for (chset = 0; chset < num_chsets; chset++) { |
|
1757 |
+ chstart = get_bits_count(&s->gb); |
|
1758 |
+ base_channel = s->prim_channels; |
|
1759 |
+ |
|
1760 |
+ /* XXCH and Core headers differ, see 6.4.2 "XXCH Channel Set Header" vs. |
|
1761 |
+ 5.3.2 "Primary Audio Coding Header", DTS Spec 1.3.1 */ |
|
1762 |
+ dca_parse_audio_coding_header(s, base_channel, 1); |
|
1763 |
+ |
|
1764 |
+ /* decode channel data */ |
|
1765 |
+ for (i = 0; i < (s->sample_blocks / 8); i++) { |
|
1766 |
+ if (dca_decode_block(s, base_channel, i)) { |
|
1767 |
+ av_log(s->avctx, AV_LOG_ERROR, |
|
1768 |
+ "Error decoding DTS-XXCH extension\n"); |
|
1769 |
+ continue; |
|
1770 |
+ } |
|
1771 |
+ } |
|
1772 |
+ |
|
1773 |
+ /* skip to end of this section */ |
|
1774 |
+ i = get_bits_count(&s->gb); |
|
1775 |
+ if (chstart + fsize[chset] * 8 > i) |
|
1776 |
+ skip_bits_long(&s->gb, chstart + fsize[chset] * 8 - i); |
|
1777 |
+ } |
|
1778 |
+ |
|
1779 |
+ return 0; |
|
1780 |
+} |
|
1781 |
+ |
|
1730 | 1782 |
/** |
1731 | 1783 |
* Parse extension substream header (HD) |
1732 | 1784 |
*/ |
... | ... |
@@ -1823,6 +1914,8 @@ static void dca_exss_parse_header(DCAContext *s) |
1823 | 1823 |
|
1824 | 1824 |
if(mkr == 0x655e315e) |
1825 | 1825 |
dca_xbr_parse_frame(s); |
1826 |
+ else |
|
1827 |
+ av_log(s->avctx, AV_LOG_DEBUG, "DTS-MA: unknown marker = 0x%08x\n", mkr); |
|
1826 | 1828 |
} |
1827 | 1829 |
} |
1828 | 1830 |
|
... | ... |
@@ -1885,7 +1978,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, |
1885 | 1885 |
|
1886 | 1886 |
/* only scan for extensions if ext_descr was unknown or indicated a |
1887 | 1887 |
* supported XCh extension */ |
1888 |
- if (s->core_ext_mask < 0 || s->core_ext_mask & DCA_EXT_XCH) { |
|
1888 |
+ if (s->core_ext_mask < 0 || s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH)) { |
|
1889 | 1889 |
|
1890 | 1890 |
/* if ext_descr was unknown, clear s->core_ext_mask so that the |
1891 | 1891 |
* extensions scan can fill it up */ |
... | ... |
@@ -1923,7 +2016,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, |
1923 | 1923 |
} |
1924 | 1924 |
|
1925 | 1925 |
/* much like core primary audio coding header */ |
1926 |
- dca_parse_audio_coding_header(s, s->xch_base_channel); |
|
1926 |
+ dca_parse_audio_coding_header(s, s->xch_base_channel, 0); |
|
1927 | 1927 |
|
1928 | 1928 |
for (i = 0; i < (s->sample_blocks / 8); i++) |
1929 | 1929 |
if ((ret = dca_decode_block(s, s->xch_base_channel, i))) { |
... | ... |
@@ -1939,6 +2032,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, |
1939 | 1939 |
/* usually found either in core or HD part in DTS-HD HRA streams, |
1940 | 1940 |
* but not in DTS-ES which contains XCh extensions instead */ |
1941 | 1941 |
s->core_ext_mask |= DCA_EXT_XXCH; |
1942 |
+ dca_xxch_decode_frame(s); |
|
1942 | 1943 |
break; |
1943 | 1944 |
|
1944 | 1945 |
case 0x1d95f262: { |