Author: duncan
Date: Tue Oct 24 16:17:34 2006
New Revision: 1925

Modified:
   branches/mmpython-0-4/mmpython/audio/eyeD3/mp3.py
   branches/mmpython-0-4/mmpython/audio/eyeD3/tag.py

Log:
[ 1568261 ] MP3 header search slow as hell
Patch applied


Modified: branches/mmpython-0-4/mmpython/audio/eyeD3/mp3.py
==============================================================================
--- branches/mmpython-0-4/mmpython/audio/eyeD3/mp3.py   (original)
+++ branches/mmpython-0-4/mmpython/audio/eyeD3/mp3.py   Tue Oct 24 16:17:34 2006
@@ -122,6 +122,19 @@
 
       return 1;
 
+   def find(self, buffer):
+      idx = buffer.find("\xff")
+      while idx != -1:
+         candidate = buffer[idx:idx+4]
+         if len(candidate) < 4:
+            return None
+
+         header = bin2dec(bytes2bin(candidate))
+         if self.isValid(header):
+            return header
+
+         idx = buffer.find("\xff", idx + 1)
+
    # This may throw an Mp3Exception if the header is malformed.
    def decode(self, header):
       # MPEG audio version from bits 19 and 20.

Modified: branches/mmpython-0-4/mmpython/audio/eyeD3/tag.py
==============================================================================
--- branches/mmpython-0-4/mmpython/audio/eyeD3/tag.py   (original)
+++ branches/mmpython-0-4/mmpython/audio/eyeD3/tag.py   Tue Oct 24 16:17:34 2006
@@ -1320,16 +1320,15 @@
       if len(bString) < 4:
          raise InvalidAudioFormatException("Unable to find a valid mp3 "\
                                            "frame");
-      frameHead = bin2dec(bytes2bin(bString));
       header = eyeD3_mp3.Header();
+      frameHead = header.find(bString)
       # Keep reading until we find a valid mp3 frame header.
-      while not header.isValid(frameHead):
-         frameHead <<= 8;
-         bString = f.read(1);
-         if len(bString) != 1:
+      while not frameHead:
+         bString = bString[-3:] + f.read(4096);
+         if len(bString) <= 3:
             raise InvalidAudioFormatException("Unable to find a valid mp3 "\
                                               "frame");
-         frameHead |= ord(bString[0]);
+         frameHead = header.find(bString)
       TRACE_MSG("mp3 header %x found at position: %d (0x%x)" % \
                 (frameHead, f.tell() - 4, f.tell() - 4));
 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to