Revision 853daff6

View differences:

libavcodec/dca.c
99 99
    DCA_EXT_EXSS_XLL   = 0x200, ///< lossless extension in ExSS
100 100
};
101 101

  
102
/* -1 are reserved or unknown */
103
static const int dca_ext_audio_descr_mask[] = {
104
    DCA_EXT_XCH,
105
    -1,
106
    DCA_EXT_X96,
107
    DCA_EXT_XCH | DCA_EXT_X96,
108
    -1,
109
    -1,
110
    DCA_EXT_XXCH,
111
    -1,
112
};
113

  
114
/* extensions that reside in core substream */
115
#define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
116

  
102 117
/* Tables for mapping dts channel configurations to libavcodec multichannel api.
103 118
 * Some compromises have been made for special configurations. Most configurations
104 119
 * are never used so complete accuracy is not needed.
......
327 342
    int current_subframe;
328 343
    int current_subsubframe;
329 344

  
345
    int core_ext_mask;          ///< present extensions in the core substream
346

  
330 347
    /* XCh extension information */
331
    int xch_present;
348
    int xch_present;            ///< XCh extension present and valid
332 349
    int xch_base_channel;       ///< index of first (only) channel containing XCH data
333 350

  
334
    /* Other detected extensions in the core substream */
335
    int xxch_present;
336
    int x96_present;
337

  
338 351
    /* ExSS header parser */
339 352
    int static_fields;          ///< static fields present
340 353
    int mix_metadata;           ///< mixing metadata present
......
1508 1521

  
1509 1522
    if (!(extensions_mask & DCA_EXT_CORE))
1510 1523
        av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n");
1511
    if (!!(extensions_mask & DCA_EXT_XCH) != s->xch_present)
1512
        av_log(s->avctx, AV_LOG_WARNING, "DTS XCh detection mismatch.\n");
1513
    if (!!(extensions_mask & DCA_EXT_XXCH) != s->xxch_present)
1514
        av_log(s->avctx, AV_LOG_WARNING, "DTS XXCh detection mismatch.\n");
1515
    if (!!(extensions_mask & DCA_EXT_X96) != s->x96_present)
1516
        av_log(s->avctx, AV_LOG_WARNING, "DTS X96 detection mismatch.\n");
1524
    if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask)
1525
        av_log(s->avctx, AV_LOG_WARNING, "DTS extensions detection mismatch (%d, %d)\n",
1526
               extensions_mask & DCA_CORE_EXTS, s->core_ext_mask);
1517 1527

  
1518 1528
    return 0;
1519 1529
}
......
1623 1633

  
1624 1634

  
1625 1635
    s->xch_present = 0;
1626
    s->x96_present = 0;
1627
    s->xxch_present = 0;
1628 1636

  
1629 1637
    s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer,
1630 1638
                                               DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE);
......
1652 1660
    /* record number of core channels incase less than max channels are requested */
1653 1661
    num_core_channels = s->prim_channels;
1654 1662

  
1655
    /* extensions start at 32-bit boundaries into bitstream */
1656
    skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1663
    if (s->ext_coding)
1664
        s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
1665
    else
1666
        s->core_ext_mask = 0;
1657 1667

  
1658 1668
    core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8;
1659 1669

  
1670
    /* only scan for extensions if ext_descr was unknown or indicated a
1671
     * supported XCh extension */
1672
    if (s->core_ext_mask < 0 || s->core_ext_mask & DCA_EXT_XCH) {
1673

  
1674
        /* if ext_descr was unknown, clear s->core_ext_mask so that the
1675
         * extensions scan can fill it up */
1676
        s->core_ext_mask = FFMAX(s->core_ext_mask, 0);
1677

  
1678
        /* extensions start at 32-bit boundaries into bitstream */
1679
        skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1680

  
1660 1681
    while(core_ss_end - get_bits_count(&s->gb) >= 32) {
1661 1682
        uint32_t bits = get_bits_long(&s->gb, 32);
1662 1683

  
......
1675 1696
            /* skip length-to-end-of-frame field for the moment */
1676 1697
            skip_bits(&s->gb, 10);
1677 1698

  
1678
            s->profile = FFMAX(s->profile, FF_PROFILE_DTS_ES);
1699
            s->core_ext_mask |= DCA_EXT_XCH;
1679 1700

  
1680 1701
            /* extension amode should == 1, number of channels in extension */
1681 1702
            /* AFAIK XCh is not used for more channels */
......
1699 1720
            /* XXCh: extended channels */
1700 1721
            /* usually found either in core or HD part in DTS-HD HRA streams,
1701 1722
             * but not in DTS-ES which contains XCh extensions instead */
1702
            s->xxch_present = 1;
1703
            s->profile = FFMAX(s->profile, FF_PROFILE_DTS_ES);
1723
            s->core_ext_mask |= DCA_EXT_XXCH;
1704 1724
            break;
1705 1725

  
1706 1726
        case 0x1d95f262: {
......
1713 1733
            av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", fsize96);
1714 1734
            av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4));
1715 1735

  
1716
            s->x96_present = 1;
1717
            s->profile = FFMAX(s->profile, FF_PROFILE_DTS_96_24);
1736
            s->core_ext_mask |= DCA_EXT_X96;
1718 1737
            break;
1719 1738
        }
1720 1739
        }
......
1722 1741
        skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1723 1742
    }
1724 1743

  
1744
    } else {
1745
        /* no supported extensions, skip the rest of the core substream */
1746
        skip_bits_long(&s->gb, core_ss_end - get_bits_count(&s->gb));
1747
    }
1748

  
1749
    if (s->core_ext_mask & DCA_EXT_X96)
1750
        s->profile = FF_PROFILE_DTS_96_24;
1751
    else if (s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH))
1752
        s->profile = FF_PROFILE_DTS_ES;
1753

  
1725 1754
    /* check for ExSS (HD part) */
1726 1755
    if (s->dca_buffer_size - s->frame_size > 32
1727 1756
        && get_bits_long(&s->gb, 32) == DCA_HD_MARKER)

Also available in: Unified diff