diff options
author | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2018-05-14 14:57:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@automotivelinux.org> | 2018-05-14 14:57:27 +0000 |
commit | 5c5ca783ee759af83a80f91e265da69205cbcfbf (patch) | |
tree | 2f0e618e5719a2f8424015c36654e00192dfd78b | |
parent | 10603589e76fa39147544aa9eb90cab424df1ea9 (diff) | |
parent | b596f34b0a0be06becea4f9b0a0917f12f2e16f8 (diff) |
-rw-r--r-- | binding/afm-mediaplayer-binding.c | 68 |
1 files changed, 49 insertions, 19 deletions
diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c index 600f6de..116f0d1 100644 --- a/binding/afm-mediaplayer-binding.c +++ b/binding/afm-mediaplayer-binding.c @@ -37,6 +37,7 @@ static struct afb_event metadata_event; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static GList *playlist = NULL; +static GList *metadata_track = NULL; static GList *current_track = NULL; typedef struct _CustomData { @@ -502,20 +503,34 @@ static gchar *get_album_art(GstTagList *tags) return NULL; } -static void metadata(struct afb_req request) +static json_object *populate_json_metadata_image(json_object *jresp) { - struct playlist_item *track; GstTagList *tags = NULL; - json_object *jresp; - pthread_mutex_lock(&mutex); + g_signal_emit_by_name(G_OBJECT(data.playbin), "get-audio-tags", 0, &tags); - if (current_track == NULL || current_track->data == NULL) { - afb_req_fail(request, "failed", "No playlist"); - pthread_mutex_unlock(&mutex); - return; + if (tags) { + gchar *image = get_album_art(tags); + + json_object_object_add(jresp, "image", + json_object_new_string(image ? image : "data:null")); + + g_free(image); + + gst_tag_list_free(tags); } + return jresp; +} + +static json_object *populate_json_metadata(void) +{ + struct playlist_item *track; + json_object *jresp; + + if (current_track == NULL || current_track->data == NULL) + return NULL; + track = current_track->data; jresp = populate_json(track); @@ -530,22 +545,23 @@ static void metadata(struct afb_req request) json_object_object_add(jresp, "volume", json_object_new_int(data.volume)); - g_signal_emit_by_name(G_OBJECT(data.playbin), "get-audio-tags", 0, &tags); + jresp = populate_json_metadata_image(jresp); - if (tags) { - gchar *image = get_album_art(tags); + return jresp; +} - if (image) { - json_object_object_add(jresp, "image", - json_object_new_string(image)); - g_free(image); - } - gst_tag_list_free(tags); - } +static void metadata(struct afb_req request) +{ + json_object *jresp; + pthread_mutex_lock(&mutex); + jresp = populate_json_metadata(); pthread_mutex_unlock(&mutex); - afb_req_success(request, jresp, "Metadata results"); + if (jresp == NULL) + afb_req_fail(request, "failed", "No metadata"); + else + afb_req_success(request, jresp, "Metadata results"); } static void subscribe(struct afb_req request) @@ -553,8 +569,17 @@ static void subscribe(struct afb_req request) const char *value = afb_req_value(request, "value"); if (!strcasecmp(value, "metadata")) { + json_object *jresp = NULL; + afb_req_subscribe(request, metadata_event); afb_req_success(request, NULL, NULL); + + pthread_mutex_lock(&mutex); + jresp = populate_json_metadata(); + pthread_mutex_unlock(&mutex); + + afb_event_push(metadata_event, jresp); + return; } else if (!strcasecmp(value, "playlist")) { json_object *jresp = json_object_new_object(); @@ -673,6 +698,11 @@ static gboolean position_event(CustomData *data) json_object_object_add(jresp, "status", json_object_new_string("playing")); + if (metadata_track != current_track) { + jresp = populate_json_metadata_image(jresp); + metadata_track = current_track; + } + pthread_mutex_unlock(&mutex); afb_event_push(metadata_event, jresp); |