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
24 #include "wine/test.h"
35 #include "mmdeviceapi.h"
36 #include "audioclient.h"
38 static void test_uninitialized(IAudioClient
*ac
)
44 HANDLE handle
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
47 hr
= IAudioClient_GetBufferSize(ac
, &num
);
48 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetBufferSize call returns %08x\n", hr
);
50 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
51 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetStreamLatency call returns %08x\n", hr
);
53 hr
= IAudioClient_GetCurrentPadding(ac
, &num
);
54 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetCurrentPadding call returns %08x\n", hr
);
56 hr
= IAudioClient_Start(ac
);
57 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Start call returns %08x\n", hr
);
59 hr
= IAudioClient_Stop(ac
);
60 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Stop call returns %08x\n", hr
);
62 hr
= IAudioClient_Reset(ac
);
63 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Reset call returns %08x\n", hr
);
65 hr
= IAudioClient_SetEventHandle(ac
, handle
);
66 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized SetEventHandle call returns %08x\n", hr
);
68 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&unk
);
69 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetService call returns %08x\n", hr
);
74 static void test_audioclient(IAudioClient
*ac
)
79 WAVEFORMATEX
*pwfx
, *pwfx2
;
80 REFERENCE_TIME t1
, t2
;
82 HANDLE handle
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
84 hr
= IAudioClient_QueryInterface(ac
, &IID_IUnknown
, NULL
);
85 ok(hr
== E_POINTER
, "QueryInterface(NULL) returned %08x\n", hr
);
87 unk
= (void*)(LONG_PTR
)0x12345678;
88 hr
= IAudioClient_QueryInterface(ac
, &IID_NULL
, (void**)&unk
);
89 ok(hr
== E_NOINTERFACE
, "QueryInterface(IID_NULL) returned %08x\n", hr
);
90 ok(!unk
, "QueryInterface(IID_NULL) returned non-null pointer %p\n", unk
);
92 hr
= IAudioClient_QueryInterface(ac
, &IID_IUnknown
, (void**)&unk
);
93 ok(hr
== S_OK
, "QueryInterface(IID_IUnknown) returned %08x\n", hr
);
96 ref
= IUnknown_Release(unk
);
97 ok(ref
== 1, "Released count is %u\n", ref
);
100 hr
= IAudioClient_QueryInterface(ac
, &IID_IAudioClient
, (void**)&unk
);
101 ok(hr
== S_OK
, "QueryInterface(IID_IAudioClient) returned %08x\n", hr
);
104 ref
= IUnknown_Release(unk
);
105 ok(ref
== 1, "Released count is %u\n", ref
);
108 hr
= IAudioClient_GetDevicePeriod(ac
, NULL
, NULL
);
109 ok(hr
== E_POINTER
, "Invalid GetDevicePeriod call returns %08x\n", hr
);
111 hr
= IAudioClient_GetDevicePeriod(ac
, &t1
, NULL
);
112 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
114 hr
= IAudioClient_GetDevicePeriod(ac
, NULL
, &t2
);
115 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
117 hr
= IAudioClient_GetDevicePeriod(ac
, &t1
, &t2
);
118 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
119 trace("Returned periods: %u.%05u ms %u.%05u ms\n",
120 (UINT
)(t1
/10000), (UINT
)(t1
% 10000),
121 (UINT
)(t2
/10000), (UINT
)(t2
% 10000));
123 hr
= IAudioClient_GetMixFormat(ac
, NULL
);
124 ok(hr
== E_POINTER
, "GetMixFormat returns %08x\n", hr
);
126 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
127 ok(hr
== S_OK
, "Valid GetMixFormat returns %08x\n", hr
);
129 trace("Tag: %04x\n", pwfx
->wFormatTag
);
130 trace("bits: %u\n", pwfx
->wBitsPerSample
);
131 trace("chan: %u\n", pwfx
->nChannels
);
132 trace("rate: %u\n", pwfx
->nSamplesPerSec
);
133 trace("align: %u\n", pwfx
->nBlockAlign
);
134 trace("extra: %u\n", pwfx
->cbSize
);
135 ok(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
, "wFormatTag is %x\n", pwfx
->wFormatTag
);
136 if (pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
138 WAVEFORMATEXTENSIBLE
*pwfxe
= (void*)pwfx
;
139 trace("Res: %u\n", pwfxe
->Samples
.wReserved
);
140 trace("Mask: %x\n", pwfxe
->dwChannelMask
);
142 IsEqualGUID(&pwfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)?"PCM":
143 (IsEqualGUID(&pwfxe
->SubFormat
,
144 &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
, "IsFormatSupported(0xffffffff) call returns %08x\n", hr
);
171 test_uninitialized(ac
);
173 hr
= IAudioClient_Initialize(ac
, 3, 0, 5000000, 0, pwfx
, NULL
);
174 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Initialize with invalid sharemode returns %08x\n", hr
);
176 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0xffffffff, 5000000, 0, pwfx
, NULL
);
177 ok(hr
== E_INVALIDARG
, "Initialize with invalid flags returns %08x\n", hr
);
179 /* It seems that if length > 2s or periodicity != 0 the length is ignored and call succeeds
180 * Since we can only initialize successfully once, skip those tests.
182 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, NULL
, NULL
);
183 ok(hr
== E_POINTER
, "Initialize with null format returns %08x\n", hr
);
185 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, pwfx
, NULL
);
186 ok(hr
== S_OK
, "Valid Initialize returns %08x\n", hr
);
190 skip("Cannot initialize %08x, remainder of tests is useless\n", hr
);
195 hr
= IAudioClient_GetStreamLatency(ac
, NULL
);
196 ok(hr
== E_POINTER
, "GetStreamLatency(NULL) call returns %08x\n", hr
);
198 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
199 ok(hr
== S_OK
, "Valid GetStreamLatency call returns %08x\n", hr
);
200 trace("Returned latency: %u.%05u ms\n",
201 (UINT
)(t1
/10000), (UINT
)(t1
% 10000));
203 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, pwfx
, NULL
);
204 ok(hr
== AUDCLNT_E_ALREADY_INITIALIZED
, "Calling Initialize twice returns %08x\n", hr
);
206 hr
= IAudioClient_SetEventHandle(ac
, NULL
);
207 ok(hr
== E_INVALIDARG
, "SetEventHandle(NULL) returns %08x\n", hr
);
209 hr
= IAudioClient_SetEventHandle(ac
, handle
);
210 ok(hr
== AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED
||
211 hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
) ||
212 hr
== HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME
) /* Some Vista */
213 , "SetEventHandle returns %08x\n", hr
);
215 hr
= IAudioClient_Reset(ac
);
216 ok(hr
== S_OK
, "Reset on a resetted stream returns %08x\n", hr
);
218 hr
= IAudioClient_Stop(ac
);
219 ok(hr
== S_FALSE
, "Stop on a stopped stream returns %08x\n", hr
);
221 hr
= IAudioClient_Start(ac
);
222 ok(hr
== S_OK
, "Start on a stopped stream returns %08x\n", hr
);
231 IMMDeviceEnumerator
*mme
= NULL
;
232 IMMDevice
*dev
= NULL
;
233 IAudioClient
*ac
= NULL
;
235 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
236 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&mme
);
239 skip("mmdevapi not available: 0x%08x\n", hr
);
243 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme
, eRender
, eMultimedia
, &dev
);
244 ok(hr
== S_OK
|| hr
== E_NOTFOUND
, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr
);
245 if (hr
!= S_OK
|| !dev
)
247 if (hr
== E_NOTFOUND
)
248 skip("No sound card available\n");
250 skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr
);
254 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
, NULL
, (void**)&ac
);
255 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
258 test_audioclient(ac
);
259 IAudioClient_Release(ac
);
261 IMMDevice_Release(dev
);
265 IMMDeviceEnumerator_Release(mme
);