X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fdtsdec.c;h=8c985b887736becf6e67783ac7937a16e4b2f5e0;hb=7ae4d574e87364620ac1832e538650af0bf6bf11;hp=ef283916e79f07e48c757bc51c9e7c6528a488c0;hpb=f8d1bb2f2ce9031940019e1cda4d30bc409ee349;p=ffmpeg diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c index ef283916e79..8c985b88773 100644 --- a/libavformat/dtsdec.c +++ b/libavformat/dtsdec.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/crc.h" + #include "libavcodec/bytestream.h" #include "libavcodec/dca.h" #include "libavcodec/dca_syncwords.h" @@ -32,23 +34,50 @@ static int dts_probe(AVProbeData *p) const uint8_t *buf, *bufp; uint32_t state = -1; int markers[4*16] = {0}; - int sum, max, i; + int exss_markers = 0, exss_nextpos = 0; + int sum, max, pos, i; int64_t diff = 0; uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 }; - buf = p->buf + FFMIN(4096, p->buf_size); - - for(; buf < (p->buf+p->buf_size)-2; buf+=2) { + for (pos = FFMIN(4096, p->buf_size); pos < p->buf_size - 2; pos += 2) { int marker, sample_blocks, sample_rate, sr_code, framesize; - int lfe; + int lfe, wide_hdr, hdr_size; GetBitContext gb; - bufp = buf; + bufp = buf = p->buf + pos; state = (state << 16) | bytestream_get_be16(&bufp); - if (buf - p->buf >= 4) + if (pos >= 4) diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4)); + /* extension substream (EXSS) */ + if (state == DCA_SYNCWORD_SUBSTREAM) { + if (pos < exss_nextpos) + continue; + + init_get_bits(&gb, buf - 2, 96); + skip_bits_long(&gb, 42); + + wide_hdr = get_bits1(&gb); + hdr_size = get_bits(&gb, 8 + 4 * wide_hdr) + 1; + framesize = get_bits(&gb, 16 + 4 * wide_hdr) + 1; + if (hdr_size & 3 || framesize & 3) + continue; + if (hdr_size < 16 || framesize < hdr_size) + continue; + if (pos - 2 + hdr_size > p->buf_size) + continue; + if (av_crc(av_crc_get_table(AV_CRC_16_CCITT), 0xffff, buf + 3, hdr_size - 5)) + continue; + + if (pos == exss_nextpos) + exss_markers++; + else + exss_markers = FFMAX(1, exss_markers - 1); + exss_nextpos = pos + framesize; + continue; + } + /* regular bitstream */ if (state == DCA_SYNCWORD_CORE_BE && (bytestream_get_be16(&bufp) & 0xFC00) == 0xFC00) @@ -103,6 +132,9 @@ static int dts_probe(AVProbeData *p) markers[marker] ++; } + if (exss_markers > 3) + return AVPROBE_SCORE_EXTENSION + 1; + sum = max = 0; for (i=0; i