]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/dtsdec.c
Move WMA case from ff_get_audio_frame_size() to av_get_audio_frame_duration()
[ffmpeg] / libavformat / dtsdec.c
index 0ebf8472c5cb6250497c82d0107f1dec8e58fd4f..f6a939a1d8626b1e7e988ff65e3b31ad7b1ed590 100644 (file)
@@ -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;