pulse_mixer: moved code to pulse_mixer_setup()
Prepare for adding proper error handling.
This commit is contained in:
		| @@ -191,6 +191,36 @@ pulse_mixer_finish(struct mixer *data) | |||||||
| 	g_free(pm); | 	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 | static bool | ||||||
| pulse_mixer_open(G_GNUC_UNUSED struct mixer *data) | pulse_mixer_open(G_GNUC_UNUSED struct mixer *data) | ||||||
| { | { | ||||||
| @@ -208,29 +238,10 @@ pulse_mixer_open(G_GNUC_UNUSED struct mixer *data) | |||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	pa_context_set_state_callback(pm->context, context_state_cb, pm); | 	if (!pulse_mixer_setup(pm)) { | ||||||
|  |  | ||||||
| 	if (pa_context_connect(pm->context, pm->server, |  | ||||||
| 			       (pa_context_flags_t)0, NULL) < 0) { |  | ||||||
| 		g_debug("context server fail"); |  | ||||||
| 		return false; | 		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; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann