Module: wine Branch: master Commit: 7e334a7a945c1c89f6a4b40d010b30a820176ee3 URL: https://gitlab.winehq.org/wine/wine/-/commit/7e334a7a945c1c89f6a4b40d010b30a...
Author: Anton Baskanov baskanov@gmail.com Date: Sun Apr 23 18:05:43 2023 +0700
dsound: Allocate big enough committedbuff up front.
---
dlls/dsound/buffer.c | 15 +++------------ dlls/dsound/dsound_private.h | 2 +- dlls/dsound/mixer.c | 1 + 3 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index 403c88c2c95..7b830604a60 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -264,7 +264,6 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *i { IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface); DWORD oldFreq; - void *newcommitted;
TRACE("(%p,%ld)\n",This,freq);
@@ -290,17 +289,9 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *i
oldFreq = This->freq; This->freq = freq; - if (freq != oldFreq) { + if (freq != oldFreq) DSOUND_RecalcFormat(This);
- newcommitted = realloc(This->committedbuff, This->writelead); - if(!newcommitted) { - ReleaseSRWLockExclusive(&This->lock); - return DSERR_OUTOFMEMORY; - } - This->committedbuff = newcommitted; - } - ReleaseSRWLockExclusive(&This->lock);
return DS_OK; @@ -1112,7 +1103,7 @@ HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *ds /* calculate fragment size and write lead */ DSOUND_RecalcFormat(dsb);
- dsb->committedbuff = malloc(dsb->writelead); + dsb->committedbuff = malloc(dsb->maxwritelead); if(!dsb->committedbuff) { IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface); return DSERR_OUTOFMEMORY; @@ -1216,7 +1207,7 @@ HRESULT IDirectSoundBufferImpl_Duplicate( return DSERR_OUTOFMEMORY; }
- committedbuff = malloc(pdsb->writelead); + committedbuff = malloc(pdsb->maxwritelead); if (committedbuff == NULL) { free(dsb); *ppdsb = NULL; diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index 4d8cf84385d..d9f488c25b8 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -140,7 +140,7 @@ struct IDirectSoundBufferImpl PWAVEFORMATEX pwfx; BufferMemory* buffer; DWORD playflags,state,leadin; - DWORD writelead,buflen; + DWORD writelead,maxwritelead,buflen; DWORD freq; DSVOLUMEPAN volpan; DSBUFFERDESC dsbd; diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index 4d0c54735cf..bf05805221b 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -130,6 +130,7 @@ void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb)
/* calculate the 10ms write lead */ dsb->writelead = (dsb->freq / 100) * dsb->pwfx->nBlockAlign; + dsb->maxwritelead = (DSBFREQUENCY_MAX / 100) * dsb->pwfx->nBlockAlign;
if (oldFreqAdjustDen) dsb->freqAccNum = (dsb->freqAccNum * dsb->freqAdjustDen + oldFreqAdjustDen / 2) / oldFreqAdjustDen;