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
This commit is contained in:
Song Bing 2015-02-15 13:51:36 +08:00 committed by Sebastian Dröge
parent eeea911c2e
commit fb9ca25f7f

View file

@ -215,13 +215,17 @@ gst_stream_synchronizer_wait (GstStreamSynchronizer * self, GstPad * pad)
while (!self->eos && !self->flushing) { while (!self->eos && !self->flushing) {
stream = gst_pad_get_element_private (pad); stream = gst_pad_get_element_private (pad);
if (!stream) { if (!stream) {
GST_WARNING_OBJECT (pad, "EOS for unknown stream"); GST_WARNING_OBJECT (pad, "unknown stream");
return ret; return ret;
} }
if (stream->flushing) { if (stream->flushing) {
GST_DEBUG_OBJECT (pad, "Flushing"); GST_DEBUG_OBJECT (pad, "Flushing");
break; break;
} }
if (!stream->wait) {
GST_DEBUG_OBJECT (pad, "Stream not waiting anymore");
break;
}
if (self->send_gap_event) { if (self->send_gap_event) {
GstEvent *event; GstEvent *event;
@ -383,6 +387,7 @@ gst_stream_synchronizer_sink_event (GstPad * pad, GstObject * parent,
for (l = self->streams; l; l = l->next) { for (l = self->streams; l; l = l->next) {
GstStream *ostream = l->data; GstStream *ostream = l->data;
ostream->wait = FALSE;
g_cond_broadcast (&ostream->stream_finish_cond); 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_event_copy_segment (event, &segment);
GST_STREAM_SYNCHRONIZER_LOCK (self); GST_STREAM_SYNCHRONIZER_LOCK (self);
stream = gst_pad_get_element_private (pad);
if (stream) { gst_stream_synchronizer_wait (self, pad);
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;
}
}
if (self->shutdown) { if (self->shutdown) {
GST_STREAM_SYNCHRONIZER_UNLOCK (self); GST_STREAM_SYNCHRONIZER_UNLOCK (self);
@ -415,6 +412,7 @@ gst_stream_synchronizer_sink_event (GstPad * pad, GstObject * parent,
goto done; goto done;
} }
stream = gst_pad_get_element_private (pad);
if (stream && segment.format == GST_FORMAT_TIME) { if (stream && segment.format == GST_FORMAT_TIME) {
if (stream->new_stream) { if (stream->new_stream) {
stream->new_stream = FALSE; stream->new_stream = FALSE;
@ -552,6 +550,7 @@ gst_stream_synchronizer_sink_event (GstPad * pad, GstObject * parent,
if (seen_data) { if (seen_data) {
self->send_gap_event = TRUE; self->send_gap_event = TRUE;
stream->gap_duration = GST_CLOCK_TIME_NONE; stream->gap_duration = GST_CLOCK_TIME_NONE;
stream->wait = TRUE;
ret = gst_stream_synchronizer_wait (self, srcpad); ret = gst_stream_synchronizer_wait (self, srcpad);
} }
} }