Commit a9a80b56 authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

dsound: Stricter validation for formats in secondary buffers.

parent 80428310
......@@ -470,17 +470,32 @@ static HRESULT DirectSoundDevice_CreateSoundBuffer(
}
} else {
IDirectSoundBufferImpl * dsb;
WAVEFORMATEXTENSIBLE *pwfxe;
if (dsbd->lpwfxFormat == NULL) {
WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
"secondary buffer\n");
return DSERR_INVALIDPARAM;
}
pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
if (pwfxe->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
if(dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_PCM &&
dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_IEEE_FLOAT &&
dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_EXTENSIBLE) {
WARN("We can't mix this format: 0x%x\n", dsbd->lpwfxFormat->wFormatTag);
return E_NOTIMPL;
}
if(dsbd->lpwfxFormat->wBitsPerSample < 8 || dsbd->lpwfxFormat->wBitsPerSample % 8 != 0 ||
dsbd->lpwfxFormat->nChannels == 0 || dsbd->lpwfxFormat->nSamplesPerSec == 0 ||
dsbd->lpwfxFormat->nAvgBytesPerSec == 0 ||
dsbd->lpwfxFormat->nBlockAlign != dsbd->lpwfxFormat->nChannels * dsbd->lpwfxFormat->wBitsPerSample / 8) {
WARN("Format inconsistency\n");
return DSERR_INVALIDPARAM;
}
if (dsbd->lpwfxFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
{
WAVEFORMATEXTENSIBLE *pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
/* check if cbSize is at least 22 bytes */
if (pwfxe->Format.cbSize < (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
{
......@@ -510,8 +525,7 @@ static HRESULT DirectSoundDevice_CreateSoundBuffer(
}
if (pwfxe->Samples.wValidBitsPerSample && pwfxe->Samples.wValidBitsPerSample < dsbd->lpwfxFormat->wBitsPerSample)
{
FIXME("Non-packed formats not supported right now: %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
return DSERR_CONTROLUNAVAIL;
WARN("Non-packed formats may not function : %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
}
}
......
......@@ -1233,39 +1233,36 @@ EXIT:
return rc;
}
static HRESULT test_invalid_fmts(LPGUID lpGuid)
static HRESULT do_invalid_fmt_test(IDirectSound *dso,
IDirectSoundBuffer *buf, WAVEFORMATEX *wfx, IDirectSoundBuffer **out_buf)
{
HRESULT rc;
LPDIRECTSOUND dso=NULL;
LPDIRECTSOUNDBUFFER primary=NULL;
*out_buf = NULL;
if(!buf){
DSBUFFERDESC bufdesc;
/* Create the DirectSound object */
rc=pDirectSoundCreate(lpGuid,&dso,NULL);
ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
"DirectSoundCreate() failed: %08x\n",rc);
if (rc!=DS_OK)
return rc;
/* We must call SetCooperativeLevel before creating primary buffer */
/* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
if (rc!=DS_OK){
IDirectSound_Release(dso);
return rc;
}
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
"to create a primary buffer %08x\n",rc);
bufdesc.dwSize = sizeof(bufdesc);
bufdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY;
bufdesc.dwBufferBytes = 4096;
bufdesc.lpwfxFormat = wfx;
rc = IDirectSound_CreateSoundBuffer(dso, &bufdesc, out_buf, NULL);
}else{
rc = IDirectSoundBuffer_SetFormat(buf, wfx);
if(SUCCEEDED(rc)){
IDirectSoundBuffer_AddRef(buf);
*out_buf = buf;
}
}
return rc;
}
if (rc==DS_OK && primary!=NULL) {
/* if no buffer is given, use CreateSoundBuffer instead of SetFormat */
static void perform_invalid_fmt_tests(const char *testname, IDirectSound *dso, IDirectSoundBuffer *buf)
{
WAVEFORMATEX wfx;
WAVEFORMATEXTENSIBLE fmtex;
HRESULT rc;
IDirectSoundBuffer *got_buf;
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 0;
......@@ -1273,123 +1270,126 @@ static HRESULT test_invalid_fmts(LPGUID lpGuid)
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 0;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 2;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 12;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 0;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = 0;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = 0;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample / 8) - 1;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample / 8) + 1;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign + 1;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == S_OK, "SetFormat: %08x\n", rc);
rc = IDirectSoundBuffer_GetFormat(primary, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "GetFormat: %08x\n", rc);
ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "format: 0x%x\n", wfx.wFormatTag);
ok(wfx.nChannels == 2, "channels: %u\n", wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "rate: %u\n", wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "bps: %u\n", wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "blockalign: %u\n", wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4 + 1, "avgbytes: %u\n", wfx.nAvgBytesPerSec);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4 + 1, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
IDirectSoundBuffer_Release(got_buf);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign - 1;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == S_OK, "SetFormat: %08x\n", rc);
rc = IDirectSoundBuffer_GetFormat(primary, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "GetFormat: %08x\n", rc);
ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "format: 0x%x\n", wfx.wFormatTag);
ok(wfx.nChannels == 2, "channels: %u\n", wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "rate: %u\n", wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "bps: %u\n", wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "blockalign: %u\n", wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4 - 1, "avgbytes: %u\n", wfx.nAvgBytesPerSec);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4 - 1, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
IDirectSoundBuffer_Release(got_buf);
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign + 1;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == S_OK, "SetFormat: %08x\n", rc);
rc = IDirectSoundBuffer_GetFormat(primary, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "GetFormat: %08x\n", rc);
ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "format: 0x%x\n", wfx.wFormatTag);
ok(wfx.nChannels == 2, "channels: %u\n", wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "rate: %u\n", wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "bps: %u\n", wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "blockalign: %u\n", wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4 + 1, "avgbytes: %u\n", wfx.nAvgBytesPerSec);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4 + 1, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
IDirectSoundBuffer_Release(got_buf);
wfx.wFormatTag = WAVE_FORMAT_ALAW;
wfx.nChannels = 2;
......@@ -1397,21 +1397,24 @@ static HRESULT test_invalid_fmts(LPGUID lpGuid)
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
ok(rc == S_OK, "SetFormat: %08x\n", rc);
rc = IDirectSoundBuffer_GetFormat(primary, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "GetFormat: %08x\n", rc);
ok(wfx.wFormatTag == WAVE_FORMAT_ALAW, "format: 0x%x\n", wfx.wFormatTag);
ok(wfx.nChannels == 2, "channels: %u\n", wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "rate: %u\n", wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "bps: %u\n", wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "blockalign: %u\n", wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4, "avgbytes: %u\n", wfx.nAvgBytesPerSec);
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
ok(buf ? rc == S_OK : (rc == E_NOTIMPL || rc == DSERR_INVALIDCALL /* winxp */), "%s: SetFormat: %08x\n", testname, rc);
if(got_buf){
rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
ok(wfx.wFormatTag == WAVE_FORMAT_ALAW, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
ok(wfx.nAvgBytesPerSec == 44100 * 4, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
IDirectSoundBuffer_Release(got_buf);
}
if(!gotdx8){
win_skip("Not doing the WAVE_FORMAT_EXTENSIBLE tests\n");
goto done;
return;
}
fmtex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
......@@ -1424,21 +1427,22 @@ static HRESULT test_invalid_fmts(LPGUID lpGuid)
fmtex.Samples.wValidBitsPerSample = 0;
fmtex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
fmtex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
rc = IDirectSoundBuffer_SetFormat(primary, (WAVEFORMATEX*)&fmtex);
ok(rc == S_OK, "SetFormat: %08x\n", rc);
rc = IDirectSoundBuffer_GetFormat(primary, (WAVEFORMATEX*)&fmtex, sizeof(fmtex), NULL);
ok(rc == S_OK, "GetFormat: %08x\n", rc);
ok(fmtex.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "format: 0x%x\n", fmtex.Format.wFormatTag);
ok(fmtex.Format.nChannels == 2, "channels: %u\n", fmtex.Format.nChannels);
ok(fmtex.Format.nSamplesPerSec == 44100, "rate: %u\n", fmtex.Format.nSamplesPerSec);
ok(fmtex.Format.wBitsPerSample == 16, "bps: %u\n", fmtex.Format.wBitsPerSample);
ok(fmtex.Format.nBlockAlign == 4, "blockalign: %u\n", fmtex.Format.nBlockAlign);
ok(fmtex.Format.nAvgBytesPerSec == 44100 * 4, "avgbytes: %u\n", fmtex.Format.nAvgBytesPerSec);
rc = do_invalid_fmt_test(dso, buf, (WAVEFORMATEX*)&fmtex, &got_buf);
ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
rc = IDirectSoundBuffer_GetFormat(got_buf, (WAVEFORMATEX*)&fmtex, sizeof(fmtex), NULL);
ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
ok(fmtex.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "%s: format: 0x%x\n", testname, fmtex.Format.wFormatTag);
ok(fmtex.Format.nChannels == 2, "%s: channels: %u\n", testname, fmtex.Format.nChannels);
ok(fmtex.Format.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, fmtex.Format.nSamplesPerSec);
ok(fmtex.Format.wBitsPerSample == 16, "%s: bps: %u\n", testname, fmtex.Format.wBitsPerSample);
ok(fmtex.Format.nBlockAlign == 4, "%s: blockalign: %u\n", testname, fmtex.Format.nBlockAlign);
ok(fmtex.Format.nAvgBytesPerSec == 44100 * 4, "%s: avgbytes: %u\n", testname, fmtex.Format.nAvgBytesPerSec);
ok(fmtex.Samples.wValidBitsPerSample == 0 || /* <= XP */
fmtex.Samples.wValidBitsPerSample == 16, /* >= Vista */
"validbits: %u\n", fmtex.Samples.wValidBitsPerSample);
ok(IsEqualGUID(&fmtex.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM), "subtype incorrect\n");
"%s: validbits: %u\n", testname, fmtex.Samples.wValidBitsPerSample);
ok(IsEqualGUID(&fmtex.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM), "%s: subtype incorrect\n", testname);
IDirectSoundBuffer_Release(got_buf);
fmtex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
fmtex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
......@@ -1450,19 +1454,20 @@ static HRESULT test_invalid_fmts(LPGUID lpGuid)
fmtex.Samples.wValidBitsPerSample = 20;
fmtex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
fmtex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
rc = IDirectSoundBuffer_SetFormat(primary, (WAVEFORMATEX*)&fmtex);
ok(rc == S_OK, "SetFormat: %08x\n", rc);
rc = IDirectSoundBuffer_GetFormat(primary, (WAVEFORMATEX*)&fmtex, sizeof(fmtex), NULL);
ok(rc == S_OK, "GetFormat: %08x\n", rc);
ok(fmtex.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "format: 0x%x\n", fmtex.Format.wFormatTag);
ok(fmtex.Format.nChannels == 2, "channels: %u\n", fmtex.Format.nChannels);
ok(fmtex.Format.nSamplesPerSec == 44100, "rate: %u\n", fmtex.Format.nSamplesPerSec);
ok(fmtex.Format.wBitsPerSample == 24, "bps: %u\n", fmtex.Format.wBitsPerSample);
ok(fmtex.Format.nBlockAlign == 6, "blockalign: %u\n", fmtex.Format.nBlockAlign);
ok(fmtex.Format.nAvgBytesPerSec == 44100 * 6, "avgbytes: %u\n", fmtex.Format.nAvgBytesPerSec);
ok(fmtex.Samples.wValidBitsPerSample == 20, "validbits: %u\n", fmtex.Samples.wValidBitsPerSample);
ok(IsEqualGUID(&fmtex.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM), "subtype incorrect\n");
rc = do_invalid_fmt_test(dso, buf, (WAVEFORMATEX*)&fmtex, &got_buf);
ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
rc = IDirectSoundBuffer_GetFormat(got_buf, (WAVEFORMATEX*)&fmtex, sizeof(fmtex), NULL);
ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
ok(fmtex.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "%s: format: 0x%x\n", testname, fmtex.Format.wFormatTag);
ok(fmtex.Format.nChannels == 2, "%s: channels: %u\n", testname, fmtex.Format.nChannels);
ok(fmtex.Format.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, fmtex.Format.nSamplesPerSec);
ok(fmtex.Format.wBitsPerSample == 24, "%s: bps: %u\n", testname, fmtex.Format.wBitsPerSample);
ok(fmtex.Format.nBlockAlign == 6, "%s: blockalign: %u\n", testname, fmtex.Format.nBlockAlign);
ok(fmtex.Format.nAvgBytesPerSec == 44100 * 6, "%s: avgbytes: %u\n", testname, fmtex.Format.nAvgBytesPerSec);
ok(fmtex.Samples.wValidBitsPerSample == 20, "%s: validbits: %u\n", testname, fmtex.Samples.wValidBitsPerSample);
ok(IsEqualGUID(&fmtex.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM), "%s: subtype incorrect\n", testname);
IDirectSoundBuffer_Release(got_buf);
fmtex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
fmtex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
......@@ -1474,13 +1479,46 @@ static HRESULT test_invalid_fmts(LPGUID lpGuid)
fmtex.Samples.wValidBitsPerSample = 32;
fmtex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
fmtex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
rc = IDirectSoundBuffer_SetFormat(primary, (WAVEFORMATEX*)&fmtex);
ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
rc = do_invalid_fmt_test(dso, buf, (WAVEFORMATEX*)&fmtex, &got_buf);
ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
}
IDirectSoundBuffer_Release(primary);
static HRESULT test_invalid_fmts(LPGUID lpGuid)
{
HRESULT rc;
LPDIRECTSOUND dso=NULL;
LPDIRECTSOUNDBUFFER buffer=NULL;
DSBUFFERDESC bufdesc;
/* Create the DirectSound object */
rc=pDirectSoundCreate(lpGuid,&dso,NULL);
ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
"DirectSoundCreate() failed: %08x\n",rc);
if (rc!=DS_OK)
return rc;
/* We must call SetCooperativeLevel before creating primary buffer */
/* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
if (rc!=DS_OK){
IDirectSound_Release(dso);
return rc;
}
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&buffer,NULL);
ok(rc==DS_OK && buffer!=NULL,"IDirectSound_CreateSoundBuffer() failed "
"to create a primary buffer %08x\n",rc);
if (rc==DS_OK && buffer!=NULL) {
perform_invalid_fmt_tests("primary", dso, buffer);
IDirectSoundBuffer_Release(buffer);
}
done:
perform_invalid_fmt_tests("secondary", dso, NULL);
IDirectSound_Release(dso);
return S_OK;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment