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 #define NONAMELESSUNION
28 #elif defined(HAVE_OPENAL_AL_H)
29 #include <OpenAL/al.h>
30 #include <OpenAL/alc.h>
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
41 #include "mmdeviceapi.h"
44 #include "audioclient.h"
45 #include "endpointvolume.h"
46 #include "audiopolicy.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
54 typedef struct ACRender ACRender;
55 typedef struct ACCapture ACCapture;
56 typedef struct ACSession ACSession;
57 typedef struct ASVolume ASVolume;
58 typedef struct AClock AClock;
60 typedef struct ACImpl {
61 const IAudioClientVtbl *lpVtbl;
66 CRITICAL_SECTION *crst;
68 DWORD locked, flags, bufsize, pad, padpartial, ofs, psize;
73 REFERENCE_TIME laststamp;
85 const IAudioRenderClientVtbl *lpVtbl;
91 const IAudioCaptureClientVtbl *lpVtbl;
97 const IAudioSessionControl2Vtbl *lpVtbl;
103 const IAudioClockVtbl *lpVtbl;
104 const IAudioClock2Vtbl *lp2Vtbl;
109 static const IAudioClientVtbl ACImpl_Vtbl;
110 static const IAudioRenderClientVtbl ACRender_Vtbl;
111 static const IAudioCaptureClientVtbl ACCapture_Vtbl;
112 static const IAudioSessionControl2Vtbl ACSession_Vtbl;
113 static const IAudioClockVtbl AClock_Vtbl;
114 static const IAudioClock2Vtbl AClock2_Vtbl;
116 static HRESULT AudioRenderClient_Create(ACImpl *parent, ACRender **ppv);
117 static void AudioRenderClient_Destroy(ACRender *This);
118 static HRESULT AudioCaptureClient_Create(ACImpl *parent, ACCapture **ppv);
119 static void AudioCaptureClient_Destroy(ACCapture *This);
120 static HRESULT AudioSessionControl_Create(ACImpl *parent, ACSession **ppv);
121 static void AudioSessionControl_Destroy(ACSession *This);
122 static HRESULT AudioClock_Create(ACImpl *parent, AClock **ppv);
123 static void AudioClock_Destroy(AClock *This);
125 static int get_format_PCM(WAVEFORMATEX *format)
127 if (format->nChannels > 2) {
128 FIXME("nChannels > 2 not documented for WAVE_FORMAT_PCM!\n");
134 if (format->nBlockAlign != format->wBitsPerSample/8*format->nChannels) {
135 WARN("Invalid nBlockAlign %u, from %u %u\n",
136 format->nBlockAlign, format->wBitsPerSample, format->nChannels);
140 switch (format->wBitsPerSample) {
142 switch (format->nChannels) {
143 case 1: return AL_FORMAT_MONO8;
144 case 2: return AL_FORMAT_STEREO8;
148 switch (format->nChannels) {
149 case 1: return AL_FORMAT_MONO16;
150 case 2: return AL_FORMAT_STEREO16;
155 if (!(format->wBitsPerSample % 8))
156 WARN("Could not get OpenAL format (%d-bit, %d channels)\n",
157 format->wBitsPerSample, format->nChannels);
161 /* Speaker configs */
162 #define MONO SPEAKER_FRONT_CENTER
163 #define STEREO (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT)
164 #define REAR (SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
165 #define QUAD (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
166 #define X5DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
167 #define X6DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_CENTER|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT)
168 #define X7DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT)
170 static int get_format_EXT(WAVEFORMATEX *format)
172 WAVEFORMATEXTENSIBLE *wfe;
174 if(format->cbSize < sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX)) {
175 WARN("Invalid cbSize specified for WAVE_FORMAT_EXTENSIBLE (%d)\n", format->cbSize);
179 wfe = (WAVEFORMATEXTENSIBLE*)format;
180 wfe->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX);
181 if (wfe->Samples.wValidBitsPerSample &&
182 wfe->Samples.wValidBitsPerSample != format->wBitsPerSample) {
183 FIXME("wValidBitsPerSample(%u) != wBitsPerSample(%u) unsupported\n",
184 wfe->Samples.wValidBitsPerSample, format->wBitsPerSample);
188 TRACE("Extensible values:\n"
190 " ChannelMask = 0x%08x\n"
192 wfe->Samples.wReserved, wfe->dwChannelMask,
193 debugstr_guid(&wfe->SubFormat));
195 if (wfe->dwChannelMask != MONO
196 && wfe->dwChannelMask != STEREO
197 && !palIsExtensionPresent("AL_EXT_MCFORMATS")) {
198 /* QUAD PCM might still work, special case */
199 if (palIsExtensionPresent("AL_LOKI_quadriphonic")
200 && IsEqualGUID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)
201 && wfe->dwChannelMask == QUAD) {
202 if (format->wBitsPerSample == 16)
203 return AL_FORMAT_QUAD16_LOKI;
204 else if (format->wBitsPerSample == 8)
205 return AL_FORMAT_QUAD8_LOKI;
207 WARN("Not all formats available\n");
211 if(IsEqualGUID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) {
212 if (format->wBitsPerSample == 8) {
213 switch (wfe->dwChannelMask) {
214 case MONO: return AL_FORMAT_MONO8;
215 case STEREO: return AL_FORMAT_STEREO8;
216 case REAR: return AL_FORMAT_REAR8;
217 case QUAD: return AL_FORMAT_QUAD8;
218 case X5DOT1: return AL_FORMAT_51CHN8;
219 case X6DOT1: return AL_FORMAT_61CHN8;
220 case X7DOT1: return AL_FORMAT_71CHN8;
223 } else if (format->wBitsPerSample == 16) {
224 switch (wfe->dwChannelMask) {
225 case MONO: return AL_FORMAT_MONO16;
226 case STEREO: return AL_FORMAT_STEREO16;
227 case REAR: return AL_FORMAT_REAR16;
228 case QUAD: return AL_FORMAT_QUAD16;
229 case X5DOT1: return AL_FORMAT_51CHN16;
230 case X6DOT1: return AL_FORMAT_61CHN16;
231 case X7DOT1: return AL_FORMAT_71CHN16;
235 else if (!(format->wBitsPerSample % 8))
236 ERR("Could not get OpenAL PCM format (%d-bit, mask 0x%08x)\n",
237 format->wBitsPerSample, wfe->dwChannelMask);
240 else if(IsEqualGUID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) {
241 if (format->wBitsPerSample != 32) {
242 WARN("Invalid valid bits %u/32\n", format->wBitsPerSample);
245 switch (wfe->dwChannelMask) {
246 case MONO: return AL_FORMAT_MONO_FLOAT32;
247 case STEREO: return AL_FORMAT_STEREO_FLOAT32;
248 case REAR: return AL_FORMAT_REAR32;
249 case QUAD: return AL_FORMAT_QUAD32;
250 case X5DOT1: return AL_FORMAT_51CHN32;
251 case X6DOT1: return AL_FORMAT_61CHN32;
252 case X7DOT1: return AL_FORMAT_71CHN32;
254 ERR("Could not get OpenAL float format (%d-bit, mask 0x%08x)\n",
255 format->wBitsPerSample, wfe->dwChannelMask);
259 else if (!IsEqualGUID(&wfe->SubFormat, &GUID_NULL))
260 ERR("Unhandled extensible format: %s\n", debugstr_guid(&wfe->SubFormat));
264 static ALint get_format(WAVEFORMATEX *in)
267 if (in->wFormatTag == WAVE_FORMAT_PCM)
268 ret = get_format_PCM(in);
269 else if (in->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
270 ret = get_format_EXT(in);
274 static REFERENCE_TIME gettime(void) {
275 LARGE_INTEGER stamp, freq;
276 QueryPerformanceCounter(&stamp);
277 QueryPerformanceFrequency(&freq);
278 return (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
281 HRESULT AudioClient_Create(MMDevice *parent, IAudioClient **ppv)
283 ACImpl *This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
284 *ppv = (IAudioClient*)This;
286 return E_OUTOFMEMORY;
287 This->crst = &parent->crst;
288 This->lpVtbl = &ACImpl_Vtbl;
290 This->parent = parent;
294 static void AudioClient_Destroy(ACImpl *This)
297 DeleteTimerQueueTimer(NULL, This->timer_id, INVALID_HANDLE_VALUE);
299 AudioRenderClient_Destroy(This->render);
301 AudioCaptureClient_Destroy(This->capture);
303 AudioSessionControl_Destroy(This->session);
305 AudioClock_Destroy(This->clock);
306 if (This->parent->flow == eRender && This->init) {
307 setALContext(This->parent->ctx);
308 IAudioClient_Stop((IAudioClient*)This);
309 IAudioClient_Reset((IAudioClient*)This);
310 palDeleteSources(1, &This->source);
315 palcCaptureCloseDevice(This->capdev);
316 HeapFree(GetProcessHeap(), 0, This->pwfx);
317 HeapFree(GetProcessHeap(), 0, This->buffer);
318 HeapFree(GetProcessHeap(), 0, This);
321 static void CALLBACK AC_tick(void *data, BOOLEAN fired)
326 EnterCriticalSection(This->crst);
328 IAudioClient_GetCurrentPadding((IAudioClient*)This, &pad);
329 LeaveCriticalSection(This->crst);
332 /* Open device and set/update internal mixing format based on information
333 * openal provides us. if the device cannot be opened, assume 48khz
334 * Guessing the frequency is harmless, since if GetMixFormat fails to open
335 * the device, then Initialize will likely fail as well
337 static HRESULT AC_OpenRenderAL(ACImpl *This)
339 char alname[MAX_PATH];
340 MMDevice *cur = This->parent;
342 alname[sizeof(alname)-1] = 0;
344 return cur->ctx ? S_OK : AUDCLNT_E_SERVICE_NOT_RUNNING;
346 WideCharToMultiByte(CP_UNIXCP, 0, cur->alname, -1,
347 alname, sizeof(alname)/sizeof(*alname)-1, NULL, NULL);
348 cur->device = palcOpenDevice(alname);
350 ALCenum err = palcGetError(NULL);
351 FIXME("Could not open device %s: 0x%04x\n", alname, err);
352 return AUDCLNT_E_DEVICE_IN_USE;
354 cur->ctx = palcCreateContext(cur->device, NULL);
356 ALCenum err = palcGetError(cur->device);
357 FIXME("Could not create context: 0x%04x\n", err);
358 return AUDCLNT_E_SERVICE_NOT_RUNNING;
361 return AUDCLNT_E_DEVICE_IN_USE;
365 static HRESULT AC_OpenCaptureAL(ACImpl *This)
367 char alname[MAX_PATH];
370 freq = This->pwfx->nSamplesPerSec;
371 size = This->bufsize;
373 alname[sizeof(alname)-1] = 0;
375 FIXME("Attempting to open device while already open\n");
378 WideCharToMultiByte(CP_UNIXCP, 0, This->parent->alname, -1,
379 alname, sizeof(alname)/sizeof(*alname)-1, NULL, NULL);
380 This->capdev = palcCaptureOpenDevice(alname, freq, This->format, size);
382 ALCenum err = palcGetError(NULL);
383 FIXME("Could not open device %s with buf size %u: 0x%04x\n",
384 alname, This->bufsize, err);
385 return AUDCLNT_E_DEVICE_IN_USE;
390 static HRESULT WINAPI AC_QueryInterface(IAudioClient *iface, REFIID riid, void **ppv)
392 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ppv);
397 if (IsEqualIID(riid, &IID_IUnknown)
398 || IsEqualIID(riid, &IID_IAudioClient))
401 IUnknown_AddRef((IUnknown*)*ppv);
404 WARN("Unknown interface %s\n", debugstr_guid(riid));
405 return E_NOINTERFACE;
408 static ULONG WINAPI AC_AddRef(IAudioClient *iface)
410 ACImpl *This = (ACImpl*)iface;
412 ref = InterlockedIncrement(&This->ref);
413 TRACE("Refcount now %i\n", ref);
417 static ULONG WINAPI AC_Release(IAudioClient *iface)
419 ACImpl *This = (ACImpl*)iface;
421 ref = InterlockedDecrement(&This->ref);
422 TRACE("Refcount now %i\n", ref);
424 AudioClient_Destroy(This);
428 static HRESULT WINAPI AC_Initialize(IAudioClient *iface, AUDCLNT_SHAREMODE mode, DWORD flags, REFERENCE_TIME duration, REFERENCE_TIME period, const WAVEFORMATEX *pwfx, const GUID *sessionguid)
430 ACImpl *This = (ACImpl*)iface;
433 REFERENCE_TIME time, bufsize;
435 TRACE("(%p)->(%x,%x,%u,%u,%p,%s)\n", This, mode, flags, (int)duration, (int)period, pwfx, debugstr_guid(sessionguid));
437 return AUDCLNT_E_ALREADY_INITIALIZED;
438 if (mode != AUDCLNT_SHAREMODE_SHARED
439 && mode != AUDCLNT_SHAREMODE_EXCLUSIVE) {
440 WARN("Unknown mode %x\n", mode);
441 return AUDCLNT_E_NOT_INITIALIZED;
444 if (flags & ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS
445 |AUDCLNT_STREAMFLAGS_LOOPBACK
446 |AUDCLNT_STREAMFLAGS_EVENTCALLBACK
447 |AUDCLNT_STREAMFLAGS_NOPERSIST
448 |AUDCLNT_STREAMFLAGS_RATEADJUST
449 |AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED
450 |AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE
451 |AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED)) {
452 WARN("Unknown flags 0x%08x\n", flags);
456 WARN("Flags 0x%08x ignored\n", flags);
460 WARN("Session guid %s ignored\n", debugstr_guid(sessionguid));
462 hr = IAudioClient_IsFormatSupported(iface, mode, pwfx, &pwfx2);
463 CoTaskMemFree(pwfx2);
464 if (FAILED(hr) || pwfx2)
465 return AUDCLNT_E_UNSUPPORTED_FORMAT;
466 EnterCriticalSection(This->crst);
467 HeapFree(GetProcessHeap(), 0, This->pwfx);
468 This->pwfx = HeapAlloc(GetProcessHeap(), 0, sizeof(*pwfx) + pwfx->cbSize);
473 memcpy(This->pwfx, pwfx, sizeof(*pwfx) + pwfx->cbSize);
475 hr = IAudioClient_GetDevicePeriod(iface, &time, NULL);
479 This->psize = (DWORD64)This->pwfx->nSamplesPerSec * time / (DWORD64)10000000;
480 if (duration > 20000000)
483 bufsize = duration / time * This->psize;
485 bufsize += This->psize;
486 This->bufsize = bufsize;
487 This->psize *= This->pwfx->nBlockAlign;
488 bufsize *= pwfx->nBlockAlign;
490 This->format = get_format(This->pwfx);
491 if (This->parent->flow == eRender) {
493 ALuint buf = 0, towrite;
495 hr = AC_OpenRenderAL(This);
499 /* Test the returned format */
500 towrite = sizeof(silence);
501 towrite -= towrite % This->pwfx->nBlockAlign;
502 if (This->pwfx->wBitsPerSample != 8)
503 memset(silence, 0, sizeof(silence));
505 memset(silence, 128, sizeof(silence));
506 setALContext(This->parent->ctx);
508 palGenBuffers(1, &buf);
509 palBufferData(buf, This->format, silence, towrite, This->pwfx->nSamplesPerSec);
510 palDeleteBuffers(1, &buf);
512 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
513 else if (!This->source) {
514 palGenSources(1, &This->source);
515 palSourcei(This->source, AL_LOOPING, AL_FALSE);
521 hr = AC_OpenCaptureAL(This);
526 This->buffer = HeapAlloc(GetProcessHeap(), 0, bufsize);
533 This->running = FALSE;
536 LeaveCriticalSection(This->crst);
540 static HRESULT WINAPI AC_GetBufferSize(IAudioClient *iface, UINT32 *frames)
542 ACImpl *This = (ACImpl*)iface;
543 TRACE("(%p)->(%p)\n", This, frames);
545 return AUDCLNT_E_NOT_INITIALIZED;
548 *frames = This->bufsize;
552 static HRESULT WINAPI AC_GetStreamLatency(IAudioClient *iface, REFERENCE_TIME *latency)
554 ACImpl *This = (ACImpl*)iface;
555 TRACE("(%p)->(%p)\n", This, latency);
558 return AUDCLNT_E_NOT_INITIALIZED;
568 static HRESULT WINAPI AC_GetCurrentPadding(IAudioClient *iface, UINT32 *numpad)
570 ACImpl *This = (ACImpl*)iface;
573 TRACE("(%p)->(%p)\n", This, numpad);
575 return AUDCLNT_E_NOT_INITIALIZED;
578 EnterCriticalSection(This->crst);
579 if (This->parent->flow == eRender) {
581 ALint state, padpart;
582 setALContext(This->parent->ctx);
584 palGetSourcei(This->source, AL_BYTE_OFFSET, &padpart);
585 palGetSourcei(This->source, AL_SOURCE_STATE, &state);
586 padpart /= This->pwfx->nBlockAlign;
587 if (state == AL_STOPPED && This->running)
589 if (This->running && This->padpartial != padpart) {
590 This->padpartial = padpart;
591 This->laststamp = gettime();
592 #if 0 /* Manipulative lie */
593 } else if (This->running) {
594 ALint size = This->pad - padpart;
595 if (size > This->psize)
597 played = (gettime() - This->laststamp)*8;
598 played = played * This->pwfx->nSamplesPerSec / 10000000;
603 *numpad = This->pad - This->padpartial - played;
604 if (This->handle && *numpad + This->psize <= This->bufsize)
605 SetEvent(This->handle);
609 DWORD block = This->pwfx->nBlockAlign;
610 DWORD psize = This->psize / block;
611 palcGetIntegerv(This->capdev, ALC_CAPTURE_SAMPLES, 1, &avail);
613 DWORD ofs = This->ofs + This->pad;
615 ofs %= This->bufsize;
616 buf1 = This->buffer + (ofs * block);
617 This->laststamp = gettime();
619 SetEvent(This->handle);
621 if (ofs + avail <= This->bufsize)
622 palcCaptureSamples(This->capdev, buf1, avail);
624 DWORD part1 = This->bufsize - This->ofs;
625 palcCaptureSamples(This->capdev, buf1, part1);
626 palcCaptureSamples(This->capdev, This->buffer, avail - part1);
629 This->frameswritten += avail;
630 /* Increase ofs if the app forgets to read */
631 if (This->pad > This->bufsize) {
633 WARN("Overflowed! %u bytes\n", This->pad - This->bufsize);
634 This->ofs += This->pad - This->bufsize;
635 rest = This->ofs % psize;
637 This->ofs += psize - rest;
638 This->ofs %= This->bufsize;
639 This->pad = This->bufsize - rest;
642 if (This->pad >= psize)
647 LeaveCriticalSection(This->crst);
649 TRACE("%u queued\n", *numpad);
653 static HRESULT WINAPI AC_IsFormatSupported(IAudioClient *iface, AUDCLNT_SHAREMODE mode, const WAVEFORMATEX *pwfx, WAVEFORMATEX **outpwfx)
655 ACImpl *This = (ACImpl*)iface;
656 TRACE("(%p)->(%x,%p,%p)\n", This, mode, pwfx, outpwfx);
660 if (mode == AUDCLNT_SHAREMODE_SHARED && !outpwfx)
662 if (mode != AUDCLNT_SHAREMODE_SHARED
663 && mode != AUDCLNT_SHAREMODE_EXCLUSIVE) {
664 WARN("Unknown mode %x\n", mode);
667 if (pwfx->wFormatTag != WAVE_FORMAT_EXTENSIBLE
668 && pwfx->wFormatTag != WAVE_FORMAT_PCM)
669 return AUDCLNT_E_UNSUPPORTED_FORMAT;
670 if (pwfx->nSamplesPerSec < 8000
671 || pwfx->nSamplesPerSec > 192000)
672 return AUDCLNT_E_UNSUPPORTED_FORMAT;
673 if (pwfx->wFormatTag != WAVE_FORMAT_EXTENSIBLE
674 || !IsEqualIID(&((WAVEFORMATEXTENSIBLE*)pwfx)->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) {
675 if (pwfx->wBitsPerSample > 16)
676 return AUDCLNT_E_UNSUPPORTED_FORMAT;
683 static HRESULT WINAPI AC_GetMixFormat(IAudioClient *iface, WAVEFORMATEX **pwfx)
685 ACImpl *This = (ACImpl*)iface;
686 PROPVARIANT pv = { VT_EMPTY };
689 TRACE("(%p)->(%p)\n", This, pwfx);
693 hr = MMDevice_GetPropValue(&This->parent->devguid, This->parent->flow,
694 &PKEY_AudioEngine_DeviceFormat, &pv);
695 *pwfx = (WAVEFORMATEX*)pv.u.blob.pBlobData;
696 if (SUCCEEDED(hr) && pv.vt == VT_EMPTY)
699 TRACE("Returning 0x%08x\n", hr);
703 static HRESULT WINAPI AC_GetDevicePeriod(IAudioClient *iface, REFERENCE_TIME *defperiod, REFERENCE_TIME *minperiod)
705 ACImpl *This = (ACImpl*)iface;
707 TRACE("(%p)->(%p)\n", This, minperiod);
708 if (!defperiod && !minperiod)
718 static HRESULT WINAPI AC_Start(IAudioClient *iface)
720 ACImpl *This = (ACImpl*)iface;
722 REFERENCE_TIME refresh;
724 TRACE("(%p)\n", This);
726 return AUDCLNT_E_NOT_INITIALIZED;
727 if (This->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) {
729 return AUDCLNT_E_EVENTHANDLE_NOT_SET;
730 FIXME("Event handles not fully tested\n");
732 EnterCriticalSection(This->crst);
734 hr = AUDCLNT_E_NOT_STOPPED;
737 if (This->parent->flow == eRender) {
738 setALContext(This->parent->ctx);
739 palSourcePlay(This->source);
744 palcCaptureStart(This->capdev);
746 AC_GetDevicePeriod(iface, &refresh, NULL);
747 if (!This->timer_id && This->handle)
748 CreateTimerQueueTimer(&This->timer_id, NULL, AC_tick, This,
749 refresh / 20000, refresh / 20000,
750 WT_EXECUTEINTIMERTHREAD);
751 /* Set to 0, otherwise risk running the clock backwards
752 * This will cause AudioClock::GetPosition to return the maximum
753 * possible value for the current buffer
756 This->running = TRUE;
759 LeaveCriticalSection(This->crst);
763 static HRESULT WINAPI AC_Stop(IAudioClient *iface)
765 ACImpl *This = (ACImpl*)iface;
767 TRACE("(%p)\n", This);
769 return AUDCLNT_E_NOT_INITIALIZED;
772 EnterCriticalSection(This->crst);
773 if (This->parent->flow == eRender) {
775 setALContext(This->parent->ctx);
776 This->running = FALSE;
777 palSourcePause(This->source);
780 palGetSourcei(This->source, AL_SOURCE_STATE, &state);
781 if (state != AL_PLAYING)
789 palcCaptureStop(This->capdev);
790 timer_id = This->timer_id;
792 LeaveCriticalSection(This->crst);
794 DeleteTimerQueueTimer(NULL, timer_id, INVALID_HANDLE_VALUE);
798 static HRESULT WINAPI AC_Reset(IAudioClient *iface)
800 ACImpl *This = (ACImpl*)iface;
802 TRACE("(%p)\n", This);
804 return AUDCLNT_E_NOT_INITIALIZED;
806 return AUDCLNT_E_NOT_STOPPED;
807 EnterCriticalSection(This->crst);
809 hr = AUDCLNT_E_BUFFER_OPERATION_PENDING;
812 if (This->parent->flow == eRender) {
815 setALContext(This->parent->ctx);
816 palSourceStop(This->source);
817 palGetSourcei(This->source, AL_BUFFERS_PROCESSED, &n);
819 palSourceUnqueueBuffers(This->source, 1, &buf);
820 palDeleteBuffers(1, &buf);
826 palcGetIntegerv(This->capdev, ALC_CAPTURE_SAMPLES, 1, &avail);
828 palcCaptureSamples(This->capdev, This->buffer, avail);
830 This->pad = This->padpartial = 0;
832 This->frameswritten = 0;
834 LeaveCriticalSection(This->crst);
838 static HRESULT WINAPI AC_SetEventHandle(IAudioClient *iface, HANDLE handle)
840 ACImpl *This = (ACImpl*)iface;
841 TRACE("(%p)\n", This);
843 return AUDCLNT_E_NOT_INITIALIZED;
846 if (!(This->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK))
847 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED;
848 This->handle = handle;
852 static HRESULT WINAPI AC_GetService(IAudioClient *iface, REFIID riid, void **ppv)
854 ACImpl *This = (ACImpl*)iface;
856 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppv);
858 return AUDCLNT_E_NOT_INITIALIZED;
863 if (IsEqualIID(riid, &IID_IAudioRenderClient)) {
864 if (This->parent->flow != eRender)
865 return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
867 hr = AudioRenderClient_Create(This, &This->render);
869 } else if (IsEqualIID(riid, &IID_IAudioCaptureClient)) {
870 if (This->parent->flow != eCapture)
871 return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
873 hr = AudioCaptureClient_Create(This, &This->capture);
874 *ppv = This->capture;
875 } else if (IsEqualIID(riid, &IID_IAudioSessionControl)) {
877 hr = AudioSessionControl_Create(This, &This->session);
878 *ppv = This->session;
879 } else if (IsEqualIID(riid, &IID_IAudioClock)) {
881 hr = AudioClock_Create(This, &This->clock);
889 IUnknown_AddRef((IUnknown*)*ppv);
893 FIXME("stub %s\n", debugstr_guid(riid));
894 return E_NOINTERFACE;
897 static const IAudioClientVtbl ACImpl_Vtbl =
905 AC_GetCurrentPadding,
906 AC_IsFormatSupported,
916 static HRESULT AudioRenderClient_Create(ACImpl *parent, ACRender **ppv)
920 This = *ppv = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
922 return E_OUTOFMEMORY;
923 This->lpVtbl = &ACRender_Vtbl;
925 This->parent = parent;
929 static void AudioRenderClient_Destroy(ACRender *This)
931 This->parent->render = NULL;
932 HeapFree(GetProcessHeap(), 0, This);
935 static HRESULT WINAPI ACR_QueryInterface(IAudioRenderClient *iface, REFIID riid, void **ppv)
937 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ppv);
942 if (IsEqualIID(riid, &IID_IUnknown)
943 || IsEqualIID(riid, &IID_IAudioRenderClient))
946 IUnknown_AddRef((IUnknown*)*ppv);
949 WARN("Unknown interface %s\n", debugstr_guid(riid));
950 return E_NOINTERFACE;
953 static ULONG WINAPI ACR_AddRef(IAudioRenderClient *iface)
955 ACRender *This = (ACRender*)iface;
957 ref = InterlockedIncrement(&This->ref);
958 TRACE("Refcount now %i\n", ref);
962 static ULONG WINAPI ACR_Release(IAudioRenderClient *iface)
964 ACRender *This = (ACRender*)iface;
966 ref = InterlockedDecrement(&This->ref);
967 TRACE("Refcount now %i\n", ref);
969 AudioRenderClient_Destroy(This);
973 static HRESULT WINAPI ACR_GetBuffer(IAudioRenderClient *iface, UINT32 frames, BYTE **data)
975 ACRender *This = (ACRender*)iface;
976 DWORD free, framesize;
977 TRACE("(%p)->(%u,%p)\n", This, frames, data);
984 if (This->parent->locked) {
986 return AUDCLNT_E_OUT_OF_ORDER;
988 AC_GetCurrentPadding((IAudioClient*)This->parent, &free);
989 if (This->parent->bufsize-free < frames) {
990 ERR("Too large: %u %u %u\n", This->parent->bufsize, free, frames);
991 return AUDCLNT_E_BUFFER_TOO_LARGE;
993 EnterCriticalSection(This->parent->crst);
994 This->parent->locked = frames;
995 framesize = This->parent->pwfx->nBlockAlign;
997 /* Exact offset doesn't matter, offset could be 0 forever
998 * but increasing it is easier to debug */
999 if (This->parent->ofs + frames > This->parent->bufsize)
1000 This->parent->ofs = 0;
1001 *data = This->parent->buffer + This->parent->ofs * framesize;
1003 LeaveCriticalSection(This->parent->crst);
1007 static HRESULT WINAPI ACR_ReleaseBuffer(IAudioRenderClient *iface, UINT32 written, DWORD flags)
1009 ACRender *This = (ACRender*)iface;
1010 BYTE *buf = This->parent->buffer;
1011 DWORD framesize = This->parent->pwfx->nBlockAlign;
1012 DWORD ofs = This->parent->ofs;
1013 DWORD bufsize = This->parent->bufsize;
1014 DWORD locked = This->parent->locked;
1015 DWORD freq = This->parent->pwfx->nSamplesPerSec;
1016 DWORD bpp = This->parent->pwfx->wBitsPerSample;
1019 TRACE("(%p)->(%u,%x)\n", This, written, flags);
1021 if (locked < written)
1022 return AUDCLNT_E_INVALID_SIZE;
1024 if (flags & ~AUDCLNT_BUFFERFLAGS_SILENT)
1025 return E_INVALIDARG;
1028 FIXME("Handled right?\n");
1029 This->parent->locked = 0;
1033 if (!This->parent->locked)
1034 return AUDCLNT_E_OUT_OF_ORDER;
1036 EnterCriticalSection(This->parent->crst);
1037 setALContext(This->parent->parent->ctx);
1039 This->parent->ofs += written;
1040 This->parent->ofs %= bufsize;
1041 This->parent->pad += written;
1042 This->parent->frameswritten += written;
1045 written *= framesize;
1046 bufsize *= framesize;
1047 locked *= framesize;
1049 if (flags & AUDCLNT_BUFFERFLAGS_SILENT)
1050 memset(buf+ofs, bpp != 8 ? 0 : 128, written);
1051 TRACE("buf: %p, ofs: %x, written %u, freq %u\n", buf, ofs, written, freq);
1053 palGenBuffers(1, &albuf);
1054 palBufferData(albuf, This->parent->format, buf+ofs, written, freq);
1055 palSourceQueueBuffers(This->parent->source, 1, &albuf);
1056 TRACE("Queued %u\n", albuf);
1058 if (This->parent->running) {
1059 ALint state = AL_PLAYING, done = 0, padpart = 0;
1061 palGetSourcei(This->parent->source, AL_BUFFERS_PROCESSED, &done);
1062 palGetSourcei(This->parent->source, AL_BYTE_OFFSET, &padpart);
1063 palGetSourcei(This->parent->source, AL_SOURCE_STATE, &state);
1064 padpart /= framesize;
1066 if (state == AL_STOPPED) {
1067 padpart = This->parent->pad;
1068 /* Buffer might have been processed in the small window
1069 * between first and third call */
1070 palGetSourcei(This->parent->source, AL_BUFFERS_PROCESSED, &done);
1072 if (done || This->parent->padpartial != padpart)
1073 This->parent->laststamp = gettime();
1074 This->parent->padpartial = padpart;
1077 ALint size, bits, chan;
1080 palSourceUnqueueBuffers(This->parent->source, 1, &which);
1081 palGetBufferi(which, AL_SIZE, &size);
1082 palGetBufferi(which, AL_BITS, &bits);
1083 palGetBufferi(which, AL_CHANNELS, &chan);
1084 size /= bits * chan / 8;
1085 if (size > This->parent->pad) {
1087 size = This->parent->pad;
1089 This->parent->pad -= size;
1090 This->parent->padpartial -= size;
1091 TRACE("Unqueued %u\n", which);
1092 palDeleteBuffers(1, &which);
1095 if (state != AL_PLAYING) {
1096 ERR("Starting from %x\n", state);
1097 palSourcePlay(This->parent->source);
1101 This->parent->locked = 0;
1105 LeaveCriticalSection(This->parent->crst);
1110 static const IAudioRenderClientVtbl ACRender_Vtbl = {
1118 static HRESULT AudioCaptureClient_Create(ACImpl *parent, ACCapture **ppv)
1121 This = *ppv = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1123 return E_OUTOFMEMORY;
1124 This->lpVtbl = &ACCapture_Vtbl;
1126 This->parent = parent;
1130 static void AudioCaptureClient_Destroy(ACCapture *This)
1132 This->parent->capture = NULL;
1133 HeapFree(GetProcessHeap(), 0, This);
1136 static HRESULT WINAPI ACC_QueryInterface(IAudioCaptureClient *iface, REFIID riid, void **ppv)
1138 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ppv);
1143 if (IsEqualIID(riid, &IID_IUnknown)
1144 || IsEqualIID(riid, &IID_IAudioCaptureClient))
1147 IUnknown_AddRef((IUnknown*)*ppv);
1150 WARN("Unknown interface %s\n", debugstr_guid(riid));
1151 return E_NOINTERFACE;
1154 static ULONG WINAPI ACC_AddRef(IAudioCaptureClient *iface)
1156 ACCapture *This = (ACCapture*)iface;
1158 ref = InterlockedIncrement(&This->ref);
1159 TRACE("Refcount now %i\n", ref);
1163 static ULONG WINAPI ACC_Release(IAudioCaptureClient *iface)
1165 ACCapture *This = (ACCapture*)iface;
1167 ref = InterlockedDecrement(&This->ref);
1168 TRACE("Refcount now %i\n", ref);
1170 AudioCaptureClient_Destroy(This);
1174 static HRESULT WINAPI ACC_GetBuffer(IAudioCaptureClient *iface, BYTE **data, UINT32 *frames, DWORD *flags, UINT64 *devpos, UINT64 *qpcpos)
1176 ACCapture *This = (ACCapture*)iface;
1178 DWORD block = This->parent->pwfx->nBlockAlign;
1180 TRACE("(%p)->(%p,%p,%p,%p,%p)\n", This, data, frames, flags, devpos, qpcpos);
1187 FIXME("Flags can be null?\n");
1190 EnterCriticalSection(This->parent->crst);
1191 hr = AUDCLNT_E_OUT_OF_ORDER;
1192 if (This->parent->locked)
1194 IAudioCaptureClient_GetNextPacketSize(iface, frames);
1195 ofs = This->parent->ofs;
1196 bufsize = This->parent->bufsize;
1197 if ( (ofs*block) % This->parent->psize)
1198 ERR("Unaligned offset %u with %u\n", ofs*block, This->parent->psize);
1199 *data = This->parent->buffer + ofs * block;
1200 This->parent->locked = *frames;
1202 *devpos = This->parent->frameswritten - This->parent->pad;
1204 *qpcpos = This->parent->laststamp;
1208 hr = AUDCLNT_S_BUFFER_EMPTY;
1210 LeaveCriticalSection(This->parent->crst);
1214 static HRESULT WINAPI ACC_ReleaseBuffer(IAudioCaptureClient *iface, UINT32 written)
1216 ACCapture *This = (ACCapture*)iface;
1218 EnterCriticalSection(This->parent->crst);
1219 if (!written || written == This->parent->locked)
1220 This->parent->locked = 0;
1221 else if (!This->parent->locked)
1222 hr = AUDCLNT_E_OUT_OF_ORDER;
1224 hr = AUDCLNT_E_INVALID_SIZE;
1225 This->parent->ofs += written;
1226 This->parent->ofs %= This->parent->bufsize;
1227 This->parent->pad -= written;
1228 LeaveCriticalSection(This->parent->crst);
1232 static HRESULT WINAPI ACC_GetNextPacketSize(IAudioCaptureClient *iface, UINT32 *frames)
1234 ACCapture *This = (ACCapture*)iface;
1236 return AC_GetCurrentPadding((IAudioClient*)This->parent, frames);
1239 static const IAudioCaptureClientVtbl ACCapture_Vtbl =
1246 ACC_GetNextPacketSize
1249 static HRESULT AudioSessionControl_Create(ACImpl *parent, ACSession **ppv)
1252 This = *ppv = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1254 return E_OUTOFMEMORY;
1255 This->lpVtbl = &ACSession_Vtbl;
1257 This->parent = parent;
1261 static void AudioSessionControl_Destroy(ACSession *This)
1263 This->parent->session = NULL;
1264 HeapFree(GetProcessHeap(), 0, This);
1267 static HRESULT WINAPI ACS_QueryInterface(IAudioSessionControl2 *iface, REFIID riid, void **ppv)
1269 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ppv);
1274 if (IsEqualIID(riid, &IID_IUnknown)
1275 || IsEqualIID(riid, &IID_IAudioSessionControl)
1276 || IsEqualIID(riid, &IID_IAudioSessionControl2))
1279 IUnknown_AddRef((IUnknown*)*ppv);
1282 WARN("Unknown interface %s\n", debugstr_guid(riid));
1283 return E_NOINTERFACE;
1286 static ULONG WINAPI ACS_AddRef(IAudioSessionControl2 *iface)
1288 ACSession *This = (ACSession*)iface;
1290 ref = InterlockedIncrement(&This->ref);
1291 TRACE("Refcount now %i\n", ref);
1295 static ULONG WINAPI ACS_Release(IAudioSessionControl2 *iface)
1297 ACSession *This = (ACSession*)iface;
1299 ref = InterlockedDecrement(&This->ref);
1300 TRACE("Refcount now %i\n", ref);
1302 AudioSessionControl_Destroy(This);
1306 static HRESULT WINAPI ACS_GetState(IAudioSessionControl2 *iface, AudioSessionState *state)
1308 ACSession *This = (ACSession*)iface;
1309 TRACE("(%p)->(%p)\n", This, state);
1313 *state = This->parent->parent->state;
1317 static HRESULT WINAPI ACS_GetDisplayName(IAudioSessionControl2 *iface, WCHAR **name)
1319 ACSession *This = (ACSession*)iface;
1320 TRACE("(%p)->(%p)\n", This, name);
1327 static HRESULT WINAPI ACS_SetDisplayName(IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session)
1329 ACSession *This = (ACSession*)iface;
1330 TRACE("(%p)->(%p,%s)\n", This, name, debugstr_guid(session));
1335 static HRESULT WINAPI ACS_GetIconPath(IAudioSessionControl2 *iface, WCHAR **path)
1337 ACSession *This = (ACSession*)iface;
1338 TRACE("(%p)->(%p)\n", This, path);
1345 static HRESULT WINAPI ACS_SetIconPath(IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session)
1347 ACSession *This = (ACSession*)iface;
1348 TRACE("(%p)->(%p,%s)\n", This, path, debugstr_guid(session));
1353 static HRESULT WINAPI ACS_GetGroupingParam(IAudioSessionControl2 *iface, GUID *group)
1355 ACSession *This = (ACSession*)iface;
1356 TRACE("(%p)->(%p)\n", This, group);
1363 static HRESULT WINAPI ACS_SetGroupingParam(IAudioSessionControl2 *iface, GUID *group, const GUID *session)
1365 ACSession *This = (ACSession*)iface;
1366 TRACE("(%p)->(%s,%s)\n", This, debugstr_guid(group), debugstr_guid(session));
1371 static HRESULT WINAPI ACS_RegisterAudioSessionNotification(IAudioSessionControl2 *iface, IAudioSessionEvents *events)
1373 ACSession *This = (ACSession*)iface;
1374 TRACE("(%p)->(%p)\n", This, events);
1379 static HRESULT WINAPI ACS_UnregisterAudioSessionNotification(IAudioSessionControl2 *iface, IAudioSessionEvents *events)
1381 ACSession *This = (ACSession*)iface;
1382 TRACE("(%p)->(%p)\n", This, events);
1387 static HRESULT WINAPI ACS_GetSessionIdentifier(IAudioSessionControl2 *iface, WCHAR **id)
1389 ACSession *This = (ACSession*)iface;
1390 TRACE("(%p)->(%p)\n", This, id);
1397 static HRESULT WINAPI ACS_GetSessionInstanceIdentifier(IAudioSessionControl2 *iface, WCHAR **id)
1399 ACSession *This = (ACSession*)iface;
1400 TRACE("(%p)->(%p)\n", This, id);
1407 static HRESULT WINAPI ACS_GetProcessId(IAudioSessionControl2 *iface, DWORD *pid)
1409 ACSession *This = (ACSession*)iface;
1410 TRACE("(%p)->(%p)\n", This, pid);
1414 *pid = GetCurrentProcessId();
1418 static HRESULT WINAPI ACS_IsSystemSoundsSession(IAudioSessionControl2 *iface)
1420 ACSession *This = (ACSession*)iface;
1421 TRACE("(%p)\n", This);
1426 static HRESULT WINAPI ACS_SetDuckingPreference(IAudioSessionControl2 *iface, BOOL optout)
1428 ACSession *This = (ACSession*)iface;
1429 TRACE("(%p)\n", This);
1434 static const IAudioSessionControl2Vtbl ACSession_Vtbl =
1444 ACS_GetGroupingParam,
1445 ACS_SetGroupingParam,
1446 ACS_RegisterAudioSessionNotification,
1447 ACS_UnregisterAudioSessionNotification,
1448 ACS_GetSessionIdentifier,
1449 ACS_GetSessionInstanceIdentifier,
1451 ACS_IsSystemSoundsSession,
1452 ACS_SetDuckingPreference
1455 static HRESULT AudioClock_Create(ACImpl *parent, AClock **ppv)
1458 This = *ppv = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1460 return E_OUTOFMEMORY;
1461 This->lpVtbl = &AClock_Vtbl;
1462 This->lp2Vtbl = &AClock2_Vtbl;
1464 This->parent = parent;
1468 static void AudioClock_Destroy(AClock *This)
1470 This->parent->clock = NULL;
1471 HeapFree(GetProcessHeap(), 0, This);
1474 static HRESULT WINAPI AClock_QueryInterface(IAudioClock *iface, REFIID riid, void **ppv)
1476 AClock *This = (AClock*)iface;
1477 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ppv);
1482 if (IsEqualIID(riid, &IID_IUnknown)
1483 || IsEqualIID(riid, &IID_IAudioClock))
1485 else if (IsEqualIID(riid, &IID_IAudioClock2))
1486 *ppv = &This->lp2Vtbl;
1488 IUnknown_AddRef((IUnknown*)*ppv);
1491 WARN("Unknown interface %s\n", debugstr_guid(riid));
1492 return E_NOINTERFACE;
1495 static ULONG WINAPI AClock_AddRef(IAudioClock *iface)
1497 AClock *This = (AClock*)iface;
1499 ref = InterlockedIncrement(&This->ref);
1500 TRACE("Refcount now %i\n", ref);
1504 static ULONG WINAPI AClock_Release(IAudioClock *iface)
1506 AClock *This = (AClock*)iface;
1508 ref = InterlockedDecrement(&This->ref);
1509 TRACE("Refcount now %i\n", ref);
1511 AudioClock_Destroy(This);
1515 static HRESULT WINAPI AClock_GetFrequency(IAudioClock *iface, UINT64 *freq)
1517 AClock *This = (AClock*)iface;
1518 TRACE("(%p)->(%p)\n", This, freq);
1520 *freq = (UINT64)This->parent->pwfx->nSamplesPerSec;
1524 static HRESULT WINAPI AClock_GetPosition(IAudioClock *iface, UINT64 *pos, UINT64 *qpctime)
1526 AClock *This = (AClock*)iface;
1529 TRACE("(%p)->(%p,%p)\n", This, pos, qpctime);
1534 EnterCriticalSection(This->parent->crst);
1535 AC_GetCurrentPadding((IAudioClient*)This->parent, &pad);
1536 *pos = This->parent->frameswritten - pad;
1538 *qpctime = gettime();
1539 LeaveCriticalSection(This->parent->crst);
1544 static HRESULT WINAPI AClock_GetCharacteristics(IAudioClock *iface, DWORD *chars)
1546 AClock *This = (AClock*)iface;
1547 TRACE("(%p)->(%p)\n", This, chars);
1551 *chars = AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ;
1555 static const IAudioClockVtbl AClock_Vtbl =
1557 AClock_QueryInterface,
1560 AClock_GetFrequency,
1562 AClock_GetCharacteristics
1565 static AClock *get_clock_from_clock2(IAudioClock2 *iface)
1567 return (AClock*)((char*)iface - offsetof(AClock,lp2Vtbl));
1570 static HRESULT WINAPI AClock2_QueryInterface(IAudioClock2 *iface, REFIID riid, void **ppv)
1572 AClock *This = get_clock_from_clock2(iface);
1573 return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
1576 static ULONG WINAPI AClock2_AddRef(IAudioClock2 *iface)
1578 AClock *This = get_clock_from_clock2(iface);
1579 return IUnknown_AddRef((IUnknown*)This);
1582 static ULONG WINAPI AClock2_Release(IAudioClock2 *iface)
1584 AClock *This = get_clock_from_clock2(iface);
1585 return IUnknown_Release((IUnknown*)This);
1588 static HRESULT WINAPI AClock2_GetPosition(IAudioClock2 *iface, UINT64 *pos, UINT64 *qpctime)
1590 AClock *This = get_clock_from_clock2(iface);
1591 return AClock_GetPosition((IAudioClock*)This, pos, qpctime);
1594 static const IAudioClock2Vtbl AClock2_Vtbl =
1596 AClock2_QueryInterface,