From: Mark Harmstone Subject: [PATCH 3/3] dsound: Keep track of locked bytes. Message-Id: <54EFB84A.3080907@burntcomma.com> Date: Fri, 27 Feb 2015 00:20:26 +0000 Changes dsound so that it keeps a count of locked bytes. This is needed for SetFX, which throws an error if the buffer is not completely unlocked. --- dlls/dsound/buffer.c | 17 ++++++++++++++++- dlls/dsound/dsound_private.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index b1eb9a3..680075e 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -519,16 +519,20 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8 *iface, DW TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor); TRACE("->%d.0\n",writebytes); + This->buffer->lockedbytes += writebytes; } else { DWORD remainder = writebytes + writecursor - This->buflen; *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor; *audiobytes1 = This->buflen-writecursor; + This->buffer->lockedbytes += *audiobytes1; if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING) WARN("Overwriting mixing position, case 2\n"); if (lplpaudioptr2) *(LPBYTE*)lplpaudioptr2 = This->buffer->memory; - if (audiobytes2) + if (audiobytes2) { *audiobytes2 = writebytes-(This->buflen-writecursor); + This->buffer->lockedbytes += *audiobytes2; + } if (audiobytes2 && This->sec_mixpos < remainder && This->state == STATE_PLAYING) WARN("Overwriting mixing position, case 3\n"); TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor); @@ -644,7 +648,17 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface, { if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen) hres = DSERR_INVALIDPARAM; + else + iter->buffer->lockedbytes -= x1; } + + if (x2) + { + if(x2 + (DWORD_PTR)p2 - (DWORD_PTR)iter->buffer->memory > iter->buflen) + hres = DSERR_INVALIDPARAM; + else + iter->buffer->lockedbytes -= x2; + } RtlReleaseResource(&iter->lock); } RtlReleaseResource(&This->device->buffer_list_lock); @@ -927,6 +941,7 @@ HRESULT IDirectSoundBufferImpl_Create( } dsb->buffer->ref = 1; + dsb->buffer->lockedbytes = 0; list_init(&dsb->buffer->buffers); list_add_head(&dsb->buffer->buffers, &dsb->entry); FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0); diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index 3de0068..715c5f3 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -107,6 +107,7 @@ struct DirectSoundDevice typedef struct BufferMemory { LONG ref; + LONG lockedbytes; LPBYTE memory; struct list buffers; } BufferMemory;