pulse_mixer: moved code to pulse_mixer_setup()

Prepare for adding proper error handling.
This commit is contained in:
Max Kellermann 2009-03-26 19:49:39 +01:00
parent 3be1850744
commit d113c07190

View File

@ -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;
}