From ed2d5d3363d3ee1b689871ab09cc5a68785419b9 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 19 Oct 2017 10:48:47 -0700 Subject: binding: mediaplayer: add base64 album art reporting Report the album art if any via the metadata verb in base64 data URI format. Bug-AGL: SPEC-931 Change-Id: Ifa9f5d799161a2b6a5a163e35b53a182f29fbd4b Signed-off-by: Matt Ranostay --- binding/afm-mediaplayer-binding.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'binding') diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c index 10580e3..b0876fa 100644 --- a/binding/afm-mediaplayer-binding.c +++ b/binding/afm-mediaplayer-binding.c @@ -22,8 +22,10 @@ #include #include #include +#include #include #include +#include #include #include "afm-common.h" @@ -382,9 +384,56 @@ static void controls(struct afb_req request) pthread_mutex_unlock(&mutex); } +static gchar *get_album_art(GstTagList *tags) +{ + GstSample *sample = NULL; + guint i; + + for (i = 0; ; i++) { + const GValue *value; + GstStructure *caps; + int type; + + value = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, i); + if (value == NULL) + break; + + sample = gst_value_get_sample(value); + caps = gst_caps_get_structure(gst_sample_get_caps(sample), 0); + gst_structure_get_enum(caps, "image-type", + GST_TYPE_TAG_IMAGE_TYPE, &type); + + if (type == GST_TAG_IMAGE_TYPE_FRONT_COVER) + break; + } + + if (sample) { + GstBuffer *buffer = gst_sample_get_buffer(sample); + GstMapInfo map; + gchar *data, *mime_type, *image; + + if (!gst_buffer_map (buffer, &map, GST_MAP_READ)) + return NULL; + + image = g_base64_encode(map.data, map.size); + mime_type = g_content_type_guess(NULL, map.data, map.size, NULL); + + data = g_strconcat("data:", mime_type, ";base64,", image, NULL); + + g_free(image); + g_free(mime_type); + gst_buffer_unmap(buffer, &map); + + return data; + } + + return NULL; +} + static void metadata(struct afb_req request) { struct playlist_item *track; + GstTagList *tags = NULL; json_object *jresp; pthread_mutex_lock(&mutex); @@ -409,6 +458,19 @@ 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); + + if (tags) { + gchar *image = get_album_art(tags); + + if (image) { + json_object_object_add(jresp, "image", + json_object_new_string(image)); + g_free(image); + } + gst_tag_list_free(tags); + } + pthread_mutex_unlock(&mutex); afb_req_success(request, jresp, "Metadata results"); -- cgit 1.2.3-korg