diff audacious/playlist.c @ 355:1c701dfe5098 trunk

[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...
author nenolod
date Thu, 29 Dec 2005 22:10:26 -0800
parents 763afa52f416
children 99928e1275a1
line wrap: on
line diff
--- 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);
 }