From 895d8847015cfcb2a4924c7ea5e785d8de377705 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Wed, 8 Nov 2017 17:15:09 +0100 Subject: [PATCH] oggdemux: Solidify gst_ogg_demux_loop_push() some more There were still some races going on where seeking events wouldn't be properly intercepted/executed by this thread. * Instead of always waiting for the GCond to be emitted, first just check if there is an event available * Take ownership of the event *while* the lock is taken and not after releasing/reacquiring it * Finally acquire lock at the very top and release it at the end to make it a bit more streamlined This removes the remaining issues with seeks not being executed --- ext/ogg/gstoggdemux.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/ext/ogg/gstoggdemux.c b/ext/ogg/gstoggdemux.c index fc7f644..21817a8 100644 --- a/ext/ogg/gstoggdemux.c +++ b/ext/ogg/gstoggdemux.c @@ -4949,35 +4949,36 @@ pause: static gpointer gst_ogg_demux_loop_push (GstOggDemux * ogg) { - GstEvent *event; + GstEvent *event = NULL; - while (1) { - g_mutex_lock (&ogg->seek_event_mutex); - /* Inform other threads that we started */ - ogg->seek_thread_started = TRUE; - g_cond_broadcast (&ogg->thread_started_cond); + g_mutex_lock (&ogg->seek_event_mutex); + /* Inform other threads that we started */ + ogg->seek_thread_started = TRUE; + g_cond_broadcast (&ogg->thread_started_cond); - if (ogg->seek_event_thread_stop) { - g_mutex_unlock (&ogg->seek_event_mutex); - break; + + while (!ogg->seek_event_thread_stop) { + + while (!ogg->seek_event_thread_stop) { + GST_PUSH_LOCK (ogg); + event = ogg->seek_event; + ogg->seek_event = NULL; + if (event) + ogg->seek_event_drop_till = gst_event_get_seqnum (event); + GST_PUSH_UNLOCK (ogg); + + if (event) + break; + + g_cond_wait (&ogg->seek_event_cond, &ogg->seek_event_mutex); } - g_cond_wait (&ogg->seek_event_cond, &ogg->seek_event_mutex); + if (ogg->seek_event_thread_stop) { - g_mutex_unlock (&ogg->seek_event_mutex); break; } - g_mutex_unlock (&ogg->seek_event_mutex); - - GST_PUSH_LOCK (ogg); - event = ogg->seek_event; - ogg->seek_event = NULL; - if (event) { - ogg->seek_event_drop_till = gst_event_get_seqnum (event); - } - GST_PUSH_UNLOCK (ogg); + g_assert (event); - if (!event) - continue; + g_mutex_unlock (&ogg->seek_event_mutex); GST_DEBUG_OBJECT (ogg->sinkpad, "Pushing event %" GST_PTR_FORMAT, event); if (!gst_pad_push_event (ogg->sinkpad, event)) { @@ -4991,7 +4992,12 @@ gst_ogg_demux_loop_push (GstOggDemux * ogg) } else { GST_DEBUG_OBJECT (ogg->sinkpad, "Pushed event ok"); } + + g_mutex_lock (&ogg->seek_event_mutex); } + + g_mutex_unlock (&ogg->seek_event_mutex); + gst_object_unref (ogg); return NULL; } -- 2.7.4