summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
Diffstat (limited to 'binding')
-rw-r--r--binding/afm-mediaplayer-binding.c99
1 files changed, 52 insertions, 47 deletions
diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c
index 15e29a2..a7510f1 100644
--- a/binding/afm-mediaplayer-binding.c
+++ b/binding/afm-mediaplayer-binding.c
@@ -34,7 +34,7 @@
static afb_event_t playlist_event;
static afb_event_t metadata_event;
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+static GMutex mutex;
static GList *playlist = NULL;
static GList *metadata_track = NULL;
@@ -291,7 +291,7 @@ static void audio_playlist(afb_req_t request)
const char *value = afb_req_value(request, "list");
json_object *jresp = NULL;
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
if (value) {
json_object *jquery;
@@ -317,7 +317,7 @@ static void audio_playlist(afb_req_t request)
afb_req_success(request, jresp, "Playlist results");
}
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
}
static int seek_stream(const char *value, int cmd)
@@ -561,15 +561,15 @@ static void controls(afb_req_t request)
return;
}
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
if (data.avrcp_connected || !g_strcmp0(value, "connect")) {
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
avrcp_controls(request);
return;
}
gstreamer_controls(request);
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
}
static GstSample *parse_album(GstTagList *tags, gchar *tag_type)
@@ -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;
}
@@ -709,9 +686,9 @@ static void subscribe(afb_req_t request)
afb_req_subscribe(request, metadata_event);
afb_req_success(request, NULL, NULL);
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
jresp = populate_json_metadata();
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
afb_event_push(metadata_event, jresp);
@@ -724,9 +701,9 @@ static void subscribe(afb_req_t request)
afb_req_subscribe(request, playlist_event);
afb_req_success(request, NULL, NULL);
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
jresp = populate_json_playlist(jresp);
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
afb_event_push(playlist_event, jresp);
@@ -759,7 +736,7 @@ static gboolean handle_message(GstBus *bus, GstMessage *msg, CustomData *data)
case GST_MESSAGE_EOS: {
int ret;
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
data->position = GST_CLOCK_TIME_NONE;
data->duration = GST_CLOCK_TIME_NONE;
@@ -783,12 +760,42 @@ static gboolean handle_message(GstBus *bus, GstMessage *msg, CustomData *data)
set_media_uri(current_track->data, loop_playlist);
}
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
break;
}
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;
}
@@ -801,7 +808,7 @@ static gboolean position_event(CustomData *data)
struct playlist_item *track;
json_object *jresp = NULL, *metadata;
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
if (data->one_time) {
data->one_time = FALSE;
@@ -809,14 +816,14 @@ static gboolean position_event(CustomData *data)
json_object *jresp = json_object_new_object();
json_object_object_add(jresp, "status",
json_object_new_string("stopped"));
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
afb_event_push(metadata_event, jresp);
return TRUE;
}
if (!data->playing || current_track == NULL) {
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
return TRUE;
}
@@ -838,14 +845,12 @@ 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);
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
afb_event_push(metadata_event, jresp);
@@ -914,7 +919,7 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object
json_object *val = NULL;
gboolean ret;
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
ret = json_object_object_get_ex(object, "Media", &val);
if (ret)
@@ -932,7 +937,7 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object
path = json_object_get_string(val);
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
while (l) {
struct playlist_item *item = l->data;
@@ -957,7 +962,7 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object
} else if (!g_ascii_strcasecmp(event, "Bluetooth-Manager/media")) {
json_object *val;
- pthread_mutex_lock(&mutex);
+ g_mutex_lock(&mutex);
if (json_object_object_get_ex(object, "connected", &val)) {
gboolean state = json_object_get_boolean(val);
@@ -977,7 +982,7 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object
}
}
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
json_object_get(object);
afb_event_push(metadata_event, object);
@@ -991,7 +996,7 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object
jresp = json_object_new_object();
jresp = populate_json_playlist(jresp);
- pthread_mutex_unlock(&mutex);
+ g_mutex_unlock(&mutex);
afb_event_push(playlist_event, jresp);
}