changeset 768:1d3f70ac6b31 trunk

[svn] - remote metadata handling is moved into input_process_remote_metadata(). this function converts string into utf-8 if necessary (mainly for zina). - revise seekable determination logic. duration may be negative value (zina..). - if remote url is passed, scan_file() will use fast scan method irrespective of preference value. - scattered http:// matching codes are aggregate into audmad_is_remote(). - some cleanups.
author yaz
date Fri, 02 Mar 2007 00:14:11 -0800
parents 96b884703411
children 13b8037d5d23
files ChangeLog src/madplug/decoder.c src/madplug/fileinfo.c src/madplug/input.c src/madplug/plugin.c src/madplug/plugin.h
diffstat 6 files changed, 104 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 01 20:09:48 2007 -0800
+++ b/ChangeLog	Fri Mar 02 00:14:11 2007 -0800
@@ -1,3 +1,11 @@
+2007-03-02 04:09:48 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
+  revision [1632]
+  - try to use str_to_utf8() to fill up tuple. we discovered that indecent ogg stream sends non-utf8 metadata.
+  
+  trunk/src/vorbis/vorbis.c |   12 ++++++------
+  1 file changed, 6 insertions(+), 6 deletions(-)
+
+
 2007-03-02 02:22:51 +0000  Giacomo Lozito <james@develia.org>
   revision [1630]
   - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
--- a/src/madplug/decoder.c	Thu Mar 01 20:09:48 2007 -0800
+++ b/src/madplug/decoder.c	Fri Mar 02 00:14:11 2007 -0800
@@ -190,6 +190,7 @@
 
 #ifdef DEBUG
     g_message("f: scan_file");
