diff src/madplug/decoder.c @ 674:fadf4c18a1cf trunk

[svn] madplug bug fix: - no longer crashes on extra long TCON tag. - now scan_file() calculates track length properly.
author yaz
date Mon, 19 Feb 2007 18:08:27 -0800
parents 8ed0af226d0e
children 1733b12ef974
line wrap: on
line diff
--- a/src/madplug/decoder.c	Mon Feb 19 04:55:14 2007 -0800
+++ b/src/madplug/decoder.c	Mon Feb 19 18:08:27 2007 -0800
@@ -186,6 +186,7 @@
 
     info->bitrate = 0;
     info->pos = mad_timer_zero;
+    info->duration.seconds = 0; // should be cleared before loop, if we use it as break condition.
 
 #ifdef DEBUG
     g_message("f: scan_file");
@@ -210,7 +211,7 @@
 
         mad_stream_buffer(&stream, buffer, len + remainder);
 
-        while (info->duration.seconds == 0) {
+        while (!fast || (fast && info->frames < N_AVERAGE_FRAMES)) {
             if (mad_header_decode(&header, &stream) == -1) {
                 if (stream.error == MAD_ERROR_BUFLEN) {
                     break;
@@ -246,6 +247,7 @@
                 continue;
             }
             info->frames++;
+
 #ifdef DEBUG
 #ifdef DEBUG_INTENSIVELY
             g_message("duration = %lu",
@@ -266,8 +268,12 @@
 
                 if (audmad_config.use_xing) {
                     frame.header = header;
-                    if (mad_frame_decode(&frame, &stream) == -1)
-                        break;
+                    if (mad_frame_decode(&frame, &stream) == -1) {
+#ifdef DEBUG
+                        printf("xing frame decode failed\n");
+#endif
+                        goto no_xing;
+                    }
                     if (xing_parse
                         (&info->xing, stream.anc_ptr,
                          stream.anc_bitlen) == 0) {
@@ -303,7 +309,7 @@
                 if (info->channels != MAD_NCHANNELS(&header))
                     g_warning("number of channels varies!!");
             }
-
+        no_xing:
             if (fast && info->frames >= N_AVERAGE_FRAMES) {
                 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES;
                 info->frames = (info->size - tagsize) / frame_size;