diff --git a/src/mixer/pulse_mixer.c b/src/mixer/pulse_mixer.c index a300a29fa..5d458b18f 100644 --- a/src/mixer/pulse_mixer.c +++ b/src/mixer/pulse_mixer.c @@ -191,6 +191,36 @@ pulse_mixer_finish(struct mixer *data) g_free(pm); } +static bool +pulse_mixer_setup(struct pulse_mixer *pm) +{ + pa_context_set_state_callback(pm->context, context_state_cb, pm); + + if (pa_context_connect(pm->context, pm->server, + (pa_context_flags_t)0, NULL) < 0) { + g_debug("context server fail"); + return false; + } + + pa_threaded_mainloop_lock(pm->mainloop); + + if (pa_threaded_mainloop_start(pm->mainloop) < 0) { + g_debug("error start mainloop"); + return false; + } + + pa_threaded_mainloop_wait(pm->mainloop); + + if (pa_context_get_state(pm->context) != PA_CONTEXT_READY) { + g_debug("error context not ready"); + return false; + } + + pa_threaded_mainloop_unlock(pm->mainloop); + + return true; +} + static bool pulse_mixer_open(G_GNUC_UNUSED struct mixer *data) { @@ -208,29 +238,10 @@ pulse_mixer_open(G_GNUC_UNUSED struct mixer *data) return false; } - pa_context_set_state_callback(pm->context, context_state_cb, pm); - - if (pa_context_connect(pm->context, pm->server, - (pa_context_flags_t)0, NULL) < 0) { - g_debug("context server fail"); + if (!pulse_mixer_setup(pm)) { return false; } - pa_threaded_mainloop_lock(pm->mainloop); - if (pa_threaded_mainloop_start(pm->mainloop) < 0) { - g_debug("error start mainloop"); - return false; - } - - pa_threaded_mainloop_wait(pm->mainloop); - - if (pa_context_get_state(pm->context) != PA_CONTEXT_READY) { - g_debug("error context not ready"); - return false; - } - - pa_threaded_mainloop_unlock(pm->mainloop); - return true; }