diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-09-04 20:56:57 -0700 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-09-06 20:23:24 -0700 |
commit | 42872410a9f13c5bae877a7290caf4a5ff5f34a5 (patch) | |
tree | a0e9e99127ac6b863a07032bbaf167df706ea994 /binding/afm-mediaplayer-binding.c | |
parent | 7c71ec7991097b8b88d9b7280324293beda13194 (diff) |
binding: mediaplayer: process audio tags in message handler
To reduce blocking api calls, and to avoid race conditions
interactions beween UI and binding on startup, change to
parsing album art from GST_MESSAGE_TAG event.
Bug-AGL: SPEC-2774
Change-Id: I67463824a6966f175bf2c3c423d75d0edd183c4d
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding/afm-mediaplayer-binding.c')
-rw-r--r-- | binding/afm-mediaplayer-binding.c | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c index c7cebdf..a7510f1 100644 --- a/binding/afm-mediaplayer-binding.c +++ b/binding/afm-mediaplayer-binding.c @@ -630,26 +630,6 @@ static gchar *get_album_art(GstTagList *tags) return NULL; } -static json_object *populate_json_metadata_image(json_object *jresp) -{ - GstTagList *tags = NULL; - - g_signal_emit_by_name(G_OBJECT(data.playbin), "get-audio-tags", 0, &tags); - - 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; @@ -673,9 +653,6 @@ static json_object *populate_json_metadata(void) json_object_object_add(jresp, "volume", json_object_new_int64(data.volume)); - metadata = populate_json_metadata_image(metadata); - json_object_object_add(jresp, "track", metadata); - return jresp; } @@ -789,6 +766,36 @@ static gboolean handle_message(GstBus *bus, GstMessage *msg, CustomData *data) case GST_MESSAGE_DURATION: data->duration = GST_CLOCK_TIME_NONE; break; + case GST_MESSAGE_TAG: { + GstTagList *tags = NULL; + gchar *image = NULL; + json_object *jresp, *jobj; + + // TODO: This will get triggered multipl times due to gstreamer + // pipeline, and should be fixed in the future to stop spurious + // events + gst_message_parse_tag(msg, &tags); + + if (!tags) + break; + + image = get_album_art(tags); + + jobj = json_object_new_object(); + json_object_object_add(jobj, "image", + json_object_new_string(image ? image : "")); + + g_free(image); + + jresp = json_object_new_object(); + json_object_object_add(jresp, "track", jobj); + + afb_event_push(metadata_event, jresp); + + gst_tag_list_unref(tags); + + break; + } default: break; } @@ -838,10 +845,8 @@ static gboolean position_event(CustomData *data) json_object_object_add(jresp, "status", json_object_new_string("playing")); - if (metadata_track != current_track) { - metadata = populate_json_metadata_image(metadata); + if (metadata_track != current_track) metadata_track = current_track; - } json_object_object_add(jresp, "track", metadata); |