Mercurial > audlegacy-plugins
changeset 1329:4b07404814ca
- reduce the number of file open in loading.
- make use of new vfs_is_remote() and vfs_is_streaming().
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sun, 22 Jul 2007 22:21:28 +0900 |
parents | 38fb3bb3e21e |
children | 0fdf6ee112f5 |
files | src/madplug/fileinfo.c src/madplug/plugin.c |
diffstat | 2 files changed, 28 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/madplug/fileinfo.c Sun Jul 22 04:28:20 2007 +0900 +++ b/src/madplug/fileinfo.c Sun Jul 22 22:21:28 2007 +0900 @@ -587,7 +587,7 @@ ("single channel"), ("dual channel"), "joint stereo", "stereo" }; gchar *tmp, *utf_filename; - + gchar *realfn = NULL; #ifdef DEBUG { tmp = str_to_utf8(fileurl); @@ -597,7 +597,7 @@ } #endif - if(!vfs_file_test(fileurl, G_FILE_TEST_EXISTS)) { + if(!vfs_is_remote(fileurl) && !vfs_file_test(fileurl, G_FILE_TEST_EXISTS)) { return; } @@ -605,23 +605,13 @@ if(audmad_is_remote(fileurl)) { info.remote = TRUE; - return; //file info dialog for remote streaming doesn't make sense. + if(vfs_is_streaming(info.infile)) + return; //file info dialog for remote streaming doesn't make sense. } - tmp = g_filename_from_uri(fileurl, NULL, NULL); - if (tmp == NULL) - { -#ifdef DEBUG - tmp = str_to_utf8(fileurl); - g_message("f: audmad_get_file_info: %s , g_filename_from_uri failed", tmp); - g_free(tmp); - tmp = NULL; -#endif - return; - } - utf_filename = str_to_utf8(tmp); - g_free(tmp); - tmp = NULL; + realfn = g_filename_from_uri(fileurl, NULL, NULL); + utf_filename = str_to_utf8(realfn ? realfn : fileurl); + g_free(realfn); realfn = NULL; create_window(); info.fileinfo_request = TRUE;
--- a/src/madplug/plugin.c Sun Jul 22 04:28:20 2007 +0900 +++ b/src/madplug/plugin.c Sun Jul 22 22:21:28 2007 +0900 @@ -288,12 +288,8 @@ gboolean audmad_is_remote(gchar *url) { - if (!strncasecmp("http://", url, 7) - || !strncasecmp("https://", url, 8) - || !strncasecmp("lastfm://", url, 9)) - return TRUE; - else - return FALSE; + gboolean rv = vfs_is_remote(url); + return rv; } // audacious vfs fast version @@ -638,6 +634,8 @@ struct id3_file *id3file = NULL; struct id3_tag *tag = NULL; + gboolean local_fd = FALSE; + #ifdef DEBUG string = str_to_utf8(filename); g_message("f: mad: audmad_get_song_tuple: %s", string); @@ -646,7 +644,7 @@ #endif if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ - if(fd || (info.playback && info.playback->playing)) { + if((fd && vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) { gchar *tmp = NULL; tuple = bmp_title_input_new(); @@ -692,10 +690,15 @@ tuple = bmp_title_input_new(); - if (!fd) - id3file = id3_file_open(filename, ID3_FILE_MODE_READONLY); - else - id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY); + // if !fd, pre-open the file with vfs_fopen() and reuse fd. + if(!fd) { + fd = vfs_fopen(filename, "rb"); + if(!fd) + return NULL; + local_fd = TRUE; + } + + id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY); if (id3file) { @@ -739,7 +742,7 @@ else { char *dummy = NULL; int length = 0; - audmad_get_song_length(filename, &length, fd ? fd : NULL); + audmad_get_song_length(filename, &length, fd); tuple->length = length; g_free(dummy); } @@ -762,7 +765,7 @@ } id3_file_close(id3file); - } + } // id3file else { // no id3tag realfn = g_filename_from_uri(filename, NULL, NULL); tuple->file_name = g_path_get_basename(realfn ? realfn : filename); @@ -774,12 +777,16 @@ char *dummy = NULL; int length = 0; if(tuple->length == -1) { - audmad_get_song_length(filename, &length, fd ? fd : NULL); + audmad_get_song_length(filename, &length, fd); tuple->length = length; } g_free(dummy); } } + + if(local_fd) + vfs_fclose(fd); + #ifdef DEBUG g_message("e: mad: audmad_get_song_tuple"); #endif