changeset 2697:afbdd52324e3 libavformat

fix misdetection of mp3could_not_find_codec_parameters.mp3
author michael
date Sat, 03 Nov 2007 13:48:30 +0000
parents 7671acabd99c
children 26a111e617a8
files mpeg.c
diffstat 1 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mpeg.c	Sat Nov 03 06:43:29 2007 +0000
+++ b/mpeg.c	Sat Nov 03 13:48:30 2007 +0000
@@ -44,6 +44,26 @@
         return 0;
 }
 
+static int check_pes(uint8_t *p, uint8_t *end){
+    int pes1;
+    int pes2=      (p[3] & 0xC0) == 0x80
+                && (p[4] & 0xC0) != 0x40
+                &&((p[4] & 0xC0) == 0x00 || (p[4]&0xC0)>>2 == (p[6]&0xF0));
+
+    for(p+=3; p<end && *p == 0xFF; p++);
+    if((*p&0xC0) == 0x40) p+=2;
+    if((*p&0xF0) == 0x20){
+        pes1= p[0]&p[2]&p[4]&1;
+        p+=5;
+    }else if((*p&0xF0) == 0x30){
+        pes1= p[0]&p[2]&p[4]&p[5]&p[7]&p[9]&1;
+        p+=10;
+    }else
+        pes1 = *p == 0x0F;
+
+    return pes1||pes2;
+}
+
 static int mpegps_probe(AVProbeData *p)
 {
     uint32_t code= -1;
@@ -58,11 +78,13 @@
     for(i=0; i<p->buf_size; i++){
         code = (code<<8) + p->buf[i];
         if ((code & 0xffffff00) == 0x100) {
+            int pes= check_pes(p->buf+i, p->buf+i+p->buf_size);
+
             if(code == SYSTEM_HEADER_START_CODE) sys++;
             else if(code == PRIVATE_STREAM_1)    priv1++;
             else if(code == PACK_START_CODE)     pspack++;
-            else if((code & 0xf0) == VIDEO_ID)   vid++;
-            else if((code & 0xe0) == AUDIO_ID)   audio++;
+            else if((code & 0xf0) == VIDEO_ID && pes) vid++;
+            else if((code & 0xe0) == AUDIO_ID && pes) audio++;
         }
     }