Commit af3f01ca authored by David Reid's avatar David Reid

sndio: Fix unnecessarily inefficient device enumeration.

parent 9690e3bb
...@@ -15398,52 +15398,54 @@ mal_result mal_context_enumerate_devices__sndio(mal_context* pContext, mal_enum_ ...@@ -15398,52 +15398,54 @@ mal_result mal_context_enumerate_devices__sndio(mal_context* pContext, mal_enum_
mal_itoa_s(iDevice, devpath+strlen(devpath), sizeof(devpath)-strlen(devpath), 10); mal_itoa_s(iDevice, devpath+strlen(devpath), sizeof(devpath)-strlen(devpath), 10);
struct stat st; struct stat st;
if (stat(devpath, &st) == 0) { if (stat(devpath, &st) != 0) {
// The device exists, but we need to check if it's usable as playback and/or capture. This is done break;
// via the sndio API by using the "snd/N" format for the device name. }
char devid[256];
mal_strcpy_s(devid, sizeof(devid), "snd/"); // The device exists, but we need to check if it's usable as playback and/or capture. This is done
mal_itoa_s(iDevice, devid+strlen(devid), sizeof(devid)-strlen(devid), 10); // via the sndio API by using the "snd/N" format for the device name.
char devid[256];
mal_bool32 isTerminating = MAL_FALSE; mal_strcpy_s(devid, sizeof(devid), "snd/");
struct mal_sio_hdl* handle; mal_itoa_s(iDevice, devid+strlen(devid), sizeof(devid)-strlen(devid), 10);
// Playback. mal_bool32 isTerminating = MAL_FALSE;
if (!isTerminating) { struct mal_sio_hdl* handle;
handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, MAL_SIO_PLAY, 0);
if (handle != NULL) { // Playback.
// Supports playback. if (!isTerminating) {
mal_device_info deviceInfo; handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, MAL_SIO_PLAY, 0);
mal_zero_object(&deviceInfo); if (handle != NULL) {
mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), devid); // Supports playback.
mal_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), devid); mal_device_info deviceInfo;
mal_zero_object(&deviceInfo);
isTerminating = !callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), devid);
mal_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), devid);
((mal_sio_close_proc)pContext->sndio.sio_close)(handle);
} isTerminating = !callback(pContext, mal_device_type_playback, &deviceInfo, pUserData);
((mal_sio_close_proc)pContext->sndio.sio_close)(handle);
} }
}
// Capture.
if (!isTerminating) { // Capture.
handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, MAL_SIO_REC, 0); if (!isTerminating) {
if (handle != NULL) { handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, MAL_SIO_REC, 0);
// Supports capture. if (handle != NULL) {
mal_device_info deviceInfo; // Supports capture.
mal_zero_object(&deviceInfo); mal_device_info deviceInfo;
mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), devid); mal_zero_object(&deviceInfo);
mal_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), devid); mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), devid);
mal_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), devid);
isTerminating = !callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); isTerminating = !callback(pContext, mal_device_type_capture, &deviceInfo, pUserData);
((mal_sio_close_proc)pContext->sndio.sio_close)(handle); ((mal_sio_close_proc)pContext->sndio.sio_close)(handle);
}
}
if (isTerminating) {
break;
} }
} }
if (isTerminating) {
break;
}
} }
return MAL_SUCCESS; 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