From 946cbbccc15f707857a550065fa7ba0028e4d627 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Wed, 12 Sep 2018 05:29:09 -0500 Subject: decklink: wait for stop with a timeout Decklink sometimes does not notify us through the callback that it has stopped scheduled playback either because it was uncleanly shutdown without an explicit stop or for unknown other reasons. Wait on the cond for a short amount of time before checking if scheduled playback has stopped without notification. https://bugzilla.gnome.org/show_bug.cgi?id=797130 --- sys/decklink/gstdecklinkvideosink.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sys/decklink/gstdecklinkvideosink.cpp b/sys/decklink/gstdecklinkvideosink.cpp index 7f362f508..8a9f4bcf0 100644 --- a/sys/decklink/gstdecklinkvideosink.cpp +++ b/sys/decklink/gstdecklinkvideosink.cpp @@ -852,6 +852,21 @@ gst_decklink_video_sink_stop (GstDecklinkVideoSink * self) return TRUE; } +static void +_wait_for_stop_notify (GstDecklinkVideoSink *self) +{ + bool active = false; + + self->output->output->IsScheduledPlaybackRunning (&active); + while (active) { + /* cause sometimes decklink stops without notifying us... */ + guint64 wait_time = g_get_monotonic_time () + G_TIME_SPAN_SECOND; + if (!g_cond_wait_until (&self->output->cond, &self->output->lock, wait_time)) + GST_WARNING_OBJECT (self, "Failed to wait for stop notification"); + self->output->output->IsScheduledPlaybackRunning (&active); + } +} + static void gst_decklink_video_sink_start_scheduled_playback (GstElement * element) { @@ -923,10 +938,7 @@ gst_decklink_video_sink_start_scheduled_playback (GstElement * element) return; } // Wait until scheduled playback actually stopped - do { - g_cond_wait (&self->output->cond, &self->output->lock); - self->output->output->IsScheduledPlaybackRunning (&active); - } while (active); + _wait_for_stop_notify (self); } GST_DEBUG_OBJECT (self, @@ -986,13 +998,9 @@ gst_decklink_video_sink_stop_scheduled_playback (GstDecklinkVideoSink * self) res)); ret = GST_STATE_CHANGE_FAILURE; } else { - bool active = false; // Wait until scheduled playback actually stopped - do { - g_cond_wait (&self->output->cond, &self->output->lock); - self->output->output->IsScheduledPlaybackRunning (&active); - } while (active); + _wait_for_stop_notify (self); } if (start_time > 0) self->scheduled_stop_time = start_time; -- cgit v1.2.3