Commit f9557f13 authored by David Reid's avatar David Reid

JACK: Fail context init if JACK is unusable.

parent 3405d9d5
...@@ -12173,14 +12173,11 @@ typedef const char* (* mal_jack_port_name_proc) (const mal_ ...@@ -12173,14 +12173,11 @@ typedef const char* (* mal_jack_port_name_proc) (const mal_
typedef void* (* mal_jack_port_get_buffer_proc) (mal_jack_port_t* port, mal_jack_nframes_t nframes); typedef void* (* mal_jack_port_get_buffer_proc) (mal_jack_port_t* port, mal_jack_nframes_t nframes);
typedef void (* mal_jack_free_proc) (void* ptr); typedef void (* mal_jack_free_proc) (void* ptr);
mal_result mal_context_open_client__jack(mal_context* pContext, mal_device_type type, const mal_device_id* pDeviceID, mal_jack_client_t** ppClient) mal_result mal_context_open_client__jack(mal_context* pContext, mal_jack_client_t** ppClient)
{ {
mal_assert(pContext != NULL); mal_assert(pContext != NULL);
mal_assert(ppClient != NULL); mal_assert(ppClient != NULL);
(void)type;
(void)pDeviceID;
if (ppClient) { if (ppClient) {
*ppClient = NULL; *ppClient = NULL;
} }
...@@ -12193,7 +12190,7 @@ mal_result mal_context_open_client__jack(mal_context* pContext, mal_device_type ...@@ -12193,7 +12190,7 @@ mal_result mal_context_open_client__jack(mal_context* pContext, mal_device_type
mal_jack_status_t status; mal_jack_status_t status;
mal_jack_client_t* pClient = ((mal_jack_client_open_proc)pContext->jack.jack_client_open)(clientName, (pContext->config.jack.tryStartServer) ? 0 : mal_JackNoStartServer, &status, NULL); mal_jack_client_t* pClient = ((mal_jack_client_open_proc)pContext->jack.jack_client_open)(clientName, (pContext->config.jack.tryStartServer) ? 0 : mal_JackNoStartServer, &status, NULL);
if (pClient == NULL) { if (pClient == NULL) {
return mal_context_post_error(pContext, NULL, MAL_LOG_LEVEL_ERROR, "[JACK] Failed to open client.", MAL_FAILED_TO_OPEN_BACKEND_DEVICE); return MAL_FAILED_TO_OPEN_BACKEND_DEVICE;
} }
if (ppClient) { if (ppClient) {
...@@ -12263,9 +12260,9 @@ mal_result mal_context_get_device_info__jack(mal_context* pContext, mal_device_t ...@@ -12263,9 +12260,9 @@ mal_result mal_context_get_device_info__jack(mal_context* pContext, mal_device_t
// The channel count and sample rate can only be determined by opening the device. // The channel count and sample rate can only be determined by opening the device.
mal_jack_client_t* pClient; mal_jack_client_t* pClient;
mal_result result = mal_context_open_client__jack(pContext, deviceType, pDeviceID, &pClient); mal_result result = mal_context_open_client__jack(pContext, &pClient);
if (result != MAL_SUCCESS) { if (result != MAL_SUCCESS) {
return result; return mal_context_post_error(pContext, NULL, MAL_LOG_LEVEL_ERROR, "[JACK] Failed to open client.", MAL_FAILED_TO_OPEN_BACKEND_DEVICE);
} }
pDeviceInfo->minSampleRate = ((mal_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((mal_jack_client_t*)pClient); pDeviceInfo->minSampleRate = ((mal_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((mal_jack_client_t*)pClient);
...@@ -12375,6 +12372,16 @@ mal_result mal_context_init__jack(mal_context* pContext) ...@@ -12375,6 +12372,16 @@ mal_result mal_context_init__jack(mal_context* pContext)
pContext->onEnumDevices = mal_context_enumerate_devices__jack; pContext->onEnumDevices = mal_context_enumerate_devices__jack;
pContext->onGetDeviceInfo = mal_context_get_device_info__jack; pContext->onGetDeviceInfo = mal_context_get_device_info__jack;
// Getting here means the JACK library is installed, but it doesn't necessarily mean it's usable. We need to quickly test this by connecting
// a temporary client.
mal_jack_client_t* pDummyClient;
mal_result result = mal_context_open_client__jack(pContext, &pDummyClient);
if (result != MAL_SUCCESS) {
return MAL_NO_BACKEND;
}
((mal_jack_client_close_proc)pContext->jack.jack_client_close)((mal_jack_client_t*)pDummyClient);
return MAL_SUCCESS; return MAL_SUCCESS;
} }
...@@ -12488,9 +12495,9 @@ mal_result mal_device_init__jack(mal_context* pContext, mal_device_type type, ma ...@@ -12488,9 +12495,9 @@ mal_result mal_device_init__jack(mal_context* pContext, mal_device_type type, ma
// Open the client. // Open the client.
mal_result result = mal_context_open_client__jack(pContext, type, pDeviceID, (mal_jack_client_t**)&pDevice->jack.pClient); mal_result result = mal_context_open_client__jack(pContext, (mal_jack_client_t**)&pDevice->jack.pClient);
if (result != MAL_SUCCESS) { if (result != MAL_SUCCESS) {
return result; return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[JACK] Failed to open client.", MAL_FAILED_TO_OPEN_BACKEND_DEVICE);
} }
// Callbacks. // Callbacks.
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