+    g_message("scan_file frames = %d\n", info->frames);
 #endif                          /* DEBUG */
 
     while (1) {
--- a/src/madplug/fileinfo.c	Thu Mar 01 20:09:48 2007 -0800
+++ b/src/madplug/fileinfo.c	Fri Mar 02 00:14:11 2007 -0800
@@ -574,9 +574,9 @@
 #endif
     input_init(&info, filename);
 
-    if (!strncasecmp("http://", filename, 7) || !strncasecmp("https://", filename, 8)) {
+    if(audmad_is_remote(filename)) {
         info.remote = TRUE;
-	return; //file info dialog for remote streaming doesn't make sense.
+        return; //file info dialog for remote streaming doesn't make sense.
     }
 
     utf_filename = str_to_utf8(filename);
--- a/src/madplug/input.c	Thu Mar 01 20:09:48 2007 -0800
+++ b/src/madplug/input.c	Fri Mar 02 00:14:11 2007 -0800
@@ -121,9 +121,8 @@
     info->size = vfs_ftell(info->infile);
     vfs_fseek(info->infile, 0, SEEK_SET);
     info->remote = info->size == 0 ? TRUE : FALSE; //proxy connection may result in non-zero size.
-    if (!strncasecmp("http://", url, 7) || !strncasecmp("https://", url, 8)) {
+    if(audmad_is_remote((gchar *)url))
         info->remote = TRUE;
-    }
 
 #ifdef DEBUG
     g_message("i: info->size = %lu", (long unsigned int)info->size);
@@ -342,7 +341,7 @@
     TitleInput *title_input;
 
 #ifdef DEBUG
-    g_message("f: input_read_tag\n");
+    g_message("f: input_read_tag");
 #endif
     if (info->tuple == NULL) {
         title_input = bmp_title_input_new();
@@ -397,7 +396,7 @@
     if (string) {
         title_input->length = atoi(string);
 #ifdef DEBUG
-        g_message("input_read_tag: TLEN = %d\n", title_input->length);
+        g_message("input_read_tag: TLEN = %d", title_input->length);
 #endif	
         g_free(string);
         string = NULL;
@@ -414,11 +413,53 @@
         audmad_config.id3_format : xmms_get_gentitle_format(), title_input);
 
 #ifdef DEBUG
-    g_message("e: input_read_tag\n");
+    g_message("e: input_read_tag");
 #endif
 
 }
 
+static void input_process_remote_metadata(struct mad_info_t *info)
+{
+    if(info->remote && mad_timer_count(info->duration, MAD_UNITS_SECONDS) <= 0){
+        gchar *tmp = NULL;
+
+        g_free(info->title);
+        info->title = NULL;
+        g_free(info->tuple->track_name);
+        info->tuple->track_name = NULL;
+        g_free(info->tuple->album_name);
+        info->tuple->album_name = NULL;
+
+        tmp = vfs_get_metadata(info->infile, "track-name");
+        if(tmp){
+            info->tuple->track_name = str_to_utf8(tmp);
+            info->title = g_strdup(info->tuple->track_name);
+            g_free(tmp);
+            tmp = NULL;
+        }
+
+        tmp = vfs_get_metadata(info->infile, "stream-name");
+        if(tmp){
+            info->tuple->album_name = str_to_utf8(tmp);
+            g_free(tmp);
+            tmp = NULL;
+        }
+
+        if (info->tuple->track_name && info->tuple->album_name)
+            tmp = g_strdup_printf("%s (%s)", info->tuple->track_name, info->tuple->album_name);
+        else if (info->tuple->album_name)
+            tmp = g_strdup(info->tuple->album_name);
+        else
+            tmp = g_strdup(""); // really?
+
+        mad_plugin->set_info(tmp,
+                             -1, // indicate the stream is unseekable
+                             info->bitrate, info->freq, info->channels);
+        g_free(tmp);
+    }
+}
+
+
 /**
  * Retrieve meta-information about URL.
  * For local files this means ID3 tag etc.
@@ -441,29 +482,7 @@
     vfs_fseek(info->infile, 0, SEEK_SET);
     info->offset = 0;
 
-    if(info->remote && mad_timer_count(info->duration, MAD_UNITS_SECONDS) == 0){
-        gchar *stream_name = vfs_get_metadata(info->infile, "stream-name");
-        gchar *track_name = vfs_get_metadata(info->infile, "track-name");
-        gchar *tmp = NULL;
-
-        g_free(info->title);
-        g_free(info->tuple->track_name);
-        g_free(info->tuple->album_name);
-
-        info->title = g_strdup(track_name);
-        info->tuple->track_name = g_strdup(track_name);
-        info->tuple->album_name = g_strdup(stream_name);
-
-        if (track_name != NULL)
-            tmp = g_strdup_printf("%s (%s)", track_name, stream_name);
-        else
-	    tmp = g_strdup(stream_name);
-
-        mad_plugin->set_info(tmp,
-                             -1, // indicates the stream is unseekable
-                             info->bitrate, info->freq, info->channels);
-        g_free(tmp); g_free(stream_name); g_free(track_name);
-    }
+    input_process_remote_metadata(info);
 
     /* use the filename for the title as a last resort */
     if (!info->title) {
@@ -490,7 +509,7 @@
  */
 // this function may be called before info->playback initialized.
 int
-input_get_data(struct mad_info_t *madinfo, guchar * buffer,
+input_get_data(struct mad_info_t *info, guchar * buffer,
                int buffer_size)
 {
     int len = 0;
@@ -500,43 +519,21 @@
 #endif
 #endif
     /* simply read to data from the file */
-    len = vfs_fread(buffer, 1, buffer_size, madinfo->infile); //vfs_fread returns num of elements.
+    len = vfs_fread(buffer, 1, buffer_size, info->infile); //vfs_fread returns num of elements.
 
     if(len == 0){
-	    if(madinfo->playback)
-		    madinfo->playback->eof = TRUE;
+	    if(info->playback)
+		    info->playback->eof = TRUE;
     }
-    
-    if(madinfo->remote && mad_timer_count(madinfo->duration, MAD_UNITS_SECONDS) == 0){
-        gchar *stream_name = vfs_get_metadata(madinfo->infile, "stream-name");
-        gchar *track_name = vfs_get_metadata(madinfo->infile, "track-name");
-        gchar *tmp = NULL;
-
-        g_free(madinfo->title);
-        g_free(madinfo->tuple->track_name);
-        g_free(madinfo->tuple->album_name);
 
-        madinfo->title = g_strdup(track_name);
-        madinfo->tuple->track_name = g_strdup(track_name);
-        madinfo->tuple->album_name = g_strdup(stream_name);
-
-        if (track_name != NULL)
-            tmp = g_strdup_printf("%s (%s)", track_name, stream_name);
-        else
-	    tmp = g_strdup(stream_name);
-
-        mad_plugin->set_info(tmp,
-                             -1, // indicate the stream is unseekable
-			     madinfo->bitrate, madinfo->freq, madinfo->channels);
-        g_free(tmp); g_free(stream_name); g_free(track_name);
-    }
+    input_process_remote_metadata(info);
     
 #ifdef DEBUG
 #ifdef DEBUG_INTENSIVELY
-    g_message ("e: input_get_data: size=%d offset=%d", len, madinfo->offset);
+    g_message ("e: input_get_data: size=%d offset=%d", len, info->offset);
 #endif
 #endif
-    madinfo->offset += len;
+    info->offset += len;
     return len;
 }
 
--- a/src/madplug/plugin.c	Thu Mar 01 20:09:48 2007 -0800
+++ b/src/madplug/plugin.c	Fri Mar 02 00:14:11 2007 -0800
@@ -206,6 +206,13 @@
         ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3];
 }
 
+gboolean audmad_is_remote(gchar *url)
+{
+    if (!strncasecmp("http://", url, 7) || !strncasecmp("https://", url, 8))
+        return TRUE;
+    else
+        return FALSE;
+}
 
 // audacious vfs fast version
 static int audmad_is_our_fd(char *filename, VFSFile *fin)
@@ -219,16 +226,8 @@
 
     info.remote = FALSE;
 
-#if 1
-    // XXX: temporary fix
-    if (!strncasecmp("http://", filename, 7) || !strncasecmp("https://", filename, 8))
-    {
-#ifdef DEBUG
-        g_message("audmad_is_our_fd: remote");
-#endif
+    if(audmad_is_remote(filename))
         info.remote = TRUE;
-    }
-#endif
 
     /* I've seen some flac files beginning with id3 frames..
        so let's exclude known non-mp3 filename extensions */
@@ -342,7 +341,8 @@
         return;
     }
 
-    rtn = input_get_info(&info, audmad_config.fast_play_time_calc);
+    // remote access must use fast scan.
+    rtn = input_get_info(&info, audmad_is_remote(url) ? TRUE : audmad_config.fast_play_time_calc);
 
     if (rtn == FALSE) {
         g_message("error reading input info");
@@ -392,7 +392,9 @@
 
     // don't try to get from stopped stream.
     if(myinfo.remote && (!myinfo.playback || !myinfo.playback->playing)){
-        g_print("get_song_info: remote!\n");
+#ifdef DEBUG
+        g_message("get_song_info: remote and not playing.");
+#endif
         return;
     }
 
@@ -496,17 +498,28 @@
     string = NULL;
 #endif
 
-    if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) == 0){
+    if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){
         if(info.playback && info.playback->playing) {
+            gchar *tmp = NULL;
             tuple = bmp_title_input_new();
 #ifdef DEBUG
-            printf("info.playback->playing = %d\n",info.playback->playing);
+            g_message("info.playback->playing = %d",info.playback->playing);
 #endif
-            tuple->track_name = vfs_get_metadata(info.infile, "track-name");
-            tuple->album_name = vfs_get_metadata(info.infile, "stream-name");
+            tmp = vfs_get_metadata(info.infile, "track-name");
+            if(tmp){
+                tuple->track_name = str_to_utf8(tmp);
+                g_free(tmp);
+                tmp = NULL;
+            }
+            tmp = vfs_get_metadata(info.infile, "stream-name");
+            if(tmp){
+                tuple->album_name = str_to_utf8(tmp);
+                g_free(tmp);
+                tmp = NULL;
+            }
 #ifdef DEBUG
-            printf("audmad_get_song_tuple: track_name = %s\n", tuple->track_name);
-            printf("audmad_get_song_tuple: stream_name = %s\n", tuple->album_name);
+            g_message("audmad_get_song_tuple: track_name = %s", tuple->track_name);
+            g_message("audmad_get_song_tuple: stream_name = %s", tuple->album_name);
 #endif
             tuple->file_name = g_path_get_basename(filename);
             tuple->file_path = g_path_get_dirname(filename);
@@ -514,12 +527,12 @@
             tuple->length = -1;
             tuple->mtime = 0; // this indicates streaming
 #ifdef DEBUG
-            printf("get_song_tuple remote: tuple\n");
+            g_message("get_song_tuple remote: tuple");
 #endif
             return tuple;
         }
 #ifdef DEBUG
-        printf("get_song_tuple: remote: NULL\n");
+        g_message("get_song_tuple: remote: NULL");
 #endif
         return NULL;
     }
