From 8664e1176984d3e67c15a52a22737e4d8d9ef782 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 19 Oct 2013 21:23:44 +0200 Subject: artwork: fixed cover art widget not getting pixbuf on startup --- plugins/artwork/artwork.c | 52 +++++++++++++++++++++++++++++++---------------- plugins/artwork/artwork.h | 4 ++-- 2 files changed, 37 insertions(+), 19 deletions(-) (limited to 'plugins/artwork') 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 #endif +#include #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 -- cgit v1.2.3