diff options
author | waker <wakeroid@gmail.com> | 2010-11-14 19:15:52 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2010-11-14 19:15:52 +0100 |
commit | e99691495ae098275ba7a3029960d2156ed28537 (patch) | |
tree | d5f5cd734cfde60771191594fcff4e15b9e8ff12 /plugins/gtkui | |
parent | d78c38b33247a6ba153847ee720c7786109f00f9 (diff) |
album art cache fixes
Diffstat (limited to 'plugins/gtkui')
-rw-r--r-- | plugins/gtkui/coverart.c | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c index 7fb50554..9a42172a 100644 --- a/plugins/gtkui/coverart.c +++ b/plugins/gtkui/coverart.c @@ -21,6 +21,7 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> +#include <sys/stat.h> #include "coverart.h" #include "../artwork/artwork.h" #include "gtkui.h" @@ -38,6 +39,7 @@ extern DB_artwork_plugin_t *coverart_plugin; typedef struct { struct timeval tm; char *fname; + time_t filetime; int width; GdkPixbuf *pixbuf; } cached_pixbuf_t; @@ -140,7 +142,10 @@ loading_thread (void *none) { usleep (500000); continue; } - + struct stat stat_buf; + if (stat (queue->fname, &stat_buf) < 0) { + trace ("failed to stat file %s\n", queue->fname); + } // GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (queue->fname, NULL); GError *error = NULL; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale (queue->fname, queue->width, queue->width, TRUE, &error); @@ -151,6 +156,9 @@ loading_thread (void *none) { g_error_free (error); error = NULL; } + if (stat (DEFAULT_COVER_PATH, &stat_buf) < 0) { + trace ("failed to stat file %s\n", queue->fname); + } pixbuf = gdk_pixbuf_new_from_file_at_scale (DEFAULT_COVER_PATH, queue->width, queue->width, TRUE, &error); if (!pixbuf) { fprintf (stderr, "gdk_pixbuf_new_from_file_at_scale %s %d failed, error: %s\n", DEFAULT_COVER_PATH, queue->width, error->message); @@ -163,43 +171,16 @@ loading_thread (void *none) { if (!pixbuf) { // make default empty image pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 2, 2); + stat_buf.st_mtime = 0; } -#if 0 - else { - int w, h; - w = gdk_pixbuf_get_width (pixbuf); - h = gdk_pixbuf_get_height (pixbuf); - int width = queue->width; - if (w != width) { - int height; - if (w > h) { - height = width * h / w; - } - else if (h > w) { - height = width; - width = height * w / h; - } - else { - height = width; - } - if (width < 5 || height < 5) { - trace ("will not scale to %dx%d\n", width, height); - queue_pop (); - continue; - } - trace ("scaling %dx%d -> %dx%d\n", w, h, width, height); - GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); - g_object_unref (pixbuf); - pixbuf = scaled; - } - } -#endif if (cache_min != -1) { deadbeef->mutex_lock (mutex); + cache[cache_min].filetime = stat_buf.st_mtime; cache[cache_min].pixbuf = pixbuf; cache[cache_min].fname = strdup (queue->fname); gettimeofday (&cache[cache_min].tm, NULL); cache[cache_min].width = queue->width; + struct stat stat_buf; deadbeef->mutex_unlock (mutex); } queue_pop (); @@ -231,11 +212,15 @@ get_pixbuf (const char *fname, int width) { for (int i = 0; i < CACHE_SIZE; i++) { if (cache[i].pixbuf) { if (!strcmp (fname, cache[i].fname) && cache[i].width == width) { - gettimeofday (&cache[i].tm, NULL); - GdkPixbuf *pb = cache[i].pixbuf; - g_object_ref (pb); - deadbeef->mutex_unlock (mutex); - return pb; + // check if cached filetime hasn't changed + struct stat stat_buf; + if (!stat (fname, &stat_buf) && stat_buf.st_mtime == cache[i].filetime) { + gettimeofday (&cache[i].tm, NULL); + GdkPixbuf *pb = cache[i].pixbuf; + g_object_ref (pb); + deadbeef->mutex_unlock (mutex); + return pb; + } } } } |