Commit 3405d9d5 authored by David Reid's avatar David Reid

PulseAudio: Fail context init when PA is unusable.

parent 37d6bb6a
......@@ -11337,7 +11337,6 @@ done:
return result;
}
mal_result mal_context_init__pulse(mal_context* pContext)
{
mal_assert(pContext != NULL);
......@@ -11489,6 +11488,33 @@ mal_result mal_context_init__pulse(mal_context* pContext)
pContext->onEnumDevices = mal_context_enumerate_devices__pulse;
pContext->onGetDeviceInfo = mal_context_get_device_info__pulse;
// Although we have found the libpulse library, it doesn't necessarily mean PulseAudio is useable. We need to initialize
// and connect a dummy PulseAudio context to test PulseAudio's usability.
mal_pa_mainloop* pMainLoop = ((mal_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)();
if (pMainLoop == NULL) {
return MAL_NO_BACKEND;
}
mal_pa_mainloop_api* pAPI = ((mal_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)(pMainLoop);
if (pAPI == NULL) {
((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop);
return MAL_NO_BACKEND;
}
mal_pa_context* pPulseContext = ((mal_pa_context_new_proc)pContext->pulse.pa_context_new)(pAPI, pContext->config.pulse.pApplicationName);
if (pPulseContext == NULL) {
((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop);
return MAL_NO_BACKEND;
}
int error = ((mal_pa_context_connect_proc)pContext->pulse.pa_context_connect)(pPulseContext, pContext->config.pulse.pServerName, 0, NULL);
if (error != MAL_PA_OK) {
((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext);
((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop);
return MAL_NO_BACKEND;
}
return MAL_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment