oggdemux: Wait for push loop to be started
authorEdward Hervey <edward@centricular.com>
Tue, 7 Nov 2017 14:05:19 +0000 (15:05 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Tue, 7 Nov 2017 14:16:52 +0000 (15:16 +0100)
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
ext/ogg/gstoggdemux.h

index 781ab0c..c931589 100644 (file)
@@ -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;
       }
index db1f393..016c14a 100644 (file)
@@ -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;
 };