@@ -562,7 +575,7 @@
                 if (string) {
                     tuple->length = atoi(string);
 #ifdef DEBUG
-                    printf("get_song_tuple: TLEN = %d\n", tuple->length);
+                    g_message("get_song_tuple: TLEN = %d", tuple->length);
 #endif	
                     g_free(string);
                     string = NULL;
@@ -618,7 +631,8 @@
 
 }
 
-
+// probably this function is nolonger needed.
+#if 0
 /**
  * Retrieve meta-information about URL.
  * For local files this means ID3 tag etc.
@@ -662,6 +676,8 @@
 #endif
     return TRUE;
 }
+#endif
+
 
 static gchar *fmts[] = { "mp3", "mp2", "mpg", NULL };
 
--- a/src/madplug/plugin.h	Thu Mar 01 20:09:48 2007 -0800
+++ b/src/madplug/plugin.h	Fri Mar 02 00:14:11 2007 -0800
@@ -70,8 +70,7 @@
     gint fmt;       /**< sample format */
     gint size;      /**< file size in bytes or -1 */
     gchar *title;   /**< title for xmms */
-    mad_timer_t duration;
-            /**< total play time */
+    mad_timer_t duration;   /**< total play time */
     struct id3_tag *tag;
     struct id3_file *id3file;
     struct xing xing;
@@ -131,6 +130,7 @@
 
 void audmad_config_compute(struct audmad_config_t *config);
 // compute scale values from "_db" strings
+gboolean audmad_is_remote(gchar *url);
 
 extern gpointer decode_loop(gpointer arg);
 extern void audmad_error(gchar * fmt, ...);