From f8456e2a1aaa9ae3a146ffb2a4510bff581eb88d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ren=C3=A9=20Stadler?= Date: Mon, 4 Jul 2011 08:58:14 +0300 Subject: [PATCH] pulsesink: small cleanup of copy-paste code --- ext/pulse/pulsesink.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index 2537f75..469d946 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -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; } -- 2.7.4