summaryrefslogtreecommitdiffstats
path: root/Alc/backends/winmm.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-01-20 12:36:23 -0800
committerChris Robinson <[email protected]>2012-01-20 12:36:23 -0800
commit0ef3a30b84759c3a1e9046fe790b02f845cbdedb (patch)
treee6471c7cd8166c3763814febd2175a3524a10cee /Alc/backends/winmm.c
parentb375897374efa8a80d3324519ce1cda8de0c8044 (diff)
Fix WaveIn shutdown for real
The processing thread must be messaged when shutting down, and depending on the state of the device, waveInReset may not do it. Additionally, all buffers must be removed from the device before they can be unprepared and the device closed.
Diffstat (limited to 'Alc/backends/winmm.c')
-rw-r--r--Alc/backends/winmm.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c
index 7a9a0e01..df43a81d 100644
--- a/Alc/backends/winmm.c
+++ b/Alc/backends/winmm.c
@@ -253,13 +253,10 @@ static DWORD WINAPI CaptureThreadProc(LPVOID lpParameter)
{
if(msg.message != WIM_DATA)
continue;
-
+ /* Don't wait for other buffers to finish before quitting. We're
+ * closing so we don't need them. */
if(pData->bWaveShutdown)
- {
- if(pData->lWaveBuffersCommitted == 0)
- break;
- continue;
- }
+ break;
pWaveHdr = ((LPWAVEHDR)msg.lParam);
@@ -624,15 +621,15 @@ static void WinMMCloseCapture(ALCdevice *pDevice)
void *buffer = NULL;
int i;
- /* Unintuitively.. call waveInStart to make sure WinMM keeps processing
- * buffers so the processing thread can drop them and exit when it reaches
- * 0. */
+ /* Tell the processing thread to quit and wait for it to do so. */
pData->bWaveShutdown = AL_TRUE;
- waveInStart(pData->hWaveHandle.In);
+ PostThreadMessage(pData->ulWaveThreadID, WM_QUIT, 0, 0);
- // Wait for signal that Wave Thread has been destroyed
WaitForSingleObjectEx(pData->hWaveThreadEvent, 5000, FALSE);
+ /* Make sure capture is stopped and all pending buffers are flushed. */
+ waveInReset(pData->hWaveHandle.In);
+
CloseHandle(pData->hWaveThread);
pData->hWaveThread = 0;