Commit e15fd218 authored by Andrew Opalach's avatar Andrew Opalach Committed by David Reid

WASAPI: Fix drain on device stop

parent 4c7021e5
...@@ -23157,13 +23157,12 @@ static ma_result ma_device_stop__wasapi_nolock(ma_device* pDevice) ...@@ -23157,13 +23157,12 @@ static ma_result ma_device_stop__wasapi_nolock(ma_device* pDevice)
*/ */
if (ma_atomic_bool32_get(&pDevice->wasapi.isStartedPlayback)) { if (ma_atomic_bool32_get(&pDevice->wasapi.isStartedPlayback)) {
/* We need to make sure we put a timeout here or else we'll risk getting stuck in a deadlock in some cases. */ /* We need to make sure we put a timeout here or else we'll risk getting stuck in a deadlock in some cases. */
DWORD waitTime = pDevice->wasapi.actualBufferSizeInFramesPlayback / pDevice->playback.internalSampleRate; DWORD waitTime = pDevice->wasapi.actualBufferSizeInFramesPlayback / (pDevice->playback.internalSampleRate / 1000);
if (pDevice->playback.shareMode == ma_share_mode_exclusive) { if (pDevice->playback.shareMode == ma_share_mode_exclusive) {
WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, waitTime); WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, waitTime);
} } else {
else { ma_uint32 prevFramesAvailablePlayback = (ma_uint32)-1;
ma_uint32 prevFramesAvaialablePlayback = (ma_uint32)-1;
ma_uint32 framesAvailablePlayback; ma_uint32 framesAvailablePlayback;
for (;;) { for (;;) {
result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback); result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback);
...@@ -23179,13 +23178,13 @@ static ma_result ma_device_stop__wasapi_nolock(ma_device* pDevice) ...@@ -23179,13 +23178,13 @@ static ma_result ma_device_stop__wasapi_nolock(ma_device* pDevice)
Just a safety check to avoid an infinite loop. If this iteration results in a situation where the number of available frames Just a safety check to avoid an infinite loop. If this iteration results in a situation where the number of available frames
has not changed, get out of the loop. I don't think this should ever happen, but I think it's nice to have just in case. has not changed, get out of the loop. I don't think this should ever happen, but I think it's nice to have just in case.
*/ */
if (framesAvailablePlayback == prevFramesAvaialablePlayback) { if (framesAvailablePlayback == prevFramesAvailablePlayback) {
break; break;
} }
prevFramesAvaialablePlayback = framesAvailablePlayback; prevFramesAvailablePlayback = framesAvailablePlayback;
WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, waitTime * 1000);
ResetEvent((HANDLE)pDevice->wasapi.hEventPlayback); /* Manual reset. */ ResetEvent((HANDLE)pDevice->wasapi.hEventPlayback); /* Manual reset. */
WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, waitTime);
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment