[FFmpeg-cvslog] avformat/dtsdec: check more of the dca headers in dts_probe()

Michael Niedermayer git at videolan.org
Wed Aug 6 22:35:28 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Aug  6 21:21:53 2014 +0200| [6a44699746501332207d967e27297cc6cfa987dd] | committer: 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: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6a44699746501332207d967e27297cc6cfa987dd
---

 libavformat/dtsdec.c |   52 +++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index 0ebf847..f6a939a 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -20,6 +20,8 @@
  */
 
 #include "libavcodec/bytestream.h"
+#include "libavcodec/get_bits.h"
+#include "libavcodec/dca.h"
 #include "avformat.h"
 #include "rawdec.h"
 
@@ -35,31 +37,59 @@ static int dts_probe(AVProbeData *p)
     int markers[4] = {0};
     int sum, max, i;
     int64_t diff = 0;
+    uint8_t hdr[12 + FF_INPUT_BUFFER_PADDING_SIZE] = { 0 };
 
     buf = p->buf + FFMIN(4096, p->buf_size);
 
     for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
+        int marker, sample_blocks, sample_rate, sr_code, framesize;
+        GetBitContext gb;
+
         bufp = buf;
         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 */
         if (state == DCA_MARKER_RAW_BE)
-            markers[0]++;
-        if (state == DCA_MARKER_RAW_LE)
-            markers[1]++;
+            marker = 0;
+        else if (state == DCA_MARKER_RAW_LE)
+            marker = 1;
 
         /* 14 bits big-endian bitstream */
-        if (state == DCA_MARKER_14B_BE)
-            if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
-                markers[2]++;
+        else if (state == DCA_MARKER_14B_BE &&
+                 (bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
+            marker = 2;
 
         /* 14 bits little-endian bitstream */
-        if (state == DCA_MARKER_14B_LE)
-            if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
-                markers[3]++;
+        else if (state == DCA_MARKER_14B_LE &&
+                 (bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
+            marker = 3;
+        else
+            continue;
 
-        if (buf - p->buf >= 4)
-            diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4));
+        if (avpriv_dca_convert_bitstream(buf-2, 12, hdr, 12) < 0)
+            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];
     max = 0;



More information about the ffmpeg-cvslog mailing list