diff options
author | Chris Robinson <[email protected]> | 2010-06-09 23:32:35 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-06-09 23:32:35 -0700 |
commit | a1f987c016d61563c9f105646dc1fe2b8275894d (patch) | |
tree | 88af92fab5c6d37926370045ecdbb1abc17ce7c2 /Alc/dsound.c | |
parent | cff805e0a37d6b1866f00863ea968ad2d5ad6d45 (diff) |
Improve handling of lost DirectSound buffers
Diffstat (limited to 'Alc/dsound.c')
-rw-r--r-- | Alc/dsound.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/Alc/dsound.c b/Alc/dsound.c index 7fe6825c..3365f5ef 100644 --- a/Alc/dsound.c +++ b/Alc/dsound.c @@ -158,6 +158,7 @@ static ALuint DSoundProc(ALvoid *ptr) DWORD PlayCursor; VOID *WritePtr1, *WritePtr2; DWORD WriteCnt1, WriteCnt2; + BOOL Playing = FALSE; DWORD FrameSize; DWORD FragSize; DWORD avail; @@ -187,6 +188,16 @@ static ALuint DSoundProc(ALvoid *ptr) if(avail < FragSize) { + if(!Playing) + { + err = IDirectSoundBuffer_Play(pData->DSsbuffer, 0, 0, DSBPLAY_LOOPING); + if(FAILED(err)) + { + AL_PRINT("Failed to play buffer: 0x%lx\n", err); + aluHandleDisconnect(pDevice); + return 1; + } + } Sleep(1); continue; } @@ -197,14 +208,16 @@ static ALuint DSoundProc(ALvoid *ptr) WriteCnt2 = 0; err = IDirectSoundBuffer_Lock(pData->DSsbuffer, LastCursor, avail, &WritePtr1, &WriteCnt1, &WritePtr2, &WriteCnt2, 0); - // If the buffer is lost, restore it, play and lock + // If the buffer is lost, restore it and lock if(err == DSERR_BUFFERLOST) { err = IDirectSoundBuffer_Restore(pData->DSsbuffer); if(SUCCEEDED(err)) - err = IDirectSoundBuffer_Play(pData->DSsbuffer, 0, 0, DSBPLAY_LOOPING); - if(SUCCEEDED(err)) - err = IDirectSoundBuffer_Lock(pData->DSsbuffer, LastCursor, avail, &WritePtr1, &WriteCnt1, &WritePtr2, &WriteCnt2, 0); + { + Playing = FALSE; + LastCursor = 0; + err = IDirectSoundBuffer_Lock(pData->DSsbuffer, 0, DSBCaps.dwBufferBytes, &WritePtr1, &WriteCnt1, &WritePtr2, &WriteCnt2, 0); + } } // Successfully locked the output buffer @@ -218,7 +231,11 @@ static ALuint DSoundProc(ALvoid *ptr) IDirectSoundBuffer_Unlock(pData->DSsbuffer, WritePtr1, WriteCnt1, WritePtr2, WriteCnt2); } else + { AL_PRINT("Buffer lock error: %#lx\n", err); + aluHandleDisconnect(pDevice); + return 1; + } // Update old write cursor location LastCursor += WriteCnt1+WriteCnt2; @@ -443,9 +460,6 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) } if(SUCCEEDED(hr)) - hr = IDirectSoundBuffer_Play(pData->DSsbuffer, 0, 0, DSBPLAY_LOOPING); - - if(SUCCEEDED(hr)) { device->Format = format; SetDefaultWFXChannelOrder(device); |