From: Giovanni Mascellani gmascellani@codeweavers.com
So that the format selection happens before actual testing, in such a way that actual testing is then easy to move to a helper function. --- dlls/mmdevapi/tests/render.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/dlls/mmdevapi/tests/render.c b/dlls/mmdevapi/tests/render.c index 9ac82a65400..bce0a37750d 100644 --- a/dlls/mmdevapi/tests/render.c +++ b/dlls/mmdevapi/tests/render.c @@ -523,15 +523,6 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) for (k = 0; k < ARRAY_SIZE(sample_formats); k++) { char format_chr[3];
- hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - continue; - - hr = IAudioClient_GetMixFormat(ac, &pwfx); - ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); - fmt.Format.wFormatTag = extensible ? WAVE_FORMAT_EXTENSIBLE : sample_formats[k][0]; fmt.Format.nSamplesPerSec = sampling_rates[i]; fmt.Format.wBitsPerSample = sample_formats[k][1]; @@ -540,8 +531,6 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) fmt.Format.nAvgBytesPerSec= fmt.Format.nBlockAlign * fmt.Format.nSamplesPerSec;
if (extensible) { - WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; - fmt.Samples.wValidBitsPerSample = fmt.Format.wBitsPerSample; switch (fmt.Format.nChannels) { case 1: fmt.dwChannelMask = KSAUDIO_SPEAKER_MONO; break; @@ -550,11 +539,6 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) case 6: fmt.dwChannelMask = KSAUDIO_SPEAKER_5POINT1; break; case 8: fmt.dwChannelMask = KSAUDIO_SPEAKER_7POINT1_SURROUND; break; } - /* We don't want to fight with the driver over the speaker configuration, - * so just take whatever they give us, if it's valid. */ - if (fmt.Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE - && pxwfx->dwChannelMask != 0) - fmt.dwChannelMask = pxwfx->dwChannelMask; fmt.SubFormat = sample_formats[k][0] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; } @@ -563,6 +547,25 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) format_chr[1] = extensible ? 'X' : '\0'; format_chr[2] = '\0';
+ hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + continue; + + hr = IAudioClient_GetMixFormat(ac, &pwfx); + ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); + + if (extensible) { + WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; + + /* We don't want to fight with the driver over the speaker configuration, + * so just take whatever they give us, if it's valid. */ + if (fmt.Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE + && pxwfx->dwChannelMask != 0) + fmt.dwChannelMask = pxwfx->dwChannelMask; + } + pwfx2 = (WAVEFORMATEX*)0xDEADF00D; hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)&fmt, &pwfx2); hrs = hr;
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/mmdevapi/tests/render.c | 64 +++++++++++++++++------------------- 1 file changed, 31 insertions(+), 33 deletions(-)
diff --git a/dlls/mmdevapi/tests/render.c b/dlls/mmdevapi/tests/render.c index bce0a37750d..cfeb76a144d 100644 --- a/dlls/mmdevapi/tests/render.c +++ b/dlls/mmdevapi/tests/render.c @@ -518,11 +518,11 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible)
fmt.Format.cbSize = extensible ? sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) : 0;
+ winetest_push_context("%s", mode == AUDCLNT_SHAREMODE_SHARED ? "shared" : "exclusive"); + for (i = 0; i < ARRAY_SIZE(sampling_rates); i++) { for (j = 0; j < ARRAY_SIZE(channel_counts); j++) { for (k = 0; k < ARRAY_SIZE(sample_formats); k++) { - char format_chr[3]; - fmt.Format.wFormatTag = extensible ? WAVE_FORMAT_EXTENSIBLE : sample_formats[k][0]; fmt.Format.nSamplesPerSec = sampling_rates[i]; fmt.Format.wBitsPerSample = sample_formats[k][1]; @@ -543,15 +543,18 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; }
- format_chr[0] = sample_formats[k][0] == WAVE_FORMAT_PCM ? 'P' : 'F'; - format_chr[1] = extensible ? 'X' : '\0'; - format_chr[2] = '\0'; + winetest_push_context("%c%s%lux%ux%u", sample_formats[k][0] == WAVE_FORMAT_PCM ? 'P' : 'F', + extensible ? "X" : "", fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, + fmt.Format.nChannels);
hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08lx\n", hr); if(hr != S_OK) + { + winetest_pop_context(); continue; + }
hr = IAudioClient_GetMixFormat(ac, &pwfx); ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); @@ -570,9 +573,7 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)&fmt, &pwfx2); hrs = hr; if (hr == S_OK) - trace("IsSupported(%s, %s%lux%2ux%u)\n", - mode == AUDCLNT_SHAREMODE_SHARED ? "shared " : "exclus.", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels); + trace("IsFormatSupported() is true\n");
/* In shared mode you can only change bit width, not sampling rate or channel count. */ if (mode == AUDCLNT_SHAREMODE_SHARED) { @@ -581,12 +582,10 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) if (fmt.Format.nChannels > 2 && !extensible) expected = AUDCLNT_E_UNSUPPORTED_FORMAT; todo_wine_if(hr != expected) - ok(hr == expected, "IsFormatSupported(shared, %s%lux%2ux%u) returns %08lx, expected %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, expected); + ok(hr == expected, "IsFormatSupported() returns %08lx, expected %08lx\n", hr, expected); } else { ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == hexcl, - "IsFormatSupported(exclusive, %s%lux%2ux%u) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + "IsFormatSupported() returns %08lx\n", hr); }
/* Only shared mode suggests something ... GetMixFormat! */ @@ -596,34 +595,28 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) pwfx2->nSamplesPerSec == pwfx->nSamplesPerSec && pwfx2->nChannels == pwfx->nChannels && pwfx2->wBitsPerSample == pwfx->wBitsPerSample, - "Suggestion %s%lux%2ux%u differs from GetMixFormat\n", - format_chr, pwfx2->nSamplesPerSec, pwfx2->wBitsPerSample, pwfx2->nChannels); + "Closest match differs from GetMixFormat\n"); }
hr = IAudioClient_Initialize(ac, mode, 0, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); if ((hrs == S_OK) ^ (hr == S_OK)) - trace("Initialize (%s, %s%lux%2ux%u) returns %08lx unlike IsFormatSupported\n", - mode == AUDCLNT_SHAREMODE_SHARED ? "shared " : "exclus.", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + trace("Initialize() returns %08lx unlike IsFormatSupported\n", hr); if (mode == AUDCLNT_SHAREMODE_SHARED) { expected = hrs == S_OK ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; if (fmt.Format.nChannels > 2 && !extensible) expected = E_INVALIDARG; todo_wine_if(fmt.Format.nChannels > 2 && !extensible) - ok(hr == expected, "Initialize(shared, %s%lux%2ux%u) returns %08lx, expected %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, expected); + ok(hr == expected, "Initialize() returns %08lx, expected %08lx\n", hr, expected); } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) /* Unsupported format implies "create failed" and shadows "not allowed" */ ok(hrs == hexcl && (hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs), - "Initialize(noexcl., %s%lux%2ux%u) returns %08lx(%08lx)\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, hrs); + "Initialize() returns %08lx(%08lx)\n", hr, hrs); else /* For some drivers Initialize() doesn't match IsFormatSupported(). */ ok(hrs == S_OK ? hr == S_OK || broken(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED) : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || (hr == E_INVALIDARG && fmt.Format.nChannels > 2 && !extensible) || broken(hr == S_OK), - "Initialize(exclus., %s%lux%2ux%u) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + "Initialize() returns %08lx\n", hr);
IAudioClient_Release(ac);
@@ -631,7 +624,10 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08lx\n", hr); if(hr != S_OK) + { + winetest_pop_context(); continue; + }
/* With AUDCLNT_STREAMFLAGS_RATEADJUST channel count must match, but sampling rate doesn't. */ hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_RATEADJUST, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); @@ -641,20 +637,17 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) if (fmt.Format.nChannels > 2 && !extensible) expected = E_INVALIDARG; todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(shared, %s%lux%2ux%u, RATEADJUST) returns %08lx, expected %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, expected); + ok(hr == expected, "Initialize(RATEADJUST) returns %08lx, expected %08lx\n", hr, expected); } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) /* Unsupported format implies "create failed" and shadows "not allowed" */ ok(hrs == hexcl && (hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs), - "Initialize(noexcl., %s%lux%2ux%u, RATEADJUST) returns %08lx(%08lx)\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, hrs); + "Initialize(RATEADJUST) returns %08lx(%08lx)\n", hr, hrs); else /* For some drivers Initialize() doesn't match IsFormatSupported(). */ ok(hrs == S_OK ? hr == S_OK || broken(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED) : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || (hr == E_INVALIDARG && fmt.Format.nChannels > 2 && !extensible) || broken(hr == S_OK), - "Initialize(exclus., %s%lux%2ux%u, RATEADJUST) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + "Initialize(RATEADJUST) returns %08lx\n", hr);
IAudioClient_Release(ac);
@@ -662,19 +655,20 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08lx\n", hr); if(hr != S_OK) + { + winetest_pop_context(); continue; + }
/* With AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM it always succeeds. */ hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); if (mode == AUDCLNT_SHAREMODE_SHARED) { expected = fmt.Format.nChannels <= 2 || extensible ? S_OK : E_INVALIDARG; todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(shared, %s%lux%2ux%u, AUTOCONVERTPCM) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + ok(hr == expected, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); } else { todo_wine_if(hr != E_INVALIDARG) - ok(hr == E_INVALIDARG, "Initialize(exclus., %s%lux%2ux%u, AUTOCONVERTPCM) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + ok(hr == E_INVALIDARG, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); }
/* Bug in native (Vista/w2k8/w7): after Initialize failed, better @@ -687,9 +681,13 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) CoTaskMemFree(pwfx2); CoTaskMemFree(pwfx); IAudioClient_Release(ac); + + winetest_pop_context(); } } } + + winetest_pop_context(); }
static void test_references(void)
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/mmdevapi/tests/render.c | 271 +++++++++++++++++------------------ 1 file changed, 135 insertions(+), 136 deletions(-)
diff --git a/dlls/mmdevapi/tests/render.c b/dlls/mmdevapi/tests/render.c index cfeb76a144d..a1c733cd368 100644 --- a/dlls/mmdevapi/tests/render.c +++ b/dlls/mmdevapi/tests/render.c @@ -507,14 +507,146 @@ cleanup: CoTaskMemFree(pwfx); }
-static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) +static void test_format(AUDCLNT_SHAREMODE mode, WAVEFORMATEXTENSIBLE *fmt) { IAudioClient *ac; HRESULT hr, hrs, expected; WAVEFORMATEX *pwfx, *pwfx2; + BOOL compatible, extensible; + + extensible = fmt->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE; + + hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + return; + + hr = IAudioClient_GetMixFormat(ac, &pwfx); + ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); + + if (extensible) { + WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; + + /* We don't want to fight with the driver over the speaker configuration, + * so just take whatever they give us, if it's valid. */ + if (fmt->Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE + && pxwfx->dwChannelMask != 0) + fmt->dwChannelMask = pxwfx->dwChannelMask; + } + + pwfx2 = (WAVEFORMATEX*)0xDEADF00D; + hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)fmt, &pwfx2); + hrs = hr; + if (hr == S_OK) + trace("IsFormatSupported() is true\n"); + + /* In shared mode you can only change bit width, not sampling rate or channel count. */ + if (mode == AUDCLNT_SHAREMODE_SHARED) { + compatible = fmt->Format.nSamplesPerSec == pwfx->nSamplesPerSec && fmt->Format.nChannels == pwfx->nChannels; + expected = compatible ? S_OK : S_FALSE; + if (fmt->Format.nChannels > 2 && !extensible) + expected = AUDCLNT_E_UNSUPPORTED_FORMAT; + todo_wine_if(hr != expected) + ok(hr == expected, "IsFormatSupported() returns %08lx, expected %08lx\n", hr, expected); + } else { + ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == hexcl, + "IsFormatSupported() returns %08lx\n", hr); + } + + /* Only shared mode suggests something ... GetMixFormat! */ + ok((hr == S_FALSE)^(pwfx2 == NULL), "hr %lx<->suggest %p\n", hr, pwfx2); + if (pwfx2) { + ok(pwfx2->wFormatTag == pwfx->wFormatTag && + pwfx2->nSamplesPerSec == pwfx->nSamplesPerSec && + pwfx2->nChannels == pwfx->nChannels && + pwfx2->wBitsPerSample == pwfx->wBitsPerSample, + "Closest match differs from GetMixFormat\n"); + } + + hr = IAudioClient_Initialize(ac, mode, 0, 5000000, 0, (WAVEFORMATEX*)fmt, NULL); + if ((hrs == S_OK) ^ (hr == S_OK)) + trace("Initialize() returns %08lx unlike IsFormatSupported\n", hr); + if (mode == AUDCLNT_SHAREMODE_SHARED) { + expected = hrs == S_OK ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; + if (fmt->Format.nChannels > 2 && !extensible) + expected = E_INVALIDARG; + todo_wine_if(fmt->Format.nChannels > 2 && !extensible) + ok(hr == expected, "Initialize() returns %08lx, expected %08lx\n", hr, expected); + } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) + /* Unsupported format implies "create failed" and shadows "not allowed" */ + ok(hrs == hexcl && (hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs), + "Initialize() returns %08lx(%08lx)\n", hr, hrs); + else + /* For some drivers Initialize() doesn't match IsFormatSupported(). */ + ok(hrs == S_OK ? hr == S_OK || broken(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED) + : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || + (hr == E_INVALIDARG && fmt->Format.nChannels > 2 && !extensible) || broken(hr == S_OK), + "Initialize() returns %08lx\n", hr); + + IAudioClient_Release(ac); + + hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + return; + + /* With AUDCLNT_STREAMFLAGS_RATEADJUST channel count must match, but sampling rate doesn't. */ + hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_RATEADJUST, 5000000, 0, (WAVEFORMATEX*)fmt, NULL); + if (mode == AUDCLNT_SHAREMODE_SHARED) { + compatible = fmt->Format.nChannels == pwfx->nChannels; + expected = compatible ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; + if (fmt->Format.nChannels > 2 && !extensible) + expected = E_INVALIDARG; + todo_wine_if(hr != expected) + ok(hr == expected, "Initialize(RATEADJUST) returns %08lx, expected %08lx\n", hr, expected); + } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) + /* Unsupported format implies "create failed" and shadows "not allowed" */ + ok(hrs == hexcl && (hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs), + "Initialize(RATEADJUST) returns %08lx(%08lx)\n", hr, hrs); + else + /* For some drivers Initialize() doesn't match IsFormatSupported(). */ + ok(hrs == S_OK ? hr == S_OK || broken(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED) + : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || + (hr == E_INVALIDARG && fmt->Format.nChannels > 2 && !extensible) || broken(hr == S_OK), + "Initialize(RATEADJUST) returns %08lx\n", hr); + + IAudioClient_Release(ac); + + hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + return; + + /* With AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM it always succeeds. */ + hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM, 5000000, 0, (WAVEFORMATEX*)fmt, NULL); + if (mode == AUDCLNT_SHAREMODE_SHARED) { + expected = fmt->Format.nChannels <= 2 || extensible ? S_OK : E_INVALIDARG; + todo_wine_if(hr != expected) + ok(hr == expected, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); + } else { + todo_wine_if(hr != E_INVALIDARG) + ok(hr == E_INVALIDARG, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); + } + + /* Bug in native (Vista/w2k8/w7): after Initialize failed, better + * Release this ac and Activate a new one. + * A second call (with a known working format) would yield + * ALREADY_INITIALIZED in shared mode yet be unusable, and in exclusive + * mode some entity keeps a lock on the device, causing DEVICE_IN_USE to + * all subsequent calls until the audio engine service is restarted. */ + + CoTaskMemFree(pwfx2); + CoTaskMemFree(pwfx); + IAudioClient_Release(ac); +} + +static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) +{ WAVEFORMATEXTENSIBLE fmt; int i, j, k; - BOOL compatible;
fmt.Format.cbSize = extensible ? sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) : 0;
@@ -547,140 +679,7 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) extensible ? "X" : "", fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels);
- hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - { - winetest_pop_context(); - continue; - } - - hr = IAudioClient_GetMixFormat(ac, &pwfx); - ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); - - if (extensible) { - WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; - - /* We don't want to fight with the driver over the speaker configuration, - * so just take whatever they give us, if it's valid. */ - if (fmt.Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE - && pxwfx->dwChannelMask != 0) - fmt.dwChannelMask = pxwfx->dwChannelMask; - } - - pwfx2 = (WAVEFORMATEX*)0xDEADF00D; - hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)&fmt, &pwfx2); - hrs = hr; - if (hr == S_OK) - trace("IsFormatSupported() is true\n"); - - /* In shared mode you can only change bit width, not sampling rate or channel count. */ - if (mode == AUDCLNT_SHAREMODE_SHARED) { - compatible = fmt.Format.nSamplesPerSec == pwfx->nSamplesPerSec && fmt.Format.nChannels == pwfx->nChannels; - expected = compatible ? S_OK : S_FALSE; - if (fmt.Format.nChannels > 2 && !extensible) - expected = AUDCLNT_E_UNSUPPORTED_FORMAT; - todo_wine_if(hr != expected) - ok(hr == expected, "IsFormatSupported() returns %08lx, expected %08lx\n", hr, expected); - } else { - ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == hexcl, - "IsFormatSupported() returns %08lx\n", hr); - } - - /* Only shared mode suggests something ... GetMixFormat! */ - ok((hr == S_FALSE)^(pwfx2 == NULL), "hr %lx<->suggest %p\n", hr, pwfx2); - if (pwfx2) { - ok(pwfx2->wFormatTag == pwfx->wFormatTag && - pwfx2->nSamplesPerSec == pwfx->nSamplesPerSec && - pwfx2->nChannels == pwfx->nChannels && - pwfx2->wBitsPerSample == pwfx->wBitsPerSample, - "Closest match differs from GetMixFormat\n"); - } - - hr = IAudioClient_Initialize(ac, mode, 0, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); - if ((hrs == S_OK) ^ (hr == S_OK)) - trace("Initialize() returns %08lx unlike IsFormatSupported\n", hr); - if (mode == AUDCLNT_SHAREMODE_SHARED) { - expected = hrs == S_OK ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; - if (fmt.Format.nChannels > 2 && !extensible) - expected = E_INVALIDARG; - todo_wine_if(fmt.Format.nChannels > 2 && !extensible) - ok(hr == expected, "Initialize() returns %08lx, expected %08lx\n", hr, expected); - } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) - /* Unsupported format implies "create failed" and shadows "not allowed" */ - ok(hrs == hexcl && (hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs), - "Initialize() returns %08lx(%08lx)\n", hr, hrs); - else - /* For some drivers Initialize() doesn't match IsFormatSupported(). */ - ok(hrs == S_OK ? hr == S_OK || broken(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED) - : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || - (hr == E_INVALIDARG && fmt.Format.nChannels > 2 && !extensible) || broken(hr == S_OK), - "Initialize() returns %08lx\n", hr); - - IAudioClient_Release(ac); - - hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - { - winetest_pop_context(); - continue; - } - - /* With AUDCLNT_STREAMFLAGS_RATEADJUST channel count must match, but sampling rate doesn't. */ - hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_RATEADJUST, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); - if (mode == AUDCLNT_SHAREMODE_SHARED) { - compatible = fmt.Format.nChannels == pwfx->nChannels; - expected = compatible ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; - if (fmt.Format.nChannels > 2 && !extensible) - expected = E_INVALIDARG; - todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(RATEADJUST) returns %08lx, expected %08lx\n", hr, expected); - } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) - /* Unsupported format implies "create failed" and shadows "not allowed" */ - ok(hrs == hexcl && (hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs), - "Initialize(RATEADJUST) returns %08lx(%08lx)\n", hr, hrs); - else - /* For some drivers Initialize() doesn't match IsFormatSupported(). */ - ok(hrs == S_OK ? hr == S_OK || broken(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED) - : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || - (hr == E_INVALIDARG && fmt.Format.nChannels > 2 && !extensible) || broken(hr == S_OK), - "Initialize(RATEADJUST) returns %08lx\n", hr); - - IAudioClient_Release(ac); - - hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - { - winetest_pop_context(); - continue; - } - - /* With AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM it always succeeds. */ - hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); - if (mode == AUDCLNT_SHAREMODE_SHARED) { - expected = fmt.Format.nChannels <= 2 || extensible ? S_OK : E_INVALIDARG; - todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); - } else { - todo_wine_if(hr != E_INVALIDARG) - ok(hr == E_INVALIDARG, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); - } - - /* Bug in native (Vista/w2k8/w7): after Initialize failed, better - * Release this ac and Activate a new one. - * A second call (with a known working format) would yield - * ALREADY_INITIALIZED in shared mode yet be unusable, and in exclusive - * mode some entity keeps a lock on the device, causing DEVICE_IN_USE to - * all subsequent calls until the audio engine service is restarted. */ - - CoTaskMemFree(pwfx2); - CoTaskMemFree(pwfx); - IAudioClient_Release(ac); + test_format(mode, &fmt);
winetest_pop_context(); }
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/mmdevapi/tests/capture.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/dlls/mmdevapi/tests/capture.c b/dlls/mmdevapi/tests/capture.c index 918a6d0c2f6..b02645f767c 100644 --- a/dlls/mmdevapi/tests/capture.c +++ b/dlls/mmdevapi/tests/capture.c @@ -575,15 +575,6 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) for (k = 0; k < ARRAY_SIZE(sample_formats); k++) { char format_chr[3];
- hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - continue; - - hr = IAudioClient_GetMixFormat(ac, &pwfx); - ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); - fmt.Format.wFormatTag = extensible ? WAVE_FORMAT_EXTENSIBLE : sample_formats[k][0]; fmt.Format.nSamplesPerSec = sampling_rates[i]; fmt.Format.wBitsPerSample = sample_formats[k][1]; @@ -592,8 +583,6 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) fmt.Format.nAvgBytesPerSec= fmt.Format.nBlockAlign * fmt.Format.nSamplesPerSec;
if (extensible) { - WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; - fmt.Samples.wValidBitsPerSample = fmt.Format.wBitsPerSample; switch (fmt.Format.nChannels) { case 1: fmt.dwChannelMask = KSAUDIO_SPEAKER_MONO; break; @@ -602,11 +591,6 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) case 6: fmt.dwChannelMask = KSAUDIO_SPEAKER_5POINT1; break; case 8: fmt.dwChannelMask = KSAUDIO_SPEAKER_7POINT1_SURROUND; break; } - /* We don't want to fight with the driver over the speaker configuration, - * so just take whatever they give us, if it's valid. */ - if (fmt.Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE - && pxwfx->dwChannelMask != 0) - fmt.dwChannelMask = ((WAVEFORMATEXTENSIBLE*)pwfx)->dwChannelMask; fmt.SubFormat = sample_formats[k][0] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; } @@ -615,6 +599,25 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) format_chr[1] = extensible ? 'X' : '\0'; format_chr[2] = '\0';
+ hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + continue; + + hr = IAudioClient_GetMixFormat(ac, &pwfx); + ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); + + if (extensible) { + WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; + + /* We don't want to fight with the driver over the speaker configuration, + * so just take whatever they give us, if it's valid. */ + if (fmt.Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE + && pxwfx->dwChannelMask != 0) + fmt.dwChannelMask = ((WAVEFORMATEXTENSIBLE*)pwfx)->dwChannelMask; + } + pwfx2 = (WAVEFORMATEX*)0xDEADF00D; hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)&fmt, &pwfx2); hrs = hr;
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/mmdevapi/tests/capture.c | 61 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 31 deletions(-)
diff --git a/dlls/mmdevapi/tests/capture.c b/dlls/mmdevapi/tests/capture.c index b02645f767c..38c2ec9f800 100644 --- a/dlls/mmdevapi/tests/capture.c +++ b/dlls/mmdevapi/tests/capture.c @@ -570,11 +570,11 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible)
fmt.Format.cbSize = extensible ? sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) : 0;
+ winetest_push_context("%s", mode == AUDCLNT_SHAREMODE_SHARED ? "shared" : "exclusive"); + for (i = 0; i < ARRAY_SIZE(sampling_rates); i++) { for (j = 0; j < ARRAY_SIZE(channel_counts); j++) { for (k = 0; k < ARRAY_SIZE(sample_formats); k++) { - char format_chr[3]; - fmt.Format.wFormatTag = extensible ? WAVE_FORMAT_EXTENSIBLE : sample_formats[k][0]; fmt.Format.nSamplesPerSec = sampling_rates[i]; fmt.Format.wBitsPerSample = sample_formats[k][1]; @@ -595,15 +595,18 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; }
- format_chr[0] = sample_formats[k][0] == WAVE_FORMAT_PCM ? 'P' : 'F'; - format_chr[1] = extensible ? 'X' : '\0'; - format_chr[2] = '\0'; + winetest_push_context("%c%s%lux%ux%u", sample_formats[k][0] == WAVE_FORMAT_PCM ? 'P' : 'F', + extensible ? "X" : "", fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, + fmt.Format.nChannels);
hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08lx\n", hr); if(hr != S_OK) + { + winetest_pop_context(); continue; + }
hr = IAudioClient_GetMixFormat(ac, &pwfx); ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); @@ -622,9 +625,7 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)&fmt, &pwfx2); hrs = hr; if (hr == S_OK) - trace("IsSupported(%s, %s%lux%2ux%u)\n", - mode == AUDCLNT_SHAREMODE_SHARED ? "shared " : "exclus.", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels); + trace("IsSupported() is true\n");
/* In shared mode you can only change bit width, not sampling rate or channel count. */ if (mode == AUDCLNT_SHAREMODE_SHARED) { @@ -633,12 +634,10 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) if (fmt.Format.nChannels > 2 && !extensible) expected = AUDCLNT_E_UNSUPPORTED_FORMAT; todo_wine_if(hr != expected) - ok(hr == expected, "IsFormatSupported(shared, %s%lux%2ux%u) returns %08lx, expected %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, expected); + ok(hr == expected, "IsFormatSupported() returns %08lx, expected %08lx\n", hr, expected); } else { ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || (hr == E_INVALIDARG && extensible), - "IsFormatSupported(exclusive, %s%lux%2ux%u) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + "IsFormatSupported() returns %08lx\n", hr); }
/* Only shared mode suggests something ... GetMixFormat! */ @@ -648,33 +647,27 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) pwfx2->nSamplesPerSec == pwfx->nSamplesPerSec && pwfx2->nChannels == pwfx->nChannels && pwfx2->wBitsPerSample == pwfx->wBitsPerSample, - "Suggestion %s%lux%2ux%u differs from GetMixFormat\n", - format_chr, pwfx2->nSamplesPerSec, pwfx2->wBitsPerSample, pwfx2->nChannels); + "Closes match differs from GetMixFormat\n"); }
hr = IAudioClient_Initialize(ac, mode, 0, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); if ((hrs == S_OK) ^ (hr == S_OK)) - trace("Initialize (%s, %s%lux%2ux%u) returns %08lx unlike IsFormatSupported\n", - mode == AUDCLNT_SHAREMODE_SHARED ? "shared " : "exclus.", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + trace("Initialize() returns %08lx unlike IsFormatSupported\n", hr); if (mode == AUDCLNT_SHAREMODE_SHARED) { HRESULT expected = hrs == S_OK ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; if (fmt.Format.nChannels > 2 && !extensible) expected = E_INVALIDARG; todo_wine_if(fmt.Format.nChannels > 2 && !extensible) - ok(hr == expected, "Initialize(shared, %s%lux%2ux%u) returns %08lx, expected %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, expected); + ok(hr == expected, "Initialize() returns %08lx, expected %08lx\n", hr, expected); } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) /* Unsupported format implies "create failed" and shadows "not allowed" */ ok(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs, - "Initialize(noexcl., %s%lux%2ux%u) returns %08lx(%08lx)\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, hrs); + "Initialize() returns %08lx(%08lx)\n", hr, hrs); else todo_wine_if(hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED || (hr == S_OK && hrs != S_OK)) ok(hrs == S_OK ? hr == S_OK : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == E_INVALIDARG, - "Initialize(exclus., %s%lux%2ux%u) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + "Initialize() returns %08lx\n", hr);
IAudioClient_Release(ac);
@@ -682,7 +675,10 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08lx\n", hr); if(hr != S_OK) + { + winetest_pop_context(); continue; + }
/* With AUDCLNT_STREAMFLAGS_RATEADJUST channel count must match, but sampling rate doesn't. */ hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_RATEADJUST, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); @@ -692,13 +688,11 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) if (fmt.Format.nChannels > 2 && !extensible) expected = E_INVALIDARG; todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(shared, %s%lux%2ux%u, RATEADJUST) returns %08lx, expected %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr, expected); + ok(hr == expected, "Initialize(RATEADJUST) returns %08lx, expected %08lx\n", hr, expected); } else { ok(hr == S_OK || hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED || hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == E_INVALIDARG, - "Initialize(exclus., %s%lux%2ux%u, RATEADJUST) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + "Initialize(RATEADJUST) returns %08lx\n", hr); }
IAudioClient_Release(ac); @@ -707,27 +701,32 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08lx\n", hr); if(hr != S_OK) + { + winetest_pop_context(); continue; + }
/* With AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM it always succeeds. */ hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); if (mode == AUDCLNT_SHAREMODE_SHARED) { expected = fmt.Format.nChannels <= 2 || extensible? S_OK : E_INVALIDARG; todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(shared, %s%lux%2ux%u, AUTOCONVERTPCM) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + ok(hr == expected, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); } else { todo_wine_if(hr != E_INVALIDARG) - ok(hr == E_INVALIDARG, "Initialize(exclus., %s%lux%2ux%u, AUTOCONVERTPCM) returns %08lx\n", - format_chr, fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels, hr); + ok(hr == E_INVALIDARG, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); }
CoTaskMemFree(pwfx2); CoTaskMemFree(pwfx); IAudioClient_Release(ac); + + winetest_pop_context(); } } } + + winetest_pop_context(); }
static void test_streamvolume(void)
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/mmdevapi/tests/capture.c | 245 +++++++++++++++++----------------- 1 file changed, 122 insertions(+), 123 deletions(-)
diff --git a/dlls/mmdevapi/tests/capture.c b/dlls/mmdevapi/tests/capture.c index 38c2ec9f800..78260bd643e 100644 --- a/dlls/mmdevapi/tests/capture.c +++ b/dlls/mmdevapi/tests/capture.c @@ -559,14 +559,133 @@ cleanup: CoTaskMemFree(pwfx); }
-static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) +static void test_format(AUDCLNT_SHAREMODE mode, WAVEFORMATEXTENSIBLE *fmt) { IAudioClient *ac; HRESULT hr, hrs, expected; WAVEFORMATEX *pwfx, *pwfx2; + BOOL compatible, extensible; + + extensible = fmt->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE; + + hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + return; + + hr = IAudioClient_GetMixFormat(ac, &pwfx); + ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); + + if (extensible) { + WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; + + /* We don't want to fight with the driver over the speaker configuration, + * so just take whatever they give us, if it's valid. */ + if (fmt->Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE + && pxwfx->dwChannelMask != 0) + fmt->dwChannelMask = ((WAVEFORMATEXTENSIBLE*)pwfx)->dwChannelMask; + } + + pwfx2 = (WAVEFORMATEX*)0xDEADF00D; + hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)fmt, &pwfx2); + hrs = hr; + if (hr == S_OK) + trace("IsSupported() is true\n"); + + /* In shared mode you can only change bit width, not sampling rate or channel count. */ + if (mode == AUDCLNT_SHAREMODE_SHARED) { + compatible = fmt->Format.nSamplesPerSec == pwfx->nSamplesPerSec && fmt->Format.nChannels == pwfx->nChannels; + expected = compatible ? S_OK : S_FALSE; + if (fmt->Format.nChannels > 2 && !extensible) + expected = AUDCLNT_E_UNSUPPORTED_FORMAT; + todo_wine_if(hr != expected) + ok(hr == expected, "IsFormatSupported() returns %08lx, expected %08lx\n", hr, expected); + } else { + ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || (hr == E_INVALIDARG && extensible), + "IsFormatSupported() returns %08lx\n", hr); + } + + /* Only shared mode suggests something ... GetMixFormat! */ + ok((hr == S_FALSE)^(pwfx2 == NULL), "hr %lx<->suggest %p\n", hr, pwfx2); + if (pwfx2) { + ok(pwfx2->wFormatTag == pwfx->wFormatTag && + pwfx2->nSamplesPerSec == pwfx->nSamplesPerSec && + pwfx2->nChannels == pwfx->nChannels && + pwfx2->wBitsPerSample == pwfx->wBitsPerSample, + "Closes match differs from GetMixFormat\n"); + } + + hr = IAudioClient_Initialize(ac, mode, 0, 5000000, 0, (WAVEFORMATEX*)fmt, NULL); + if ((hrs == S_OK) ^ (hr == S_OK)) + trace("Initialize() returns %08lx unlike IsFormatSupported\n", hr); + if (mode == AUDCLNT_SHAREMODE_SHARED) { + HRESULT expected = hrs == S_OK ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; + if (fmt->Format.nChannels > 2 && !extensible) + expected = E_INVALIDARG; + todo_wine_if(fmt->Format.nChannels > 2 && !extensible) + ok(hr == expected, "Initialize() returns %08lx, expected %08lx\n", hr, expected); + } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) + /* Unsupported format implies "create failed" and shadows "not allowed" */ + ok(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs, + "Initialize() returns %08lx(%08lx)\n", hr, hrs); + else + todo_wine_if(hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED || (hr == S_OK && hrs != S_OK)) + ok(hrs == S_OK ? hr == S_OK + : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == E_INVALIDARG, + "Initialize() returns %08lx\n", hr); + + IAudioClient_Release(ac); + + hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + return; + + /* With AUDCLNT_STREAMFLAGS_RATEADJUST channel count must match, but sampling rate doesn't. */ + hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_RATEADJUST, 5000000, 0, (WAVEFORMATEX*)fmt, NULL); + if (mode == AUDCLNT_SHAREMODE_SHARED) { + compatible = fmt->Format.nChannels == pwfx->nChannels; + expected = compatible ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; + if (fmt->Format.nChannels > 2 && !extensible) + expected = E_INVALIDARG; + todo_wine_if(hr != expected) + ok(hr == expected, "Initialize(RATEADJUST) returns %08lx, expected %08lx\n", hr, expected); + } else { + ok(hr == S_OK || hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED + || hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == E_INVALIDARG, + "Initialize(RATEADJUST) returns %08lx\n", hr); + } + + IAudioClient_Release(ac); + + hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, + NULL, (void**)&ac); + ok(hr == S_OK, "Activation failed with %08lx\n", hr); + if(hr != S_OK) + return; + + /* With AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM it always succeeds. */ + hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM, 5000000, 0, (WAVEFORMATEX*)fmt, NULL); + if (mode == AUDCLNT_SHAREMODE_SHARED) { + expected = fmt->Format.nChannels <= 2 || extensible? S_OK : E_INVALIDARG; + todo_wine_if(hr != expected) + ok(hr == expected, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); + } else { + todo_wine_if(hr != E_INVALIDARG) + ok(hr == E_INVALIDARG, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); + } + + CoTaskMemFree(pwfx2); + CoTaskMemFree(pwfx); + IAudioClient_Release(ac); +} + +static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) +{ WAVEFORMATEXTENSIBLE fmt; int i, j, k; - BOOL compatible;
fmt.Format.cbSize = extensible ? sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) : 0;
@@ -599,127 +718,7 @@ static void test_formats(AUDCLNT_SHAREMODE mode, BOOL extensible) extensible ? "X" : "", fmt.Format.nSamplesPerSec, fmt.Format.wBitsPerSample, fmt.Format.nChannels);
- hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - { - winetest_pop_context(); - continue; - } - - hr = IAudioClient_GetMixFormat(ac, &pwfx); - ok(hr == S_OK, "GetMixFormat failed: %08lx\n", hr); - - if (extensible) { - WAVEFORMATEXTENSIBLE *pxwfx = (WAVEFORMATEXTENSIBLE*)pwfx; - - /* We don't want to fight with the driver over the speaker configuration, - * so just take whatever they give us, if it's valid. */ - if (fmt.Format.nChannels == pwfx->nChannels && pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE - && pxwfx->dwChannelMask != 0) - fmt.dwChannelMask = ((WAVEFORMATEXTENSIBLE*)pwfx)->dwChannelMask; - } - - pwfx2 = (WAVEFORMATEX*)0xDEADF00D; - hr = IAudioClient_IsFormatSupported(ac, mode, (WAVEFORMATEX*)&fmt, &pwfx2); - hrs = hr; - if (hr == S_OK) - trace("IsSupported() is true\n"); - - /* In shared mode you can only change bit width, not sampling rate or channel count. */ - if (mode == AUDCLNT_SHAREMODE_SHARED) { - compatible = fmt.Format.nSamplesPerSec == pwfx->nSamplesPerSec && fmt.Format.nChannels == pwfx->nChannels; - expected = compatible ? S_OK : S_FALSE; - if (fmt.Format.nChannels > 2 && !extensible) - expected = AUDCLNT_E_UNSUPPORTED_FORMAT; - todo_wine_if(hr != expected) - ok(hr == expected, "IsFormatSupported() returns %08lx, expected %08lx\n", hr, expected); - } else { - ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || (hr == E_INVALIDARG && extensible), - "IsFormatSupported() returns %08lx\n", hr); - } - - /* Only shared mode suggests something ... GetMixFormat! */ - ok((hr == S_FALSE)^(pwfx2 == NULL), "hr %lx<->suggest %p\n", hr, pwfx2); - if (pwfx2) { - ok(pwfx2->wFormatTag == pwfx->wFormatTag && - pwfx2->nSamplesPerSec == pwfx->nSamplesPerSec && - pwfx2->nChannels == pwfx->nChannels && - pwfx2->wBitsPerSample == pwfx->wBitsPerSample, - "Closes match differs from GetMixFormat\n"); - } - - hr = IAudioClient_Initialize(ac, mode, 0, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); - if ((hrs == S_OK) ^ (hr == S_OK)) - trace("Initialize() returns %08lx unlike IsFormatSupported\n", hr); - if (mode == AUDCLNT_SHAREMODE_SHARED) { - HRESULT expected = hrs == S_OK ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; - if (fmt.Format.nChannels > 2 && !extensible) - expected = E_INVALIDARG; - todo_wine_if(fmt.Format.nChannels > 2 && !extensible) - ok(hr == expected, "Initialize() returns %08lx, expected %08lx\n", hr, expected); - } else if (hrs == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED) - /* Unsupported format implies "create failed" and shadows "not allowed" */ - ok(hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == hrs, - "Initialize() returns %08lx(%08lx)\n", hr, hrs); - else - todo_wine_if(hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED || (hr == S_OK && hrs != S_OK)) - ok(hrs == S_OK ? hr == S_OK - : hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == E_INVALIDARG, - "Initialize() returns %08lx\n", hr); - - IAudioClient_Release(ac); - - hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - { - winetest_pop_context(); - continue; - } - - /* With AUDCLNT_STREAMFLAGS_RATEADJUST channel count must match, but sampling rate doesn't. */ - hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_RATEADJUST, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); - if (mode == AUDCLNT_SHAREMODE_SHARED) { - compatible = fmt.Format.nChannels == pwfx->nChannels; - expected = compatible ? S_OK : AUDCLNT_E_UNSUPPORTED_FORMAT; - if (fmt.Format.nChannels > 2 && !extensible) - expected = E_INVALIDARG; - todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(RATEADJUST) returns %08lx, expected %08lx\n", hr, expected); - } else { - ok(hr == S_OK || hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED - || hr == AUDCLNT_E_ENDPOINT_CREATE_FAILED || hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == E_INVALIDARG, - "Initialize(RATEADJUST) returns %08lx\n", hr); - } - - IAudioClient_Release(ac); - - hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, - NULL, (void**)&ac); - ok(hr == S_OK, "Activation failed with %08lx\n", hr); - if(hr != S_OK) - { - winetest_pop_context(); - continue; - } - - /* With AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM it always succeeds. */ - hr = IAudioClient_Initialize(ac, mode, AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM, 5000000, 0, (WAVEFORMATEX*)&fmt, NULL); - if (mode == AUDCLNT_SHAREMODE_SHARED) { - expected = fmt.Format.nChannels <= 2 || extensible? S_OK : E_INVALIDARG; - todo_wine_if(hr != expected) - ok(hr == expected, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); - } else { - todo_wine_if(hr != E_INVALIDARG) - ok(hr == E_INVALIDARG, "Initialize(AUTOCONVERTPCM) returns %08lx\n", hr); - } - - CoTaskMemFree(pwfx2); - CoTaskMemFree(pwfx); - IAudioClient_Release(ac); + test_format(mode, &fmt);
winetest_pop_context(); }