diff src/madplug/plugin.c @ 897:44a922a4a591 trunk

[svn] - fix validation of mpeg2 files, by ccr.
author nenolod
date Sat, 24 Mar 2007 17:31:14 -0700
parents 0f9c8d4d3ac4
children a8494c2a87eb
line wrap: on
line diff
--- a/src/madplug/plugin.c	Sat Mar 24 09:44:44 2007 -0700
+++ b/src/madplug/plugin.c	Sat Mar 24 17:31:14 2007 -0700
@@ -198,7 +198,7 @@
     layer = (head >> 17) & 0x3;
     if (!layer)
         return FALSE; /* 00 = reserved */
-    layer = 3 - layer;
+    layer = 4 - layer;
 
     /* check if bitrate index bits (12-15) are acceptable */
     bitIndex = (head >> 12) & 0xf;
@@ -243,7 +243,10 @@
             if (bitRate > 192)
                 return FALSE;
         } else {
-            /* any other mode with bitrates 32-56 and 80 */
+            /* any other mode with bitrates 32-56 and 80.
+             * NOTICE! this check is not entirely correct, but I think
+             * it is sufficient in most cases.
+             */
             if (((bitRate >= 32 && bitRate <= 56) || bitRate == 80))
                 return FALSE;
         }
@@ -252,8 +255,11 @@
     /* calculate approx. frame size */
     padding = (head >> 9) & 1;
     sampleRate = mp3_samplerate_table[version][sampleIndex];
-    *frameSize = (144 * bitRate * 1000) / (sampleRate + padding);
-        
+    if (layer == 1)
+        *frameSize = ((12 * bitRate * 1000 / sampleRate) + padding) * 4; 
+    else
+        *frameSize = (144 * bitRate * 1000) / (sampleRate + padding);
+    
     /* check if bits 16 - 19 are all set (MPEG 1 Layer I, not protected?) */
     if (((head >> 19) & 1) == 1 &&
         ((head >> 17) & 3) == 3 && ((head >> 16) & 1) == 1)