mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Minor refactor the OpenSL backend.
This commit is contained in:
+37
-32
@@ -42367,36 +42367,51 @@ static ma_result ma_device_stop__opensl(ma_device* pDevice)
|
|||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ma_result ma_device_wait__opensl(ma_device* pDevice)
|
static ma_result ma_device_step__opensl(ma_device* pDevice, ma_blocking_mode blockingMode)
|
||||||
{
|
|
||||||
ma_device_state_opensl* pDeviceStateOpenSL = ma_device_get_backend_state__opensl(pDevice);
|
|
||||||
ma_device_state_async_wait(&pDeviceStateOpenSL->async);
|
|
||||||
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ma_result ma_device_step__opensl(ma_device* pDevice)
|
|
||||||
{
|
{
|
||||||
ma_device_state_opensl* pDeviceStateOpenSL = ma_device_get_backend_state__opensl(pDevice);
|
ma_device_state_opensl* pDeviceStateOpenSL = ma_device_get_backend_state__opensl(pDevice);
|
||||||
ma_device_type deviceType = ma_device_get_type(pDevice);
|
ma_device_type deviceType = ma_device_get_type(pDevice);
|
||||||
|
|
||||||
if (ma_device_get_status(pDevice) != ma_device_status_started) {
|
for (;;) {
|
||||||
return MA_SUCCESS; /* Device not started. Nothing to do. */
|
ma_result result;
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
|
if (blockingMode == MA_BLOCKING_MODE_BLOCKING) {
|
||||||
if (pDeviceStateOpenSL->isDrainingCapture) {
|
ma_device_state_async_wait(&pDeviceStateOpenSL->async);
|
||||||
return MA_SUCCESS; /* Currently draining. Do not want to be firing the callback in this case. */
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) {
|
if (!ma_device_is_started(pDevice)) {
|
||||||
if (pDeviceStateOpenSL->isDrainingPlayback) {
|
return MA_DEVICE_NOT_STARTED; /* Device not started. Nothing to do. */
|
||||||
return MA_SUCCESS; /* Currently draining. Do not want to be firing the callback in this case. */
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ma_device_state_async_step(&pDeviceStateOpenSL->async, pDevice);
|
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
|
||||||
|
if (pDeviceStateOpenSL->isDrainingCapture) {
|
||||||
|
return MA_SUCCESS; /* Currently draining. Do not want to be firing the callback in this case. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) {
|
||||||
|
if (pDeviceStateOpenSL->isDrainingPlayback) {
|
||||||
|
return MA_SUCCESS; /* Currently draining. Do not want to be firing the callback in this case. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = ma_device_state_async_step(&pDeviceStateOpenSL->async, pDevice);
|
||||||
|
if (result == MA_SUCCESS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != MA_NO_DATA_AVAILABLE) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Getting here means no data was processed. In non-blocking mode we don't care, just get out of the loop. */
|
||||||
|
if (blockingMode == MA_BLOCKING_MODE_NON_BLOCKING) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Getting here means we're in blocking mode and no data was processed. In this case we'd rather keep waiting for data to be available. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -42406,17 +42421,7 @@ static void ma_device_loop__opensl(ma_device* pDevice)
|
|||||||
MA_ASSERT(pDevice != NULL);
|
MA_ASSERT(pDevice != NULL);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ma_result result = ma_device_wait__opensl(pDevice);
|
ma_result result = ma_device_step__opensl(pDevice, MA_BLOCKING_MODE_BLOCKING);
|
||||||
if (result != MA_SUCCESS) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the wait terminated due to the device being stopped, abort now. */
|
|
||||||
if (!ma_device_is_started(pDevice)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = ma_device_step__opensl(pDevice);
|
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user