diff options
author | Scott Murray <scott.murray@konsulko.com> | 2019-12-19 09:37:28 -0500 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2019-12-19 10:07:40 -0500 |
commit | c7d5a53e76514e90a9a555ac72b9e61c0f2171e6 (patch) | |
tree | aa6870e3425e43c0d3daffa56a68b7fd8a456410 /binding | |
parent | 174b63ed864873c197c30831ee029d211c490034 (diff) |
Fixes for corking and restart behaviorhalibut_8.0.6halibut_8.0.5halibut_8.0.4halibut/8.0.6halibut/8.0.5halibut/8.0.48.0.68.0.58.0.4halibut
Fixes:
- Track playing state in binding code to properly ignore signal-composer
events when not playing.
- Add changing of pipeline state in response to the GstBus
GST_MESSAGE_REQUEST_STATE message to the KF code, this is required to
have the second request to switch back to PLAYING state be sent, and
hence properly keeping track of corked state. Also added required
gstreamer main loop so GstBus actually works.
- The alsasrc used in the KF code's gstreamer pipeline seems to not
handle the switch to READY state on pause (currently required to
trigger Wireplumber policy) as expected; it seems to keep feeding the
pipeline, causing long stalls on restart. For now, taking the stream
fully down to NULL state seems to work around this issue.
Bug-AGL: SPEC-3061, SPEC-3046
Change-Id: I7d4493e3475a67a5e18065982673b5cd145c4773
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r-- | binding/radio-binding.c | 10 | ||||
-rw-r--r-- | binding/radio_impl_kingfisher.c | 34 |
2 files changed, 38 insertions, 6 deletions
diff --git a/binding/radio-binding.c b/binding/radio-binding.c index 0de45a6..61798eb 100644 --- a/binding/radio-binding.c +++ b/binding/radio-binding.c @@ -36,6 +36,8 @@ static afb_event_t freq_event; static afb_event_t scan_event; static afb_event_t status_event; +static bool playing; + static const char *signalcomposer_events[] = { "event.media.next", "event.media.previous", @@ -316,6 +318,7 @@ static void start(afb_req_t request) { radio_impl_ops->set_output(NULL); radio_impl_ops->start(); + playing = true; afb_req_success(request, NULL, NULL); json_object *jresp = json_object_new_object(); @@ -333,6 +336,7 @@ static void start(afb_req_t request) static void stop(afb_req_t request) { radio_impl_ops->stop(); + playing = false; afb_req_success(request, NULL, NULL); json_object *jresp = json_object_new_object(); @@ -522,9 +526,11 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object if (strncmp(uid, "event.media.", 12)) return; - if (radio_impl_ops->get_corking_state && - radio_impl_ops->get_corking_state()) + if (!playing || + (radio_impl_ops->get_corking_state && + radio_impl_ops->get_corking_state())) { return; + } json_object_object_get_ex(object, "value", &tmp); if (tmp == NULL) diff --git a/binding/radio_impl_kingfisher.c b/binding/radio_impl_kingfisher.c index 937fa98..eb4d0a0 100644 --- a/binding/radio_impl_kingfisher.c +++ b/binding/radio_impl_kingfisher.c @@ -79,19 +79,31 @@ static gboolean handle_message(GstBus *bus, GstMessage *msg, __attribute__((unus GstState state; if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_REQUEST_STATE) { - gst_message_parse_request_state(msg, &state); - if (state == GST_STATE_PAUSED) + if (state == GST_STATE_PAUSED) { corking = true; - else if (state == GST_STATE_PLAYING) + + // NOTE: Explicitly using PAUSED here, this case currently + // is separate from the general PAUSED/READY issue wrt + // Wireplumber policy. + gst_element_set_state(pipeline, GST_STATE_PAUSED); + } else if (state == GST_STATE_PLAYING) { corking = false; + gst_element_set_state(pipeline, GST_STATE_PLAYING); + } } return TRUE; } +static void *gstreamer_loop_thread(void *ptr) +{ + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + return NULL; +} + static int kf_init(void) { GKeyFile* conf_file; @@ -101,6 +113,7 @@ static int kf_init(void) char cmd[SI_CTL_CMDLINE_MAXLEN]; int rc; char gst_pipeline_str[GST_PIPELINE_LEN]; + pthread_t thread_id; if(present) return 0; @@ -212,6 +225,10 @@ static int kf_init(void) gst_bus_add_watch(gst_element_get_bus(pipeline), (GstBusFunc) handle_message, NULL); + rc = pthread_create(&thread_id, NULL, gstreamer_loop_thread, NULL); + if(rc != 0) + return rc; + present = true; return 0; } @@ -364,19 +381,28 @@ static void kf_stop(void) if(present && running) { // Stop pipeline running = false; + #ifdef WIREPLUMBER_WORKAROUND - gst_element_set_state(pipeline, GST_STATE_READY); + // NOTE: Using NULL here instead of READY, as it seems to trigger + // some odd behavior in the pipeline; alsasrc does not seem to + // stop, and things get hung up on restart as there are a bunch + // of "old" samples that seemingly confuse pwaudiosink. Going + // to NULL state seems to tear down things enough to avoid + // whatever happens. + gst_element_set_state(pipeline, GST_STATE_NULL); #else gst_element_set_state(pipeline, GST_STATE_PAUSED); #endif corking = false; +#ifndef WIREPLUMBER_WORKAROUND // Flush pipeline // This seems required to avoid stutters on starts after a stop event = gst_event_new_flush_start(); gst_element_send_event(GST_ELEMENT(pipeline), event); event = gst_event_new_flush_stop(TRUE); gst_element_send_event(GST_ELEMENT(pipeline), event); +#endif } } |