# HG changeset patch # User nenolod # Date 1135923026 28800 # Node ID 1c701dfe50987576ebff29b84ba7d4cf43868ef2 # Parent e2775c9b8b1364f483dcd2ca6491ab9dc213a887 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount of times we probe a resource to a strict limit of two times. (Once to detect the type, and the second time to get the stream information.) Something this simple should have been done to begin with... diff -r e2775c9b8b13 -r 1c701dfe5098 audacious/input.c --- a/audacious/input.c Thu Dec 29 02:29:29 2005 -0800 +++ b/audacious/input.c Thu Dec 29 22:10:26 2005 -0800 @@ -375,8 +375,27 @@ input_show_unplayable_files(filename); } - -gboolean +/* + * input_check_file() + * + * Inputs: + * filename to check recursively against input plugins + * whether or not to show an error + * + * Outputs: + * pointer to input plugin which can handle this file + * otherwise, NULL + * + * (the previous code returned a boolean of whether or not we can + * play the file... even WORSE for performance) + * + * Side Effects: + * various input plugins open the file and probe it + * -- this can have very ugly effects performance wise on streams + * + * --nenolod, Dec 31 2005 + */ +InputPlugin * input_check_file(const gchar * filename, gboolean show_warning) { GList *node; @@ -390,7 +409,7 @@ if (ip && input_is_enabled(ip->filename) && ip->is_our_file(filename_proxy)) { g_free(filename_proxy); - return TRUE; + return ip; } } @@ -400,7 +419,7 @@ input_file_not_playable(filename); } - return FALSE; + return NULL; } diff -r e2775c9b8b13 -r 1c701dfe5098 audacious/input.h --- a/audacious/input.h Thu Dec 29 02:29:29 2005 -0800 +++ b/audacious/input.h Thu Dec 29 22:10:26 2005 -0800 @@ -39,7 +39,7 @@ void set_current_input_plugin(InputPlugin * ip); InputVisType input_get_vis_type(); void free_vis_data(void); -gboolean input_check_file(const gchar * filename, gboolean show_warning); +InputPlugin *input_check_file(const gchar * filename, gboolean show_warning); void input_play(gchar * filename); void input_stop(void); void input_pause(void); diff -r e2775c9b8b13 -r 1c701dfe5098 audacious/playlist.c --- a/audacious/playlist.c Thu Dec 29 02:29:29 2005 -0800 +++ b/audacious/playlist.c Thu Dec 29 22:10:26 2005 -0800 @@ -120,7 +120,8 @@ PlaylistEntry * playlist_entry_new(const gchar * filename, const gchar * title, - const gint length) + const gint length, + InputPlugin * dec) { PlaylistEntry *entry; @@ -129,6 +130,7 @@ entry->title = str_to_utf8(title); entry->length = length; entry->selected = FALSE; + entry->decoder = dec; return entry; } @@ -152,7 +154,11 @@ g_return_val_if_fail(entry != NULL, FALSE); - input_get_song_info(entry->filename, &title, &length); + if (entry->decoder == NULL) + input_get_song_info(entry->filename, &title, &length); + else + entry->decoder->get_song_info(entry->filename, &title, &length); + if (!title && length == -1) return FALSE; @@ -419,13 +425,14 @@ __playlist_ins_with_info(const gchar * filename, gint pos, const gchar * title, - gint len) + gint len, + InputPlugin * dec) { g_return_if_fail(filename != NULL); PLAYLIST_LOCK(); playlist = g_list_insert(playlist, - playlist_entry_new(filename, title, len), + playlist_entry_new(filename, title, len, dec), pos); PLAYLIST_UNLOCK(); @@ -433,9 +440,9 @@ } static void -__playlist_ins(const gchar * filename, gint pos) +__playlist_ins(const gchar * filename, gint pos, InputPlugin *dec) { - __playlist_ins_with_info(filename, pos, NULL, -1); + __playlist_ins_with_info(filename, pos, NULL, -1, dec); playlist_recalc_total_time(); } @@ -461,21 +468,21 @@ return playlist_format_get_from_name(filename) != PLAYLIST_FORMAT_UNKNOWN; } - gboolean playlist_ins(const gchar * filename, gint pos) { gchar buf[64], *p; gint r; VFSFile *file; + InputPlugin *dec; if (is_playlist_name(filename)) { playlist_load_ins(filename, pos); return TRUE; } - if (input_check_file(filename, TRUE)) { - __playlist_ins(filename, pos); + if ((dec = input_check_file(filename, TRUE)) != NULL) { + __playlist_ins(filename, pos, dec); playlist_generate_shuffle_list(); playlistwin_update_list(); return TRUE; @@ -668,7 +675,7 @@ g_hash_table_foreach_remove(htab, devino_destroy, NULL); for (node = list; node; node = g_list_next(node)) { - __playlist_ins(node->data, pos); + __playlist_ins(node->data, pos, NULL); g_free(node->data); entries++; if (pos >= 0) @@ -1269,6 +1276,7 @@ { gchar *filename; gchar *tmp, *path; + InputPlugin *dec; /* for decoder cache */ g_return_if_fail(filename_p != NULL); g_return_if_fail(playlist_name != NULL); @@ -1285,16 +1293,21 @@ if ((tmp = strrchr(path, '/'))) *tmp = '\0'; else { - __playlist_ins_with_info(filename, pos, title, len); + dec = input_check_file(filename, FALSE); + __playlist_ins_with_info(filename, pos, title, len, dec); return; } tmp = g_build_filename(path, filename, NULL); - __playlist_ins_with_info(tmp, pos, title, len); + dec = input_check_file(filename, FALSE); + __playlist_ins_with_info(tmp, pos, title, len, dec); g_free(tmp); g_free(path); } else - __playlist_ins_with_info(filename, pos, title, len); + { + dec = input_check_file(filename, FALSE); + __playlist_ins_with_info(filename, pos, title, len, dec); + } g_free(filename); } diff -r e2775c9b8b13 -r 1c701dfe5098 audacious/playlist.h --- a/audacious/playlist.h Thu Dec 29 02:29:29 2005 -0800 +++ b/audacious/playlist.h Thu Dec 29 22:10:26 2005 -0800 @@ -21,7 +21,7 @@ #define PLAYLIST_H #include - +#include "input.h" typedef enum { PLAYLIST_SORT_PATH, @@ -44,12 +44,14 @@ gchar *title; gint length; gboolean selected; + InputPlugin *decoder; }; typedef struct _PlaylistEntry PlaylistEntry; PlaylistEntry *playlist_entry_new(const gchar * filename, - const gchar * title, const gint len); + const gchar * title, const gint len, + InputPlugin * dec); void playlist_entry_free(PlaylistEntry * entry); void playlist_init(void);