[Ffmpeg-cvslog] r6225 - trunk/libavformat/mp3.c

gpoirier subversion
Sun Sep 10 22:31:58 CEST 2006


Author: gpoirier
Date: Sun Sep 10 22:31:58 2006
New Revision: 6225

Modified:
   trunk/libavformat/mp3.c

Log:
allow ffmpeg to read mp3s beginning with partial frames
Patch by Andreas Oman andreas A olebyn P nu
Original thread:
Date: Sep 10, 2006 7:26 AM
Subject: Re: [Ffmpeg-devel] [PATCH] allow ffmpeg to read mp3s beginning with partial frames


Modified: trunk/libavformat/mp3.c
==============================================================================
--- trunk/libavformat/mp3.c	(original)
+++ trunk/libavformat/mp3.c	Sun Sep 10 22:31:58 2006
@@ -17,6 +17,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
+#include "mpegaudio.h"
 
 #define ID3_HEADER_SIZE 10
 #define ID3_TAG_SIZE 128
@@ -243,27 +244,38 @@
 
 static int mp3_read_probe(AVProbeData *p)
 {
-    int d;
+    int max_frames;
+    int fsize, frames;
+    uint32_t header;
+    uint8_t *buf, *buf2, *end;
+    AVCodecContext avctx;
 
-    if(p->buf_size < 4)
+    if(p->buf_size < ID3_HEADER_SIZE)
         return 0;
 
-    if(p->buf[0] == 'I' && p->buf[1] == 'D' && p->buf[2] == '3' &&
-       p->buf[3] < 5)
+    if(id3_match(p->buf))
         return AVPROBE_SCORE_MAX;
 
-    if(p->buf[0] != 0xff)
-        return 0;
-
-    d = p->buf[1];
-    if((d & 0xe0) != 0xe0 || ((d & 0x18) == 0x08 || (d & 0x06) == 0))
-        return 0;
-
-    d = p->buf[2];
-    if((d & 0xf0) == 0xf0 || (d & 0x0c) == 0x0c)
-        return 0;
-
-    return AVPROBE_SCORE_MAX;
+    max_frames = 0;
+    buf = p->buf;
+    end = buf + FFMIN(4096, p->buf_size - sizeof(uint32_t));
+
+    for(; buf < end; buf++) {
+        buf2 = buf;
+
+        for(frames = 0; buf < end; frames++) {
+            header = (buf2[0] << 24) | (buf2[1] << 16) | (buf2[2] << 8) | buf2[3];
+            fsize = mpa_decode_header(&avctx, header);
+            if(fsize < 0)
+                break;
+            buf2 += fsize;
+        }
+        max_frames = FFMAX(max_frames, frames);
+    }
+    if     (max_frames>=3) return AVPROBE_SCORE_MAX/2+1;
+    else if(max_frames==2) return AVPROBE_SCORE_MAX/4;
+    else if(max_frames==1) return 1;
+    else                   return 0;
 }
 
 static int mp3_read_header(AVFormatContext *s,




More information about the ffmpeg-cvslog mailing list