sndio: Fix unnecessarily inefficient device enumeration.

This commit is contained in:
David Reid
2018-07-30 12:09:07 +10:00
parent 9690e3bb9e
commit af3f01ca6f
+37 -35
View File
@@ -15398,51 +15398,53 @@ 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/");
mal_itoa_s(iDevice, devid+strlen(devid), sizeof(devid)-strlen(devid), 10);
mal_bool32 isTerminating = MAL_FALSE; // The device exists, but we need to check if it's usable as playback and/or capture. This is done
struct mal_sio_hdl* handle; // via the sndio API by using the "snd/N" format for the device name.
char devid[256];
mal_strcpy_s(devid, sizeof(devid), "snd/");
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) {
// Supports playback.
mal_device_info deviceInfo;
mal_zero_object(&deviceInfo);
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_playback, &deviceInfo, pUserData); // Playback.
if (!isTerminating) {
handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, MAL_SIO_PLAY, 0);
if (handle != NULL) {
// Supports playback.
mal_device_info deviceInfo;
mal_zero_object(&deviceInfo);
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. // Capture.
if (!isTerminating) { if (!isTerminating) {
handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, MAL_SIO_REC, 0); handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, MAL_SIO_REC, 0);
if (handle != NULL) { if (handle != NULL) {
// Supports capture. // Supports capture.
mal_device_info deviceInfo; mal_device_info deviceInfo;
mal_zero_object(&deviceInfo); mal_zero_object(&deviceInfo);
mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), devid); mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), devid);
mal_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), 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) { if (isTerminating) {
break; break;
}
} }
} }