diff options
author | Tydus <Tydus@Tydus.org> | 2011-11-13 20:41:34 +0800 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-11-13 19:13:30 +0100 |
commit | 9b4c475971c510ae2a153d5df56a31833c2eb341 (patch) | |
tree | 92ef26e7e264237807aa3ff25df0ef82b302deaa /plugins/artwork | |
parent | d565d295038bc65e06d4be871183dae9fcf3f823 (diff) |
Implemented fetching artwork filename synchronizely
Diffstat (limited to 'plugins/artwork')
-rw-r--r-- | plugins/artwork/artwork.c | 37 | ||||
-rw-r--r-- | plugins/artwork/artwork.h | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 19bc0ede..2ad9c0cd 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; @@ -1232,6 +1237,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; @@ -1250,6 +1283,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; @@ -1421,6 +1457,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); |