oggdemux: Solidify gst_ogg_demux_loop_push() some more
authorEdward Hervey <edward@centricular.com>
Wed, 8 Nov 2017 16:15:09 +0000 (17:15 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Wed, 8 Nov 2017 16:51:52 +0000 (17:51 +0100)
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

index fc7f644..21817a8 100644 (file)
@@ -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;
 }