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/dsound.c | 53 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'Alc/backends/dsound.c') diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index feca3cfa..0eab62a4 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -392,6 +392,16 @@ static void DSoundClosePlayback(ALCdevice *device) { DSoundPlaybackData *pData = device->ExtraData; + if(pData->DSnotify) + IDirectSoundNotify_Release(pData->DSnotify); + pData->DSnotify = NULL; + if(pData->DSsbuffer) + IDirectSoundBuffer_Release(pData->DSsbuffer); + pData->DSsbuffer = NULL; + if(pData->DSpbuffer != NULL) + IDirectSoundBuffer_Release(pData->DSpbuffer); + pData->DSpbuffer = NULL; + IDirectSound_Release(pData->lpDS); CloseHandle(pData->hNotifyEvent); free(pData); @@ -408,6 +418,16 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) memset(&OutputType, 0, sizeof(OutputType)); + if(pData->DSnotify) + IDirectSoundNotify_Release(pData->DSnotify); + pData->DSnotify = NULL; + if(pData->DSsbuffer) + IDirectSoundBuffer_Release(pData->DSsbuffer); + pData->DSsbuffer = NULL; + if(pData->DSpbuffer != NULL) + IDirectSoundBuffer_Release(pData->DSpbuffer); + pData->DSpbuffer = NULL; + switch(device->FmtType) { case DevFmtByte: @@ -578,15 +598,6 @@ retry_open: } } - if(SUCCEEDED(hr)) - { - ResetEvent(pData->hNotifyEvent); - SetDefaultWFXChannelOrder(device); - pData->thread = StartThread(DSoundPlaybackProc, device); - if(pData->thread == NULL) - hr = E_FAIL; - } - if(FAILED(hr)) { if(pData->DSnotify != NULL) @@ -601,6 +612,20 @@ retry_open: return ALC_FALSE; } + ResetEvent(pData->hNotifyEvent); + SetDefaultWFXChannelOrder(device); + + return ALC_TRUE; +} + +static ALCboolean DSoundStartPlayback(ALCdevice *device) +{ + DSoundPlaybackData *pData = (DSoundPlaybackData*)device->ExtraData; + + pData->thread = StartThread(DSoundPlaybackProc, device); + if(pData->thread == NULL) + return ALC_FALSE; + return ALC_TRUE; } @@ -616,14 +641,7 @@ static void DSoundStopPlayback(ALCdevice *device) pData->thread = NULL; pData->killNow = 0; - - IDirectSoundNotify_Release(pData->DSnotify); - pData->DSnotify = NULL; - IDirectSoundBuffer_Release(pData->DSsbuffer); - pData->DSsbuffer = NULL; - if(pData->DSpbuffer != NULL) - IDirectSoundBuffer_Release(pData->DSpbuffer); - pData->DSpbuffer = NULL; + IDirectSoundBuffer_Stop(pData->DSsbuffer); } @@ -918,6 +936,7 @@ static const BackendFuncs DSoundFuncs = { DSoundOpenPlayback, DSoundClosePlayback, DSoundResetPlayback, + DSoundStartPlayback, DSoundStopPlayback, DSoundOpenCapture, DSoundCloseCapture, -- cgit v1.2.3