dsound: Don't write more than three periods to IAudioClient.

Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Andrew Eikum 2017-01-03 11:08:10 -06:00 committed by Alexandre Julliard
parent 046fc19cd1
commit 0190c50a8c
1 changed files with 11 additions and 8 deletions

View File

@ -296,12 +296,12 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
{ {
HRESULT hres; HRESULT hres;
REFERENCE_TIME period; REFERENCE_TIME period;
UINT32 frames; UINT32 acbuf_frames, aclen_frames;
DWORD period_ms; DWORD period_ms;
IAudioClient *client = NULL; IAudioClient *client = NULL;
IAudioRenderClient *render = NULL; IAudioRenderClient *render = NULL;
IAudioStreamVolume *volume = NULL; IAudioStreamVolume *volume = NULL;
DWORD fraglen; DWORD frag_frames;
WAVEFORMATEX *wfx = NULL; WAVEFORMATEX *wfx = NULL;
DWORD oldspeakerconfig = device->speaker_config; DWORD oldspeakerconfig = device->speaker_config;
@ -350,17 +350,20 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
WARN("GetStreamLatency failed with %08x\n", hres); WARN("GetStreamLatency failed with %08x\n", hres);
goto err; goto err;
} }
hres = IAudioClient_GetBufferSize(client, &frames); hres = IAudioClient_GetBufferSize(client, &acbuf_frames);
if (FAILED(hres)) { if (FAILED(hres)) {
WARN("GetBufferSize failed with %08x\n", hres); WARN("GetBufferSize failed with %08x\n", hres);
goto err; goto err;
} }
period_ms = (period + 9999) / 10000; period_ms = (period + 9999) / 10000;
fraglen = MulDiv(wfx->nSamplesPerSec, period, 10000000) * wfx->nBlockAlign; frag_frames = MulDiv(wfx->nSamplesPerSec, period, 10000000);
TRACE("period %u ms fraglen %u buflen %u\n", period_ms, fraglen, frames * wfx->nBlockAlign);
hres = DSOUND_PrimaryOpen(device, wfx, frames, forcewave); aclen_frames = min(acbuf_frames, 3 * frag_frames);
TRACE("period %u ms fraglen %u buflen %u\n", period_ms, frag_frames * wfx->nBlockAlign, aclen_frames * wfx->nBlockAlign);
hres = DSOUND_PrimaryOpen(device, wfx, aclen_frames, forcewave);
if(FAILED(hres)) if(FAILED(hres))
goto err; goto err;
@ -368,8 +371,8 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
device->client = client; device->client = client;
device->render = render; device->render = render;
device->volume = volume; device->volume = volume;
device->fraglen = fraglen; device->fraglen = frag_frames * wfx->nBlockAlign;
device->aclen = frames * wfx->nBlockAlign; device->aclen = aclen_frames * wfx->nBlockAlign;
if (period_ms < 3) if (period_ms < 3)
device->sleeptime = 5; device->sleeptime = 5;