diff options
author | foo86 <foobaz86@gmail.com> | 2016-05-03 16:06:41 +0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2016-05-04 19:14:32 -0300 |
commit | bb7c55807090ee77621c4a4692d00a231b722e1a (patch) | |
tree | b96513d5d11d5a1fb79520d9ebd8893406a1ac0c | |
parent | fe483ac4285408f669886df304da8d714001bb1b (diff) | |
download | ffmpeg-bb7c55807090ee77621c4a4692d00a231b722e1a.tar.gz |
avformat/dtsdec: detect core-less streams
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r-- | libavformat/dtsdec.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c index ef283916e7..702a417e56 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,51 @@ 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 }; + const AVCRC *crctab = av_crc_get_table(AV_CRC_16_CCITT); - 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(crctab, 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 +133,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<FF_ARRAY_ELEMS(markers); i++) { sum += markers[i]; |