diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-10-19 21:23:44 +0200 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-10-19 21:23:44 +0200 |
commit | 8664e1176984d3e67c15a52a22737e4d8d9ef782 (patch) | |
tree | bd8c78c82b6768e653d85b66c348bbb0a1277fa3 | |
parent | 13b691e6cb2bfa1be3fb7456e5bac0fd1512d703 (diff) |
artwork: fixed cover art widget not getting pixbuf on startup
-rw-r--r-- | plugins/artwork/artwork.c | 52 | ||||
-rw-r--r-- | plugins/artwork/artwork.h | 4 | ||||
-rw-r--r-- | plugins/gtkui/coverart.c | 59 | ||||
-rw-r--r-- | plugins/gtkui/widgets.c | 7 |
4 files changed, 72 insertions, 50 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 51b80102..facfd486 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -19,6 +19,7 @@ #if HAVE_SYS_SYSLIMITS_H #include <sys/syslimits.h> #endif +#include <assert.h> #include "../../deadbeef.h" #include "artwork.h" #include "lastfm.h" @@ -52,13 +53,20 @@ DB_functions_t *deadbeef; DB_FILE *current_file; +#define MAX_CALLBACKS 200 + +typedef struct cover_callback_s { + artwork_callback cb; + void *ud; +} cover_callback_t; + typedef struct cover_query_s { char *fname; char *artist; char *album; int size; - artwork_callback callback; - void *user_data; + cover_callback_t callbacks[MAX_CALLBACKS]; + int numcb; struct cover_query_s *next; } cover_query_t; @@ -134,23 +142,28 @@ queue_add (const char *fname, const char *artist, const char *album, int img_siz deadbeef->mutex_lock (mutex); for (cover_query_t *q = queue; q; q = q->next) { - if (!strcasecmp (artist, q->artist) && !strcasecmp (album, q->album) && img_size == q->size && callback == q->callback) { - deadbeef->mutex_unlock (mutex); - if (callback) { - callback (NULL, NULL, NULL, user_data); + if (!strcasecmp (artist, q->artist) && !strcasecmp (album, q->album) && img_size == q->size) { + // already in queue, add callback + if (q->numcb < MAX_CALLBACKS && callback) { + q->callbacks[q->numcb].cb = callback; + q->callbacks[q->numcb].ud = user_data; + q->numcb++; } - return; // already in queue + deadbeef->mutex_unlock (mutex); + return; } } + trace ("artwork:queue_add %s %s %s %d\n", fname, artist, album, img_size); cover_query_t *q = malloc (sizeof (cover_query_t)); memset (q, 0, sizeof (cover_query_t)); q->fname = strdup (fname); q->artist = strdup (artist); q->album = strdup (album); q->size = img_size; - q->callback = callback; - q->user_data = user_data; + q->callbacks[q->numcb].cb = callback; + q->callbacks[q->numcb].ud = user_data; + q->numcb++; if (queue_tail) { queue_tail->next = q; queue_tail = q; @@ -176,8 +189,10 @@ queue_pop (void) { if (queue->album) { free (queue->album); } - if (queue->callback) { - queue->callback (NULL, NULL, NULL, queue->user_data); + for (int i = 0; i < queue->numcb; i++) { + if (queue->callbacks[i].cb) { + queue->callbacks[i].cb (NULL, NULL, NULL, queue->callbacks[i].ud); + } } free (queue); } @@ -1151,9 +1166,11 @@ fetcher_thread (void *none) make_cache_path (scaled_path, sizeof (scaled_path), param->album, param->artist, param->size); copy_file (cache_path, scaled_path, param->size); } - if (param->callback) { - param->callback (param->fname, param->artist, param->album, param->user_data); - param->callback = NULL; + for (int i = 0; i < param->numcb; i++) { + if (param->callbacks[i].cb) { + param->callbacks[i].cb (param->fname, param->artist, param->album, param->callbacks[i].ud); + param->callbacks[i].cb = NULL; + } } } queue_pop (); @@ -1195,7 +1212,6 @@ find_image (const char *path) { char* get_album_art (const char *fname, const char *artist, const char *album, int size, artwork_callback callback, void *user_data) { - trace ("get_album_art: %s (%s - %s)\n", fname, artist, album); char path [1024]; if (!album) { @@ -1302,8 +1318,10 @@ artwork_reset (int fast) { free (queue->next->fname); free (queue->next->artist); free (queue->next->album); - if (queue->next->callback == sync_callback) { - sync_callback (NULL, NULL, NULL, queue->next->user_data); + for (int i = 0; i < queue->next->numcb; i++) { + if (queue->next->callbacks[i].cb == sync_callback) { + sync_callback (NULL, NULL, NULL, queue->next->callbacks[i].ud); + } } queue->next = next; if (next == NULL) { diff --git a/plugins/artwork/artwork.h b/plugins/artwork/artwork.h index 117e263d..9d8a2a7d 100644 --- a/plugins/artwork/artwork.h +++ b/plugins/artwork/artwork.h @@ -10,13 +10,13 @@ typedef void (*artwork_callback) (const char *fname, const char *artist, const c typedef struct { DB_misc_t plugin; // returns filename of cached image, or NULL - // negative size has special meanings: - // -1: return default cover if not available (otherwise NULL will be returned) char* (*get_album_art) (const char *fname, const char *artist, const char *album, int size, artwork_callback callback, void *user_data); // this has to be called to clear queue on exit, before caller terminates // `fast=1' means "don't wait, just flush queue" void (*reset) (int fast); + + // returns path to default album art const char *(*get_default_cover) (void); // synchronously get filename diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c index 1a2e4b6f..a1180415 100644 --- a/plugins/gtkui/coverart.c +++ b/plugins/gtkui/coverart.c @@ -44,16 +44,22 @@ GdkPixbuf *pixbuf_default; typedef struct { struct timeval tm; char *fname; - time_t filetime; int width; GdkPixbuf *pixbuf; } cached_pixbuf_t; +#define MAX_CALLBACKS 200 + +typedef struct cover_callback_s { + void (*cb) (void*ud); + void *ud; +} cover_callback_t; + typedef struct load_query_s { char *fname; int width; - void (*callback) (void *user_data); - void *user_data; + cover_callback_t callbacks[MAX_CALLBACKS]; + int numcb; struct load_query_s *next; } load_query_t; @@ -71,9 +77,14 @@ queue_add (const char *fname, int width, void (*callback) (void *user_data), voi load_query_t *q; if (fname) { for (q = queue; q; q = q->next) { - if (q->fname && !strcmp (q->fname, fname) && width == q->width && q->callback == callback) { + if (q->fname && !strcmp (q->fname, fname) && width == q->width) { + if (q->numcb < MAX_CALLBACKS && callback) { + q->callbacks[q->numcb].cb = callback; + q->callbacks[q->numcb].ud = user_data; + q->numcb++; + } deadbeef->mutex_unlock (mutex); - return; // dupe + return; } } } @@ -83,8 +94,9 @@ queue_add (const char *fname, int width, void (*callback) (void *user_data), voi q->fname = strdup (fname); } q->width = width; - q->callback = callback; - q->user_data = user_data; + q->callbacks[q->numcb].cb = callback; + q->callbacks[q->numcb].ud = user_data; + q->numcb++; if (tail) { tail->next = q; tail = q; @@ -147,8 +159,10 @@ loading_thread (void *none) { } deadbeef->mutex_unlock (mutex); if (!queue->fname) { - if (queue->callback) { - queue->callback (queue->user_data); + for (int i = 0; i < queue->numcb; i++) { + if (queue->callbacks[i].cb) { + queue->callbacks[i].cb (queue->callbacks[i].ud); + } } queue_pop (); continue; @@ -159,11 +173,6 @@ 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 = NULL; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_file_at_scale (queue->fname, queue->width, queue->width, TRUE, &error); @@ -178,17 +187,17 @@ loading_thread (void *none) { } 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); } - if (queue->callback) { - queue->callback (queue->user_data); + for (int i = 0; i < queue->numcb; i++) { + if (queue->callbacks[i].cb) { + queue->callbacks[i].cb (queue->callbacks[i].ud); + } } queue_pop (); } @@ -228,15 +237,11 @@ get_pixbuf (const char *fname, int width, void (*callback)(void *user_data), voi for (int i = 0; i < CACHE_SIZE; i++) { if (cache[i].pixbuf) { if (!strcmp (fname, cache[i].fname) && cache[i].width == width) { - // 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; - } + gettimeofday (&cache[i].tm, NULL); + GdkPixbuf *pb = cache[i].pixbuf; + g_object_ref (pb); + deadbeef->mutex_unlock (mutex); + return pb; } } } diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c index 7ab09e7f..951d8a80 100644 --- a/plugins/gtkui/widgets.c +++ b/plugins/gtkui/widgets.c @@ -2061,9 +2061,7 @@ coverart_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { w_coverart_t *w = user_data; int real_size = min (width, height); - if (w->cover_size == -1) { - w->cover_size = w->new_cover_size = real_size; - } + if (real_size > 0 && it) { if (w->new_cover_size != real_size) { w->new_cover_size = real_size; @@ -2073,6 +2071,7 @@ coverart_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { } if (w->cover_size == -1) { w->cover_size = real_size; + g_idle_add (deferred_cover_load_cb, w); } else { if (!w->cover_refresh_timeout_id) { @@ -2090,7 +2089,7 @@ coverart_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { if (!album || !*album) { album = deadbeef->pl_find_meta (it, "title"); } - GdkPixbuf *pixbuf = get_cover_art_callb (it ? deadbeef->pl_find_meta ((it), ":URI") : NULL, artist, album, real_size == size ? size : -1, coverart_avail_callback_single, user_data); + GdkPixbuf *pixbuf = get_cover_art_callb (deadbeef->pl_find_meta ((it), ":URI"), artist, album, real_size == size ? size : -1, coverart_avail_callback_single, user_data); deadbeef->pl_unlock (); int hq = 0; |