pulsesink: small cleanup of copy-paste code
authorRené Stadler <rene.stadler@nokia.com>
Mon, 4 Jul 2011 05:58:14 +0000 (08:58 +0300)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Tue, 5 Jul 2011 14:36:17 +0000 (16:36 +0200)
ext/pulse/pulsesink.c

index 2537f75..469d946 100644 (file)
@@ -2560,6 +2560,23 @@ gst_pulsesink_event (GstBaseSink * sink, GstEvent * event)
   return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
 }
 
+static void
+gst_pulsesink_release_mainloop (GstPulseSink * psink)
+{
+  if (!mainloop)
+    return;
+
+  g_mutex_lock (pa_shared_resource_mutex);
+  mainloop_ref_ct--;
+  if (!mainloop_ref_ct) {
+    GST_INFO_OBJECT (psink, "terminating pa main loop thread");
+    pa_threaded_mainloop_stop (mainloop);
+    pa_threaded_mainloop_free (mainloop);
+    mainloop = NULL;
+  }
+  g_mutex_unlock (pa_shared_resource_mutex);
+}
+
 static GstStateChangeReturn
 gst_pulsesink_change_state (GstElement * element, GstStateChange transition)
 {
@@ -2602,17 +2619,7 @@ gst_pulsesink_change_state (GstElement * element, GstStateChange transition)
               GST_BASE_AUDIO_SINK (pulsesink)->provided_clock));
       break;
     case GST_STATE_CHANGE_READY_TO_NULL:
-      if (mainloop) {
-        g_mutex_lock (pa_shared_resource_mutex);
-        mainloop_ref_ct--;
-        if (!mainloop_ref_ct) {
-          GST_INFO_OBJECT (element, "terminating pa main loop thread");
-          pa_threaded_mainloop_stop (mainloop);
-          pa_threaded_mainloop_free (mainloop);
-          mainloop = NULL;
-        }
-        g_mutex_unlock (pa_shared_resource_mutex);
-      }
+      gst_pulsesink_release_mainloop (pulsesink);
       break;
     default:
       break;
@@ -2633,15 +2640,7 @@ state_failure:
     if (transition == GST_STATE_CHANGE_NULL_TO_READY) {
       /* Clear the PA mainloop if baseaudiosink failed to open the ring_buffer */
       g_assert (mainloop);
-      g_mutex_lock (pa_shared_resource_mutex);
-      mainloop_ref_ct--;
-      if (!mainloop_ref_ct) {
-        GST_INFO_OBJECT (element, "terminating pa main loop thread");
-        pa_threaded_mainloop_stop (mainloop);
-        pa_threaded_mainloop_free (mainloop);
-        mainloop = NULL;
-      }
-      g_mutex_unlock (pa_shared_resource_mutex);
+      gst_pulsesink_release_mainloop (pulsesink);
     }
     return ret;
   }