Skip to content

Commit

Permalink
AAudio: Potential fix for a failed assertion.
Browse files Browse the repository at this point in the history
Public issue #833
  • Loading branch information
mackron committed Apr 28, 2024
1 parent 88436b2 commit 1b35118
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions miniaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37736,7 +37736,9 @@ static ma_aaudio_data_callback_result_t ma_stream_data_callback_capture__aaudio(
ma_device* pDevice = (ma_device*)pUserData;
MA_ASSERT(pDevice != NULL);

ma_device_handle_backend_data_callback(pDevice, NULL, pAudioData, frameCount);
if (frameCount > 0) {
ma_device_handle_backend_data_callback(pDevice, NULL, pAudioData, (ma_uint32)frameCount);
}

(void)pStream;
return MA_AAUDIO_CALLBACK_RESULT_CONTINUE;
Expand All @@ -37747,7 +37749,14 @@ static ma_aaudio_data_callback_result_t ma_stream_data_callback_playback__aaudio
ma_device* pDevice = (ma_device*)pUserData;
MA_ASSERT(pDevice != NULL);

ma_device_handle_backend_data_callback(pDevice, pAudioData, NULL, frameCount);
/*
I've had a report that AAudio can sometimes post a frame count of 0. We need to check for that here
so we don't get any errors at a deeper level. I'm doing the same with the capture side for safety,
though I've not yet had any reports about that one.
*/
if (frameCount > 0) {
ma_device_handle_backend_data_callback(pDevice, pAudioData, NULL, (ma_uint32)frameCount);
}

(void)pStream;
return MA_AAUDIO_CALLBACK_RESULT_CONTINUE;
Expand Down Expand Up @@ -42635,6 +42644,15 @@ MA_API ma_result ma_device_handle_backend_data_callback(ma_device* pDevice, void
return MA_INVALID_ARGS;
}

/*
There is an assert deeper in the code that checks that frameCount > 0. Since this is a public facing
API we'll need to check for that here. I've had reports that AAudio can sometimes post a frame count
of 0.
*/
if (frameCount == 0) {
return MA_INVALID_ARGS;
}

if (pDevice->type == ma_device_type_duplex) {
if (pInput != NULL) {
ma_device__handle_duplex_callback_capture(pDevice, frameCount, pInput, &pDevice->duplexRB.rb);
Expand Down

0 comments on commit 1b35118

Please sign in to comment.