From fe6e532c876bf3ec6776f76f9542038ac9c94d68 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 5 Mar 2012 07:11:09 -0800 Subject: Use a separate backend callback to start playback of the device This allows us to properly update the ALCdevice and its resources with the new parameters before starting playback, instead of expecting the mixer to block and wait after it has begun. This also lets us avoid holding the device lock while resetting and starting the device, which helps prevent lock inversion on some backends (ie, one thread locking A then B, and another thread locking B then A), ultimately allowing certain backends to asynchronously update the ALCdevice without risk of lockup. Capture still has issues here, however. --- Alc/backends/winmm.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'Alc/backends/winmm.c') diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index 9f2c6316..57d27974 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -395,6 +395,21 @@ static void WinMMClosePlayback(ALCdevice *device) } static ALCboolean WinMMResetPlayback(ALCdevice *device) +{ + WinMMData *pData = (WinMMData*)device->ExtraData; + + device->UpdateSize = (ALuint)((ALuint64)device->UpdateSize * + pData->Frequency / device->Frequency); + device->UpdateSize = device->UpdateSize*device->NumUpdates / 4; + device->NumUpdates = 4; + device->Frequency = pData->Frequency; + + SetDefaultWFXChannelOrder(device); + + return ALC_TRUE; +} + +static ALCboolean WinMMStartPlayback(ALCdevice *device) { WinMMData *pData = (WinMMData*)device->ExtraData; ALbyte *BufferData; @@ -405,12 +420,6 @@ static ALCboolean WinMMResetPlayback(ALCdevice *device) if(pData->hWaveThread == NULL) return ALC_FALSE; - device->UpdateSize = (ALuint)((ALuint64)device->UpdateSize * - pData->Frequency / device->Frequency); - device->Frequency = pData->Frequency; - - SetDefaultWFXChannelOrder(device); - pData->lWaveBuffersCommitted = 0; // Create 4 Buffers @@ -689,6 +698,7 @@ static const BackendFuncs WinMMFuncs = { WinMMOpenPlayback, WinMMClosePlayback, WinMMResetPlayback, + WinMMStartPlayback, WinMMStopPlayback, WinMMOpenCapture, WinMMCloseCapture, -- cgit v1.2.3