diff src/madplug/plugin.c @ 1328:38fb3bb3e21e

- make probing for tuple completely reuse fd. - fix bugs in __audmad_get_song_tuple() against remote sources.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sun, 22 Jul 2007 04:28:20 +0900
parents e991d29a9c9a
children 4b07404814ca
line wrap: on
line diff
--- a/src/madplug/plugin.c	Sat Jul 21 12:20:08 2007 -0500
+++ b/src/madplug/plugin.c	Sun Jul 22 04:28:20 2007 +0900
@@ -447,7 +447,7 @@
     }
 #endif                          /* DEBUG */
 
-    if (input_init(&info, url) == FALSE) {
+    if (input_init(&info, url, NULL) == FALSE) {
         g_message("error initialising input");
         return;
     }
@@ -506,7 +506,7 @@
     g_free(tmp);
 #endif                          /* DEBUG */
 
-    if (input_init(&myinfo, url) == FALSE) {
+    if (input_init(&myinfo, url, NULL) == FALSE) {
 #ifdef DEBUG
         g_message("error initialising input");
 #endif
@@ -533,6 +533,38 @@
 #endif                          /* DEBUG */
 }
 
+static void
+audmad_get_song_length(char *url, int *length, VFSFile *fd)
+{
+    struct mad_info_t myinfo;
+#ifdef DEBUG
+    gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL);
+    g_message("f: audmad_get_song_length: %s", tmp);
+    g_free(tmp);
+#endif                          /* DEBUG */
+
+    if (input_init(&myinfo, url, fd ? fd : NULL) == FALSE) {
+#ifdef DEBUG
+        g_message("error initialising input");
+#endif
+        return;
+    }
+
+    if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) {
+        if(myinfo.tuple->length == -1)
+            *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
+        else
+            *length = myinfo.tuple->length;
+    }
+    else {
+        *length = -1;
+    }
+    input_term(&myinfo);
+#ifdef DEBUG
+    g_message("e: audmad_get_song_info");
+#endif                          /* DEBUG */
+}
+
 static void audmad_about()
 {
     static GtkWidget *aboutbox;
@@ -617,21 +649,24 @@
         if(fd || (info.playback && info.playback->playing)) {
             gchar *tmp = NULL;
             tuple = bmp_title_input_new();
+
 #ifdef DEBUG
-            g_message("info.playback->playing = %d",info.playback->playing);
+            if(info.playback)
+                g_message("info.playback->playing = %d",info.playback->playing);
 #endif
-            tmp = vfs_get_metadata(info.infile, "track-name");
+            tmp = vfs_get_metadata(info.infile ? info.infile : fd, "track-name");
             if(tmp){
                 tuple->track_name = str_to_utf8(tmp);
                 g_free(tmp);
                 tmp = NULL;
             }
-            tmp = vfs_get_metadata(info.infile, "stream-name");
+            tmp = vfs_get_metadata(info.infile ? info.infile : fd, "stream-name");
             if(tmp){
                 tuple->album_name = str_to_utf8(tmp);
                 g_free(tmp);
                 tmp = NULL;
             }
+
 #ifdef DEBUG
             g_message("audmad_get_song_tuple: track_name = %s", tuple->track_name);
             g_message("audmad_get_song_tuple: stream_name = %s", tuple->album_name);
@@ -653,7 +688,7 @@
         g_message("get_song_tuple: remote: NULL");
 #endif
         return NULL;
-    }
+    } /* info.remote  */
 
     tuple = bmp_title_input_new();
 
@@ -704,7 +739,7 @@
             else {
                 char *dummy = NULL;
                 int length = 0;
-                audmad_get_song_info(filename, &dummy, &length);
+                audmad_get_song_length(filename, &length, fd ? fd : NULL);
                 tuple->length = length;
                 g_free(dummy);
             }
@@ -739,7 +774,7 @@
             char *dummy = NULL;
             int length = 0;
             if(tuple->length == -1) {
-                audmad_get_song_info(filename, &dummy, &length);
+                audmad_get_song_length(filename, &length, fd ? fd : NULL);
                 tuple->length = length;
             }
             g_free(dummy);