changeset 49:3e7e13e08b27 libavformat

avoid too many false detections
author bellard
date Sun, 02 Feb 2003 20:04:03 +0000
parents e308ea014922
children 658be43f6a0d
files mpeg.c raw.c
diffstat 2 files changed, 37 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/mpeg.c	Sun Feb 02 19:51:40 2003 +0000
+++ b/mpeg.c	Sun Feb 02 20:04:03 2003 +0000
@@ -405,28 +405,31 @@
 
 static int mpegps_probe(AVProbeData *p)
 {
-    int code, c, i;
-    code = 0xff;
+    int code;
+    const uint8_t *d;
 
     /* we search the first start code. If it is a packet start code,
        then we decide it is mpeg ps. We do not send highest value to
        give a chance to mpegts */
-    for(i=0;i<p->buf_size;i++) {
-        c = p->buf[i];
-        code = (code << 8) | c;
-        if ((code & 0xffffff00) == 0x100) {
-            if (code == PACK_START_CODE ||
-                code == SYSTEM_HEADER_START_CODE ||
-                (code >= 0x1e0 && code <= 0x1ef) ||
-                (code >= 0x1c0 && code <= 0x1df) ||
-                code == PRIVATE_STREAM_2 ||
-                code == PROGRAM_STREAM_MAP ||
-                code == PRIVATE_STREAM_1 ||
-                code == PADDING_STREAM)
-                return AVPROBE_SCORE_MAX - 1;
-            else
-                return 0;
-        }
+    /* NOTE: the search range was restricted to avoid too many false
+       detections */
+
+    if (p->buf_size < 6)
+        return 0;
+    d = p->buf;
+    code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]);
+    if ((code & 0xffffff00) == 0x100) {
+        if (code == PACK_START_CODE ||
+            code == SYSTEM_HEADER_START_CODE ||
+            (code >= 0x1e0 && code <= 0x1ef) ||
+            (code >= 0x1c0 && code <= 0x1df) ||
+            code == PRIVATE_STREAM_2 ||
+            code == PROGRAM_STREAM_MAP ||
+            code == PRIVATE_STREAM_1 ||
+            code == PADDING_STREAM)
+            return AVPROBE_SCORE_MAX - 1;
+        else
+            return 0;
     }
     return 0;
 }
--- a/raw.c	Sun Feb 02 19:51:40 2003 +0000
+++ b/raw.c	Sun Feb 02 20:04:03 2003 +0000
@@ -153,23 +153,26 @@
 /* XXX: improve that by looking at several start codes */
 static int mpegvideo_probe(AVProbeData *p)
 {
-    int code, c, i;
-    code = 0xff;
+    int code;
+    const uint8_t *d;
 
     /* we search the first start code. If it is a sequence, gop or
        picture start code then we decide it is an mpeg video
        stream. We do not send highest value to give a chance to mpegts */
-    for(i=0;i<p->buf_size;i++) {
-        c = p->buf[i];
-        code = (code << 8) | c;
-        if ((code & 0xffffff00) == 0x100) {
-            if (code == SEQ_START_CODE ||
-                code == GOP_START_CODE ||
-                code == PICTURE_START_CODE)
-                return 50 - 1;
-            else
-                return 0;
-        }
+    /* NOTE: the search range was restricted to avoid too many false
+       detections */
+
+    if (p->buf_size < 6)
+        return 0;
+    d = p->buf;
+    code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]);
+    if ((code & 0xffffff00) == 0x100) {
+        if (code == SEQ_START_CODE ||
+            code == GOP_START_CODE ||
+            code == PICTURE_START_CODE)
+            return 50 - 1;
+        else
+            return 0;
     }
     return 0;
 }