summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Tydus <Tydus@Tydus.org>2011-11-13 20:41:34 +0800
committerGravatar waker <wakeroid@gmail.com>2011-11-13 19:18:51 +0100
commit0adc00102dc724f40909ec658ecef8aa10ba73c3 (patch)
treed4279d5ce56a47f74cfe2337c60945c66841ebbb /plugins
parent22abcdce0c82110828336972cf2720e3dfcc2ba1 (diff)
Implemented fetching artwork filename synchronizely
Diffstat (limited to 'plugins')
-rw-r--r--plugins/artwork/artwork.c37
-rw-r--r--plugins/artwork/artwork.h3
2 files changed, 40 insertions, 0 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c
index 63861f0d..6f01ac93 100644
--- a/plugins/artwork/artwork.c
+++ b/plugins/artwork/artwork.c
@@ -52,6 +52,11 @@ typedef struct cover_query_s {
struct cover_query_s *next;
} cover_query_t;
+typedef struct mutex_cond_s {
+ uintptr_t mutex;
+ uintptr_t cond;
+} mutex_cond_t;
+
static cover_query_t *queue;
static cover_query_t *queue_tail;
static uintptr_t mutex;
@@ -1213,6 +1218,34 @@ get_album_art (const char *fname, const char *artist, const char *album, int siz
return size == -1 ? strdup (get_default_cover ()) : NULL;
}
+static void
+sync_callback (const char *fname, const char *artist, const char *album, void *user_data) {
+ mutex_cond_t *mc = (mutex_cond_t *)user_data;
+ if (mc) {
+ deadbeef->mutex_lock (mc->mutex);
+ deadbeef->cond_signal (mc->cond);
+ deadbeef->mutex_unlock (mc->mutex);
+ }
+}
+
+char*
+get_album_art_sync (const char *fname, const char *artist, const char *album, int size) {
+ mutex_cond_t *mc = malloc (sizeof (mutex_cond_t));
+ mc->mutex = deadbeef->mutex_create ();
+ mc->cond = deadbeef->cond_create ();
+ deadbeef->mutex_lock (mc->mutex);
+ char *image_fname = get_album_art (fname, artist, album, size, sync_callback, mc);
+ while (!image_fname) {
+ deadbeef->cond_wait (mc->cond, mc->mutex);
+ image_fname = get_album_art (fname, artist, album, size, sync_callback, mc);
+ }
+ deadbeef->mutex_unlock (mc->mutex);
+ deadbeef->mutex_free (mc->mutex);
+ deadbeef->cond_free (mc->cond);
+ free (mc);
+ return image_fname;
+}
+
DB_plugin_t *
artwork_load (DB_functions_t *api) {
deadbeef = api;
@@ -1231,6 +1264,9 @@ 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);
+ }
queue->next = next;
if (next == NULL) {
queue_tail = queue;
@@ -1402,6 +1438,7 @@ static DB_artwork_plugin_t plugin = {
.plugin.plugin.configdialog = settings_dlg,
.plugin.plugin.message = artwork_message,
.get_album_art = get_album_art,
+ .get_album_art_sync = get_album_art_sync,
.reset = artwork_reset,
.get_default_cover = get_default_cover,
};
diff --git a/plugins/artwork/artwork.h b/plugins/artwork/artwork.h
index 130bf3fe..2225f088 100644
--- a/plugins/artwork/artwork.h
+++ b/plugins/artwork/artwork.h
@@ -11,6 +11,9 @@ typedef struct {
DB_misc_t plugin;
// returns filename of cached image, or NULL
char* (*get_album_art) (const char *fname, const char *artist, const char *album, int size, artwork_callback callback, void *user_data);
+ // syncronizely get filename
+ char* (*get_album_art_sync) (const char *fname, const char *artist, const char *album, int size);
+
// 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);