mmdevapi: Add return value which happens on wow64 and pure 64-bit.
[wine/multimedia.git] / dlls / mmdevapi / tests / render.c
blob9661dbdd2ad8598e3e29a06d67224ce94256af97
1 /*
2 * Copyright 2010 Maarten Lankhorst for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 /* This test is for audio playback specific mechanisms
20 * Tests:
21 * - IAudioClient with eRender and IAudioRenderClient
24 #include "wine/test.h"
26 #define COBJMACROS
28 #ifdef STANDALONE
29 #include "initguid.h"
30 #endif
32 #include "unknwn.h"
33 #include "uuids.h"
34 #include "mmdeviceapi.h"
35 #include "audioclient.h"
37 static void test_uninitialized(IAudioClient *ac)
39 HRESULT hr;
40 UINT32 num;
41 REFERENCE_TIME t1;
43 HANDLE handle = CreateEventW(NULL, FALSE, FALSE, NULL);
44 IUnknown *unk;
46 hr = IAudioClient_GetBufferSize(ac, &num);
47 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetBufferSize call returns %08x\n", hr);
49 hr = IAudioClient_GetStreamLatency(ac, &t1);
50 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetStreamLatency call returns %08x\n", hr);
52 hr = IAudioClient_GetCurrentPadding(ac, &num);
53 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetCurrentPadding call returns %08x\n", hr);
55 hr = IAudioClient_Start(ac);
56 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Start call returns %08x\n", hr);
58 hr = IAudioClient_Stop(ac);
59 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Stop call returns %08x\n", hr);
61 hr = IAudioClient_Reset(ac);
62 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Reset call returns %08x\n", hr);
64 hr = IAudioClient_SetEventHandle(ac, handle);
65 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized SetEventHandle call returns %08x\n", hr);
67 hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&unk);
68 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetService call returns %08x\n", hr);
70 CloseHandle(handle);
73 static void test_audioclient(IAudioClient *ac)
75 IUnknown *unk;
76 HRESULT hr;
77 ULONG ref;
78 WAVEFORMATEX *pwfx, *pwfx2;
79 REFERENCE_TIME t1, t2;
81 HANDLE handle = CreateEventW(NULL, FALSE, FALSE, NULL);
83 hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, NULL);
84 ok(hr == E_POINTER, "QueryInterface(NULL) returned %08x\n", hr);
86 unk = (void*)(LONG_PTR)0x12345678;
87 hr = IAudioClient_QueryInterface(ac, &IID_NULL, (void**)&unk);
88 ok(hr == E_NOINTERFACE, "QueryInterface(IID_NULL) returned %08x\n", hr);
89 ok(!unk, "QueryInterface(IID_NULL) returned non-null pointer %p\n", unk);
91 hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, (void**)&unk);
92 ok(hr == S_OK, "QueryInterface(IID_IUnknown) returned %08x\n", hr);
93 if (unk)
95 ref = IUnknown_Release(unk);
96 ok(ref == 1, "Released count is %u\n", ref);
99 hr = IAudioClient_QueryInterface(ac, &IID_IAudioClient, (void**)&unk);
100 ok(hr == S_OK, "QueryInterface(IID_IAudioClient) returned %08x\n", hr);
101 if (unk)
103 ref = IUnknown_Release(unk);
104 ok(ref == 1, "Released count is %u\n", ref);
107 hr = IAudioClient_GetDevicePeriod(ac, NULL, NULL);
108 ok(hr == E_POINTER, "Invalid GetDevicePeriod call returns %08x\n", hr);
110 hr = IAudioClient_GetDevicePeriod(ac, &t1, NULL);
111 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
113 hr = IAudioClient_GetDevicePeriod(ac, NULL, &t2);
114 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
116 hr = IAudioClient_GetDevicePeriod(ac, &t1, &t2);
117 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
118 trace("Returned periods: %u.%05u ms %u.%05u ms\n",
119 (UINT)(t1/10000), (UINT)(t1 % 10000),
120 (UINT)(t2/10000), (UINT)(t2 % 10000));
122 hr = IAudioClient_GetMixFormat(ac, NULL);
123 ok(hr == E_POINTER, "GetMixFormat returns %08x\n", hr);
125 hr = IAudioClient_GetMixFormat(ac, &pwfx);
126 ok(hr == S_OK, "Valid GetMixFormat returns %08x\n", hr);
128 if (hr == S_OK)
130 trace("pwfx: %p\n", pwfx);
131 trace("Tag: %04x\n", pwfx->wFormatTag);
132 trace("bits: %u\n", pwfx->wBitsPerSample);
133 trace("chan: %u\n", pwfx->nChannels);
134 trace("rate: %u\n", pwfx->nSamplesPerSec);
135 trace("align: %u\n", pwfx->nBlockAlign);
136 trace("extra: %u\n", pwfx->cbSize);
137 ok(pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE, "wFormatTag is %x\n", pwfx->wFormatTag);
138 if (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
140 WAVEFORMATEXTENSIBLE *pwfxe = (void*)pwfx;
141 trace("Res: %u\n", pwfxe->Samples.wReserved);
142 trace("Mask: %x\n", pwfxe->dwChannelMask);
143 trace("Alg: %s\n",
144 IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)?"PCM":
145 (IsEqualGUID(&pwfxe->SubFormat,
146 &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)?"FLOAT":"Other"));
149 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2);
150 ok(hr == S_OK, "Valid IsFormatSupported(Shared) call returns %08x\n", hr);
151 ok(pwfx2 == NULL, "pwfx2 is non-null\n");
152 CoTaskMemFree(pwfx2);
154 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, NULL, NULL);
155 ok(hr == E_POINTER, "IsFormatSupported(NULL) call returns %08x\n", hr);
157 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, NULL);
158 ok(hr == E_POINTER, "IsFormatSupported(Shared,NULL) call returns %08x\n", hr);
160 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL);
161 ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr);
163 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, &pwfx2);
164 ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr);
165 ok(pwfx2 == NULL, "pwfx2 non-null on exclusive IsFormatSupported\n");
167 hr = IAudioClient_IsFormatSupported(ac, 0xffffffff, pwfx, NULL);
168 ok(hr == E_INVALIDARG ||
169 hr == AUDCLNT_E_UNSUPPORTED_FORMAT,
170 "IsFormatSupported(0xffffffff) call returns %08x\n", hr);
173 test_uninitialized(ac);
175 hr = IAudioClient_Initialize(ac, 3, 0, 5000000, 0, pwfx, NULL);
176 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Initialize with invalid sharemode returns %08x\n", hr);
178 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0xffffffff, 5000000, 0, pwfx, NULL);
179 ok(hr == E_INVALIDARG, "Initialize with invalid flags returns %08x\n", hr);
181 /* It seems that if length > 2s or periodicity != 0 the length is ignored and call succeeds
182 * Since we can only initialize successfully once, skip those tests.
184 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, NULL, NULL);
185 ok(hr == E_POINTER, "Initialize with null format returns %08x\n", hr);
187 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL);
188 ok(hr == S_OK, "Valid Initialize returns %08x\n", hr);
190 if (hr != S_OK)
192 skip("Cannot initialize %08x, remainder of tests is useless\n", hr);
193 CoTaskMemFree(pwfx);
194 return;
197 hr = IAudioClient_GetStreamLatency(ac, NULL);
198 ok(hr == E_POINTER, "GetStreamLatency(NULL) call returns %08x\n", hr);
200 hr = IAudioClient_GetStreamLatency(ac, &t1);
201 ok(hr == S_OK, "Valid GetStreamLatency call returns %08x\n", hr);
202 trace("Returned latency: %u.%05u ms\n",
203 (UINT)(t1/10000), (UINT)(t1 % 10000));
205 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL);
206 ok(hr == AUDCLNT_E_ALREADY_INITIALIZED, "Calling Initialize twice returns %08x\n", hr);
208 hr = IAudioClient_SetEventHandle(ac, NULL);
209 ok(hr == E_INVALIDARG, "SetEventHandle(NULL) returns %08x\n", hr);
211 hr = IAudioClient_SetEventHandle(ac, handle);
212 ok(hr == AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED ||
213 broken(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME)) ||
214 broken(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) /* Some 2k8 */ ||
215 broken(hr == HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME)) /* Some Vista */
216 , "SetEventHandle returns %08x\n", hr);
218 hr = IAudioClient_Reset(ac);
219 ok(hr == S_OK, "Reset on a resetted stream returns %08x\n", hr);
221 hr = IAudioClient_Stop(ac);
222 ok(hr == S_FALSE, "Stop on a stopped stream returns %08x\n", hr);
224 hr = IAudioClient_Start(ac);
225 ok(hr == S_OK, "Start on a stopped stream returns %08x\n", hr);
227 CloseHandle(handle);
228 CoTaskMemFree(pwfx);
231 START_TEST(render)
233 HRESULT hr;
234 IMMDeviceEnumerator *mme = NULL;
235 IMMDevice *dev = NULL;
236 IAudioClient *ac = NULL;
238 CoInitializeEx(NULL, COINIT_MULTITHREADED);
239 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
240 if (FAILED(hr))
242 skip("mmdevapi not available: 0x%08x\n", hr);
243 goto cleanup;
246 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme, eRender, eMultimedia, &dev);
247 ok(hr == S_OK || hr == E_NOTFOUND, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr);
248 if (hr != S_OK || !dev)
250 if (hr == E_NOTFOUND)
251 skip("No sound card available\n");
252 else
253 skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr);
254 goto cleanup;
257 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac);
258 ok(hr == S_OK, "Activation failed with %08x\n", hr);
259 if (ac)
261 test_audioclient(ac);
262 IAudioClient_Release(ac);
264 IMMDevice_Release(dev);
266 cleanup:
267 if (mme)
268 IMMDeviceEnumerator_Release(mme);
269 CoUninitialize();