mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 16:54:03 +02:00
PulseAudio: Fail context init when PA is unusable.
This commit is contained in:
@@ -11337,7 +11337,6 @@ done:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mal_result mal_context_init__pulse(mal_context* pContext)
|
mal_result mal_context_init__pulse(mal_context* pContext)
|
||||||
{
|
{
|
||||||
mal_assert(pContext != NULL);
|
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->onEnumDevices = mal_context_enumerate_devices__pulse;
|
||||||
pContext->onGetDeviceInfo = mal_context_get_device_info__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;
|
return MAL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user