mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
WinMM: Drain the playback device when stopping.
This commit is contained in:
+15
@@ -13945,10 +13945,25 @@ static ma_result ma_device_stop__winmm(ma_device* pDevice)
|
||||
}
|
||||
|
||||
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
|
||||
ma_uint32 iPeriod;
|
||||
WAVEHDR* pWAVEHDR;
|
||||
|
||||
if (pDevice->winmm.hDevicePlayback == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
/* We need to drain the device. To do this we just loop over each header and if it's locked just wait for the event. */
|
||||
pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback;
|
||||
for (iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; iPeriod += 1) {
|
||||
if (pWAVEHDR[iPeriod].dwUser == 1) { /* 1 = locked. */
|
||||
if (WaitForSingleObject((HANDLE)pDevice->winmm.hEventPlayback, INFINITE) != WAIT_OBJECT_0) {
|
||||
break; /* An error occurred so just abandon ship and stop the device without draining. */
|
||||
}
|
||||
|
||||
pWAVEHDR[iPeriod].dwUser = 0;
|
||||
}
|
||||
}
|
||||
|
||||
resultMM = ((MA_PFN_waveOutReset)pDevice->pContext->winmm.waveOutReset)((HWAVEOUT)pDevice->winmm.hDevicePlayback);
|
||||
if (resultMM != MMSYSERR_NOERROR) {
|
||||
ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] WARNING: Failed to reset playback device.", ma_result_from_MMRESULT(resultMM));
|
||||
|
||||
Reference in New Issue
Block a user