Return result codes from step/wait/loop callbacks.

This commit is contained in:
David Reid
2025-12-16 18:08:32 +10:00
parent df79b33aeb
commit 60d757a226
3 changed files with 39 additions and 15 deletions
+17 -7
View File
@@ -463,7 +463,7 @@ static ma_device_state_pipewire* ma_device_get_backend_state__pipewire(ma_device
}
static void ma_device_step__pipewire(ma_device* pDevice);
static ma_result ma_device_step__pipewire(ma_device* pDevice);
static void ma_backend_info__pipewire(ma_device_backend_info* pBackendInfo)
@@ -1570,7 +1570,7 @@ static ma_result ma_device_stop__pipewire(ma_device* pDevice)
}
static void ma_device_wait__pipewire(ma_device* pDevice)
static ma_result ma_device_wait__pipewire(ma_device* pDevice)
{
ma_device_state_pipewire* pDeviceStatePipeWire = ma_device_get_backend_state__pipewire(pDevice);
ma_context_state_pipewire* pContextStatePipeWire = ma_context_get_backend_state__pipewire(ma_device_get_context(pDevice));
@@ -1581,12 +1581,12 @@ static void ma_device_wait__pipewire(ma_device* pDevice)
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
if (ma_pcm_rb_available_read(&pDeviceStatePipeWire->capture.rb) > 0) {
return;
return MA_SUCCESS;
}
}
if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) {
if (ma_pcm_rb_available_write(&pDeviceStatePipeWire->playback.rb) > 0) {
return;
return MA_SUCCESS;
}
}
@@ -1601,9 +1601,11 @@ static void ma_device_wait__pipewire(ma_device* pDevice)
break;
}
}
return MA_SUCCESS;
}
static void ma_device_step__pipewire(ma_device* pDevice)
static ma_result ma_device_step__pipewire(ma_device* pDevice)
{
ma_device_state_pipewire* pDeviceStatePipeWire = ma_device_get_backend_state__pipewire(pDevice);
ma_context_state_pipewire* pContextStatePipeWire = ma_context_get_backend_state__pipewire(ma_device_get_context(pDevice));
@@ -1668,19 +1670,27 @@ static void ma_device_step__pipewire(ma_device* pDevice)
}
}
}
return MA_SUCCESS;
}
static void ma_device_loop__pipewire(ma_device* pDevice)
{
for (;;) {
ma_device_wait__pipewire(pDevice);
ma_result result = ma_device_wait__pipewire(pDevice);
if (result != MA_SUCCESS) {
break;
}
/* If the wait terminated due to the device being stopped, abort now. */
if (!ma_device_is_started(pDevice)) {
break;
}
ma_device_step__pipewire(pDevice);
result = ma_device_step__pipewire(pDevice);
if (result != MA_SUCCESS) {
break;
}
}
}
+15 -5
View File
@@ -169,7 +169,7 @@ static ma_device_state_sdl* ma_device_get_backend_state__sdl(ma_device* pDevice)
}
static void ma_device_step__sdl(ma_device* pDevice);
static ma_result ma_device_step__sdl(ma_device* pDevice);
static void ma_backend_info__sdl(ma_device_backend_info* pBackendInfo)
@@ -593,29 +593,39 @@ static ma_result ma_device_stop__sdl(ma_device* pDevice)
}
static void ma_device_wait__sdl(ma_device* pDevice)
static ma_result ma_device_wait__sdl(ma_device* pDevice)
{
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice);
ma_device_state_async_wait(&pDeviceStateSDL->async);
return MA_SUCCESS;
}
static void ma_device_step__sdl(ma_device* pDevice)
static ma_result ma_device_step__sdl(ma_device* pDevice)
{
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice);
ma_device_state_async_step(&pDeviceStateSDL->async, pDevice);
return MA_SUCCESS;
}
static void ma_device_loop__sdl(ma_device* pDevice)
{
for (;;) {
ma_device_wait__sdl(pDevice);
ma_result result = ma_device_wait__sdl(pDevice);
if (result != MA_SUCCESS) {
break;
}
/* If the wait terminated due to the device being stopped, abort now. */
if (!ma_device_is_started(pDevice)) {
break;
}
ma_device_step__sdl(pDevice);
result = ma_device_step__sdl(pDevice);
if (result != MA_SUCCESS) {
break;
}
}
}
+7 -3
View File
@@ -21174,7 +21174,7 @@ static ma_uint32 ma_device_get_available_frames__null(ma_device* pDevice)
}
}
static void ma_device_wait__null(ma_device* pDevice)
static ma_result ma_device_wait__null(ma_device* pDevice)
{
while (ma_device_is_started(pDevice)) {
/* Check the frames available based on the timer. We want to wait until we have at least a whole period available. */
@@ -21184,9 +21184,11 @@ static void ma_device_wait__null(ma_device* pDevice)
ma_sleep(1);
}
return MA_SUCCESS;
}
static void ma_device_step__null(ma_device* pDevice)
static ma_result ma_device_step__null(ma_device* pDevice)
{
ma_device_state_null* pDeviceStateNull = ma_device_get_backend_state__null(pDevice);
ma_uint32 framesAvailable;
@@ -21199,7 +21201,7 @@ static void ma_device_step__null(ma_device* pDevice)
framesAvailable = ma_device_get_available_frames__null(pDevice);
if (framesAvailable == 0) {
/* Not enough frames available for processing. Do nothing. */
return;
return MA_SUCCESS;
}
/* For capture we need to submit silence. For playback we just read and discard. */
@@ -21212,6 +21214,8 @@ static void ma_device_step__null(ma_device* pDevice)
/* The cursor needs to be advanced by the number of frames we just processed. */
pDeviceStateNull->cursor += framesAvailable;
return MA_SUCCESS;
}
static void ma_device_loop__null(ma_device* pDevice)