From 0a49b93ade8e2a634f5c40e0dddf60cdce098a7c Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 7 Nov 2017 15:05:19 +0100 Subject: [PATCH] oggdemux: Wait for push loop to be started Code using the push_loop_thread (using for sending seeks) assumes that the thread was properly started, except that this isn't always true and the thread might not have completely started. Instead wait for the thread to properly start before doing anything else. --- ext/ogg/gstoggdemux.c | 15 +++++++++++++++ ext/ogg/gstoggdemux.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/ext/ogg/gstoggdemux.c b/ext/ogg/gstoggdemux.c index 781ab0c..c931589 100644 --- a/ext/ogg/gstoggdemux.c +++ b/ext/ogg/gstoggdemux.c @@ -4947,6 +4947,10 @@ gst_ogg_demux_loop_push (GstOggDemux * ogg) 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); + if (ogg->seek_event_thread_stop) { g_mutex_unlock (&ogg->seek_event_mutex); break; @@ -5070,8 +5074,18 @@ gst_ogg_demux_sink_activate_mode (GstPad * sinkpad, GstObject * parent, ogg->seek_event_thread_stop = FALSE; g_mutex_init (&ogg->seek_event_mutex); g_cond_init (&ogg->seek_event_cond); + g_cond_init (&ogg->thread_started_cond); + ogg->seek_thread_started = FALSE; ogg->seek_event_thread = g_thread_new ("seek_event_thread", (GThreadFunc) gst_ogg_demux_loop_push, gst_object_ref (ogg)); + /* And wait for the thread to start. + * FIXME : This is hackish. And one wonders why we need a separate thread to + * seek to a certain offset */ + g_mutex_lock (&ogg->seek_event_mutex); + while (!ogg->seek_thread_started) { + g_cond_wait (&ogg->thread_started_cond, &ogg->seek_event_mutex); + } + g_mutex_unlock (&ogg->seek_event_mutex); } else { g_mutex_lock (&ogg->seek_event_mutex); ogg->seek_event_thread_stop = TRUE; @@ -5079,6 +5093,7 @@ gst_ogg_demux_sink_activate_mode (GstPad * sinkpad, GstObject * parent, g_mutex_unlock (&ogg->seek_event_mutex); g_thread_join (ogg->seek_event_thread); g_cond_clear (&ogg->seek_event_cond); + g_cond_clear (&ogg->thread_started_cond); g_mutex_clear (&ogg->seek_event_mutex); ogg->seek_event_thread = NULL; } diff --git a/ext/ogg/gstoggdemux.h b/ext/ogg/gstoggdemux.h index db1f393..016c14a 100644 --- a/ext/ogg/gstoggdemux.h +++ b/ext/ogg/gstoggdemux.h @@ -209,6 +209,8 @@ struct _GstOggDemux GMutex seek_event_mutex; GCond seek_event_cond; gboolean seek_event_thread_stop; + gboolean seek_thread_started; + GCond thread_started_cond; guint32 seek_event_drop_till; }; -- 2.7.4