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
21 * - IAudioClient with eRender and IAudioRenderClient
27 #include "wine/test.h"
37 #include "mmdeviceapi.h"
38 #include "audioclient.h"
39 #include "audiopolicy.h"
41 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
43 static IMMDeviceEnumerator *mme = NULL;
44 static IMMDevice *dev = NULL;
46 static inline const char *dbgstr_guid( const GUID *id )
49 sprintf(ret, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
50 id->Data1, id->Data2, id->Data3,
51 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
52 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
56 static void test_uninitialized(IAudioClient *ac)
62 HANDLE handle = CreateEventW(NULL, FALSE, FALSE, NULL);
65 hr = IAudioClient_GetBufferSize(ac, &num);
66 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetBufferSize call returns %08x\n", hr);
68 hr = IAudioClient_GetStreamLatency(ac, &t1);
69 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetStreamLatency call returns %08x\n", hr);
71 hr = IAudioClient_GetCurrentPadding(ac, &num);
72 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetCurrentPadding call returns %08x\n", hr);
74 hr = IAudioClient_Start(ac);
75 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Start call returns %08x\n", hr);
77 hr = IAudioClient_Stop(ac);
78 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Stop call returns %08x\n", hr);
80 hr = IAudioClient_Reset(ac);
81 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Reset call returns %08x\n", hr);
83 hr = IAudioClient_SetEventHandle(ac, handle);
84 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized SetEventHandle call returns %08x\n", hr);
86 hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&unk);
87 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetService call returns %08x\n", hr);
92 static void test_audioclient(void)
98 WAVEFORMATEX *pwfx, *pwfx2;
99 REFERENCE_TIME t1, t2;
102 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
104 ok(hr == S_OK, "Activation failed with %08x\n", hr);
108 handle = CreateEventW(NULL, FALSE, FALSE, NULL);
110 hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, NULL);
111 ok(hr == E_POINTER, "QueryInterface(NULL) returned %08x\n", hr);
113 unk = (void*)(LONG_PTR)0x12345678;
114 hr = IAudioClient_QueryInterface(ac, &IID_NULL, (void**)&unk);
115 ok(hr == E_NOINTERFACE, "QueryInterface(IID_NULL) returned %08x\n", hr);
116 ok(!unk, "QueryInterface(IID_NULL) returned non-null pointer %p\n", unk);
118 hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, (void**)&unk);
119 ok(hr == S_OK, "QueryInterface(IID_IUnknown) returned %08x\n", hr);
122 ref = IUnknown_Release(unk);
123 ok(ref == 1, "Released count is %u\n", ref);
126 hr = IAudioClient_QueryInterface(ac, &IID_IAudioClient, (void**)&unk);
127 ok(hr == S_OK, "QueryInterface(IID_IAudioClient) returned %08x\n", hr);
130 ref = IUnknown_Release(unk);
131 ok(ref == 1, "Released count is %u\n", ref);
134 hr = IAudioClient_GetDevicePeriod(ac, NULL, NULL);
135 ok(hr == E_POINTER, "Invalid GetDevicePeriod call returns %08x\n", hr);
137 hr = IAudioClient_GetDevicePeriod(ac, &t1, NULL);
138 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
140 hr = IAudioClient_GetDevicePeriod(ac, NULL, &t2);
141 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
143 hr = IAudioClient_GetDevicePeriod(ac, &t1, &t2);
144 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
145 trace("Returned periods: %u.%05u ms %u.%05u ms\n",
146 (UINT)(t1/10000), (UINT)(t1 % 10000),
147 (UINT)(t2/10000), (UINT)(t2 % 10000));
149 hr = IAudioClient_GetMixFormat(ac, NULL);
150 ok(hr == E_POINTER, "GetMixFormat returns %08x\n", hr);
152 hr = IAudioClient_GetMixFormat(ac, &pwfx);
153 ok(hr == S_OK, "Valid GetMixFormat returns %08x\n", hr);
157 trace("pwfx: %p\n", pwfx);
158 trace("Tag: %04x\n", pwfx->wFormatTag);
159 trace("bits: %u\n", pwfx->wBitsPerSample);
160 trace("chan: %u\n", pwfx->nChannels);
161 trace("rate: %u\n", pwfx->nSamplesPerSec);
162 trace("align: %u\n", pwfx->nBlockAlign);
163 trace("extra: %u\n", pwfx->cbSize);
164 ok(pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE, "wFormatTag is %x\n", pwfx->wFormatTag);
165 if (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
167 WAVEFORMATEXTENSIBLE *pwfxe = (void*)pwfx;
168 trace("Res: %u\n", pwfxe->Samples.wReserved);
169 trace("Mask: %x\n", pwfxe->dwChannelMask);
171 IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)?"PCM":
172 (IsEqualGUID(&pwfxe->SubFormat,
173 &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)?"FLOAT":"Other"));
176 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2);
177 ok(hr == S_OK, "Valid IsFormatSupported(Shared) call returns %08x\n", hr);
178 ok(pwfx2 == NULL, "pwfx2 is non-null\n");
179 CoTaskMemFree(pwfx2);
181 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, NULL, NULL);
182 ok(hr == E_POINTER, "IsFormatSupported(NULL) call returns %08x\n", hr);
184 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, NULL);
185 ok(hr == E_POINTER, "IsFormatSupported(Shared,NULL) call returns %08x\n", hr);
187 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL);
188 ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr);
190 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, &pwfx2);
191 ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr);
192 ok(pwfx2 == NULL, "pwfx2 non-null on exclusive IsFormatSupported\n");
194 hr = IAudioClient_IsFormatSupported(ac, 0xffffffff, pwfx, NULL);
195 ok(hr == E_INVALIDARG ||
196 hr == AUDCLNT_E_UNSUPPORTED_FORMAT,
197 "IsFormatSupported(0xffffffff) call returns %08x\n", hr);
200 test_uninitialized(ac);
202 hr = IAudioClient_Initialize(ac, 3, 0, 5000000, 0, pwfx, NULL);
203 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Initialize with invalid sharemode returns %08x\n", hr);
205 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0xffffffff, 5000000, 0, pwfx, NULL);
206 ok(hr == E_INVALIDARG, "Initialize with invalid flags returns %08x\n", hr);
208 /* It seems that if length > 2s or periodicity != 0 the length is ignored and call succeeds
209 * Since we can only initialize successfully once, skip those tests.
211 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, NULL, NULL);
212 ok(hr == E_POINTER, "Initialize with null format returns %08x\n", hr);
214 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL);
215 ok(hr == S_OK, "Valid Initialize returns %08x\n", hr);
219 skip("Cannot initialize %08x, remainder of tests is useless\n", hr);
224 hr = IAudioClient_GetStreamLatency(ac, NULL);
225 ok(hr == E_POINTER, "GetStreamLatency(NULL) call returns %08x\n", hr);
227 hr = IAudioClient_GetStreamLatency(ac, &t1);
228 ok(hr == S_OK, "Valid GetStreamLatency call returns %08x\n", hr);
229 trace("Returned latency: %u.%05u ms\n",
230 (UINT)(t1/10000), (UINT)(t1 % 10000));
232 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL);
233 ok(hr == AUDCLNT_E_ALREADY_INITIALIZED, "Calling Initialize twice returns %08x\n", hr);
235 hr = IAudioClient_SetEventHandle(ac, NULL);
236 ok(hr == E_INVALIDARG, "SetEventHandle(NULL) returns %08x\n", hr);
238 hr = IAudioClient_SetEventHandle(ac, handle);
239 ok(hr == AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED ||
240 broken(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME)) ||
241 broken(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) /* Some 2k8 */ ||
242 broken(hr == HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME)) /* Some Vista */
243 , "SetEventHandle returns %08x\n", hr);
245 hr = IAudioClient_Reset(ac);
246 ok(hr == S_OK, "Reset on a resetted stream returns %08x\n", hr);
248 hr = IAudioClient_Stop(ac);
249 ok(hr == S_FALSE, "Stop on a stopped stream returns %08x\n", hr);
251 hr = IAudioClient_Start(ac);
252 ok(hr == S_OK, "Start on a stopped stream returns %08x\n", hr);
254 IAudioClient_Release(ac);
260 static void test_references(void)
263 IAudioRenderClient *rc;
264 ISimpleAudioVolume *sav;
265 IAudioStreamVolume *asv;
271 /* IAudioRenderClient */
272 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
274 ok(hr == S_OK, "Activation failed with %08x\n", hr);
278 hr = IAudioClient_GetMixFormat(ac, &pwfx);
279 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
283 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000,
285 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
289 hr = IAudioClient_GetService(ac, &IID_IAudioRenderClient, (void**)&rc);
290 ok(hr == S_OK, "GetService failed: %08x\n", hr);
292 IAudioRenderClient_AddRef(rc);
293 ref = IAudioRenderClient_Release(rc);
294 ok(ref != 0, "RenderClient_Release gave wrong refcount: %u\n", ref);
296 ref = IAudioClient_Release(ac);
297 ok(ref != 0, "Client_Release gave wrong refcount: %u\n", ref);
299 ref = IAudioRenderClient_Release(rc);
300 ok(ref == 0, "RenderClient_Release gave wrong refcount: %u\n", ref);
302 /* ISimpleAudioVolume */
303 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
305 ok(hr == S_OK, "Activation failed with %08x\n", hr);
309 hr = IAudioClient_GetMixFormat(ac, &pwfx);
310 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
312 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000,
314 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
318 hr = IAudioClient_GetService(ac, &IID_ISimpleAudioVolume, (void**)&sav);
319 ok(hr == S_OK, "GetService failed: %08x\n", hr);
321 ISimpleAudioVolume_AddRef(sav);
322 ref = ISimpleAudioVolume_Release(sav);
323 ok(ref != 0, "SimpleAudioVolume_Release gave wrong refcount: %u\n", ref);
325 ref = IAudioClient_Release(ac);
326 ok(ref != 0, "Client_Release gave wrong refcount: %u\n", ref);
328 ref = ISimpleAudioVolume_Release(sav);
329 ok(ref == 0, "SimpleAudioVolume_Release gave wrong refcount: %u\n", ref);
332 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
334 ok(hr == S_OK, "Activation failed with %08x\n", hr);
338 hr = IAudioClient_GetMixFormat(ac, &pwfx);
339 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
341 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000,
343 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
347 hr = IAudioClient_GetService(ac, &IID_IAudioClock, (void**)&acl);
348 ok(hr == S_OK, "GetService failed: %08x\n", hr);
350 IAudioClock_AddRef(acl);
351 ref = IAudioClock_Release(acl);
352 ok(ref != 0, "AudioClock_Release gave wrong refcount: %u\n", ref);
354 ref = IAudioClient_Release(ac);
355 ok(ref != 0, "Client_Release gave wrong refcount: %u\n", ref);
357 ref = IAudioClock_Release(acl);
358 ok(ref == 0, "AudioClock_Release gave wrong refcount: %u\n", ref);
360 /* IAudioStreamVolume */
361 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
363 ok(hr == S_OK, "Activation failed with %08x\n", hr);
367 hr = IAudioClient_GetMixFormat(ac, &pwfx);
368 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
370 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000,
372 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
374 hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&asv);
375 ok(hr == S_OK, "GetService failed: %08x\n", hr);
377 IAudioStreamVolume_AddRef(asv);
378 ref = IAudioStreamVolume_Release(asv);
379 ok(ref != 0, "AudioStreamVolume_Release gave wrong refcount: %u\n", ref);
381 ref = IAudioClient_Release(ac);
382 ok(ref != 0, "Client_Release gave wrong refcount: %u\n", ref);
384 ref = IAudioStreamVolume_Release(asv);
385 ok(ref == 0, "AudioStreamVolume_Release gave wrong refcount: %u\n", ref);
388 static void test_event(void)
395 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
397 ok(hr == S_OK, "Activation failed with %08x\n", hr);
401 hr = IAudioClient_GetMixFormat(ac, &pwfx);
402 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
406 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED,
407 AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 5000000,
409 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
413 event = CreateEventW(NULL, FALSE, FALSE, NULL);
414 ok(event != NULL, "CreateEvent failed\n");
416 hr = IAudioClient_Start(ac);
417 ok(hr == AUDCLNT_E_EVENTHANDLE_NOT_SET, "Start failed: %08x\n", hr);
419 hr = IAudioClient_SetEventHandle(ac, event);
420 ok(hr == S_OK, "SetEventHandle failed: %08x\n", hr);
422 hr = IAudioClient_Start(ac);
423 ok(hr == S_OK, "Start failed: %08x\n", hr);
425 hr = IAudioClient_Stop(ac);
426 ok(hr == S_OK, "Start failed: %08x\n", hr);
428 /* test releasing a playing stream */
429 hr = IAudioClient_Start(ac);
430 ok(hr == S_OK, "Start failed: %08x\n", hr);
431 IAudioClient_Release(ac);
436 static void test_padding(void)
440 IAudioRenderClient *arc;
442 REFERENCE_TIME minp, defp;
444 UINT32 psize, pad, written;
446 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
448 ok(hr == S_OK, "Activation failed with %08x\n", hr);
452 hr = IAudioClient_GetMixFormat(ac, &pwfx);
453 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
457 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED,
458 0, 5000000, 0, pwfx, NULL);
459 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
461 hr = IAudioClient_GetDevicePeriod(ac, &defp, &minp);
462 ok(hr == S_OK, "GetDevicePeriod failed: %08x\n", hr);
463 ok(defp != 0, "Default period is 0\n");
464 ok(minp != 0, "Minimum period is 0\n");
465 ok(minp <= defp, "Mininum period is greater than default period\n");
467 hr = IAudioClient_GetService(ac, &IID_IAudioRenderClient, (void**)&arc);
468 ok(hr == S_OK, "GetService failed: %08x\n", hr);
470 psize = (defp / 10000000.) * pwfx->nSamplesPerSec * pwfx->nBlockAlign;
473 hr = IAudioClient_GetCurrentPadding(ac, &pad);
474 ok(hr == S_OK, "GetCurrentPadding failed: %08x\n", hr);
475 ok(pad == written, "GetCurrentPadding returned %u, should be %u\n", pad, written);
477 hr = IAudioRenderClient_GetBuffer(arc, psize, &buf);
478 ok(hr == S_OK, "GetBuffer failed: %08x\n", hr);
479 ok(buf != NULL, "NULL buffer returned\n");
481 hr = IAudioRenderClient_ReleaseBuffer(arc, psize,
482 AUDCLNT_BUFFERFLAGS_SILENT);
483 ok(hr == S_OK, "ReleaseBuffer failed: %08x\n", hr);
486 hr = IAudioClient_GetCurrentPadding(ac, &pad);
487 ok(hr == S_OK, "GetCurrentPadding failed: %08x\n", hr);
488 ok(pad == written, "GetCurrentPadding returned %u, should be %u\n", pad, written);
490 psize = (minp / 10000000.) * pwfx->nSamplesPerSec * pwfx->nBlockAlign;
492 hr = IAudioRenderClient_GetBuffer(arc, psize, &buf);
493 ok(hr == S_OK, "GetBuffer failed: %08x\n", hr);
494 ok(buf != NULL, "NULL buffer returned\n");
496 hr = IAudioRenderClient_ReleaseBuffer(arc, psize,
497 AUDCLNT_BUFFERFLAGS_SILENT);
498 ok(hr == S_OK, "ReleaseBuffer failed: %08x\n", hr);
501 hr = IAudioClient_GetCurrentPadding(ac, &pad);
502 ok(hr == S_OK, "GetCurrentPadding failed: %08x\n", hr);
503 ok(pad == written, "GetCurrentPadding returned %u, should be %u\n", pad, written);
505 /* overfull buffer. requested 1/2s buffer size, so try
506 * to get a 1/2s buffer, which should fail */
507 psize = pwfx->nSamplesPerSec / 2.;
508 hr = IAudioRenderClient_GetBuffer(arc, psize, &buf);
509 ok(hr == AUDCLNT_E_BUFFER_TOO_LARGE, "GetBuffer gave wrong error: %08x\n", hr);
511 hr = IAudioRenderClient_ReleaseBuffer(arc, psize, 0);
512 ok(hr == AUDCLNT_E_OUT_OF_ORDER, "ReleaseBuffer gave wrong error: %08x\n", hr);
514 hr = IAudioClient_GetCurrentPadding(ac, &pad);
515 ok(hr == S_OK, "GetCurrentPadding failed: %08x\n", hr);
516 ok(pad == written, "GetCurrentPadding returned %u, should be %u\n", pad, written);
520 IAudioRenderClient_Release(arc);
521 IAudioClient_Release(ac);
524 static void test_clock(void)
529 IAudioRenderClient *arc;
530 UINT64 freq, pos, pcpos, last;
534 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
536 ok(hr == S_OK, "Activation failed with %08x\n", hr);
540 hr = IAudioClient_GetMixFormat(ac, &pwfx);
541 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
545 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED,
546 0, 5000000, 0, pwfx, NULL);
547 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
549 hr = IAudioClient_GetService(ac, &IID_IAudioClock, (void**)&acl);
550 ok(hr == S_OK, "GetService(IAudioClock) failed: %08x\n", hr);
552 hr = IAudioClock_GetFrequency(acl, &freq);
553 ok(hr == S_OK, "GetFrequency failed: %08x\n", hr);
555 hr = IAudioClock_GetPosition(acl, NULL, NULL);
556 ok(hr == E_POINTER, "GetPosition wrong error: %08x\n", hr);
559 hr = IAudioClock_GetPosition(acl, &pos, &pcpos);
560 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
561 ok(pos == 0, "GetPosition returned non-zero pos before being started\n");
562 ok(pcpos != 0, "GetPosition returned zero pcpos\n");
565 hr = IAudioClient_GetService(ac, &IID_IAudioRenderClient, (void**)&arc);
566 ok(hr == S_OK, "GetService(IAudioRenderClient) failed: %08x\n", hr);
568 hr = IAudioRenderClient_GetBuffer(arc, pwfx->nSamplesPerSec / 2., &data);
569 ok(hr == S_OK, "GetBuffer failed: %08x\n", hr);
571 hr = IAudioRenderClient_ReleaseBuffer(arc, pwfx->nSamplesPerSec / 2., AUDCLNT_BUFFERFLAGS_SILENT);
572 ok(hr == S_OK, "ReleaseBuffer failed: %08x\n", hr);
574 hr = IAudioClock_GetPosition(acl, &pos, NULL);
575 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
576 ok(pos == 0, "GetPosition returned non-zero pos before being started\n");
578 hr = IAudioClient_Start(ac);
579 ok(hr == S_OK, "Start failed: %08x\n", hr);
583 hr = IAudioClock_GetPosition(acl, &pos, NULL);
584 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
585 ok(pos > 0, "Position should have been further along...\n");
588 hr = IAudioClient_Stop(ac);
589 ok(hr == S_OK, "Stop failed: %08x\n", hr);
591 hr = IAudioClock_GetPosition(acl, &pos, NULL);
592 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
593 ok(pos >= last, "Position should have been further along...\n");
596 hr = IAudioClient_Start(ac);
597 ok(hr == S_OK, "Start failed: %08x\n", hr);
601 hr = IAudioClient_Stop(ac);
602 ok(hr == S_OK, "Stop failed: %08x\n", hr);
604 hr = IAudioClock_GetPosition(acl, &pos, NULL);
605 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
606 ok(pos >= last, "Position should have been further along...\n");
609 hr = IAudioClock_GetPosition(acl, &pos, NULL);
610 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
611 ok(pos == last, "Position should have been further along...\n");
613 hr = IAudioClient_Reset(ac);
614 ok(hr == S_OK, "Reset failed: %08x\n", hr);
616 hr = IAudioClock_GetPosition(acl, &pos, NULL);
617 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
618 ok(pos == 0, "GetPosition returned non-zero pos after Reset\n");
621 hr = IAudioRenderClient_GetBuffer(arc, pwfx->nSamplesPerSec / 2., &data);
622 ok(hr == S_OK, "GetBuffer failed: %08x\n", hr);
624 hr = IAudioRenderClient_ReleaseBuffer(arc, pwfx->nSamplesPerSec / 2., AUDCLNT_BUFFERFLAGS_SILENT);
625 ok(hr == S_OK, "ReleaseBuffer failed: %08x\n", hr);
627 hr = IAudioClock_GetPosition(acl, &pos, NULL);
628 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
629 ok(pos == 0, "GetPosition returned non-zero pos after Reset\n");
632 hr = IAudioClient_Start(ac);
633 ok(hr == S_OK, "Start failed: %08x\n", hr);
637 hr = IAudioClock_GetPosition(acl, &pos, NULL);
638 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
639 ok(pos > last, "Position should have been further along...\n");
641 hr = IAudioClient_Stop(ac);
642 ok(hr == S_OK, "Stop failed: %08x\n", hr);
644 hr = IAudioClock_GetPosition(acl, &pos, NULL);
645 ok(hr == S_OK, "GetPosition failed: %08x\n", hr);
646 ok(pos >= last, "Position should have been further along...\n");
648 IAudioClock_Release(acl);
649 IAudioClient_Release(ac);
652 static void test_session(void)
654 IAudioClient *ses1_ac1, *ses1_ac2, *cap_ac = NULL;
655 IAudioSessionControl2 *ses1_ctl, *ses1_ctl2, *cap_ctl;
658 AudioSessionState state;
663 hr = CoCreateGuid(&ses1_guid);
664 ok(hr == S_OK, "CoCreateGuid failed: %08x\n", hr);
666 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
667 NULL, (void**)&ses1_ac1);
668 ok(hr == S_OK, "Activation failed with %08x\n", hr);
670 hr = IAudioClient_GetMixFormat(ses1_ac1, &pwfx);
671 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
673 hr = IAudioClient_Initialize(ses1_ac1, AUDCLNT_SHAREMODE_SHARED,
674 0, 5000000, 0, pwfx, &ses1_guid);
675 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
677 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
678 NULL, (void**)&ses1_ac2);
679 ok(hr == S_OK, "Activation failed with %08x\n", hr);
681 hr = IAudioClient_Initialize(ses1_ac2, AUDCLNT_SHAREMODE_SHARED,
682 0, 5000000, 0, pwfx, &ses1_guid);
683 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
685 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme, eCapture,
686 eMultimedia, &cap_dev);
688 WAVEFORMATEX *cap_pwfx;
690 hr = IMMDevice_Activate(cap_dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
691 NULL, (void**)&cap_ac);
692 ok(hr == S_OK, "Activate failed: %08x\n", hr);
694 hr = IAudioClient_GetMixFormat(cap_ac, &cap_pwfx);
695 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
697 hr = IAudioClient_Initialize(cap_ac, AUDCLNT_SHAREMODE_SHARED,
698 0, 5000000, 0, cap_pwfx, &ses1_guid);
699 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
701 hr = IAudioClient_GetService(cap_ac, &IID_IAudioSessionControl, (void**)&cap_ctl);
702 ok(hr == S_OK, "GetService failed: %08x\n", hr);
704 IMMDevice_Release(cap_dev);
705 CoTaskMemFree(cap_pwfx);
707 skip("No capture device available; skipping capture device in render session tests\n");
709 hr = IAudioClient_GetService(ses1_ac1, &IID_IAudioSessionControl2, (void**)&ses1_ctl);
710 ok(hr == E_NOINTERFACE, "GetService gave wrong error: %08x\n", hr);
712 hr = IAudioClient_GetService(ses1_ac1, &IID_IAudioSessionControl, (void**)&ses1_ctl);
713 ok(hr == S_OK, "GetService failed: %08x\n", hr);
715 hr = IAudioClient_GetService(ses1_ac1, &IID_IAudioSessionControl, (void**)&ses1_ctl2);
716 ok(hr == S_OK, "GetService failed: %08x\n", hr);
717 ok(ses1_ctl == ses1_ctl2, "Got different controls: %p %p\n", ses1_ctl, ses1_ctl2);
718 ref = IAudioSessionControl_Release(ses1_ctl2);
719 ok(ref != 0, "AudioSessionControl was destroyed\n");
721 hr = IAudioClient_GetService(ses1_ac2, &IID_IAudioSessionControl, (void**)&ses1_ctl2);
722 ok(hr == S_OK, "GetService failed: %08x\n", hr);
724 hr = IAudioSessionControl_GetState(ses1_ctl, NULL);
725 ok(hr == NULL_PTR_ERR, "GetState gave wrong error: %08x\n", hr);
727 hr = IAudioSessionControl_GetState(ses1_ctl, &state);
728 ok(hr == S_OK, "GetState failed: %08x\n", hr);
729 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
731 hr = IAudioSessionControl_GetState(ses1_ctl2, &state);
732 ok(hr == S_OK, "GetState failed: %08x\n", hr);
733 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
736 hr = IAudioSessionControl_GetState(cap_ctl, &state);
737 ok(hr == S_OK, "GetState failed: %08x\n", hr);
738 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
741 hr = IAudioClient_Start(ses1_ac1);
742 ok(hr == S_OK, "Start failed: %08x\n", hr);
744 hr = IAudioSessionControl_GetState(ses1_ctl, &state);
745 ok(hr == S_OK, "GetState failed: %08x\n", hr);
746 ok(state == AudioSessionStateActive, "Got wrong state: %d\n", state);
748 hr = IAudioSessionControl_GetState(ses1_ctl2, &state);
749 ok(hr == S_OK, "GetState failed: %08x\n", hr);
750 ok(state == AudioSessionStateActive, "Got wrong state: %d\n", state);
753 hr = IAudioSessionControl_GetState(cap_ctl, &state);
754 ok(hr == S_OK, "GetState failed: %08x\n", hr);
755 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
758 hr = IAudioClient_Stop(ses1_ac1);
759 ok(hr == S_OK, "Start failed: %08x\n", hr);
761 hr = IAudioSessionControl_GetState(ses1_ctl, &state);
762 ok(hr == S_OK, "GetState failed: %08x\n", hr);
763 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
765 hr = IAudioSessionControl_GetState(ses1_ctl2, &state);
766 ok(hr == S_OK, "GetState failed: %08x\n", hr);
767 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
770 hr = IAudioSessionControl_GetState(cap_ctl, &state);
771 ok(hr == S_OK, "GetState failed: %08x\n", hr);
772 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
774 hr = IAudioClient_Start(cap_ac);
775 ok(hr == S_OK, "Start failed: %08x\n", hr);
777 hr = IAudioSessionControl_GetState(ses1_ctl, &state);
778 ok(hr == S_OK, "GetState failed: %08x\n", hr);
779 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
781 hr = IAudioSessionControl_GetState(ses1_ctl2, &state);
782 ok(hr == S_OK, "GetState failed: %08x\n", hr);
783 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
785 hr = IAudioSessionControl_GetState(cap_ctl, &state);
786 ok(hr == S_OK, "GetState failed: %08x\n", hr);
787 ok(state == AudioSessionStateActive, "Got wrong state: %d\n", state);
789 hr = IAudioClient_Stop(cap_ac);
790 ok(hr == S_OK, "Stop failed: %08x\n", hr);
792 hr = IAudioSessionControl_GetState(ses1_ctl, &state);
793 ok(hr == S_OK, "GetState failed: %08x\n", hr);
794 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
796 hr = IAudioSessionControl_GetState(ses1_ctl2, &state);
797 ok(hr == S_OK, "GetState failed: %08x\n", hr);
798 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
800 hr = IAudioSessionControl_GetState(cap_ctl, &state);
801 ok(hr == S_OK, "GetState failed: %08x\n", hr);
802 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
804 ref = IAudioSessionControl_Release(cap_ctl);
805 ok(ref == 0, "AudioSessionControl wasn't released: %u\n", ref);
807 ref = IAudioClient_Release(cap_ac);
808 ok(ref == 0, "AudioClient wasn't released: %u\n", ref);
811 ref = IAudioSessionControl_Release(ses1_ctl);
812 ok(ref == 0, "AudioSessionControl wasn't released: %u\n", ref);
814 ref = IAudioClient_Release(ses1_ac1);
815 ok(ref == 0, "AudioClient wasn't released: %u\n", ref);
817 ref = IAudioClient_Release(ses1_ac2);
818 ok(ref == 1, "AudioClient had wrong refcount: %u\n", ref);
820 /* we've released all of our IAudioClient references, so check GetState */
821 hr = IAudioSessionControl_GetState(ses1_ctl2, &state);
822 ok(hr == S_OK, "GetState failed: %08x\n", hr);
823 ok(state == AudioSessionStateInactive, "Got wrong state: %d\n", state);
825 ref = IAudioSessionControl_Release(ses1_ctl2);
826 ok(ref == 0, "AudioSessionControl wasn't released: %u\n", ref);
831 static void test_streamvolume(void)
834 IAudioStreamVolume *asv;
840 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
842 ok(hr == S_OK, "Activation failed with %08x\n", hr);
846 hr = IAudioClient_GetMixFormat(ac, &fmt);
847 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
849 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000,
851 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
853 hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&asv);
854 ok(hr == S_OK, "GetService failed: %08x\n", hr);
856 hr = IAudioStreamVolume_GetChannelCount(asv, NULL);
857 ok(hr == E_POINTER, "GetChannelCount gave wrong error: %08x\n", hr);
859 hr = IAudioStreamVolume_GetChannelCount(asv, &chans);
860 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
861 ok(chans == fmt->nChannels, "GetChannelCount gave wrong number of channels: %d\n", chans);
863 hr = IAudioStreamVolume_GetChannelVolume(asv, fmt->nChannels, NULL);
864 ok(hr == E_POINTER, "GetChannelCount gave wrong error: %08x\n", hr);
866 hr = IAudioStreamVolume_GetChannelVolume(asv, fmt->nChannels, &vol);
867 ok(hr == E_INVALIDARG, "GetChannelCount gave wrong error: %08x\n", hr);
869 hr = IAudioStreamVolume_GetChannelVolume(asv, 0, NULL);
870 ok(hr == E_POINTER, "GetChannelCount gave wrong error: %08x\n", hr);
872 hr = IAudioStreamVolume_GetChannelVolume(asv, 0, &vol);
873 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
874 ok(vol == 1.f, "Channel volume was not 1: %f\n", vol);
876 hr = IAudioStreamVolume_SetChannelVolume(asv, fmt->nChannels, -1.f);
877 ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr);
879 hr = IAudioStreamVolume_SetChannelVolume(asv, 0, -1.f);
880 ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr);
882 hr = IAudioStreamVolume_SetChannelVolume(asv, 0, 2.f);
883 ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr);
885 hr = IAudioStreamVolume_SetChannelVolume(asv, 0, 0.2f);
886 ok(hr == S_OK, "SetChannelVolume failed: %08x\n", hr);
888 hr = IAudioStreamVolume_GetChannelVolume(asv, 0, &vol);
889 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
890 ok(fabsf(vol - 0.2f) < 0.05f, "Channel volume wasn't 0.2: %f\n", vol);
892 hr = IAudioStreamVolume_GetAllVolumes(asv, 0, NULL);
893 ok(hr == E_POINTER, "GetAllVolumes gave wrong error: %08x\n", hr);
895 hr = IAudioStreamVolume_GetAllVolumes(asv, fmt->nChannels, NULL);
896 ok(hr == E_POINTER, "GetAllVolumes gave wrong error: %08x\n", hr);
898 vols = HeapAlloc(GetProcessHeap(), 0, fmt->nChannels * sizeof(float));
899 ok(vols != NULL, "HeapAlloc failed\n");
901 hr = IAudioStreamVolume_GetAllVolumes(asv, fmt->nChannels - 1, vols);
902 ok(hr == E_INVALIDARG, "GetAllVolumes gave wrong error: %08x\n", hr);
904 hr = IAudioStreamVolume_GetAllVolumes(asv, fmt->nChannels, vols);
905 ok(hr == S_OK, "GetAllVolumes failed: %08x\n", hr);
906 ok(fabsf(vols[0] - 0.2f) < 0.05f, "Channel 0 volume wasn't 0.2: %f\n", vol);
907 for(i = 1; i < fmt->nChannels; ++i)
908 ok(vols[i] == 1.f, "Channel %d volume is not 1: %f\n", i, vols[i]);
910 hr = IAudioStreamVolume_SetAllVolumes(asv, 0, NULL);
911 ok(hr == E_POINTER, "SetAllVolumes gave wrong error: %08x\n", hr);
913 hr = IAudioStreamVolume_SetAllVolumes(asv, fmt->nChannels, NULL);
914 ok(hr == E_POINTER, "SetAllVolumes gave wrong error: %08x\n", hr);
916 hr = IAudioStreamVolume_SetAllVolumes(asv, fmt->nChannels - 1, vols);
917 ok(hr == E_INVALIDARG, "SetAllVolumes gave wrong error: %08x\n", hr);
919 hr = IAudioStreamVolume_SetAllVolumes(asv, fmt->nChannels, vols);
920 ok(hr == S_OK, "SetAllVolumes failed: %08x\n", hr);
922 HeapFree(GetProcessHeap(), 0, vols);
923 IAudioStreamVolume_Release(asv);
924 IAudioClient_Release(ac);
928 static void test_channelvolume(void)
931 IChannelAudioVolume *acv;
937 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
939 ok(hr == S_OK, "Activation failed with %08x\n", hr);
943 hr = IAudioClient_GetMixFormat(ac, &fmt);
944 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
946 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED,
947 AUDCLNT_STREAMFLAGS_NOPERSIST, 5000000, 0, fmt, NULL);
948 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
950 hr = IAudioClient_GetService(ac, &IID_IChannelAudioVolume, (void**)&acv);
951 ok(hr == S_OK, "GetService failed: %08x\n", hr);
953 hr = IChannelAudioVolume_GetChannelCount(acv, NULL);
954 ok(hr == NULL_PTR_ERR, "GetChannelCount gave wrong error: %08x\n", hr);
956 hr = IChannelAudioVolume_GetChannelCount(acv, &chans);
957 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
958 ok(chans == fmt->nChannels, "GetChannelCount gave wrong number of channels: %d\n", chans);
960 hr = IChannelAudioVolume_GetChannelVolume(acv, fmt->nChannels, NULL);
961 ok(hr == NULL_PTR_ERR, "GetChannelCount gave wrong error: %08x\n", hr);
963 hr = IChannelAudioVolume_GetChannelVolume(acv, fmt->nChannels, &vol);
964 ok(hr == E_INVALIDARG, "GetChannelCount gave wrong error: %08x\n", hr);
966 hr = IChannelAudioVolume_GetChannelVolume(acv, 0, NULL);
967 ok(hr == NULL_PTR_ERR, "GetChannelCount gave wrong error: %08x\n", hr);
969 hr = IChannelAudioVolume_GetChannelVolume(acv, 0, &vol);
970 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
971 ok(vol == 1.f, "Channel volume was not 1: %f\n", vol);
973 hr = IChannelAudioVolume_SetChannelVolume(acv, fmt->nChannels, -1.f, NULL);
974 ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr);
976 hr = IChannelAudioVolume_SetChannelVolume(acv, 0, -1.f, NULL);
977 ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr);
979 hr = IChannelAudioVolume_SetChannelVolume(acv, 0, 2.f, NULL);
980 ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr);
982 hr = IChannelAudioVolume_SetChannelVolume(acv, 0, 0.2f, NULL);
983 ok(hr == S_OK, "SetChannelVolume failed: %08x\n", hr);
985 hr = IChannelAudioVolume_GetChannelVolume(acv, 0, &vol);
986 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
987 ok(fabsf(vol - 0.2f) < 0.05f, "Channel volume wasn't 0.2: %f\n", vol);
989 hr = IChannelAudioVolume_GetAllVolumes(acv, 0, NULL);
990 ok(hr == NULL_PTR_ERR, "GetAllVolumes gave wrong error: %08x\n", hr);
992 hr = IChannelAudioVolume_GetAllVolumes(acv, fmt->nChannels, NULL);
993 ok(hr == NULL_PTR_ERR, "GetAllVolumes gave wrong error: %08x\n", hr);
995 vols = HeapAlloc(GetProcessHeap(), 0, fmt->nChannels * sizeof(float));
996 ok(vols != NULL, "HeapAlloc failed\n");
998 hr = IChannelAudioVolume_GetAllVolumes(acv, fmt->nChannels - 1, vols);
999 ok(hr == E_INVALIDARG, "GetAllVolumes gave wrong error: %08x\n", hr);
1001 hr = IChannelAudioVolume_GetAllVolumes(acv, fmt->nChannels, vols);
1002 ok(hr == S_OK, "GetAllVolumes failed: %08x\n", hr);
1003 ok(fabsf(vols[0] - 0.2f) < 0.05f, "Channel 0 volume wasn't 0.2: %f\n", vol);
1004 for(i = 1; i < fmt->nChannels; ++i)
1005 ok(vols[i] == 1.f, "Channel %d volume is not 1: %f\n", i, vols[i]);
1007 hr = IChannelAudioVolume_SetAllVolumes(acv, 0, NULL, NULL);
1008 ok(hr == NULL_PTR_ERR, "SetAllVolumes gave wrong error: %08x\n", hr);
1010 hr = IChannelAudioVolume_SetAllVolumes(acv, fmt->nChannels, NULL, NULL);
1011 ok(hr == NULL_PTR_ERR, "SetAllVolumes gave wrong error: %08x\n", hr);
1013 hr = IChannelAudioVolume_SetAllVolumes(acv, fmt->nChannels - 1, vols, NULL);
1014 ok(hr == E_INVALIDARG, "SetAllVolumes gave wrong error: %08x\n", hr);
1016 hr = IChannelAudioVolume_SetAllVolumes(acv, fmt->nChannels, vols, NULL);
1017 ok(hr == S_OK, "SetAllVolumes failed: %08x\n", hr);
1019 hr = IChannelAudioVolume_SetChannelVolume(acv, 0, 1.0f, NULL);
1020 ok(hr == S_OK, "SetChannelVolume failed: %08x\n", hr);
1022 HeapFree(GetProcessHeap(), 0, vols);
1023 IChannelAudioVolume_Release(acv);
1024 IAudioClient_Release(ac);
1028 static void test_simplevolume(void)
1031 ISimpleAudioVolume *sav;
1037 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
1039 ok(hr == S_OK, "Activation failed with %08x\n", hr);
1043 hr = IAudioClient_GetMixFormat(ac, &fmt);
1044 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
1046 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED,
1047 AUDCLNT_STREAMFLAGS_NOPERSIST, 5000000, 0, fmt, NULL);
1048 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
1050 hr = IAudioClient_GetService(ac, &IID_ISimpleAudioVolume, (void**)&sav);
1051 ok(hr == S_OK, "GetService failed: %08x\n", hr);
1053 hr = ISimpleAudioVolume_GetMasterVolume(sav, NULL);
1054 ok(hr == NULL_PTR_ERR, "GetMasterVolume gave wrong error: %08x\n", hr);
1056 hr = ISimpleAudioVolume_GetMasterVolume(sav, &vol);
1057 ok(hr == S_OK, "GetMasterVolume failed: %08x\n", hr);
1058 ok(vol == 1.f, "Master volume wasn't 1: %f\n", vol);
1060 hr = ISimpleAudioVolume_SetMasterVolume(sav, -1.f, NULL);
1061 ok(hr == E_INVALIDARG, "SetMasterVolume gave wrong error: %08x\n", hr);
1063 hr = ISimpleAudioVolume_SetMasterVolume(sav, 2.f, NULL);
1064 ok(hr == E_INVALIDARG, "SetMasterVolume gave wrong error: %08x\n", hr);
1066 hr = ISimpleAudioVolume_SetMasterVolume(sav, 0.2f, NULL);
1067 ok(hr == S_OK, "SetMasterVolume failed: %08x\n", hr);
1069 hr = ISimpleAudioVolume_GetMasterVolume(sav, &vol);
1070 ok(hr == S_OK, "GetMasterVolume failed: %08x\n", hr);
1071 ok(fabsf(vol - 0.2f) < 0.05f, "Master volume wasn't 0.2: %f\n", vol);
1073 hr = ISimpleAudioVolume_GetMute(sav, NULL);
1074 ok(hr == NULL_PTR_ERR, "GetMute gave wrong error: %08x\n", hr);
1077 hr = ISimpleAudioVolume_GetMute(sav, &mute);
1078 todo_wine ok(hr == S_OK, "GetMute failed: %08x\n", hr);
1079 todo_wine ok(mute == FALSE, "Session is already muted\n");
1081 hr = ISimpleAudioVolume_SetMute(sav, TRUE, NULL);
1082 todo_wine ok(hr == S_OK, "SetMute failed: %08x\n", hr);
1085 hr = ISimpleAudioVolume_GetMute(sav, &mute);
1086 todo_wine ok(hr == S_OK, "GetMute failed: %08x\n", hr);
1087 todo_wine ok(mute == TRUE, "Session should have been muted\n");
1089 hr = ISimpleAudioVolume_GetMasterVolume(sav, &vol);
1090 ok(hr == S_OK, "GetMasterVolume failed: %08x\n", hr);
1091 ok(fabsf(vol - 0.2f) < 0.05f, "Master volume wasn't 0.2: %f\n", vol);
1093 hr = ISimpleAudioVolume_SetMasterVolume(sav, 1.f, NULL);
1094 ok(hr == S_OK, "SetMasterVolume failed: %08x\n", hr);
1097 hr = ISimpleAudioVolume_GetMute(sav, &mute);
1098 todo_wine ok(hr == S_OK, "GetMute failed: %08x\n", hr);
1099 todo_wine ok(mute == TRUE, "Session should have been muted\n");
1101 hr = ISimpleAudioVolume_SetMute(sav, FALSE, NULL);
1102 todo_wine ok(hr == S_OK, "SetMute failed: %08x\n", hr);
1104 ISimpleAudioVolume_Release(sav);
1105 IAudioClient_Release(ac);
1109 static void test_volume_dependence(void)
1111 IAudioClient *ac, *ac2;
1112 ISimpleAudioVolume *sav;
1113 IChannelAudioVolume *cav;
1114 IAudioStreamVolume *asv;
1121 hr = CoCreateGuid(&session);
1122 ok(hr == S_OK, "CoCreateGuid failed: %08x\n", hr);
1124 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
1126 ok(hr == S_OK, "Activation failed with %08x\n", hr);
1128 hr = IAudioClient_GetMixFormat(ac, &fmt);
1129 ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr);
1131 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED,
1132 AUDCLNT_STREAMFLAGS_NOPERSIST, 5000000, 0, fmt, &session);
1133 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
1135 hr = IAudioClient_GetService(ac, &IID_ISimpleAudioVolume, (void**)&sav);
1136 ok(hr == S_OK, "GetService (SimpleAudioVolume) failed: %08x\n", hr);
1138 hr = IAudioClient_GetService(ac, &IID_IChannelAudioVolume, (void**)&cav);
1139 ok(hr == S_OK, "GetService (ChannelAudioVolme) failed: %08x\n", hr);
1141 hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&asv);
1142 ok(hr == S_OK, "GetService (AudioStreamVolume) failed: %08x\n", hr);
1144 hr = IAudioStreamVolume_SetChannelVolume(asv, 0, 0.2f);
1145 ok(hr == S_OK, "ASV_SetChannelVolume failed: %08x\n", hr);
1147 hr = IChannelAudioVolume_SetChannelVolume(cav, 0, 0.4f, NULL);
1148 ok(hr == S_OK, "CAV_SetChannelVolume failed: %08x\n", hr);
1150 hr = ISimpleAudioVolume_SetMasterVolume(sav, 0.6f, NULL);
1151 ok(hr == S_OK, "SAV_SetMasterVolume failed: %08x\n", hr);
1153 hr = IAudioStreamVolume_GetChannelVolume(asv, 0, &vol);
1154 ok(hr == S_OK, "ASV_GetChannelVolume failed: %08x\n", hr);
1155 ok(fabsf(vol - 0.2) < 0.05f, "ASV_GetChannelVolume gave wrong volume: %f\n", vol);
1157 hr = IChannelAudioVolume_GetChannelVolume(cav, 0, &vol);
1158 ok(hr == S_OK, "CAV_GetChannelVolume failed: %08x\n", hr);
1159 ok(fabsf(vol - 0.4) < 0.05f, "CAV_GetChannelVolume gave wrong volume: %f\n", vol);
1161 hr = ISimpleAudioVolume_GetMasterVolume(sav, &vol);
1162 ok(hr == S_OK, "SAV_GetMasterVolume failed: %08x\n", hr);
1163 ok(fabsf(vol - 0.6) < 0.05f, "SAV_GetMasterVolume gave wrong volume: %f\n", vol);
1165 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
1166 NULL, (void**)&ac2);
1168 IChannelAudioVolume *cav2;
1169 IAudioStreamVolume *asv2;
1171 hr = IAudioClient_Initialize(ac2, AUDCLNT_SHAREMODE_SHARED,
1172 AUDCLNT_STREAMFLAGS_NOPERSIST, 5000000, 0, fmt, &session);
1173 ok(hr == S_OK, "Initialize failed: %08x\n", hr);
1175 hr = IAudioClient_GetService(ac2, &IID_IChannelAudioVolume, (void**)&cav2);
1176 ok(hr == S_OK, "GetService failed: %08x\n", hr);
1178 hr = IAudioClient_GetService(ac2, &IID_IAudioStreamVolume, (void**)&asv2);
1179 ok(hr == S_OK, "GetService failed: %08x\n", hr);
1181 hr = IChannelAudioVolume_GetChannelVolume(cav2, 0, &vol);
1182 ok(hr == S_OK, "CAV_GetChannelVolume failed: %08x\n", hr);
1183 ok(fabsf(vol - 0.4) < 0.05f, "CAV_GetChannelVolume gave wrong volume: %f\n", vol);
1185 hr = IAudioStreamVolume_GetChannelVolume(asv2, 0, &vol);
1186 ok(hr == S_OK, "ASV_GetChannelVolume failed: %08x\n", hr);
1187 ok(vol == 1.f, "ASV_GetChannelVolume gave wrong volume: %f\n", vol);
1189 hr = IChannelAudioVolume_GetChannelCount(cav2, &nch);
1190 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
1191 ok(nch == fmt->nChannels, "Got wrong channel count, expected %u: %u\n", fmt->nChannels, nch);
1193 hr = IAudioStreamVolume_GetChannelCount(asv2, &nch);
1194 ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr);
1195 ok(nch == fmt->nChannels, "Got wrong channel count, expected %u: %u\n", fmt->nChannels, nch);
1197 IAudioStreamVolume_Release(asv2);
1198 IChannelAudioVolume_Release(cav2);
1199 IAudioClient_Release(ac2);
1201 skip("Unable to open the same device twice. Skipping session volume control tests\n");
1203 hr = IChannelAudioVolume_SetChannelVolume(cav, 0, 1.f, NULL);
1204 ok(hr == S_OK, "CAV_SetChannelVolume failed: %08x\n", hr);
1206 hr = ISimpleAudioVolume_SetMasterVolume(sav, 1.f, NULL);
1207 ok(hr == S_OK, "SAV_SetMasterVolume failed: %08x\n", hr);
1210 ISimpleAudioVolume_Release(sav);
1211 IChannelAudioVolume_Release(cav);
1212 IAudioStreamVolume_Release(asv);
1213 IAudioClient_Release(ac);
1220 CoInitializeEx(NULL, COINIT_MULTITHREADED);
1221 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
1224 skip("mmdevapi not available: 0x%08x\n", hr);
1228 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme, eRender, eMultimedia, &dev);
1229 ok(hr == S_OK || hr == E_NOTFOUND, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr);
1230 if (hr != S_OK || !dev)
1232 if (hr == E_NOTFOUND)
1233 skip("No sound card available\n");
1235 skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr);
1245 test_streamvolume();
1246 test_channelvolume();
1247 test_simplevolume();
1248 test_volume_dependence();
1250 IMMDevice_Release(dev);
1254 IMMDeviceEnumerator_Release(mme);