summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2010-11-14 19:15:52 +0100
committerGravatar waker <wakeroid@gmail.com>2010-11-14 19:15:52 +0100
commite99691495ae098275ba7a3029960d2156ed28537 (patch)
treed5f5cd734cfde60771191594fcff4e15b9e8ff12
parentd78c38b33247a6ba153847ee720c7786109f00f9 (diff)
album art cache fixes
-rw-r--r--conf.c14
-rw-r--r--conf.h6
-rw-r--r--deadbeef.h2
-rw-r--r--plugins.c2
-rw-r--r--plugins/artwork/artwork.c15
-rw-r--r--plugins/gtkui/coverart.c57
6 files changed, 54 insertions, 42 deletions
diff --git a/conf.c b/conf.c
index b86e0836..c59cc92d 100644
--- a/conf.c
+++ b/conf.c
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
+#include <inttypes.h>
#include "conf.h"
static DB_conf_item_t *conf_items;
@@ -133,6 +134,12 @@ conf_get_int (const char *key, int def) {
return v ? atoi (v) : def;
}
+int64_t
+conf_get_int64 (const char *key, int64_t def) {
+ const char *v = conf_get_str (key, NULL);
+ return v ? atoll (v) : def;
+}
+
DB_conf_item_t *
conf_find (const char *group, DB_conf_item_t *prev) {
int l = strlen (group);
@@ -186,6 +193,13 @@ conf_set_int (const char *key, int val) {
}
void
+conf_set_int64 (const char *key, int64_t val) {
+ char s[20];
+ snprintf (s, sizeof (s), PRId64, val);
+ conf_set_str (key, s);
+}
+
+void
conf_set_float (const char *key, float val) {
char s[10];
snprintf (s, sizeof (s), "%0.7f", val);
diff --git a/conf.h b/conf.h
index 771c3a6b..0e96f336 100644
--- a/conf.h
+++ b/conf.h
@@ -44,6 +44,9 @@ conf_get_float (const char *key, float def);
int
conf_get_int (const char *key, int def);
+int64_t
+conf_get_int64 (const char *key, int64_t def);
+
void
conf_set_str (const char *key, const char *val);
@@ -51,6 +54,9 @@ void
conf_set_int (const char *key, int val);
void
+conf_set_int64 (const char *key, int64_t val);
+
+void
conf_set_float (const char *key, float val);
DB_conf_item_t *
diff --git a/deadbeef.h b/deadbeef.h
index 556ef1b6..76ff1551 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -498,8 +498,10 @@ typedef struct {
const char * (*conf_get_str) (const char *key, const char *def);
float (*conf_get_float) (const char *key, float def);
int (*conf_get_int) (const char *key, int def);
+ int64_t (*conf_get_int64) (const char *key, int64_t def);
void (*conf_set_str) (const char *key, const char *val);
void (*conf_set_int) (const char *key, int val);
+ void (*conf_set_int64) (const char *key, int64_t val);
void (*conf_set_float) (const char *key, float val);
DB_conf_item_t * (*conf_find) (const char *group, DB_conf_item_t *prev);
void (*conf_remove_items) (const char *key);
diff --git a/plugins.c b/plugins.c
index 331baab9..33da5ee1 100644
--- a/plugins.c
+++ b/plugins.c
@@ -237,8 +237,10 @@ static DB_functions_t deadbeef_api = {
.conf_get_str = conf_get_str,
.conf_get_float = conf_get_float,
.conf_get_int = conf_get_int,
+ .conf_get_int64 = conf_get_int64,
.conf_set_str = conf_set_str,
.conf_set_int = conf_set_int,
+ .conf_set_int64 = conf_set_int64,
.conf_set_float = conf_set_float,
.conf_find = conf_find,
.conf_remove_items = conf_remove_items,
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;
+ }
}
}
}