[SCM] libav/experimental: Improve Sofdec file detection

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 16:09:14 UTC 2013


The following commit has been merged in the experimental branch:
commit 2c18784703760803558706d3df8d5ff4789194f4
Author: Måns Rullgård <mans at mansr.com>
Date:   Thu Nov 8 21:27:37 2007 +0000

    Improve Sofdec file detection
    
    Originally committed as revision 10967 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 076cc8f..4bfd803 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -114,17 +114,18 @@ static int mpegps_read_header(AVFormatContext *s,
                               AVFormatParameters *ap)
 {
     MpegDemuxContext *m = s->priv_data;
-    uint8_t buffer[8192];
-    char *p;
+    const char *sofdec = "Sofdec";
+    int v, i = 0;
 
     m->header_state = 0xff;
     s->ctx_flags |= AVFMTCTX_NOHEADER;
 
-    get_buffer(&s->pb, buffer, sizeof(buffer));
-    if ((p=memchr(buffer, 'S', sizeof(buffer)-5)))
-        if (!memcmp(p, "Sofdec", 6))
-            m->sofdec = 1;
-    url_fseek(&s->pb, -(offset_t)sizeof(buffer), SEEK_CUR);
+    m->sofdec = -1;
+    do {
+        v = get_byte(&s->pb);
+        m->header_state = m->header_state << 8 | v;
+        m->sofdec++;
+    } while (v == sofdec[i] && i++ < 6);
 
     /* no need to do more */
     return 0;
@@ -269,10 +270,24 @@ static int mpegps_read_pes_header(AVFormatContext *s,
         goto redo;
     if (startcode == SYSTEM_HEADER_START_CODE)
         goto redo;
-    if (startcode == PADDING_STREAM ||
-        startcode == PRIVATE_STREAM_2) {
-        /* skip them */
+    if (startcode == PADDING_STREAM) {
+        url_fskip(&s->pb, get_be16(&s->pb));
+        goto redo;
+    }
+    if (startcode == PRIVATE_STREAM_2) {
         len = get_be16(&s->pb);
+        if (!m->sofdec) {
+            while (len-- >= 6) {
+                if (get_byte(&s->pb) == 'S') {
+                    uint8_t buf[5];
+                    get_buffer(&s->pb, buf, sizeof(buf));
+                    m->sofdec = !memcmp(buf, "ofdec", 5);
+                    len -= sizeof(buf);
+                    break;
+                }
+            }
+            m->sofdec -= !m->sofdec;
+        }
         url_fskip(&s->pb, len);
         goto redo;
     }
@@ -459,7 +474,7 @@ static int mpegps_read_packet(AVFormatContext *s,
         type = CODEC_TYPE_VIDEO;
     } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
         type = CODEC_TYPE_AUDIO;
-        codec_id = m->sofdec ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2;
+        codec_id = m->sofdec > 0 ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2;
     } else if (startcode >= 0x80 && startcode <= 0x87) {
         type = CODEC_TYPE_AUDIO;
         codec_id = CODEC_ID_AC3;

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list