mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 00:34:03 +02:00
AAudio: Improve handling of stream errors.
Public issue https://github.com/mackron/miniaudio/issues/590
This commit is contained in:
+8
-8
@@ -37041,6 +37041,8 @@ static ma_aaudio_input_preset_t ma_to_input_preset__aaudio(ma_aaudio_input_prese
|
|||||||
|
|
||||||
static void ma_stream_error_callback__aaudio(ma_AAudioStream* pStream, void* pUserData, ma_aaudio_result_t error)
|
static void ma_stream_error_callback__aaudio(ma_AAudioStream* pStream, void* pUserData, ma_aaudio_result_t error)
|
||||||
{
|
{
|
||||||
|
ma_result result;
|
||||||
|
ma_job job;
|
||||||
ma_device* pDevice = (ma_device*)pUserData;
|
ma_device* pDevice = (ma_device*)pUserData;
|
||||||
MA_ASSERT(pDevice != NULL);
|
MA_ASSERT(pDevice != NULL);
|
||||||
|
|
||||||
@@ -37049,18 +37051,17 @@ static void ma_stream_error_callback__aaudio(ma_AAudioStream* pStream, void* pUs
|
|||||||
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[AAudio] ERROR CALLBACK: error=%d, AAudioStream_getState()=%d\n", error, ((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream));
|
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[AAudio] ERROR CALLBACK: error=%d, AAudioStream_getState()=%d\n", error, ((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
From the documentation for AAudio, when a device is disconnected all we can do is stop it. However, we cannot stop it from the callback - we need
|
When we get an error, we'll assume that the stream is in an erroneous state and needs to be restarted. From the documentation,
|
||||||
to do it from another thread. Therefore we are going to use an event thread for the AAudio backend to do this cleanly and safely.
|
we cannot do this from the error callback. Therefore we are going to use an event thread for the AAudio backend to do this
|
||||||
|
cleanly and safely.
|
||||||
*/
|
*/
|
||||||
if (((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream) == MA_AAUDIO_STREAM_STATE_DISCONNECTED) {
|
job = ma_job_init(MA_JOB_TYPE_DEVICE_AAUDIO_REROUTE);
|
||||||
/* We need to post a job to the job thread for processing. This will reroute the device by reinitializing the stream. */
|
|
||||||
ma_result result;
|
|
||||||
ma_job job = ma_job_init(MA_JOB_TYPE_DEVICE_AAUDIO_REROUTE);
|
|
||||||
job.data.device.aaudio.reroute.pDevice = pDevice;
|
job.data.device.aaudio.reroute.pDevice = pDevice;
|
||||||
|
|
||||||
if (pStream == pDevice->aaudio.pStreamCapture) {
|
if (pStream == pDevice->aaudio.pStreamCapture) {
|
||||||
job.data.device.aaudio.reroute.deviceType = ma_device_type_capture;
|
job.data.device.aaudio.reroute.deviceType = ma_device_type_capture;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
job.data.device.aaudio.reroute.deviceType = ma_device_type_playback;
|
job.data.device.aaudio.reroute.deviceType = ma_device_type_playback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37069,7 +37070,6 @@ static void ma_stream_error_callback__aaudio(ma_AAudioStream* pStream, void* pUs
|
|||||||
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[AAudio] Device Disconnected. Failed to post job for rerouting.\n");
|
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[AAudio] Device Disconnected. Failed to post job for rerouting.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ma_aaudio_data_callback_result_t ma_stream_data_callback_capture__aaudio(ma_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t frameCount)
|
static ma_aaudio_data_callback_result_t ma_stream_data_callback_capture__aaudio(ma_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t frameCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user