aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-10-19 10:48:47 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-10-19 20:36:09 -0700
commited2d5d3363d3ee1b689871ab09cc5a68785419b9 (patch)
tree2204047a5f8dad67078c37c65483f62f062a2c60
parentac277ae6c0c278fbbe11b176e3324bd4d7337332 (diff)
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 <matt.ranostay@konsulko.com>
-rw-r--r--binding/afm-mediaplayer-binding.c62
-rw-r--r--conf.d/cmake/config.cmake2
2 files changed, 64 insertions, 0 deletions
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 <stdlib.h>
#include <unistd.h>
#include <glib.h>
+#include <gio/gio.h>
#include <pthread.h>
#include <gst/gst.h>
+#include <gst/tag/tag.h>
#include <json-c/json.h>
#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");
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
index dba407a..e7e6143 100644
--- a/conf.d/cmake/config.cmake
+++ b/conf.d/cmake/config.cmake
@@ -66,7 +66,9 @@ set (gcc_minimal_version 4.9)
set (PKG_REQUIRED_LIST
json-c
gstreamer-1.0
+ gstreamer-tag-1.0
glib-2.0
+ gio-2.0
gobject-2.0
libsystemd>=222
afb-daemon