[FFmpeg-devel] [PATCH v3 2/2] avformat/dtsdec: detect core-less streams

foo86 foobaz86 at gmail.com
Tue May 3 15:06:41 CEST 2016


---

Updated detection algorithm.

 libavformat/dtsdec.c | 47 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index ef28391..702a417 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];
-- 
2.8.1



More information about the ffmpeg-devel mailing list