Commit 6a446997 authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/dtsdec: check more of the dca headers in dts_probe()

Fixes misdetection of 664461_flac_16_44100_2.wav
Fixes Ticket3830
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 7a34b7d8
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
*/ */
#include "libavcodec/bytestream.h" #include "libavcodec/bytestream.h"
#include "libavcodec/get_bits.h"
#include "libavcodec/dca.h"
#include "avformat.h" #include "avformat.h"
#include "rawdec.h" #include "rawdec.h"
...@@ -35,31 +37,59 @@ static int dts_probe(AVProbeData *p) ...@@ -35,31 +37,59 @@ static int dts_probe(AVProbeData *p)
int markers[4] = {0}; int markers[4] = {0};
int sum, max, i; int sum, max, i;
int64_t diff = 0; int64_t diff = 0;
uint8_t hdr[12 + FF_INPUT_BUFFER_PADDING_SIZE] = { 0 };
buf = p->buf + FFMIN(4096, p->buf_size); buf = p->buf + FFMIN(4096, p->buf_size);
for(; buf < (p->buf+p->buf_size)-2; buf+=2) { for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
int marker, sample_blocks, sample_rate, sr_code, framesize;
GetBitContext gb;
bufp = buf; bufp = buf;
state = (state << 16) | bytestream_get_be16(&bufp); state = (state << 16) | bytestream_get_be16(&bufp);
if (buf - p->buf >= 4)
diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4));
/* regular bitstream */ /* regular bitstream */
if (state == DCA_MARKER_RAW_BE) if (state == DCA_MARKER_RAW_BE)
markers[0]++; marker = 0;
if (state == DCA_MARKER_RAW_LE) else if (state == DCA_MARKER_RAW_LE)
markers[1]++; marker = 1;
/* 14 bits big-endian bitstream */ /* 14 bits big-endian bitstream */
if (state == DCA_MARKER_14B_BE) else if (state == DCA_MARKER_14B_BE &&
if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0) (bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
markers[2]++; marker = 2;
/* 14 bits little-endian bitstream */ /* 14 bits little-endian bitstream */
if (state == DCA_MARKER_14B_LE) else if (state == DCA_MARKER_14B_LE &&
if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007) (bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
markers[3]++; marker = 3;
else
continue;
if (buf - p->buf >= 4) if (avpriv_dca_convert_bitstream(buf-2, 12, hdr, 12) < 0)
diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4)); continue;
init_get_bits(&gb, hdr, 96);
skip_bits_long(&gb, 39);
sample_blocks = get_bits(&gb, 7) + 1;
if (sample_blocks < 8)
continue;
framesize = get_bits(&gb, 14) + 1;
if (framesize < 95)
continue;
skip_bits(&gb, 6);
sr_code = get_bits(&gb, 4);
sample_rate = avpriv_dca_sample_rates[sr_code];
if (sample_rate == 0)
continue;
markers[marker] ++;
} }
sum = markers[0] + markers[1] + markers[2] + markers[3]; sum = markers[0] + markers[1] + markers[2] + markers[3];
max = 0; max = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment