From e1ecc15a7649b0e8cdccbc288a7491ad0f12f23f Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 12 Dec 2019 11:04:40 -0800 Subject: mediaplayer: check for corking from PipeWire Check if PipeWire is corking the audio stream and if so don't process signal-composer events till uncorked. Bug-AGL: SPEC-3023 Change-Id: Ib4d4de1f1627426d69e3f19501d38ff2d3c88a62 Signed-off-by: Matt Ranostay --- binding/afm-mediaplayer-binding.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'binding') diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c index b2e73d9..6b487d1 100644 --- a/binding/afm-mediaplayer-binding.c +++ b/binding/afm-mediaplayer-binding.c @@ -66,6 +66,7 @@ typedef struct _CustomData { GstElement *playbin, *fake_sink, *audio_sink; gboolean playing; int loop_state; + gboolean corked; gboolean one_time; long int volume; gint64 position; @@ -78,6 +79,7 @@ typedef struct _CustomData { CustomData data = { .volume = 50, + .corked = FALSE, .position = GST_CLOCK_TIME_NONE, .duration = GST_CLOCK_TIME_NONE, }; @@ -805,6 +807,23 @@ static gboolean handle_message(GstBus *bus, GstMessage *msg, CustomData *data) break; } + case GST_MESSAGE_REQUEST_STATE: { + GstState state; + + gst_message_parse_request_state(msg, &state); + + g_mutex_lock(&mutex); + + if (state == GST_STATE_PAUSED) { + data->corked = TRUE; + } else if (state == GST_STATE_PLAYING) { + data->corked = FALSE; + } + + g_mutex_unlock(&mutex); + + break; + } default: break; } @@ -1001,6 +1020,7 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object json_object *tmp = NULL; const char *uid; const char *value; + int corked; json_object_object_get_ex(object, "uid", &tmp); if (tmp == NULL) @@ -1010,6 +1030,14 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object if (strncmp(uid, "event.media.", 12)) return; + g_mutex_lock(&mutex); + corked = data.corked; + g_mutex_unlock(&mutex); + + // drop events if we are in corked state + if (corked) + return; + json_object_object_get_ex(object, "value", &tmp); if (tmp == NULL) return; -- cgit 1.2.3-korg