# HG changeset patch # User Yoshiki Yazawa # Date 1185046100 -32400 # Node ID 38fb3bb3e21ebad26722d1021c9a7d9d056b5c09 # Parent 4f9bea634312e2f181bbde96979b9bb5bb9b80d6 - make probing for tuple completely reuse fd. - fix bugs in __audmad_get_song_tuple() against remote sources. diff -r 4f9bea634312 -r 38fb3bb3e21e src/madplug/fileinfo.c --- a/src/madplug/fileinfo.c Sat Jul 21 12:20:08 2007 -0500 +++ b/src/madplug/fileinfo.c Sun Jul 22 04:28:20 2007 +0900 @@ -601,7 +601,7 @@ return; } - input_init(&info, fileurl); + input_init(&info, fileurl, NULL); if(audmad_is_remote(fileurl)) { info.remote = TRUE; @@ -627,7 +627,9 @@ info.fileinfo_request = TRUE; input_get_info(&info, info.remote ? TRUE : FALSE); - title = g_strdup_printf(_("File Info - %s"), g_basename(utf_filename)); + tmp = g_path_get_basename(utf_filename); + title = g_strdup_printf(_("File Info - %s"), tmp); + g_free(tmp); tmp = NULL; gtk_window_set_title(GTK_WINDOW(window), title); g_free(title); diff -r 4f9bea634312 -r 38fb3bb3e21e src/madplug/input.c --- a/src/madplug/input.c Sat Jul 21 12:20:08 2007 -0500 +++ b/src/madplug/input.c Sun Jul 22 04:28:20 2007 +0900 @@ -69,7 +69,7 @@ /** * init the mad_info_t struct. */ -gboolean input_init(struct mad_info_t * info, const char *url) +gboolean input_init(struct mad_info_t * info, const char *url, VFSFile *fd) { #ifdef DEBUG g_message("f: input_init"); @@ -112,10 +112,19 @@ info->filename = g_strdup(url); - info->infile = vfs_fopen(info->filename, "rb"); - if (info->infile == NULL) { - return FALSE; + if(!fd){ + info->infile = vfs_fopen(info->filename, "rb"); + if (info->infile == NULL) { + return FALSE; + } } + else{ +#ifdef DEBUG + printf("input_init: vfs_dup\n"); +#endif + info->infile = vfs_dup(fd); + } + // obtain file size info->size = vfs_fsize(info->infile); info->remote = info->size == 0 ? TRUE : FALSE; //proxy connection may result in non-zero size. @@ -370,8 +379,9 @@ curpos = vfs_ftell(info->infile); info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); } - else + else { info->id3file = id3_file_open(info->filename, ID3_FILE_MODE_READONLY); + } if (!info->id3file) { #ifdef DEBUG @@ -486,8 +496,14 @@ 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(g_basename(info->filename)); + else { + gchar *realfn = g_filename_from_uri(info->filename, NULL, NULL); + gchar *tmp2 = g_path_get_basename(realfn ? realfn : info->filename); // info->filename is uri. --yaz + tmp = str_to_utf8(tmp2); + g_free(tmp2); tmp2 = NULL; + g_free(realfn); realfn = NULL; +// tmp = g_strdup(g_basename(info->filename)); //XXX maybe ok. --yaz + } /* call set_info only if tmp is different from prev_tmp */ if ( ( ( info->prev_title != NULL ) && ( strcmp(info->prev_title,tmp) ) ) || @@ -539,11 +555,11 @@ /* use the filename for the title as a last resort */ if (!info->title) { - char *pos = strrchr(info->filename, DIR_SEPARATOR); + char *pos = strrchr(info->filename, DIR_SEPARATOR); //XXX info->filename is uri. --yaz if (pos) info->title = g_strdup(pos + 1); else - info->title = g_strdup(info->filename); + info->title = g_strdup(info->filename); //XXX info->filename is uri. --yaz } #ifdef DEBUG diff -r 4f9bea634312 -r 38fb3bb3e21e src/madplug/input.h --- a/src/madplug/input.h Sat Jul 21 12:20:08 2007 -0500 +++ b/src/madplug/input.h Sun Jul 22 04:28:20 2007 +0900 @@ -23,7 +23,7 @@ #define INPUT_H #include "plugin.h" -gboolean input_init(struct mad_info_t *songinfo, const gchar * url); +gboolean input_init(struct mad_info_t *songinfo, const gchar * url, VFSFile *fd); gboolean input_term(struct mad_info_t *songinfo); gboolean input_get_info(struct mad_info_t *songinfo, gboolean fast_scan); gint input_get_data(struct mad_info_t *songinfo, guchar * buffer, diff -r 4f9bea634312 -r 38fb3bb3e21e src/madplug/plugin.c --- 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);