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 capture specific mechanisms
21 * - IAudioClient with eCapture and IAudioCaptureClient
26 #include "wine/test.h"
36 #include "mmdeviceapi.h"
37 #include "audioclient.h"
39 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
41 /* undocumented error code */
42 #define D3D11_ERROR_4E MAKE_HRESULT(SEVERITY_ERROR, FACILITY_DIRECT3D11, 0x4e)
44 static IMMDevice
*dev
= NULL
;
45 static const LARGE_INTEGER ullZero
;
47 static void test_uninitialized(IAudioClient
*ac
)
53 HANDLE handle
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
56 hr
= IAudioClient_GetBufferSize(ac
, &num
);
57 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetBufferSize call returns %08x\n", hr
);
59 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
60 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetStreamLatency call returns %08x\n", hr
);
62 hr
= IAudioClient_GetCurrentPadding(ac
, &num
);
63 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetCurrentPadding call returns %08x\n", hr
);
65 hr
= IAudioClient_Start(ac
);
66 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Start call returns %08x\n", hr
);
68 hr
= IAudioClient_Stop(ac
);
69 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Stop call returns %08x\n", hr
);
71 hr
= IAudioClient_Reset(ac
);
72 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Reset call returns %08x\n", hr
);
74 hr
= IAudioClient_SetEventHandle(ac
, handle
);
75 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized SetEventHandle call returns %08x\n", hr
);
77 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&unk
);
78 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetService call returns %08x\n", hr
);
83 static void test_capture(IAudioClient
*ac
, HANDLE handle
, WAVEFORMATEX
*wfx
)
85 IAudioCaptureClient
*acc
;
87 UINT32 frames
, next
, pad
, sum
= 0;
91 REFERENCE_TIME period
;
93 hr
= IAudioClient_GetService(ac
, &IID_IAudioCaptureClient
, (void**)&acc
);
94 ok(hr
== S_OK
, "IAudioClient_GetService(IID_IAudioCaptureClient) returns %08x\n", hr
);
98 ok(ResetEvent(handle
), "ResetEvent\n");
100 hr
= IAudioCaptureClient_GetNextPacketSize(acc
, &next
);
101 ok(hr
== S_OK
, "IAudioCaptureClient_GetNextPacketSize returns %08x\n", hr
);
103 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
104 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
105 ok(next
== pad
, "GetNextPacketSize %u vs. GCP %u\n", next
, pad
);
106 /* later GCP will grow, while GNPS is 0 or period size */
108 hr
= IAudioCaptureClient_GetNextPacketSize(acc
, NULL
);
109 ok(hr
== E_POINTER
, "IAudioCaptureClient_GetNextPacketSize(NULL) returns %08x\n", hr
);
111 data
= (void*)0xdeadf00d;
114 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, NULL
, NULL
, NULL
, NULL
);
115 ok(hr
== E_POINTER
, "IAudioCaptureClient_GetBuffer(data, NULL, NULL) returns %08x\n", hr
);
117 hr
= IAudioCaptureClient_GetBuffer(acc
, NULL
, &frames
, NULL
, NULL
, NULL
);
118 ok(hr
== E_POINTER
, "IAudioCaptureClient_GetBuffer(NULL, &frames, NULL) returns %08x\n", hr
);
120 hr
= IAudioCaptureClient_GetBuffer(acc
, NULL
, NULL
, &flags
, NULL
, NULL
);
121 ok(hr
== E_POINTER
, "IAudioCaptureClient_GetBuffer(NULL, NULL, &flags) returns %08x\n", hr
);
123 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, NULL
, NULL
, NULL
);
124 ok(hr
== E_POINTER
, "IAudioCaptureClient_GetBuffer(&ata, &frames, NULL) returns %08x\n", hr
);
125 ok(broken((DWORD_PTR
)data
== 0xdeadf00d) || /* <= win8 */
126 data
== NULL
, "data is reset to %p\n", data
);
127 ok(frames
== 0xdeadbeef, "frames is reset to %08x\n", frames
);
128 ok(flags
== 0xabadcafe, "flags is reset to %08x\n", flags
);
130 hr
= IAudioClient_GetDevicePeriod(ac
, &period
, NULL
);
131 ok(hr
== S_OK
, "GetDevicePeriod failed: %08x\n", hr
);
132 period
= MulDiv(period
, wfx
->nSamplesPerSec
, 10000000); /* as in render.c */
134 hr
= IAudioClient_Start(ac
);
135 ok(hr
== S_OK
, "Start on a stopped stream returns %08x\n", hr
);
137 ok(WaitForSingleObject(handle
, 1000) == WAIT_OBJECT_0
, "Waiting on event handle failed!\n");
139 data
= (void*)0xdeadf00d;
140 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos
, &qpc
);
141 ok(hr
== S_OK
|| hr
== AUDCLNT_S_BUFFER_EMPTY
, "Valid IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
143 ok(frames
, "Amount of frames locked is 0!\n");
144 /* broken: some w7 machines return pad == 0 and DATA_DISCONTINUITY here,
145 * AUDCLNT_S_BUFFER_EMPTY above, yet pos == 1-2 * period rather than 0 */
146 ok(pos
== sum
|| broken(flags
& AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY
),
147 "Position %u expected %u\n", (UINT
)pos
, sum
);
149 }else if (hr
== AUDCLNT_S_BUFFER_EMPTY
){
150 ok(!frames
, "Amount of frames locked with empty buffer is %u!\n", frames
);
151 ok(broken(data
== (void*)0xdeadf00d) || /* <= win8 */
152 data
== NULL
, "No data changed to %p\n", data
);
155 trace("Wait'ed position %d pad %u flags %x, amount of frames locked: %u\n",
156 hr
==S_OK
? (UINT
)pos
: -1, pad
, flags
, frames
);
158 hr
= IAudioCaptureClient_GetNextPacketSize(acc
, &next
);
159 ok(hr
== S_OK
, "IAudioCaptureClient_GetNextPacketSize returns %08x\n", hr
);
160 ok(next
== frames
, "GetNextPacketSize %u vs. GetBuffer %u\n", next
, frames
);
162 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
163 ok(hr
== S_OK
, "Releasing buffer returns %08x\n", hr
);
165 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, 0);
166 ok(hr
== S_OK
, "Releasing 0 returns %08x\n", hr
);
168 hr
= IAudioCaptureClient_GetNextPacketSize(acc
, &next
);
169 ok(hr
== S_OK
, "IAudioCaptureClient_GetNextPacketSize returns %08x\n", hr
);
172 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
173 ok(hr
== AUDCLNT_E_OUT_OF_ORDER
, "Releasing buffer twice returns %08x\n", hr
);
177 Sleep(350); /* for sure there's data now */
179 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
180 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
182 /** GetNextPacketSize
183 * returns either 0 or one period worth of frames
184 * whereas GetCurrentPadding grows when input is not consumed. */
185 hr
= IAudioCaptureClient_GetNextPacketSize(acc
, &next
);
186 ok(hr
== S_OK
, "IAudioCaptureClient_GetNextPacketSize returns %08x\n", hr
);
187 ok(next
< pad
, "GetNextPacketSize %u vs. GCP %u\n", next
, pad
);
189 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos
, &qpc
);
190 ok(hr
== S_OK
, "Valid IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
191 ok(next
== frames
, "GetNextPacketSize %u vs. GetBuffer %u\n", next
, frames
);
194 UINT32 frames2
= frames
;
196 ok(frames
, "Amount of frames locked is 0!\n");
197 ok(pos
== sum
, "Position %u expected %u\n", (UINT
)pos
, sum
);
199 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, 0);
200 ok(hr
== S_OK
, "Releasing 0 returns %08x\n", hr
);
202 /* GCP did not decrement, no data consumed */
203 hr
= IAudioClient_GetCurrentPadding(ac
, &frames
);
204 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
205 ok(frames
== pad
|| frames
== pad
+ next
/* concurrent feeder */,
206 "GCP %u past ReleaseBuffer(0) initially %u\n", frames
, pad
);
208 /* should re-get the same data */
209 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos2
, &qpc2
);
210 ok(hr
== S_OK
, "Valid IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
211 ok(frames2
== frames
, "GetBuffer after ReleaseBuffer(0) %u/%u\n", frames2
, frames
);
212 ok(pos2
== pos
, "Position after ReleaseBuffer(0) %u/%u\n", (UINT
)pos2
, (UINT
)pos
);
213 todo_wine_if(qpc2
!= qpc
)
214 /* FIXME: Some drivers fail */
215 ok(qpc2
== qpc
, "HPC after ReleaseBuffer(0) %u vs. %u\n", (UINT
)qpc2
, (UINT
)qpc
);
218 /* trace after the GCP test because log output to MS-DOS console disturbs timing */
219 trace("Sleep.1 position %d pad %u flags %x, amount of frames locked: %u\n",
220 hr
==S_OK
? (UINT
)pos
: -1, pad
, flags
, frames
);
223 UINT32 frames2
= 0xabadcafe;
224 BYTE
*data2
= (void*)0xdeadf00d;
227 ok(pos
== sum
, "Position %u expected %u\n", (UINT
)pos
, sum
);
229 pos
= qpc
= 0xdeadbeef;
230 hr
= IAudioCaptureClient_GetBuffer(acc
, &data2
, &frames2
, &flags
, &pos
, &qpc
);
231 ok(hr
== AUDCLNT_E_OUT_OF_ORDER
, "Out of order IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
232 ok(frames2
== 0xabadcafe, "Out of order frames changed to %x\n", frames2
);
233 ok(broken(data2
== (void*)0xdeadf00d) /* <= win8 */ ||
234 data2
== NULL
, "Out of order data changed to %p\n", data2
);
235 ok(flags
== 0xabadcafe, "Out of order flags changed to %x\n", flags
);
236 ok(pos
== 0xdeadbeef, "Out of order position changed to %x\n", (UINT
)pos
);
237 ok(qpc
== 0xdeadbeef, "Out of order timer changed to %x\n", (UINT
)qpc
);
239 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
+1);
240 ok(hr
== AUDCLNT_E_INVALID_SIZE
, "Releasing buffer+1 returns %08x\n", hr
);
242 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, 1);
243 ok(hr
== AUDCLNT_E_INVALID_SIZE
, "Releasing 1 returns %08x\n", hr
);
245 hr
= IAudioClient_Reset(ac
);
246 ok(hr
== AUDCLNT_E_NOT_STOPPED
, "Reset failed: %08x\n", hr
);
249 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
250 ok(hr
== S_OK
, "Releasing buffer returns %08x\n", hr
);
254 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
255 ok(hr
== AUDCLNT_E_OUT_OF_ORDER
, "Releasing buffer twice returns %08x\n", hr
);
259 ok(next
== frames
, "GetNextPacketSize %u vs. GetDevicePeriod %u\n", next
, frames
);
261 /* GetBufferSize is not a multiple of the period size! */
262 hr
= IAudioClient_GetBufferSize(ac
, &next
);
263 ok(hr
== S_OK
, "GetBufferSize failed: %08x\n", hr
);
264 trace("GetBufferSize %u period size %u\n", next
, frames
);
266 Sleep(400); /* overrun */
268 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
269 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
271 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos
, &qpc
);
272 ok(hr
== S_OK
, "Valid IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
274 trace("Overrun position %d pad %u flags %x, amount of frames locked: %u\n",
275 hr
==S_OK
? (UINT
)pos
: -1, pad
, flags
, frames
);
278 if(flags
& AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY
){
279 /* Native's position is one period further than what we read.
280 * Perhaps that's precisely the meaning of DATA_DISCONTINUITY:
281 * signal when the position jump left a gap. */
282 ok(pos
== sum
+ frames
, "Position %u last %u frames %u\n", (UINT
)pos
, sum
, frames
);
285 ok(pos
== sum
, "Position %u last %u frames %u\n", (UINT
)pos
, sum
, frames
);
288 ok(pad
== next
, "GCP %u vs. BufferSize %u\n", (UINT32
)pad
, next
);
291 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
292 ok(hr
== S_OK
, "Releasing buffer returns %08x\n", hr
);
295 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
296 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
298 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos
, &qpc
);
299 ok(hr
== S_OK
, "Valid IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
301 trace("Cont'ed position %d pad %u flags %x, amount of frames locked: %u\n",
302 hr
==S_OK
? (UINT
)pos
: -1, pad
, flags
, frames
);
305 ok(pos
== sum
, "Position %u expected %u\n", (UINT
)pos
, sum
);
306 ok(!flags
, "flags %u\n", flags
);
308 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
309 ok(hr
== S_OK
, "Releasing buffer returns %08x\n", hr
);
313 hr
= IAudioClient_Stop(ac
);
314 ok(hr
== S_OK
, "Stop on a started stream returns %08x\n", hr
);
316 hr
= IAudioClient_Start(ac
);
317 ok(hr
== S_OK
, "Start on a stopped stream returns %08x\n", hr
);
319 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos
, &qpc
);
320 ok(hr
== S_OK
, "Valid IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
322 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
323 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
325 trace("Restart position %d pad %u flags %x, amount of frames locked: %u\n",
326 hr
==S_OK
? (UINT
)pos
: -1, pad
, flags
, frames
);
327 ok(pad
> sum
, "restarted GCP %u\n", pad
); /* GCP is still near buffer size */
330 ok(pos
== sum
, "Position %u expected %u\n", (UINT
)pos
, sum
);
331 ok(!flags
, "flags %u\n", flags
);
333 hr
= IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
334 ok(hr
== S_OK
, "Releasing buffer returns %08x\n", hr
);
338 hr
= IAudioClient_Stop(ac
);
339 ok(hr
== S_OK
, "Stop on a started stream returns %08x\n", hr
);
341 hr
= IAudioClient_Reset(ac
);
342 ok(hr
== S_OK
, "Reset on a stopped stream returns %08x\n", hr
);
345 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
346 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
347 ok(!pad
, "reset GCP %u\n", pad
);
350 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos
, &qpc
);
351 ok(hr
== AUDCLNT_S_BUFFER_EMPTY
,
352 "Initial IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
354 trace("Reset position %d pad %u flags %x, amount of frames locked: %u\n",
355 hr
==S_OK
? (UINT
)pos
: -1, pad
, flags
, frames
);
358 IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
360 hr
= IAudioClient_Start(ac
);
361 ok(hr
== S_OK
, "Start on a stopped stream returns %08x\n", hr
);
365 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
366 ok(hr
== S_OK
, "GetCurrentPadding call returns %08x\n", hr
);
368 hr
= IAudioCaptureClient_GetBuffer(acc
, &data
, &frames
, &flags
, &pos
, &qpc
);
369 ok(hr
== S_OK
, "Valid IAudioCaptureClient_GetBuffer returns %08x\n", hr
);
370 trace("Running position %d pad %u flags %x, amount of frames locked: %u\n",
371 SUCCEEDED(hr
) ? (UINT
)pos
: -1, pad
, flags
, frames
);
374 /* Some w7 machines signal DATA_DISCONTINUITY here following the
375 * previous AUDCLNT_S_BUFFER_EMPTY, others not. What logic? */
376 ok(pos
>= sum
, "Position %u gap %d\n", (UINT
)pos
, (UINT
)pos
- sum
);
377 IAudioCaptureClient_ReleaseBuffer(acc
, frames
);
380 IAudioCaptureClient_Release(acc
);
383 static void test_audioclient(void)
389 WAVEFORMATEX
*pwfx
, *pwfx2
;
390 REFERENCE_TIME t1
, t2
;
393 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
395 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
399 handle
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
401 hr
= IAudioClient_QueryInterface(ac
, &IID_IUnknown
, NULL
);
402 ok(hr
== E_POINTER
, "QueryInterface(NULL) returned %08x\n", hr
);
404 unk
= (void*)(LONG_PTR
)0x12345678;
405 hr
= IAudioClient_QueryInterface(ac
, &IID_NULL
, (void**)&unk
);
406 ok(hr
== E_NOINTERFACE
, "QueryInterface(IID_NULL) returned %08x\n", hr
);
407 ok(!unk
, "QueryInterface(IID_NULL) returned non-null pointer %p\n", unk
);
409 hr
= IAudioClient_QueryInterface(ac
, &IID_IUnknown
, (void**)&unk
);
410 ok(hr
== S_OK
, "QueryInterface(IID_IUnknown) returned %08x\n", hr
);
413 ref
= IUnknown_Release(unk
);
414 ok(ref
== 1, "Released count is %u\n", ref
);
417 hr
= IAudioClient_QueryInterface(ac
, &IID_IAudioClient
, (void**)&unk
);
418 ok(hr
== S_OK
, "QueryInterface(IID_IAudioClient) returned %08x\n", hr
);
421 ref
= IUnknown_Release(unk
);
422 ok(ref
== 1, "Released count is %u\n", ref
);
425 hr
= IAudioClient_GetDevicePeriod(ac
, NULL
, NULL
);
426 ok(hr
== E_POINTER
, "Invalid GetDevicePeriod call returns %08x\n", hr
);
428 hr
= IAudioClient_GetDevicePeriod(ac
, &t1
, NULL
);
429 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
431 hr
= IAudioClient_GetDevicePeriod(ac
, NULL
, &t2
);
432 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
434 hr
= IAudioClient_GetDevicePeriod(ac
, &t1
, &t2
);
435 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
436 trace("Returned periods: %u.%04u ms %u.%04u ms\n",
437 (UINT
)(t1
/10000), (UINT
)(t1
% 10000),
438 (UINT
)(t2
/10000), (UINT
)(t2
% 10000));
440 hr
= IAudioClient_GetMixFormat(ac
, NULL
);
441 ok(hr
== E_POINTER
, "GetMixFormat returns %08x\n", hr
);
443 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
444 ok(hr
== S_OK
, "Valid GetMixFormat returns %08x\n", hr
);
448 trace("pwfx: %p\n", pwfx
);
449 trace("Tag: %04x\n", pwfx
->wFormatTag
);
450 trace("bits: %u\n", pwfx
->wBitsPerSample
);
451 trace("chan: %u\n", pwfx
->nChannels
);
452 trace("rate: %u\n", pwfx
->nSamplesPerSec
);
453 trace("align: %u\n", pwfx
->nBlockAlign
);
454 trace("extra: %u\n", pwfx
->cbSize
);
455 ok(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
, "wFormatTag is %x\n", pwfx
->wFormatTag
);
456 if (pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
458 WAVEFORMATEXTENSIBLE
*pwfxe
= (void*)pwfx
;
459 trace("Res: %u\n", pwfxe
->Samples
.wReserved
);
460 trace("Mask: %x\n", pwfxe
->dwChannelMask
);
462 IsEqualGUID(&pwfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)?"PCM":
463 (IsEqualGUID(&pwfxe
->SubFormat
,
464 &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)?"FLOAT":"Other"));
467 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_SHARED
, pwfx
, &pwfx2
);
468 ok(hr
== S_OK
, "Valid IsFormatSupported(Shared) call returns %08x\n", hr
);
469 ok(pwfx2
== NULL
, "pwfx2 is non-null\n");
470 CoTaskMemFree(pwfx2
);
472 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_SHARED
, NULL
, NULL
);
473 ok(hr
== E_POINTER
, "IsFormatSupported(NULL) call returns %08x\n", hr
);
475 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_SHARED
, pwfx
, NULL
);
476 ok(hr
== E_POINTER
, "IsFormatSupported(Shared,NULL) call returns %08x\n", hr
);
478 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_EXCLUSIVE
, pwfx
, NULL
);
479 ok(hr
== S_OK
|| hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
, "IsFormatSupported(Exclusive) call returns %08x\n", hr
);
481 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_EXCLUSIVE
, pwfx
, &pwfx2
);
482 ok(hr
== S_OK
|| hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
, "IsFormatSupported(Exclusive) call returns %08x\n", hr
);
483 ok(pwfx2
== NULL
, "pwfx2 non-null on exclusive IsFormatSupported\n");
485 hr
= IAudioClient_IsFormatSupported(ac
, 0xffffffff, pwfx
, NULL
);
486 ok(hr
== E_INVALIDARG
/*w32*/ ||
487 broken(hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
/*w64 response from exclusive mode driver */),
488 "IsFormatSupported(0xffffffff) call returns %08x\n", hr
);
491 test_uninitialized(ac
);
493 hr
= IAudioClient_Initialize(ac
, 3, 0, 5000000, 0, pwfx
, NULL
);
494 ok(broken(hr
== AUDCLNT_E_NOT_INITIALIZED
) || /* <= win8 */
495 hr
== E_INVALIDARG
, "Initialize with invalid sharemode returns %08x\n", hr
);
497 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0xffffffff, 5000000, 0, pwfx
, NULL
);
498 ok(hr
== E_INVALIDARG
|| hr
== AUDCLNT_E_INVALID_STREAM_FLAG
, "Initialize with invalid flags returns %08x\n", hr
);
500 /* A period != 0 is ignored and the call succeeds.
501 * Since we can only initialize successfully once, skip those tests.
503 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, NULL
, NULL
);
504 ok(hr
== E_POINTER
, "Initialize with null format returns %08x\n", hr
);
506 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, AUDCLNT_STREAMFLAGS_EVENTCALLBACK
, 4987654, 0, pwfx
, NULL
);
507 ok(hr
== S_OK
, "Valid Initialize returns %08x\n", hr
);
511 skip("Cannot initialize %08x, remainder of tests is useless\n", hr
);
515 hr
= IAudioClient_GetStreamLatency(ac
, NULL
);
516 ok(hr
== E_POINTER
, "GetStreamLatency(NULL) call returns %08x\n", hr
);
518 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
519 ok(hr
== S_OK
, "Valid GetStreamLatency call returns %08x\n", hr
);
520 trace("Returned latency: %u.%04u ms\n",
521 (UINT
)(t1
/10000), (UINT
)(t1
% 10000));
523 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, pwfx
, NULL
);
524 ok(hr
== AUDCLNT_E_ALREADY_INITIALIZED
, "Calling Initialize twice returns %08x\n", hr
);
526 hr
= IAudioClient_SetEventHandle(ac
, NULL
);
527 ok(hr
== E_INVALIDARG
, "SetEventHandle(NULL) returns %08x\n", hr
);
529 hr
= IAudioClient_Start(ac
);
530 ok(hr
== AUDCLNT_E_EVENTHANDLE_NOT_SET
||
531 hr
== D3D11_ERROR_4E
/* win10 */, "Start before SetEventHandle returns %08x\n", hr
);
533 hr
= IAudioClient_SetEventHandle(ac
, handle
);
534 ok(hr
== S_OK
, "SetEventHandle returns %08x\n", hr
);
536 hr
= IAudioClient_Reset(ac
);
537 ok(hr
== S_OK
, "Reset on an already reset stream returns %08x\n", hr
);
539 hr
= IAudioClient_Stop(ac
);
540 ok(hr
== S_FALSE
, "Stop on a stopped stream returns %08x\n", hr
);
542 test_capture(ac
, handle
, pwfx
);
545 IAudioClient_Release(ac
);
550 static void test_streamvolume(void)
553 IAudioStreamVolume
*asv
;
559 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
561 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
565 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
566 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
568 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
570 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
574 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&asv
);
575 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
577 hr
= IAudioStreamVolume_GetChannelCount(asv
, NULL
);
578 ok(hr
== E_POINTER
, "GetChannelCount gave wrong error: %08x\n", hr
);
580 hr
= IAudioStreamVolume_GetChannelCount(asv
, &chans
);
581 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
582 ok(chans
== fmt
->nChannels
, "GetChannelCount gave wrong number of channels: %d\n", chans
);
584 hr
= IAudioStreamVolume_GetChannelVolume(asv
, fmt
->nChannels
, NULL
);
585 ok(hr
== E_POINTER
, "GetChannelCount gave wrong error: %08x\n", hr
);
587 hr
= IAudioStreamVolume_GetChannelVolume(asv
, fmt
->nChannels
, &vol
);
588 ok(hr
== E_INVALIDARG
, "GetChannelCount gave wrong error: %08x\n", hr
);
590 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, NULL
);
591 ok(hr
== E_POINTER
, "GetChannelCount gave wrong error: %08x\n", hr
);
593 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, &vol
);
594 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
595 ok(vol
== 1.f
, "Channel volume was not 1: %f\n", vol
);
597 hr
= IAudioStreamVolume_SetChannelVolume(asv
, fmt
->nChannels
, -1.f
);
598 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
600 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, -1.f
);
601 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
603 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, 2.f
);
604 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
606 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, 0.2f
);
607 ok(hr
== S_OK
, "SetChannelVolume failed: %08x\n", hr
);
609 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, &vol
);
610 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
611 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Channel volume wasn't 0.2: %f\n", vol
);
613 hr
= IAudioStreamVolume_GetAllVolumes(asv
, 0, NULL
);
614 ok(hr
== E_POINTER
, "GetAllVolumes gave wrong error: %08x\n", hr
);
616 hr
= IAudioStreamVolume_GetAllVolumes(asv
, fmt
->nChannels
, NULL
);
617 ok(hr
== E_POINTER
, "GetAllVolumes gave wrong error: %08x\n", hr
);
619 vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
620 ok(vols
!= NULL
, "HeapAlloc failed\n");
622 hr
= IAudioStreamVolume_GetAllVolumes(asv
, fmt
->nChannels
- 1, vols
);
623 ok(hr
== E_INVALIDARG
, "GetAllVolumes gave wrong error: %08x\n", hr
);
625 hr
= IAudioStreamVolume_GetAllVolumes(asv
, fmt
->nChannels
, vols
);
626 ok(hr
== S_OK
, "GetAllVolumes failed: %08x\n", hr
);
627 ok(fabsf(vols
[0] - 0.2f
) < 0.05f
, "Channel 0 volume wasn't 0.2: %f\n", vol
);
628 for(i
= 1; i
< fmt
->nChannels
; ++i
)
629 ok(vols
[i
] == 1.f
, "Channel %d volume is not 1: %f\n", i
, vols
[i
]);
631 hr
= IAudioStreamVolume_SetAllVolumes(asv
, 0, NULL
);
632 ok(hr
== E_POINTER
, "SetAllVolumes gave wrong error: %08x\n", hr
);
634 hr
= IAudioStreamVolume_SetAllVolumes(asv
, fmt
->nChannels
, NULL
);
635 ok(hr
== E_POINTER
, "SetAllVolumes gave wrong error: %08x\n", hr
);
637 hr
= IAudioStreamVolume_SetAllVolumes(asv
, fmt
->nChannels
- 1, vols
);
638 ok(hr
== E_INVALIDARG
, "SetAllVolumes gave wrong error: %08x\n", hr
);
640 hr
= IAudioStreamVolume_SetAllVolumes(asv
, fmt
->nChannels
, vols
);
641 ok(hr
== S_OK
, "SetAllVolumes failed: %08x\n", hr
);
643 HeapFree(GetProcessHeap(), 0, vols
);
644 IAudioStreamVolume_Release(asv
);
645 IAudioClient_Release(ac
);
649 static void test_channelvolume(void)
652 IChannelAudioVolume
*acv
;
658 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
660 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
664 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
665 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
667 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
668 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, NULL
);
669 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
671 hr
= IAudioClient_GetService(ac
, &IID_IChannelAudioVolume
, (void**)&acv
);
672 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
676 hr
= IChannelAudioVolume_GetChannelCount(acv
, NULL
);
677 ok(hr
== NULL_PTR_ERR
, "GetChannelCount gave wrong error: %08x\n", hr
);
679 hr
= IChannelAudioVolume_GetChannelCount(acv
, &chans
);
680 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
681 ok(chans
== fmt
->nChannels
, "GetChannelCount gave wrong number of channels: %d\n", chans
);
683 hr
= IChannelAudioVolume_GetChannelVolume(acv
, fmt
->nChannels
, NULL
);
684 ok(hr
== NULL_PTR_ERR
, "GetChannelCount gave wrong error: %08x\n", hr
);
686 hr
= IChannelAudioVolume_GetChannelVolume(acv
, fmt
->nChannels
, &vol
);
687 ok(hr
== E_INVALIDARG
, "GetChannelCount gave wrong error: %08x\n", hr
);
689 hr
= IChannelAudioVolume_GetChannelVolume(acv
, 0, NULL
);
690 ok(hr
== NULL_PTR_ERR
, "GetChannelCount gave wrong error: %08x\n", hr
);
692 hr
= IChannelAudioVolume_GetChannelVolume(acv
, 0, &vol
);
693 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
694 ok(vol
== 1.f
, "Channel volume was not 1: %f\n", vol
);
696 hr
= IChannelAudioVolume_SetChannelVolume(acv
, fmt
->nChannels
, -1.f
, NULL
);
697 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
699 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, -1.f
, NULL
);
700 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
702 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, 2.f
, NULL
);
703 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
705 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, 0.2f
, NULL
);
706 ok(hr
== S_OK
, "SetChannelVolume failed: %08x\n", hr
);
708 hr
= IChannelAudioVolume_GetChannelVolume(acv
, 0, &vol
);
709 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
710 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Channel volume wasn't 0.2: %f\n", vol
);
712 hr
= IChannelAudioVolume_GetAllVolumes(acv
, 0, NULL
);
713 ok(hr
== NULL_PTR_ERR
, "GetAllVolumes gave wrong error: %08x\n", hr
);
715 hr
= IChannelAudioVolume_GetAllVolumes(acv
, fmt
->nChannels
, NULL
);
716 ok(hr
== NULL_PTR_ERR
, "GetAllVolumes gave wrong error: %08x\n", hr
);
718 vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
719 ok(vols
!= NULL
, "HeapAlloc failed\n");
721 hr
= IChannelAudioVolume_GetAllVolumes(acv
, fmt
->nChannels
- 1, vols
);
722 ok(hr
== E_INVALIDARG
, "GetAllVolumes gave wrong error: %08x\n", hr
);
724 hr
= IChannelAudioVolume_GetAllVolumes(acv
, fmt
->nChannels
, vols
);
725 ok(hr
== S_OK
, "GetAllVolumes failed: %08x\n", hr
);
726 ok(fabsf(vols
[0] - 0.2f
) < 0.05f
, "Channel 0 volume wasn't 0.2: %f\n", vol
);
727 for(i
= 1; i
< fmt
->nChannels
; ++i
)
728 ok(vols
[i
] == 1.f
, "Channel %d volume is not 1: %f\n", i
, vols
[i
]);
730 hr
= IChannelAudioVolume_SetAllVolumes(acv
, 0, NULL
, NULL
);
731 ok(hr
== NULL_PTR_ERR
, "SetAllVolumes gave wrong error: %08x\n", hr
);
733 hr
= IChannelAudioVolume_SetAllVolumes(acv
, fmt
->nChannels
, NULL
, NULL
);
734 ok(hr
== NULL_PTR_ERR
, "SetAllVolumes gave wrong error: %08x\n", hr
);
736 hr
= IChannelAudioVolume_SetAllVolumes(acv
, fmt
->nChannels
- 1, vols
, NULL
);
737 ok(hr
== E_INVALIDARG
, "SetAllVolumes gave wrong error: %08x\n", hr
);
739 hr
= IChannelAudioVolume_SetAllVolumes(acv
, fmt
->nChannels
, vols
, NULL
);
740 ok(hr
== S_OK
, "SetAllVolumes failed: %08x\n", hr
);
742 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, 1.0f
, NULL
);
743 ok(hr
== S_OK
, "SetChannelVolume failed: %08x\n", hr
);
745 HeapFree(GetProcessHeap(), 0, vols
);
746 IChannelAudioVolume_Release(acv
);
747 IAudioClient_Release(ac
);
751 static void test_simplevolume(void)
754 ISimpleAudioVolume
*sav
;
760 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
762 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
766 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
767 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
769 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
770 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, NULL
);
771 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
773 hr
= IAudioClient_GetService(ac
, &IID_ISimpleAudioVolume
, (void**)&sav
);
774 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
778 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, NULL
);
779 ok(hr
== NULL_PTR_ERR
, "GetMasterVolume gave wrong error: %08x\n", hr
);
781 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
782 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
784 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, -1.f
, NULL
);
785 ok(hr
== E_INVALIDARG
, "SetMasterVolume gave wrong error: %08x\n", hr
);
787 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 2.f
, NULL
);
788 ok(hr
== E_INVALIDARG
, "SetMasterVolume gave wrong error: %08x\n", hr
);
790 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 0.2f
, NULL
);
791 ok(hr
== S_OK
, "SetMasterVolume failed: %08x\n", hr
);
793 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
794 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
795 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Master volume wasn't 0.2: %f\n", vol
);
797 hr
= ISimpleAudioVolume_GetMute(sav
, NULL
);
798 ok(hr
== NULL_PTR_ERR
, "GetMute gave wrong error: %08x\n", hr
);
801 hr
= ISimpleAudioVolume_GetMute(sav
, &mute
);
802 ok(hr
== S_OK
, "GetMute failed: %08x\n", hr
);
803 ok(mute
== FALSE
, "Session is already muted\n");
805 hr
= ISimpleAudioVolume_SetMute(sav
, TRUE
, NULL
);
806 ok(hr
== S_OK
, "SetMute failed: %08x\n", hr
);
809 hr
= ISimpleAudioVolume_GetMute(sav
, &mute
);
810 ok(hr
== S_OK
, "GetMute failed: %08x\n", hr
);
811 ok(mute
== TRUE
, "Session should have been muted\n");
813 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
814 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
815 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Master volume wasn't 0.2: %f\n", vol
);
817 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 1.f
, NULL
);
818 ok(hr
== S_OK
, "SetMasterVolume failed: %08x\n", hr
);
821 hr
= ISimpleAudioVolume_GetMute(sav
, &mute
);
822 ok(hr
== S_OK
, "GetMute failed: %08x\n", hr
);
823 ok(mute
== TRUE
, "Session should have been muted\n");
825 hr
= ISimpleAudioVolume_SetMute(sav
, FALSE
, NULL
);
826 ok(hr
== S_OK
, "SetMute failed: %08x\n", hr
);
828 ISimpleAudioVolume_Release(sav
);
829 IAudioClient_Release(ac
);
833 static void test_volume_dependence(void)
835 IAudioClient
*ac
, *ac2
;
836 ISimpleAudioVolume
*sav
;
837 IChannelAudioVolume
*cav
;
838 IAudioStreamVolume
*asv
;
845 hr
= CoCreateGuid(&session
);
846 ok(hr
== S_OK
, "CoCreateGuid failed: %08x\n", hr
);
848 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
850 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
854 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
855 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
857 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
858 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, &session
);
859 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
861 hr
= IAudioClient_GetService(ac
, &IID_ISimpleAudioVolume
, (void**)&sav
);
862 ok(hr
== S_OK
, "GetService (SimpleAudioVolume) failed: %08x\n", hr
);
864 hr
= IAudioClient_GetService(ac
, &IID_IChannelAudioVolume
, (void**)&cav
);
865 ok(hr
== S_OK
, "GetService (ChannelAudioVolume) failed: %08x\n", hr
);
867 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&asv
);
868 ok(hr
== S_OK
, "GetService (AudioStreamVolume) failed: %08x\n", hr
);
872 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, 0.2f
);
873 ok(hr
== S_OK
, "ASV_SetChannelVolume failed: %08x\n", hr
);
875 hr
= IChannelAudioVolume_SetChannelVolume(cav
, 0, 0.4f
, NULL
);
876 ok(hr
== S_OK
, "CAV_SetChannelVolume failed: %08x\n", hr
);
878 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 0.6f
, NULL
);
879 ok(hr
== S_OK
, "SAV_SetMasterVolume failed: %08x\n", hr
);
881 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, &vol
);
882 ok(hr
== S_OK
, "ASV_GetChannelVolume failed: %08x\n", hr
);
883 ok(fabsf(vol
- 0.2f
) < 0.05f
, "ASV_GetChannelVolume gave wrong volume: %f\n", vol
);
885 hr
= IChannelAudioVolume_GetChannelVolume(cav
, 0, &vol
);
886 ok(hr
== S_OK
, "CAV_GetChannelVolume failed: %08x\n", hr
);
887 ok(fabsf(vol
- 0.4f
) < 0.05f
, "CAV_GetChannelVolume gave wrong volume: %f\n", vol
);
889 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
890 ok(hr
== S_OK
, "SAV_GetMasterVolume failed: %08x\n", hr
);
891 ok(fabsf(vol
- 0.6f
) < 0.05f
, "SAV_GetMasterVolume gave wrong volume: %f\n", vol
);
893 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
896 IChannelAudioVolume
*cav2
;
897 IAudioStreamVolume
*asv2
;
899 hr
= IAudioClient_Initialize(ac2
, AUDCLNT_SHAREMODE_SHARED
,
900 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, &session
);
901 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
903 hr
= IAudioClient_GetService(ac2
, &IID_IChannelAudioVolume
, (void**)&cav2
);
904 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
906 hr
= IAudioClient_GetService(ac2
, &IID_IAudioStreamVolume
, (void**)&asv2
);
907 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
909 hr
= IChannelAudioVolume_GetChannelVolume(cav2
, 0, &vol
);
910 ok(hr
== S_OK
, "CAV_GetChannelVolume failed: %08x\n", hr
);
911 ok(fabsf(vol
- 0.4f
) < 0.05f
, "CAV_GetChannelVolume gave wrong volume: %f\n", vol
);
913 hr
= IAudioStreamVolume_GetChannelVolume(asv2
, 0, &vol
);
914 ok(hr
== S_OK
, "ASV_GetChannelVolume failed: %08x\n", hr
);
915 ok(vol
== 1.f
, "ASV_GetChannelVolume gave wrong volume: %f\n", vol
);
917 hr
= IChannelAudioVolume_GetChannelCount(cav2
, &nch
);
918 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
919 ok(nch
== fmt
->nChannels
, "Got wrong channel count, expected %u: %u\n", fmt
->nChannels
, nch
);
921 hr
= IAudioStreamVolume_GetChannelCount(asv2
, &nch
);
922 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
923 ok(nch
== fmt
->nChannels
, "Got wrong channel count, expected %u: %u\n", fmt
->nChannels
, nch
);
925 IAudioStreamVolume_Release(asv2
);
926 IChannelAudioVolume_Release(cav2
);
927 IAudioClient_Release(ac2
);
929 skip("Unable to open the same device twice. Skipping session volume control tests\n");
931 hr
= IChannelAudioVolume_SetChannelVolume(cav
, 0, 1.f
, NULL
);
932 ok(hr
== S_OK
, "CAV_SetChannelVolume failed: %08x\n", hr
);
934 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 1.f
, NULL
);
935 ok(hr
== S_OK
, "SAV_SetMasterVolume failed: %08x\n", hr
);
938 ISimpleAudioVolume_Release(sav
);
939 IChannelAudioVolume_Release(cav
);
940 IAudioStreamVolume_Release(asv
);
941 IAudioClient_Release(ac
);
944 static void test_marshal(void)
947 IAudioClient
*ac
, *acDest
;
948 IAudioCaptureClient
*cc
, *ccDest
;
952 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
954 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
958 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
959 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
961 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
963 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
967 hr
= IAudioClient_GetService(ac
, &IID_IAudioCaptureClient
, (void**)&cc
);
968 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
970 IAudioClient_Release(ac
);
974 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
975 ok(hr
== S_OK
, "CreateStreamOnHGlobal failed 0x%08x\n", hr
);
977 /* marshal IAudioClient */
979 hr
= CoMarshalInterface(pStream
, &IID_IAudioClient
, (IUnknown
*)ac
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
980 ok(hr
== S_OK
, "CoMarshalInterface IAudioClient failed 0x%08x\n", hr
);
982 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
983 hr
= CoUnmarshalInterface(pStream
, &IID_IAudioClient
, (void **)&acDest
);
984 ok(hr
== S_OK
, "CoUnmarshalInterface IAudioClient failed 0x%08x\n", hr
);
986 IAudioClient_Release(acDest
);
988 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
989 /* marshal IAudioCaptureClient */
991 hr
= CoMarshalInterface(pStream
, &IID_IAudioCaptureClient
, (IUnknown
*)cc
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
992 ok(hr
== S_OK
, "CoMarshalInterface IAudioCaptureClient failed 0x%08x\n", hr
);
994 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
995 hr
= CoUnmarshalInterface(pStream
, &IID_IAudioCaptureClient
, (void **)&ccDest
);
996 ok(hr
== S_OK
, "CoUnmarshalInterface IAudioCaptureClient failed 0x%08x\n", hr
);
998 IAudioCaptureClient_Release(ccDest
);
1000 IStream_Release(pStream
);
1002 IAudioClient_Release(ac
);
1003 IAudioCaptureClient_Release(cc
);
1010 IMMDeviceEnumerator
*mme
= NULL
;
1012 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1013 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&mme
);
1016 skip("mmdevapi not available: 0x%08x\n", hr
);
1020 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme
, eCapture
, eMultimedia
, &dev
);
1021 ok(hr
== S_OK
|| hr
== E_NOTFOUND
, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr
);
1022 if (hr
!= S_OK
|| !dev
)
1024 if (hr
== E_NOTFOUND
)
1025 skip("No sound card available\n");
1027 skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr
);
1032 test_streamvolume();
1033 test_channelvolume();
1034 test_simplevolume();
1035 test_volume_dependence();
1038 IMMDevice_Release(dev
);
1042 IMMDeviceEnumerator_Release(mme
);