oggdemux: Move mutex/cond initialization/release
authorEdward Hervey <edward@centricular.com>
Wed, 15 Nov 2017 07:27:01 +0000 (08:27 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Wed, 15 Nov 2017 09:55:55 +0000 (10:55 +0100)
We only need to initialize the mutex/cond once when creating the
element and then release them when we are done with the element.

Avoids weird "mutex_clear called when still locked" issues

ext/ogg/gstoggdemux.c

index 21817a8..fcb0337 100644 (file)
@@ -2313,6 +2313,10 @@ gst_ogg_demux_init (GstOggDemux * ogg)
 
   g_mutex_init (&ogg->chain_lock);
   g_mutex_init (&ogg->push_lock);
+  g_mutex_init (&ogg->seek_event_mutex);
+  g_cond_init (&ogg->seek_event_cond);
+  g_cond_init (&ogg->thread_started_cond);
+
   ogg->chains = g_array_new (FALSE, TRUE, sizeof (GstOggChain *));
 
   ogg->stats_nbisections = 0;
@@ -2337,6 +2341,10 @@ gst_ogg_demux_finalize (GObject * object)
   g_array_free (ogg->chains, TRUE);
   g_mutex_clear (&ogg->chain_lock);
   g_mutex_clear (&ogg->push_lock);
+  g_cond_clear (&ogg->seek_event_cond);
+  g_cond_clear (&ogg->thread_started_cond);
+  g_mutex_clear (&ogg->seek_event_mutex);
+
   ogg_sync_clear (&ogg->sync);
 
   if (ogg->newsegment)
@@ -5084,9 +5092,6 @@ gst_ogg_demux_sink_activate_mode (GstPad * sinkpad, GstObject * parent,
       ogg->resync = FALSE;
       if (active) {
         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));
@@ -5104,9 +5109,6 @@ gst_ogg_demux_sink_activate_mode (GstPad * sinkpad, GstObject * parent,
         g_cond_broadcast (&ogg->seek_event_cond);
         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;
       }
       res = TRUE;