changeset 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 1ea4cfb007e0
files ChangeLog src/madplug/decoder.c src/madplug/input.c src/madplug/plugin.c
diffstat 4 files changed, 30 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Feb 19 04:55:14 2007 -0800
+++ b/ChangeLog	Mon Feb 19 18:08:27 2007 -0800
@@ -1,3 +1,12 @@
+2007-02-19 12:55:14 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
+  revision [1432]
+  - calculate vbr bitrate properly.
+  - mainwin shows dynamic bitrate for vbr.
+  
+  trunk/src/madplug/decoder.c |   17 +++++++++++++++--
+  1 file changed, 15 insertions(+), 2 deletions(-)
+
+
 2007-02-19 08:02:50 +0000  
   revision [1430]
   fix flac detection, now flac >= 1.1.4 is supported as well
--- 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;
--- a/src/madplug/input.c	Mon Feb 19 04:55:14 2007 -0800
+++ b/src/madplug/input.c	Mon Feb 19 18:08:27 2007 -0800
@@ -123,7 +123,7 @@
     info->remote = info->size == 0 ? TRUE : FALSE;
 
 #ifdef DEBUG
-    g_message("i: info->size == %lu", (long unsigned int)info->size);
+    g_message("i: info->size = %lu", (long unsigned int)info->size);
     g_message("e: input_init");
 #endif
     return TRUE;
@@ -164,11 +164,13 @@
     id3_ucs4_t *ptr, *end, *tail, *tp;
     size_t ret_len = 0; //num of ucs4 char!
     size_t tmp_len = 0;
+    size_t string_len = 0;
     gboolean is_num = TRUE;
 
-    tail = (id3_ucs4_t *)string + mad_ucs4len((id3_ucs4_t *)string);
+    string_len = mad_ucs4len((id3_ucs4_t *)string);
+    tail = (id3_ucs4_t *)string + string_len;
 
-    ret = g_malloc0(1024);
+    ret = g_malloc0(BYTES(string_len + 1));
 
     for(ptr = (id3_ucs4_t *)string; *ptr != 0 && ptr <= tail; ptr++) {
         if(*ptr == '(') {
@@ -247,6 +249,7 @@
 #ifdef DEBUG
                 printf("plain!\n");
                 printf("ret_len = %d\n", ret_len);
+                printf("end - ptr = %d\n", BYTES(end - ptr));
 #endif
                 memcpy(ret + BYTES(ret_len), ptr, BYTES(end - ptr));
                 ret_len = ret_len + (end - ptr);
@@ -297,6 +300,9 @@
         string = mad_ucs4dup((id3_ucs4_t *)string_const);
     }
 
+    if (!string)
+        return NULL;
+
     switch (encoding) {
     case ID3_FIELD_TEXTENCODING_ISO_8859_1:
         rtn0 = (gchar *)id3_ucs4_latin1duplicate(string);
--- a/src/madplug/plugin.c	Mon Feb 19 04:55:14 2007 -0800
+++ b/src/madplug/plugin.c	Mon Feb 19 18:08:27 2007 -0800
@@ -220,7 +220,9 @@
     // XXX: temporary fix
     if (!strncasecmp("http://", filename, 7) || !strncasecmp("https://", filename, 8))
     {
+#ifdef DEBUG
         g_message("audmad_is_our_fd: remote");
+#endif
         info.remote = TRUE;
     }
 #endif