diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/artwork/artwork.c | 15 | ||||
-rw-r--r-- | plugins/gtkui/coverart.c | 57 |
2 files changed, 30 insertions, 42 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index fbbe71d9..952b018a 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -6,6 +6,7 @@ #include <dirent.h> #include <unistd.h> #include <fnmatch.h> +#include <inttypes.h> #include "../../deadbeef.h" #include "artwork.h" #include "lastfm.h" @@ -13,8 +14,8 @@ #define min(x,y) ((x)<(y)?(x):(y)) -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(...) #define DEFAULT_COVER_PATH (PREFIX "/share/deadbeef/pixmaps/noartwork.jpg") #define DEFAULT_FILEMASK "*cover*.jpg;*front*.jpg" @@ -45,7 +46,7 @@ int artwork_enable_embedded; int artwork_enable_local; int artwork_enable_lfm; int artwork_enable_aao; -int artwork_reset_time; +time_t artwork_reset_time; char artwork_filemask[200]; void @@ -589,7 +590,7 @@ get_album_art (const char *fname, const char *artist, const char *album, artwork return strdup (DEFAULT_COVER_PATH); } - trace ("found %s in cache\n", path); +// trace ("found %s in cache, resettime %" PRId64 ", filetime %" PRId64 ", time %" PRId64 "\n", path, artwork_reset_time, stat_buf.st_mtime, tm); return strdup (path); } @@ -648,13 +649,15 @@ artwork_on_configchanged (DB_event_t *ev, uintptr_t data) { || new_artwork_enable_lfm != artwork_enable_lfm || new_artwork_enable_aao != artwork_enable_aao || strcmp (new_artwork_filemask, artwork_filemask)) { + printf ("artwork config changed, invalidating cache...\n"); artwork_enable_embedded = new_artwork_enable_embedded; artwork_enable_local = new_artwork_enable_local; artwork_enable_lfm = new_artwork_enable_lfm; artwork_enable_aao = new_artwork_enable_aao; artwork_reset_time = time (NULL); strcpy (artwork_filemask, new_artwork_filemask); - deadbeef->conf_set_int ("artwork.cache_reset_time", artwork_reset_time); + deadbeef->conf_set_int64 ("artwork.cache_reset_time", artwork_reset_time); + artwork_reset (0); deadbeef->sendmessage (M_PLAYLISTREFRESH, 0, 0, 0); } @@ -670,7 +673,7 @@ artwork_plugin_start (void) artwork_enable_local = deadbeef->conf_get_int ("artwork.enable_localfolder", 1); artwork_enable_lfm = deadbeef->conf_get_int ("artwork.enable_lastfm", 0); artwork_enable_aao = deadbeef->conf_get_int ("artwork.enable_albumartorg", 0); - artwork_reset_time = deadbeef->conf_get_int ("artwork.cache_reset_time", 0); + artwork_reset_time = deadbeef->conf_get_int64 ("artwork.cache_reset_time", 0); strncpy (artwork_filemask, deadbeef->conf_get_str ("artwork.filemask", DEFAULT_FILEMASK), sizeof (artwork_filemask)); artwork_filemask[sizeof(artwork_filemask)-1] = 0; 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; + } } } } |