From fb9ca25f7f0ee850f73b2c323a2c3a8e7d2d92fc Mon Sep 17 00:00:00 2001 From: Song Bing Date: Sun, 15 Feb 2015 13:51:36 +0800 Subject: [PATCH] streamsynchronizer: Use the same waiting function for EOS and stream switches Also improve the waiting condition for stream switches, which was assuming before that the condition variable will only stop waiting once when it is signaled. But the documentation says that there might be spurious wakeups. https://bugzilla.gnome.org/show_bug.cgi?id=736655 --- gst/playback/gststreamsynchronizer.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/gst/playback/gststreamsynchronizer.c b/gst/playback/gststreamsynchronizer.c index 50fc7b9c6d..f69a7f3359 100644 --- a/gst/playback/gststreamsynchronizer.c +++ b/gst/playback/gststreamsynchronizer.c @@ -215,13 +215,17 @@ gst_stream_synchronizer_wait (GstStreamSynchronizer * self, GstPad * pad) while (!self->eos && !self->flushing) { stream = gst_pad_get_element_private (pad); if (!stream) { - GST_WARNING_OBJECT (pad, "EOS for unknown stream"); + GST_WARNING_OBJECT (pad, "unknown stream"); return ret; } if (stream->flushing) { GST_DEBUG_OBJECT (pad, "Flushing"); break; } + if (!stream->wait) { + GST_DEBUG_OBJECT (pad, "Stream not waiting anymore"); + break; + } if (self->send_gap_event) { GstEvent *event; @@ -383,6 +387,7 @@ gst_stream_synchronizer_sink_event (GstPad * pad, GstObject * parent, for (l = self->streams; l; l = l->next) { GstStream *ostream = l->data; + ostream->wait = FALSE; g_cond_broadcast (&ostream->stream_finish_cond); } } @@ -398,16 +403,8 @@ gst_stream_synchronizer_sink_event (GstPad * pad, GstObject * parent, gst_event_copy_segment (event, &segment); GST_STREAM_SYNCHRONIZER_LOCK (self); - stream = gst_pad_get_element_private (pad); - if (stream) { - if (stream->wait) { - GST_DEBUG_OBJECT (pad, "Stream %d is waiting", stream->stream_number); - g_cond_wait (&stream->stream_finish_cond, &self->lock); - stream = gst_pad_get_element_private (pad); - if (stream) - stream->wait = FALSE; - } - } + + gst_stream_synchronizer_wait (self, pad); if (self->shutdown) { GST_STREAM_SYNCHRONIZER_UNLOCK (self); @@ -415,6 +412,7 @@ gst_stream_synchronizer_sink_event (GstPad * pad, GstObject * parent, goto done; } + stream = gst_pad_get_element_private (pad); if (stream && segment.format == GST_FORMAT_TIME) { if (stream->new_stream) { stream->new_stream = FALSE; @@ -552,6 +550,7 @@ gst_stream_synchronizer_sink_event (GstPad * pad, GstObject * parent, if (seen_data) { self->send_gap_event = TRUE; stream->gap_duration = GST_CLOCK_TIME_NONE; + stream->wait = TRUE; ret = gst_stream_synchronizer_wait (self, srcpad); } }