2 * Copyright 2010 Maarten Lankhorst for CodeWeavers
3 * Copyright 2011 Andrew Eikum for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define NONAMELESSUNION
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33 #include "wine/list.h"
36 #include "mmdeviceapi.h"
42 #include "endpointvolume.h"
43 #include "audioclient.h"
44 #include "audiopolicy.h"
46 #include <alsa/asoundlib.h>
48 WINE_DEFAULT_DEBUG_CHANNEL(alsa);
49 WINE_DECLARE_DEBUG_CHANNEL(winediag);
51 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
53 static const REFERENCE_TIME DefaultPeriod = 100000;
54 static const REFERENCE_TIME MinimumPeriod = 50000;
57 typedef struct ACImpl ACImpl;
59 typedef struct _AudioSession {
70 CRITICAL_SECTION lock;
75 typedef struct _AudioSessionWrapper {
76 IAudioSessionControl2 IAudioSessionControl2_iface;
77 IChannelAudioVolume IChannelAudioVolume_iface;
78 ISimpleAudioVolume ISimpleAudioVolume_iface;
83 AudioSession *session;
84 } AudioSessionWrapper;
87 IAudioClient IAudioClient_iface;
88 IAudioRenderClient IAudioRenderClient_iface;
89 IAudioCaptureClient IAudioCaptureClient_iface;
90 IAudioClock IAudioClock_iface;
91 IAudioClock2 IAudioClock2_iface;
92 IAudioStreamVolume IAudioStreamVolume_iface;
96 snd_pcm_t *pcm_handle;
97 snd_pcm_uframes_t alsa_bufsize_frames;
98 snd_pcm_hw_params_t *hw_params; /* does not hold state between calls */
99 snd_pcm_format_t alsa_format;
106 AUDCLNT_SHAREMODE share;
110 BOOL initted, started;
111 REFERENCE_TIME mmdev_period_rt;
112 UINT64 written_frames;
113 UINT32 bufsize_frames, held_frames, tmp_buffer_frames;
114 UINT32 lcl_offs_frames; /* offs into local_buffer where valid data starts */
117 BYTE *local_buffer, *tmp_buffer;
120 CRITICAL_SECTION lock;
122 AudioSession *session;
123 AudioSessionWrapper *session_wrapper;
130 LOCKED_NORMAL, /* public buffer piece is from local_buffer */
131 LOCKED_WRAPPED /* public buffer piece is wrapped around, in tmp_buffer */
134 typedef struct _SessionMgr {
135 IAudioSessionManager2 IAudioSessionManager2_iface;
142 static HANDLE g_timer_q;
144 static CRITICAL_SECTION g_sessions_lock;
145 static struct list g_sessions = LIST_INIT(g_sessions);
147 static const WCHAR defaultW[] = {'d','e','f','a','u','l','t',0};
148 static const char defname[] = "default";
150 static const IAudioClientVtbl AudioClient_Vtbl;
151 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl;
152 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl;
153 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl;
154 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl;
155 static const IAudioClockVtbl AudioClock_Vtbl;
156 static const IAudioClock2Vtbl AudioClock2_Vtbl;
157 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl;
158 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl;
159 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl;
161 static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
163 static inline ACImpl *impl_from_IAudioClient(IAudioClient *iface)
165 return CONTAINING_RECORD(iface, ACImpl, IAudioClient_iface);
168 static inline ACImpl *impl_from_IAudioRenderClient(IAudioRenderClient *iface)
170 return CONTAINING_RECORD(iface, ACImpl, IAudioRenderClient_iface);
173 static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface)
175 return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface);
178 static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface)
180 return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface);
183 static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface)
185 return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface);
188 static inline AudioSessionWrapper *impl_from_IChannelAudioVolume(IChannelAudioVolume *iface)
190 return CONTAINING_RECORD(iface, AudioSessionWrapper, IChannelAudioVolume_iface);
193 static inline ACImpl *impl_from_IAudioClock(IAudioClock *iface)
195 return CONTAINING_RECORD(iface, ACImpl, IAudioClock_iface);
198 static inline ACImpl *impl_from_IAudioClock2(IAudioClock2 *iface)
200 return CONTAINING_RECORD(iface, ACImpl, IAudioClock2_iface);
203 static inline ACImpl *impl_from_IAudioStreamVolume(IAudioStreamVolume *iface)
205 return CONTAINING_RECORD(iface, ACImpl, IAudioStreamVolume_iface);
208 static inline SessionMgr *impl_from_IAudioSessionManager2(IAudioSessionManager2 *iface)
210 return CONTAINING_RECORD(iface, SessionMgr, IAudioSessionManager2_iface);
213 BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved)
215 if(reason == DLL_PROCESS_ATTACH){
216 g_timer_q = CreateTimerQueue();
220 InitializeCriticalSection(&g_sessions_lock);
226 /* From <dlls/mmdevapi/mmdevapi.h> */
227 enum DriverPriority {
228 Priority_Unavailable = 0,
234 int WINAPI AUDDRV_GetPriority(void)
236 return Priority_Neutral;
239 static BOOL alsa_try_open(const char *devnode, snd_pcm_stream_t stream)
244 if((err = snd_pcm_open(&handle, devnode, stream, SND_PCM_NONBLOCK)) < 0){
245 WARN("The device \"%s\" failed to open: %d (%s).\n",
246 devnode, err, snd_strerror(err));
250 snd_pcm_close(handle);
254 static HRESULT alsa_get_card_devices(snd_pcm_stream_t stream, WCHAR **ids, char **keys,
255 UINT *num, snd_ctl_t *ctl, int card, const WCHAR *cardnameW)
257 static const WCHAR dashW[] = {' ','-',' ',0};
259 snd_pcm_info_t *info;
261 info = HeapAlloc(GetProcessHeap(), 0, snd_pcm_info_sizeof());
263 return E_OUTOFMEMORY;
265 snd_pcm_info_set_subdevice(info, 0);
266 snd_pcm_info_set_stream(info, stream);
269 for(err = snd_ctl_pcm_next_device(ctl, &device); device != -1 && err >= 0;
270 err = snd_ctl_pcm_next_device(ctl, &device)){
274 snd_pcm_info_set_device(info, device);
276 if((err = snd_ctl_pcm_info(ctl, info)) < 0){
278 /* This device doesn't have the right stream direction */
281 WARN("Failed to get info for card %d, device %d: %d (%s)\n",
282 card, device, err, snd_strerror(err));
286 sprintf(devnode, "plughw:%d,%d", card, device);
287 if(!alsa_try_open(devnode, stream))
293 devname = snd_pcm_info_get_name(info);
295 WARN("Unable to get device name for card %d, device %d\n", card,
300 cardlen = lstrlenW(cardnameW);
301 len = MultiByteToWideChar(CP_UNIXCP, 0, devname, -1, NULL, 0);
302 len += lstrlenW(dashW);
304 ids[*num] = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
306 HeapFree(GetProcessHeap(), 0, info);
307 return E_OUTOFMEMORY;
309 memcpy(ids[*num], cardnameW, cardlen * sizeof(WCHAR));
310 memcpy(ids[*num] + cardlen, dashW, lstrlenW(dashW) * sizeof(WCHAR));
311 cardlen += lstrlenW(dashW);
312 MultiByteToWideChar(CP_UNIXCP, 0, devname, -1, ids[*num] + cardlen,
315 keys[*num] = HeapAlloc(GetProcessHeap(), 0, 32);
317 HeapFree(GetProcessHeap(), 0, info);
318 HeapFree(GetProcessHeap(), 0, ids[*num]);
319 return E_OUTOFMEMORY;
321 memcpy(keys[*num], devnode, sizeof(devnode));
327 HeapFree(GetProcessHeap(), 0, info);
330 WARN("Got a failure during device enumeration on card %d: %d (%s)\n",
331 card, err, snd_strerror(err));
336 static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR **ids, char **keys,
339 snd_pcm_stream_t stream = (flow == eRender ? SND_PCM_STREAM_PLAYBACK :
340 SND_PCM_STREAM_CAPTURE);
346 if(alsa_try_open(defname, stream)){
348 *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW));
349 memcpy(*ids, defaultW, sizeof(defaultW));
350 *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(defname));
351 memcpy(*keys, defname, sizeof(defname));
356 for(err = snd_card_next(&card); card != -1 && err >= 0;
357 err = snd_card_next(&card)){
359 const char *cardname;
364 sprintf(cardpath, "hw:%u", card);
366 if((err = snd_ctl_open(&ctl, cardpath, 0)) < 0){
367 WARN("Unable to open ctl for ALSA device %s: %d (%s)\n", cardpath,
368 err, snd_strerror(err));
372 if((err = snd_card_get_name(card, (char **)&cardname)) < 0){
373 WARN("Unable to get card name for ALSA device %s: %d (%s)\n",
374 cardpath, err, snd_strerror(err));
375 /* FIXME: Should be localized */
376 cardname = "Unknown soundcard";
379 len = MultiByteToWideChar(CP_UNIXCP, 0, cardname, -1, NULL, 0);
380 cardnameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
383 return E_OUTOFMEMORY;
385 MultiByteToWideChar(CP_UNIXCP, 0, cardname, -1, cardnameW, len);
387 alsa_get_card_devices(stream, ids, keys, num, ctl, card, cardnameW);
389 HeapFree(GetProcessHeap(), 0, cardnameW);
395 WARN("Got a failure during card enumeration: %d (%s)\n",
396 err, snd_strerror(err));
401 HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, char ***keys,
402 UINT *num, UINT *def_index)
406 TRACE("%d %p %p %p %p\n", flow, ids, keys, num, def_index);
408 hr = alsa_enum_devices(flow, NULL, NULL, num);
419 *ids = HeapAlloc(GetProcessHeap(), 0, *num * sizeof(WCHAR *));
420 *keys = HeapAlloc(GetProcessHeap(), 0, *num * sizeof(char *));
422 HeapFree(GetProcessHeap(), 0, *ids);
423 HeapFree(GetProcessHeap(), 0, *keys);
424 return E_OUTOFMEMORY;
429 hr = alsa_enum_devices(flow, *ids, *keys, num);
432 for(i = 0; i < *num; ++i){
433 HeapFree(GetProcessHeap(), 0, (*ids)[i]);
434 HeapFree(GetProcessHeap(), 0, (*keys)[i]);
436 HeapFree(GetProcessHeap(), 0, *ids);
437 HeapFree(GetProcessHeap(), 0, *keys);
438 return E_OUTOFMEMORY;
444 /* Using the pulse PCM device from alsa-plugins 1.0.24 triggers a bug
445 * which causes audio to cease playing after a few minutes of playback.
446 * Setting handle_underrun=1 on pulse-backed ALSA devices seems to work
447 * around this issue. */
448 static snd_config_t *make_handle_underrun_config(const char *name)
450 snd_config_t *lconf, *dev_node, *hu_node, *type_node;
451 char dev_node_name[64];
452 const char *type_str;
457 if((err = snd_config_copy(&lconf, snd_config)) < 0){
458 WARN("snd_config_copy failed: %d (%s)\n", err, snd_strerror(err));
462 sprintf(dev_node_name, "pcm.%s", name);
463 err = snd_config_search(lconf, dev_node_name, &dev_node);
465 snd_config_delete(lconf);
469 snd_config_delete(lconf);
470 WARN("snd_config_search failed: %d (%s)\n", err, snd_strerror(err));
474 /* ALSA is extremely fragile. If it runs into a config setting it doesn't
475 * recognize, it tends to fail or assert. So we only want to inject
476 * handle_underrun=1 on devices that we know will recognize it. */
477 err = snd_config_search(dev_node, "type", &type_node);
479 snd_config_delete(lconf);
483 snd_config_delete(lconf);
484 WARN("snd_config_search failed: %d (%s)\n", err, snd_strerror(err));
488 if((err = snd_config_get_string(type_node, &type_str)) < 0){
489 snd_config_delete(lconf);
493 if(strcmp(type_str, "pulse") != 0){
494 snd_config_delete(lconf);
498 err = snd_config_search(dev_node, "handle_underrun", &hu_node);
500 /* user already has an explicit handle_underrun setting, so don't
501 * use a local config */
502 snd_config_delete(lconf);
506 snd_config_delete(lconf);
507 WARN("snd_config_search failed: %d (%s)\n", err, snd_strerror(err));
511 if((err = snd_config_imake_integer(&hu_node, "handle_underrun", 1)) < 0){
512 snd_config_delete(lconf);
513 WARN("snd_config_imake_integer failed: %d (%s)\n", err,
518 if((err = snd_config_add(dev_node, hu_node)) < 0){
519 snd_config_delete(lconf);
520 WARN("snd_config_add failed: %d (%s)\n", err, snd_strerror(err));
527 HRESULT WINAPI AUDDRV_GetAudioEndpoint(const char *key, IMMDevice *dev,
528 EDataFlow dataflow, IAudioClient **out)
532 snd_pcm_stream_t stream;
534 static int handle_underrun = 1;
536 TRACE("\"%s\" %p %d %p\n", key, dev, dataflow, out);
538 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACImpl));
540 return E_OUTOFMEMORY;
542 This->IAudioClient_iface.lpVtbl = &AudioClient_Vtbl;
543 This->IAudioRenderClient_iface.lpVtbl = &AudioRenderClient_Vtbl;
544 This->IAudioCaptureClient_iface.lpVtbl = &AudioCaptureClient_Vtbl;
545 This->IAudioClock_iface.lpVtbl = &AudioClock_Vtbl;
546 This->IAudioClock2_iface.lpVtbl = &AudioClock2_Vtbl;
547 This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl;
549 if(dataflow == eRender)
550 stream = SND_PCM_STREAM_PLAYBACK;
551 else if(dataflow == eCapture)
552 stream = SND_PCM_STREAM_CAPTURE;
554 HeapFree(GetProcessHeap(), 0, This);
558 This->dataflow = dataflow;
559 if(handle_underrun && ((lconf = make_handle_underrun_config(key)))){
560 err = snd_pcm_open_lconf(&This->pcm_handle, key, stream, SND_PCM_NONBLOCK, lconf);
561 TRACE("Opening PCM device \"%s\" with handle_underrun: %d\n", key, err);
562 snd_config_delete(lconf);
563 /* Pulse <= 2010 returns EINVAL, it does not know handle_underrun. */
565 ERR_(winediag)("PulseAudio \"%s\" %d without handle_underrun. Audio may hang."
566 " Please upgrade to alsa_plugins >= 1.0.24\n", key, err);
572 err = snd_pcm_open(&This->pcm_handle, key, stream, SND_PCM_NONBLOCK);
575 HeapFree(GetProcessHeap(), 0, This);
576 WARN("Unable to open PCM \"%s\": %d (%s)\n", key, err, snd_strerror(err));
580 This->hw_params = HeapAlloc(GetProcessHeap(), 0,
581 snd_pcm_hw_params_sizeof());
582 if(!This->hw_params){
583 HeapFree(GetProcessHeap(), 0, This);
584 snd_pcm_close(This->pcm_handle);
585 return E_OUTOFMEMORY;
588 InitializeCriticalSection(&This->lock);
591 IMMDevice_AddRef(This->parent);
593 *out = &This->IAudioClient_iface;
594 IAudioClient_AddRef(&This->IAudioClient_iface);
599 static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient *iface,
600 REFIID riid, void **ppv)
602 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
607 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClient))
610 IUnknown_AddRef((IUnknown*)*ppv);
613 WARN("Unknown interface %s\n", debugstr_guid(riid));
614 return E_NOINTERFACE;
617 static ULONG WINAPI AudioClient_AddRef(IAudioClient *iface)
619 ACImpl *This = impl_from_IAudioClient(iface);
621 ref = InterlockedIncrement(&This->ref);
622 TRACE("(%p) Refcount now %u\n", This, ref);
626 static ULONG WINAPI AudioClient_Release(IAudioClient *iface)
628 ACImpl *This = impl_from_IAudioClient(iface);
630 ref = InterlockedDecrement(&This->ref);
631 TRACE("(%p) Refcount now %u\n", This, ref);
633 IAudioClient_Stop(iface);
634 IMMDevice_Release(This->parent);
635 DeleteCriticalSection(&This->lock);
636 snd_pcm_drop(This->pcm_handle);
637 snd_pcm_close(This->pcm_handle);
639 EnterCriticalSection(&g_sessions_lock);
640 list_remove(&This->entry);
641 LeaveCriticalSection(&g_sessions_lock);
643 HeapFree(GetProcessHeap(), 0, This->vols);
644 HeapFree(GetProcessHeap(), 0, This->local_buffer);
645 HeapFree(GetProcessHeap(), 0, This->tmp_buffer);
646 HeapFree(GetProcessHeap(), 0, This->hw_params);
647 CoTaskMemFree(This->fmt);
648 HeapFree(GetProcessHeap(), 0, This);
653 static void dump_fmt(const WAVEFORMATEX *fmt)
655 TRACE("wFormatTag: 0x%x (", fmt->wFormatTag);
656 switch(fmt->wFormatTag){
657 case WAVE_FORMAT_PCM:
658 TRACE("WAVE_FORMAT_PCM");
660 case WAVE_FORMAT_IEEE_FLOAT:
661 TRACE("WAVE_FORMAT_IEEE_FLOAT");
663 case WAVE_FORMAT_EXTENSIBLE:
664 TRACE("WAVE_FORMAT_EXTENSIBLE");
672 TRACE("nChannels: %u\n", fmt->nChannels);
673 TRACE("nSamplesPerSec: %u\n", fmt->nSamplesPerSec);
674 TRACE("nAvgBytesPerSec: %u\n", fmt->nAvgBytesPerSec);
675 TRACE("nBlockAlign: %u\n", fmt->nBlockAlign);
676 TRACE("wBitsPerSample: %u\n", fmt->wBitsPerSample);
677 TRACE("cbSize: %u\n", fmt->cbSize);
679 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE){
680 WAVEFORMATEXTENSIBLE *fmtex = (void*)fmt;
681 TRACE("dwChannelMask: %08x\n", fmtex->dwChannelMask);
682 TRACE("Samples: %04x\n", fmtex->Samples.wReserved);
683 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex->SubFormat));
687 static WAVEFORMATEX *clone_format(const WAVEFORMATEX *fmt)
692 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
693 size = sizeof(WAVEFORMATEXTENSIBLE);
695 size = sizeof(WAVEFORMATEX);
697 ret = CoTaskMemAlloc(size);
701 memcpy(ret, fmt, size);
703 ret->cbSize = size - sizeof(WAVEFORMATEX);
708 static void session_init_vols(AudioSession *session, UINT channels)
710 if(session->channel_count < channels){
713 if(session->channel_vols)
714 session->channel_vols = HeapReAlloc(GetProcessHeap(), 0,
715 session->channel_vols, sizeof(float) * channels);
717 session->channel_vols = HeapAlloc(GetProcessHeap(), 0,
718 sizeof(float) * channels);
719 if(!session->channel_vols)
722 for(i = session->channel_count; i < channels; ++i)
723 session->channel_vols[i] = 1.f;
725 session->channel_count = channels;
729 static AudioSession *create_session(const GUID *guid, IMMDevice *device,
734 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AudioSession));
738 memcpy(&ret->guid, guid, sizeof(GUID));
740 ret->device = device;
742 list_init(&ret->clients);
744 list_add_head(&g_sessions, &ret->entry);
746 InitializeCriticalSection(&ret->lock);
748 session_init_vols(ret, num_channels);
750 ret->master_vol = 1.f;
755 /* if channels == 0, then this will return or create a session with
756 * matching dataflow and GUID. otherwise, channels must also match */
757 static HRESULT get_audio_session(const GUID *sessionguid,
758 IMMDevice *device, UINT channels, AudioSession **out)
760 AudioSession *session;
762 if(!sessionguid || IsEqualGUID(sessionguid, &GUID_NULL)){
763 *out = create_session(&GUID_NULL, device, channels);
765 return E_OUTOFMEMORY;
771 LIST_FOR_EACH_ENTRY(session, &g_sessions, AudioSession, entry){
772 if(session->device == device &&
773 IsEqualGUID(sessionguid, &session->guid)){
774 session_init_vols(session, channels);
781 *out = create_session(sessionguid, device, channels);
783 return E_OUTOFMEMORY;
789 static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface,
790 AUDCLNT_SHAREMODE mode, DWORD flags, REFERENCE_TIME duration,
791 REFERENCE_TIME period, const WAVEFORMATEX *fmt,
792 const GUID *sessionguid)
794 ACImpl *This = impl_from_IAudioClient(iface);
795 snd_pcm_sw_params_t *sw_params = NULL;
796 snd_pcm_format_t format;
797 snd_pcm_uframes_t alsa_period_frames;
798 const WAVEFORMATEXTENSIBLE *fmtex = (const WAVEFORMATEXTENSIBLE *)fmt;
799 unsigned int rate, mmdev_period_frames, alsa_period_us;
803 TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This, mode, flags,
804 wine_dbgstr_longlong(duration), wine_dbgstr_longlong(period), fmt, debugstr_guid(sessionguid));
809 if(mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE)
810 return AUDCLNT_E_NOT_INITIALIZED;
812 if(flags & ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS |
813 AUDCLNT_STREAMFLAGS_LOOPBACK |
814 AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
815 AUDCLNT_STREAMFLAGS_NOPERSIST |
816 AUDCLNT_STREAMFLAGS_RATEADJUST |
817 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED |
818 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE |
819 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED)){
820 TRACE("Unknown flags: %08x\n", flags);
825 duration = 300000; /* 0.03s */
827 EnterCriticalSection(&This->lock);
830 LeaveCriticalSection(&This->lock);
831 return AUDCLNT_E_ALREADY_INITIALIZED;
836 if((err = snd_pcm_hw_params_any(This->pcm_handle, This->hw_params)) < 0){
837 WARN("Unable to get hw_params: %d (%s)\n", err, snd_strerror(err));
842 if((err = snd_pcm_hw_params_set_access(This->pcm_handle, This->hw_params,
843 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0){
844 WARN("Unable to set access: %d (%s)\n", err, snd_strerror(err));
849 if(fmt->wFormatTag == WAVE_FORMAT_PCM ||
850 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
851 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))){
852 if(fmt->wBitsPerSample == 8)
853 format = SND_PCM_FORMAT_U8;
854 else if(fmt->wBitsPerSample == 16)
855 format = SND_PCM_FORMAT_S16_LE;
856 else if(fmt->wBitsPerSample == 24)
857 format = SND_PCM_FORMAT_S24_3LE;
858 else if(fmt->wBitsPerSample == 32)
859 format = SND_PCM_FORMAT_S32_LE;
861 WARN("Unsupported bit depth: %u\n", fmt->wBitsPerSample);
862 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
865 }else if(fmt->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
866 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
867 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))){
868 if(fmt->wBitsPerSample == 32)
869 format = SND_PCM_FORMAT_FLOAT_LE;
870 else if(fmt->wBitsPerSample == 64)
871 format = SND_PCM_FORMAT_FLOAT64_LE;
873 WARN("Unsupported float size: %u\n", fmt->wBitsPerSample);
874 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
878 WARN("Unknown wave format: %04x\n", fmt->wFormatTag);
879 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
883 if((err = snd_pcm_hw_params_set_format(This->pcm_handle, This->hw_params,
885 WARN("Unable to set ALSA format to %u: %d (%s)\n", format, err,
891 This->alsa_format = format;
893 rate = fmt->nSamplesPerSec;
894 if((err = snd_pcm_hw_params_set_rate_near(This->pcm_handle, This->hw_params,
896 WARN("Unable to set rate to %u: %d (%s)\n", rate, err,
902 if((err = snd_pcm_hw_params_set_channels(This->pcm_handle, This->hw_params,
903 fmt->nChannels)) < 0){
904 WARN("Unable to set channels to %u: %d (%s)\n", fmt->nChannels, err,
910 alsa_period_us = duration / 100; /* duration / 10 converted to us */
911 if((err = snd_pcm_hw_params_set_period_time_near(This->pcm_handle,
912 This->hw_params, &alsa_period_us, NULL)) < 0){
913 WARN("Unable to set period time near %u: %d (%s)\n", alsa_period_us,
914 err, snd_strerror(err));
919 if((err = snd_pcm_hw_params(This->pcm_handle, This->hw_params)) < 0){
920 WARN("Unable to set hw params: %d (%s)\n", err, snd_strerror(err));
925 if((err = snd_pcm_hw_params_current(This->pcm_handle, This->hw_params)) < 0){
926 WARN("Unable to get current hw params: %d (%s)\n", err, snd_strerror(err));
931 if((err = snd_pcm_hw_params_get_period_size(This->hw_params,
932 &alsa_period_frames, NULL)) < 0){
933 WARN("Unable to get period size: %d (%s)\n", err, snd_strerror(err));
937 TRACE("alsa_period_frames: %lu\n", alsa_period_frames);
939 if((err = snd_pcm_hw_params_get_buffer_size(This->hw_params,
940 &This->alsa_bufsize_frames)) < 0){
941 WARN("Unable to get buffer size: %d (%s)\n", err, snd_strerror(err));
946 sw_params = HeapAlloc(GetProcessHeap(), 0, snd_pcm_sw_params_sizeof());
952 if((err = snd_pcm_sw_params_current(This->pcm_handle, sw_params)) < 0){
953 WARN("Unable to get sw_params: %d (%s)\n", err, snd_strerror(err));
958 if((err = snd_pcm_sw_params_set_start_threshold(This->pcm_handle,
960 WARN("Unable set start threshold to 0: %d (%s)\n", err, snd_strerror(err));
965 if((err = snd_pcm_sw_params_set_stop_threshold(This->pcm_handle,
966 sw_params, This->alsa_bufsize_frames)) < 0){
967 WARN("Unable set stop threshold to %lu: %d (%s)\n",
968 This->alsa_bufsize_frames, err, snd_strerror(err));
973 if((err = snd_pcm_sw_params(This->pcm_handle, sw_params)) < 0){
974 WARN("Unable set sw params: %d (%s)\n", err, snd_strerror(err));
979 if((err = snd_pcm_prepare(This->pcm_handle)) < 0){
980 WARN("Unable to prepare device: %d (%s)\n", err, snd_strerror(err));
986 This->mmdev_period_rt = period;
988 This->mmdev_period_rt = DefaultPeriod;
990 /* Check if the ALSA buffer is so small that it will run out before
991 * the next MMDevAPI period tick occurs. Allow a little wiggle room
992 * with 120% of the period time. */
993 mmdev_period_frames = fmt->nSamplesPerSec * (This->mmdev_period_rt / 10000000.);
994 if(This->alsa_bufsize_frames < 1.2 * mmdev_period_frames)
995 FIXME("ALSA buffer time is smaller than our period time. Expect underruns. (%lu < %u)\n",
996 This->alsa_bufsize_frames, mmdev_period_frames);
998 This->bufsize_frames = ceil((duration / 10000000.) * fmt->nSamplesPerSec);
999 This->local_buffer = HeapAlloc(GetProcessHeap(), 0,
1000 This->bufsize_frames * fmt->nBlockAlign);
1001 if(!This->local_buffer){
1005 if (fmt->wBitsPerSample == 8)
1006 memset(This->local_buffer, 128, This->bufsize_frames * fmt->nBlockAlign);
1008 memset(This->local_buffer, 0, This->bufsize_frames * fmt->nBlockAlign);
1010 This->fmt = clone_format(fmt);
1016 This->vols = HeapAlloc(GetProcessHeap(), 0, fmt->nChannels * sizeof(float));
1022 for(i = 0; i < fmt->nChannels; ++i)
1023 This->vols[i] = 1.f;
1026 This->flags = flags;
1028 EnterCriticalSection(&g_sessions_lock);
1030 hr = get_audio_session(sessionguid, This->parent, fmt->nChannels,
1033 LeaveCriticalSection(&g_sessions_lock);
1037 list_add_tail(&This->session->clients, &This->entry);
1039 LeaveCriticalSection(&g_sessions_lock);
1041 This->initted = TRUE;
1044 HeapFree(GetProcessHeap(), 0, sw_params);
1046 HeapFree(GetProcessHeap(), 0, This->local_buffer);
1047 This->local_buffer = NULL;
1048 CoTaskMemFree(This->fmt);
1050 HeapFree(GetProcessHeap(), 0, This->vols);
1054 LeaveCriticalSection(&This->lock);
1059 static HRESULT WINAPI AudioClient_GetBufferSize(IAudioClient *iface,
1062 ACImpl *This = impl_from_IAudioClient(iface);
1064 TRACE("(%p)->(%p)\n", This, out);
1069 EnterCriticalSection(&This->lock);
1072 LeaveCriticalSection(&This->lock);
1073 return AUDCLNT_E_NOT_INITIALIZED;
1076 *out = This->bufsize_frames;
1078 LeaveCriticalSection(&This->lock);
1083 static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient *iface,
1084 REFERENCE_TIME *latency)
1086 ACImpl *This = impl_from_IAudioClient(iface);
1088 TRACE("(%p)->(%p)\n", This, latency);
1093 EnterCriticalSection(&This->lock);
1096 LeaveCriticalSection(&This->lock);
1097 return AUDCLNT_E_NOT_INITIALIZED;
1100 LeaveCriticalSection(&This->lock);
1107 static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient *iface,
1110 ACImpl *This = impl_from_IAudioClient(iface);
1112 TRACE("(%p)->(%p)\n", This, out);
1117 EnterCriticalSection(&This->lock);
1120 LeaveCriticalSection(&This->lock);
1121 return AUDCLNT_E_NOT_INITIALIZED;
1124 if(This->dataflow == eRender){
1125 snd_pcm_sframes_t avail_frames;
1127 avail_frames = snd_pcm_avail_update(This->pcm_handle);
1128 if(This->alsa_bufsize_frames < avail_frames ||
1129 snd_pcm_state(This->pcm_handle) == SND_PCM_STATE_XRUN)
1130 *out = This->held_frames;
1132 *out = This->alsa_bufsize_frames - avail_frames + This->held_frames;
1133 TRACE("PCM state: %u, avail: %ld, pad: %u\n",
1134 snd_pcm_state(This->pcm_handle), avail_frames, *out);
1135 }else if(This->dataflow == eCapture){
1136 *out = This->held_frames;
1138 LeaveCriticalSection(&This->lock);
1139 return E_UNEXPECTED;
1142 LeaveCriticalSection(&This->lock);
1147 static DWORD get_channel_mask(unsigned int channels)
1153 return KSAUDIO_SPEAKER_MONO;
1155 return KSAUDIO_SPEAKER_STEREO;
1157 return KSAUDIO_SPEAKER_STEREO | SPEAKER_LOW_FREQUENCY;
1159 return KSAUDIO_SPEAKER_QUAD; /* not _SURROUND */
1161 return KSAUDIO_SPEAKER_QUAD | SPEAKER_LOW_FREQUENCY;
1163 return KSAUDIO_SPEAKER_5POINT1; /* not 5POINT1_SURROUND */
1165 return KSAUDIO_SPEAKER_5POINT1 | SPEAKER_BACK_CENTER;
1167 return KSAUDIO_SPEAKER_7POINT1; /* not 7POINT1_SURROUND */
1169 FIXME("Unknown speaker configuration: %u\n", channels);
1173 static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient *iface,
1174 AUDCLNT_SHAREMODE mode, const WAVEFORMATEX *fmt,
1177 ACImpl *This = impl_from_IAudioClient(iface);
1178 snd_pcm_format_mask_t *formats = NULL;
1180 WAVEFORMATEX *closest = NULL;
1181 const WAVEFORMATEXTENSIBLE *fmtex = (const WAVEFORMATEXTENSIBLE *)fmt;
1182 unsigned int max = 0, min = 0;
1185 TRACE("(%p)->(%x, %p, %p)\n", This, mode, fmt, out);
1187 if(!fmt || (mode == AUDCLNT_SHAREMODE_SHARED && !out))
1190 if(mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE)
1191 return E_INVALIDARG;
1193 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1194 fmt->cbSize < sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))
1195 return E_INVALIDARG;
1202 EnterCriticalSection(&This->lock);
1204 if((err = snd_pcm_hw_params_any(This->pcm_handle, This->hw_params)) < 0){
1209 formats = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1210 snd_pcm_format_mask_sizeof());
1216 snd_pcm_hw_params_get_format_mask(This->hw_params, formats);
1218 if(fmt->wFormatTag == WAVE_FORMAT_PCM ||
1219 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1220 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))){
1221 switch(fmt->wBitsPerSample){
1223 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_U8)){
1224 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1229 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S16_LE)){
1230 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1235 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S24_3LE)){
1236 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1241 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S32_LE)){
1242 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1247 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1250 }else if(fmt->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
1251 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1252 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))){
1253 switch(fmt->wBitsPerSample){
1255 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_FLOAT_LE)){
1256 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1261 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_FLOAT64_LE)){
1262 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1267 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1271 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1275 closest = clone_format(fmt);
1281 if((err = snd_pcm_hw_params_get_rate_min(This->hw_params, &min, NULL)) < 0){
1283 WARN("Unable to get min rate: %d (%s)\n", err, snd_strerror(err));
1287 if((err = snd_pcm_hw_params_get_rate_max(This->hw_params, &max, NULL)) < 0){
1289 WARN("Unable to get max rate: %d (%s)\n", err, snd_strerror(err));
1293 if(fmt->nSamplesPerSec < min || fmt->nSamplesPerSec > max){
1294 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1298 if((err = snd_pcm_hw_params_get_channels_min(This->hw_params, &min)) < 0){
1300 WARN("Unable to get min channels: %d (%s)\n", err, snd_strerror(err));
1304 if((err = snd_pcm_hw_params_get_channels_max(This->hw_params, &max)) < 0){
1306 WARN("Unable to get max channels: %d (%s)\n", err, snd_strerror(err));
1311 if(fmt->nChannels > max){
1313 closest->nChannels = max;
1314 }else if(fmt->nChannels < min){
1316 closest->nChannels = min;
1319 if(closest->wFormatTag == WAVE_FORMAT_EXTENSIBLE){
1320 DWORD mask = get_channel_mask(closest->nChannels);
1322 ((WAVEFORMATEXTENSIBLE*)closest)->dwChannelMask = mask;
1324 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1325 fmtex->dwChannelMask != 0 &&
1326 fmtex->dwChannelMask != mask)
1331 LeaveCriticalSection(&This->lock);
1332 HeapFree(GetProcessHeap(), 0, formats);
1334 if(hr == S_FALSE && out) {
1335 closest->nBlockAlign =
1336 closest->nChannels * closest->wBitsPerSample / 8;
1337 closest->nAvgBytesPerSec =
1338 closest->nBlockAlign * closest->nSamplesPerSec;
1341 CoTaskMemFree(closest);
1343 TRACE("returning: %08x\n", hr);
1347 static HRESULT WINAPI AudioClient_GetMixFormat(IAudioClient *iface,
1348 WAVEFORMATEX **pwfx)
1350 ACImpl *This = impl_from_IAudioClient(iface);
1351 WAVEFORMATEXTENSIBLE *fmt;
1352 snd_pcm_format_mask_t *formats;
1353 unsigned int max_rate, max_channels;
1357 TRACE("(%p)->(%p)\n", This, pwfx);
1363 fmt = CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE));
1365 return E_OUTOFMEMORY;
1367 formats = HeapAlloc(GetProcessHeap(), 0, snd_pcm_format_mask_sizeof());
1370 return E_OUTOFMEMORY;
1373 EnterCriticalSection(&This->lock);
1375 if((err = snd_pcm_hw_params_any(This->pcm_handle, This->hw_params)) < 0){
1376 WARN("Unable to get hw_params: %d (%s)\n", err, snd_strerror(err));
1381 snd_pcm_hw_params_get_format_mask(This->hw_params, formats);
1383 fmt->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
1384 if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_FLOAT_LE)){
1385 fmt->Format.wBitsPerSample = 32;
1386 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
1387 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S16_LE)){
1388 fmt->Format.wBitsPerSample = 16;
1389 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1390 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_U8)){
1391 fmt->Format.wBitsPerSample = 8;
1392 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1393 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S32_LE)){
1394 fmt->Format.wBitsPerSample = 32;
1395 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1396 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S24_3LE)){
1397 fmt->Format.wBitsPerSample = 24;
1398 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1400 ERR("Didn't recognize any available ALSA formats\n");
1405 if((err = snd_pcm_hw_params_get_channels_max(This->hw_params,
1406 &max_channels)) < 0){
1407 WARN("Unable to get max channels: %d (%s)\n", err, snd_strerror(err));
1412 if(max_channels > 2){
1413 FIXME("Don't know what to do with %u channels, pretending there's "
1414 "only 2 channels\n", max_channels);
1415 fmt->Format.nChannels = 2;
1417 fmt->Format.nChannels = max_channels;
1419 fmt->dwChannelMask = get_channel_mask(fmt->Format.nChannels);
1421 if((err = snd_pcm_hw_params_get_rate_max(This->hw_params, &max_rate,
1423 WARN("Unable to get max rate: %d (%s)\n", err, snd_strerror(err));
1428 if(max_rate >= 48000)
1429 fmt->Format.nSamplesPerSec = 48000;
1430 else if(max_rate >= 44100)
1431 fmt->Format.nSamplesPerSec = 44100;
1432 else if(max_rate >= 22050)
1433 fmt->Format.nSamplesPerSec = 22050;
1434 else if(max_rate >= 11025)
1435 fmt->Format.nSamplesPerSec = 11025;
1436 else if(max_rate >= 8000)
1437 fmt->Format.nSamplesPerSec = 8000;
1439 ERR("Unknown max rate: %u\n", max_rate);
1444 fmt->Format.nBlockAlign = (fmt->Format.wBitsPerSample *
1445 fmt->Format.nChannels) / 8;
1446 fmt->Format.nAvgBytesPerSec = fmt->Format.nSamplesPerSec *
1447 fmt->Format.nBlockAlign;
1449 fmt->Samples.wValidBitsPerSample = fmt->Format.wBitsPerSample;
1450 fmt->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
1452 dump_fmt((WAVEFORMATEX*)fmt);
1453 *pwfx = (WAVEFORMATEX*)fmt;
1456 LeaveCriticalSection(&This->lock);
1459 HeapFree(GetProcessHeap(), 0, formats);
1464 static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient *iface,
1465 REFERENCE_TIME *defperiod, REFERENCE_TIME *minperiod)
1467 ACImpl *This = impl_from_IAudioClient(iface);
1469 TRACE("(%p)->(%p, %p)\n", This, defperiod, minperiod);
1471 if(!defperiod && !minperiod)
1475 *defperiod = DefaultPeriod;
1477 *minperiod = MinimumPeriod;
1482 static snd_pcm_sframes_t alsa_write_best_effort(snd_pcm_t *handle, BYTE *buf,
1483 snd_pcm_uframes_t frames, ACImpl *This)
1485 snd_pcm_sframes_t written;
1487 if(This->session->mute){
1489 if((err = snd_pcm_format_set_silence(This->alsa_format, buf,
1490 frames * This->fmt->nChannels)) < 0)
1491 WARN("Setting buffer to silence failed: %d (%s)\n", err,
1495 written = snd_pcm_writei(handle, buf, frames);
1499 if(written == -EAGAIN)
1503 WARN("writei failed, recovering: %ld (%s)\n", written,
1504 snd_strerror(written));
1506 ret = snd_pcm_recover(handle, written, 0);
1508 WARN("Could not recover: %d (%s)\n", ret, snd_strerror(ret));
1512 written = snd_pcm_writei(handle, buf, frames);
1518 static void alsa_write_data(ACImpl *This)
1520 snd_pcm_sframes_t written;
1521 snd_pcm_uframes_t to_write, avail;
1524 This->local_buffer + (This->lcl_offs_frames * This->fmt->nBlockAlign);
1526 /* this call seems to be required to get an accurate snd_pcm_state() */
1527 avail = snd_pcm_avail_update(This->pcm_handle);
1529 if(snd_pcm_state(This->pcm_handle) == SND_PCM_STATE_XRUN ||
1530 avail > This->alsa_bufsize_frames){
1531 TRACE("XRun state, recovering\n");
1533 if((err = snd_pcm_recover(This->pcm_handle, -EPIPE, 1)) < 0)
1534 WARN("snd_pcm_recover failed: %d (%s)\n", err, snd_strerror(err));
1536 if((err = snd_pcm_reset(This->pcm_handle)) < 0)
1537 WARN("snd_pcm_reset failed: %d (%s)\n", err, snd_strerror(err));
1539 if((err = snd_pcm_prepare(This->pcm_handle)) < 0)
1540 WARN("snd_pcm_prepare failed: %d (%s)\n", err, snd_strerror(err));
1543 if(This->held_frames == 0)
1546 if(This->lcl_offs_frames + This->held_frames > This->bufsize_frames)
1547 to_write = This->bufsize_frames - This->lcl_offs_frames;
1549 to_write = This->held_frames;
1551 written = alsa_write_best_effort(This->pcm_handle, buf, to_write, This);
1553 WARN("Couldn't write: %ld (%s)\n", written, snd_strerror(written));
1557 This->lcl_offs_frames += written;
1558 This->lcl_offs_frames %= This->bufsize_frames;
1559 This->held_frames -= written;
1561 if(written < to_write){
1562 /* ALSA buffer probably full */
1566 if(This->held_frames){
1567 /* wrapped and have some data back at the start to write */
1568 written = alsa_write_best_effort(This->pcm_handle, This->local_buffer,
1569 This->held_frames, This);
1571 WARN("Couldn't write: %ld (%s)\n", written, snd_strerror(written));
1575 This->lcl_offs_frames += written;
1576 This->lcl_offs_frames %= This->bufsize_frames;
1577 This->held_frames -= written;
1581 static void alsa_read_data(ACImpl *This)
1583 snd_pcm_sframes_t pos, readable, nread;
1585 pos = (This->held_frames + This->lcl_offs_frames) % This->bufsize_frames;
1586 readable = This->bufsize_frames - pos;
1588 nread = snd_pcm_readi(This->pcm_handle,
1589 This->local_buffer + pos * This->fmt->nBlockAlign, readable);
1593 WARN("read failed, recovering: %ld (%s)\n", nread, snd_strerror(nread));
1595 ret = snd_pcm_recover(This->pcm_handle, nread, 0);
1597 WARN("Recover failed: %d (%s)\n", ret, snd_strerror(ret));
1601 nread = snd_pcm_readi(This->pcm_handle,
1602 This->local_buffer + pos * This->fmt->nBlockAlign, readable);
1604 WARN("read failed: %ld (%s)\n", nread, snd_strerror(nread));
1609 if(This->session->mute){
1611 if((err = snd_pcm_format_set_silence(This->alsa_format,
1612 This->local_buffer + pos * This->fmt->nBlockAlign,
1614 WARN("Setting buffer to silence failed: %d (%s)\n", err,
1618 This->held_frames += nread;
1620 if(This->held_frames > This->bufsize_frames){
1621 WARN("Overflow of unread data\n");
1622 This->lcl_offs_frames += This->held_frames;
1623 This->lcl_offs_frames %= This->bufsize_frames;
1624 This->held_frames = This->bufsize_frames;
1628 static void CALLBACK alsa_push_buffer_data(void *user, BOOLEAN timer)
1630 ACImpl *This = user;
1632 EnterCriticalSection(&This->lock);
1635 if(This->dataflow == eRender)
1636 alsa_write_data(This);
1637 else if(This->dataflow == eCapture)
1638 alsa_read_data(This);
1641 SetEvent(This->event);
1644 LeaveCriticalSection(&This->lock);
1647 static HRESULT WINAPI AudioClient_Start(IAudioClient *iface)
1649 ACImpl *This = impl_from_IAudioClient(iface);
1651 TRACE("(%p)\n", This);
1653 EnterCriticalSection(&This->lock);
1656 LeaveCriticalSection(&This->lock);
1657 return AUDCLNT_E_NOT_INITIALIZED;
1660 if((This->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && !This->event){
1661 LeaveCriticalSection(&This->lock);
1662 return AUDCLNT_E_EVENTHANDLE_NOT_SET;
1666 LeaveCriticalSection(&This->lock);
1667 return AUDCLNT_E_NOT_STOPPED;
1670 if(This->dataflow == eCapture){
1671 /* dump any data that might be leftover in the ALSA capture buffer */
1672 snd_pcm_readi(This->pcm_handle, This->local_buffer,
1673 This->bufsize_frames);
1676 if(!CreateTimerQueueTimer(&This->timer, g_timer_q, alsa_push_buffer_data,
1677 This, 0, This->mmdev_period_rt / 10000, WT_EXECUTEINTIMERTHREAD)){
1678 LeaveCriticalSection(&This->lock);
1679 WARN("Unable to create timer: %u\n", GetLastError());
1683 This->started = TRUE;
1685 LeaveCriticalSection(&This->lock);
1690 static HRESULT WINAPI AudioClient_Stop(IAudioClient *iface)
1692 ACImpl *This = impl_from_IAudioClient(iface);
1696 TRACE("(%p)\n", This);
1698 EnterCriticalSection(&This->lock);
1701 LeaveCriticalSection(&This->lock);
1702 return AUDCLNT_E_NOT_INITIALIZED;
1706 LeaveCriticalSection(&This->lock);
1710 if(snd_pcm_drop(This->pcm_handle) < 0)
1711 WARN("snd_pcm_drop failed\n");
1713 if(snd_pcm_reset(This->pcm_handle) < 0)
1714 WARN("snd_pcm_reset failed\n");
1716 if(snd_pcm_prepare(This->pcm_handle) < 0)
1717 WARN("snd_pcm_prepare failed\n");
1719 event = CreateEventW(NULL, TRUE, FALSE, NULL);
1720 wait = !DeleteTimerQueueTimer(g_timer_q, This->timer, event);
1722 WARN("DeleteTimerQueueTimer error %u\n", GetLastError());
1723 wait = wait && GetLastError() == ERROR_IO_PENDING;
1725 This->started = FALSE;
1727 LeaveCriticalSection(&This->lock);
1730 WaitForSingleObject(event, INFINITE);
1736 static HRESULT WINAPI AudioClient_Reset(IAudioClient *iface)
1738 ACImpl *This = impl_from_IAudioClient(iface);
1740 TRACE("(%p)\n", This);
1742 EnterCriticalSection(&This->lock);
1745 LeaveCriticalSection(&This->lock);
1746 return AUDCLNT_E_NOT_INITIALIZED;
1750 LeaveCriticalSection(&This->lock);
1751 return AUDCLNT_E_NOT_STOPPED;
1754 if(This->buf_state != NOT_LOCKED){
1755 LeaveCriticalSection(&This->lock);
1756 return AUDCLNT_E_BUFFER_OPERATION_PENDING;
1759 if(snd_pcm_drop(This->pcm_handle) < 0)
1760 WARN("snd_pcm_drop failed\n");
1762 if(snd_pcm_reset(This->pcm_handle) < 0)
1763 WARN("snd_pcm_reset failed\n");
1765 if(snd_pcm_prepare(This->pcm_handle) < 0)
1766 WARN("snd_pcm_prepare failed\n");
1768 This->held_frames = 0;
1769 This->written_frames = 0;
1770 This->lcl_offs_frames = 0;
1772 LeaveCriticalSection(&This->lock);
1777 static HRESULT WINAPI AudioClient_SetEventHandle(IAudioClient *iface,
1780 ACImpl *This = impl_from_IAudioClient(iface);
1782 TRACE("(%p)->(%p)\n", This, event);
1785 return E_INVALIDARG;
1787 EnterCriticalSection(&This->lock);
1790 LeaveCriticalSection(&This->lock);
1791 return AUDCLNT_E_NOT_INITIALIZED;
1794 if(!(This->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK)){
1795 LeaveCriticalSection(&This->lock);
1796 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED;
1799 This->event = event;
1801 LeaveCriticalSection(&This->lock);
1806 static HRESULT WINAPI AudioClient_GetService(IAudioClient *iface, REFIID riid,
1809 ACImpl *This = impl_from_IAudioClient(iface);
1811 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1817 EnterCriticalSection(&This->lock);
1820 LeaveCriticalSection(&This->lock);
1821 return AUDCLNT_E_NOT_INITIALIZED;
1824 if(IsEqualIID(riid, &IID_IAudioRenderClient)){
1825 if(This->dataflow != eRender){
1826 LeaveCriticalSection(&This->lock);
1827 return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
1829 IAudioRenderClient_AddRef(&This->IAudioRenderClient_iface);
1830 *ppv = &This->IAudioRenderClient_iface;
1831 }else if(IsEqualIID(riid, &IID_IAudioCaptureClient)){
1832 if(This->dataflow != eCapture){
1833 LeaveCriticalSection(&This->lock);
1834 return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
1836 IAudioCaptureClient_AddRef(&This->IAudioCaptureClient_iface);
1837 *ppv = &This->IAudioCaptureClient_iface;
1838 }else if(IsEqualIID(riid, &IID_IAudioClock)){
1839 IAudioClock_AddRef(&This->IAudioClock_iface);
1840 *ppv = &This->IAudioClock_iface;
1841 }else if(IsEqualIID(riid, &IID_IAudioStreamVolume)){
1842 IAudioStreamVolume_AddRef(&This->IAudioStreamVolume_iface);
1843 *ppv = &This->IAudioStreamVolume_iface;
1844 }else if(IsEqualIID(riid, &IID_IAudioSessionControl)){
1845 if(!This->session_wrapper){
1846 This->session_wrapper = AudioSessionWrapper_Create(This);
1847 if(!This->session_wrapper){
1848 LeaveCriticalSection(&This->lock);
1849 return E_OUTOFMEMORY;
1852 IAudioSessionControl2_AddRef(&This->session_wrapper->IAudioSessionControl2_iface);
1854 *ppv = &This->session_wrapper->IAudioSessionControl2_iface;
1855 }else if(IsEqualIID(riid, &IID_IChannelAudioVolume)){
1856 if(!This->session_wrapper){
1857 This->session_wrapper = AudioSessionWrapper_Create(This);
1858 if(!This->session_wrapper){
1859 LeaveCriticalSection(&This->lock);
1860 return E_OUTOFMEMORY;
1863 IChannelAudioVolume_AddRef(&This->session_wrapper->IChannelAudioVolume_iface);
1865 *ppv = &This->session_wrapper->IChannelAudioVolume_iface;
1866 }else if(IsEqualIID(riid, &IID_ISimpleAudioVolume)){
1867 if(!This->session_wrapper){
1868 This->session_wrapper = AudioSessionWrapper_Create(This);
1869 if(!This->session_wrapper){
1870 LeaveCriticalSection(&This->lock);
1871 return E_OUTOFMEMORY;
1874 ISimpleAudioVolume_AddRef(&This->session_wrapper->ISimpleAudioVolume_iface);
1876 *ppv = &This->session_wrapper->ISimpleAudioVolume_iface;
1880 LeaveCriticalSection(&This->lock);
1884 LeaveCriticalSection(&This->lock);
1886 FIXME("stub %s\n", debugstr_guid(riid));
1887 return E_NOINTERFACE;
1890 static const IAudioClientVtbl AudioClient_Vtbl =
1892 AudioClient_QueryInterface,
1894 AudioClient_Release,
1895 AudioClient_Initialize,
1896 AudioClient_GetBufferSize,
1897 AudioClient_GetStreamLatency,
1898 AudioClient_GetCurrentPadding,
1899 AudioClient_IsFormatSupported,
1900 AudioClient_GetMixFormat,
1901 AudioClient_GetDevicePeriod,
1905 AudioClient_SetEventHandle,
1906 AudioClient_GetService
1909 static HRESULT WINAPI AudioRenderClient_QueryInterface(
1910 IAudioRenderClient *iface, REFIID riid, void **ppv)
1912 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
1918 if(IsEqualIID(riid, &IID_IUnknown) ||
1919 IsEqualIID(riid, &IID_IAudioRenderClient))
1922 IUnknown_AddRef((IUnknown*)*ppv);
1926 WARN("Unknown interface %s\n", debugstr_guid(riid));
1927 return E_NOINTERFACE;
1930 static ULONG WINAPI AudioRenderClient_AddRef(IAudioRenderClient *iface)
1932 ACImpl *This = impl_from_IAudioRenderClient(iface);
1933 return AudioClient_AddRef(&This->IAudioClient_iface);
1936 static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
1938 ACImpl *This = impl_from_IAudioRenderClient(iface);
1939 return AudioClient_Release(&This->IAudioClient_iface);
1942 static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
1943 UINT32 frames, BYTE **data)
1945 ACImpl *This = impl_from_IAudioRenderClient(iface);
1950 TRACE("(%p)->(%u, %p)\n", This, frames, data);
1955 EnterCriticalSection(&This->lock);
1957 if(This->buf_state != NOT_LOCKED){
1958 LeaveCriticalSection(&This->lock);
1959 return AUDCLNT_E_OUT_OF_ORDER;
1963 This->buf_state = LOCKED_NORMAL;
1964 LeaveCriticalSection(&This->lock);
1968 hr = IAudioClient_GetCurrentPadding(&This->IAudioClient_iface, &pad);
1970 LeaveCriticalSection(&This->lock);
1974 if(pad + frames > This->bufsize_frames){
1975 LeaveCriticalSection(&This->lock);
1976 return AUDCLNT_E_BUFFER_TOO_LARGE;
1980 (This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
1981 if(write_pos + frames > This->bufsize_frames){
1982 if(This->tmp_buffer_frames < frames){
1983 if(This->tmp_buffer)
1984 This->tmp_buffer = HeapReAlloc(GetProcessHeap(), 0,
1985 This->tmp_buffer, frames * This->fmt->nBlockAlign);
1987 This->tmp_buffer = HeapAlloc(GetProcessHeap(), 0,
1988 frames * This->fmt->nBlockAlign);
1989 if(!This->tmp_buffer){
1990 LeaveCriticalSection(&This->lock);
1991 return E_OUTOFMEMORY;
1993 This->tmp_buffer_frames = frames;
1995 *data = This->tmp_buffer;
1996 This->buf_state = LOCKED_WRAPPED;
1998 *data = This->local_buffer + write_pos * This->fmt->nBlockAlign;
1999 This->buf_state = LOCKED_NORMAL;
2002 LeaveCriticalSection(&This->lock);
2007 static void alsa_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_frames)
2009 snd_pcm_uframes_t write_offs_frames =
2010 (This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
2011 UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign;
2012 snd_pcm_uframes_t chunk_frames = This->bufsize_frames - write_offs_frames;
2013 UINT32 chunk_bytes = chunk_frames * This->fmt->nBlockAlign;
2014 UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
2016 if(written_bytes <= chunk_bytes){
2017 memcpy(This->local_buffer + write_offs_bytes, buffer, written_bytes);
2019 memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes);
2020 memcpy(This->local_buffer, buffer + chunk_bytes,
2021 written_bytes - chunk_bytes);
2025 static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
2026 IAudioRenderClient *iface, UINT32 written_frames, DWORD flags)
2028 ACImpl *This = impl_from_IAudioRenderClient(iface);
2031 TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
2033 EnterCriticalSection(&This->lock);
2035 if(This->buf_state == NOT_LOCKED || !written_frames){
2036 This->buf_state = NOT_LOCKED;
2037 LeaveCriticalSection(&This->lock);
2038 return written_frames ? AUDCLNT_E_OUT_OF_ORDER : S_OK;
2041 if(This->buf_state == LOCKED_NORMAL)
2042 buffer = This->local_buffer + This->fmt->nBlockAlign *
2043 ((This->lcl_offs_frames + This->held_frames) % This->bufsize_frames);
2045 buffer = This->tmp_buffer;
2047 if(flags & AUDCLNT_BUFFERFLAGS_SILENT){
2048 if(This->fmt->wBitsPerSample == 8)
2049 memset(buffer, 128, written_frames * This->fmt->nBlockAlign);
2051 memset(buffer, 0, written_frames * This->fmt->nBlockAlign);
2054 if(This->buf_state == LOCKED_WRAPPED)
2055 alsa_wrap_buffer(This, buffer, written_frames);
2057 This->held_frames += written_frames;
2058 This->written_frames += written_frames;
2059 This->buf_state = NOT_LOCKED;
2061 LeaveCriticalSection(&This->lock);
2066 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = {
2067 AudioRenderClient_QueryInterface,
2068 AudioRenderClient_AddRef,
2069 AudioRenderClient_Release,
2070 AudioRenderClient_GetBuffer,
2071 AudioRenderClient_ReleaseBuffer
2074 static HRESULT WINAPI AudioCaptureClient_QueryInterface(
2075 IAudioCaptureClient *iface, REFIID riid, void **ppv)
2077 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2083 if(IsEqualIID(riid, &IID_IUnknown) ||
2084 IsEqualIID(riid, &IID_IAudioCaptureClient))
2087 IUnknown_AddRef((IUnknown*)*ppv);
2091 WARN("Unknown interface %s\n", debugstr_guid(riid));
2092 return E_NOINTERFACE;
2095 static ULONG WINAPI AudioCaptureClient_AddRef(IAudioCaptureClient *iface)
2097 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2098 return IAudioClient_AddRef(&This->IAudioClient_iface);
2101 static ULONG WINAPI AudioCaptureClient_Release(IAudioCaptureClient *iface)
2103 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2104 return IAudioClient_Release(&This->IAudioClient_iface);
2107 static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
2108 BYTE **data, UINT32 *frames, DWORD *flags, UINT64 *devpos,
2111 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2114 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This, data, frames, flags,
2117 if(!data || !frames || !flags)
2120 EnterCriticalSection(&This->lock);
2122 if(This->buf_state != NOT_LOCKED){
2123 LeaveCriticalSection(&This->lock);
2124 return AUDCLNT_E_OUT_OF_ORDER;
2127 hr = IAudioCaptureClient_GetNextPacketSize(iface, frames);
2129 LeaveCriticalSection(&This->lock);
2135 if(This->lcl_offs_frames + *frames > This->bufsize_frames){
2136 UINT32 chunk_bytes, offs_bytes, frames_bytes;
2137 if(This->tmp_buffer_frames < *frames){
2138 if(This->tmp_buffer)
2139 This->tmp_buffer = HeapReAlloc(GetProcessHeap(), 0,
2140 This->tmp_buffer, *frames * This->fmt->nBlockAlign);
2142 This->tmp_buffer = HeapAlloc(GetProcessHeap(), 0,
2143 *frames * This->fmt->nBlockAlign);
2144 if(!This->tmp_buffer){
2145 LeaveCriticalSection(&This->lock);
2146 return E_OUTOFMEMORY;
2148 This->tmp_buffer_frames = *frames;
2151 *data = This->tmp_buffer;
2152 chunk_bytes = (This->bufsize_frames - This->lcl_offs_frames) *
2153 This->fmt->nBlockAlign;
2154 offs_bytes = This->lcl_offs_frames * This->fmt->nBlockAlign;
2155 frames_bytes = *frames * This->fmt->nBlockAlign;
2156 memcpy(This->tmp_buffer, This->local_buffer + offs_bytes, chunk_bytes);
2157 memcpy(This->tmp_buffer + chunk_bytes, This->local_buffer,
2158 frames_bytes - chunk_bytes);
2160 *data = This->local_buffer +
2161 This->lcl_offs_frames * This->fmt->nBlockAlign;
2163 This->buf_state = LOCKED_NORMAL;
2165 if(devpos || qpcpos)
2166 IAudioClock_GetPosition(&This->IAudioClock_iface, devpos, qpcpos);
2168 LeaveCriticalSection(&This->lock);
2170 return *frames ? S_OK : AUDCLNT_S_BUFFER_EMPTY;
2173 static HRESULT WINAPI AudioCaptureClient_ReleaseBuffer(
2174 IAudioCaptureClient *iface, UINT32 done)
2176 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2178 TRACE("(%p)->(%u)\n", This, done);
2180 EnterCriticalSection(&This->lock);
2182 if(This->buf_state == NOT_LOCKED){
2183 LeaveCriticalSection(&This->lock);
2184 return AUDCLNT_E_OUT_OF_ORDER;
2187 This->held_frames -= done;
2188 This->lcl_offs_frames += done;
2189 This->lcl_offs_frames %= This->bufsize_frames;
2191 This->buf_state = NOT_LOCKED;
2193 LeaveCriticalSection(&This->lock);
2198 static HRESULT WINAPI AudioCaptureClient_GetNextPacketSize(
2199 IAudioCaptureClient *iface, UINT32 *frames)
2201 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2203 TRACE("(%p)->(%p)\n", This, frames);
2205 return AudioClient_GetCurrentPadding(&This->IAudioClient_iface, frames);
2208 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl =
2210 AudioCaptureClient_QueryInterface,
2211 AudioCaptureClient_AddRef,
2212 AudioCaptureClient_Release,
2213 AudioCaptureClient_GetBuffer,
2214 AudioCaptureClient_ReleaseBuffer,
2215 AudioCaptureClient_GetNextPacketSize
2218 static HRESULT WINAPI AudioClock_QueryInterface(IAudioClock *iface,
2219 REFIID riid, void **ppv)
2221 ACImpl *This = impl_from_IAudioClock(iface);
2223 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2229 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClock))
2231 else if(IsEqualIID(riid, &IID_IAudioClock2))
2232 *ppv = &This->IAudioClock2_iface;
2234 IUnknown_AddRef((IUnknown*)*ppv);
2238 WARN("Unknown interface %s\n", debugstr_guid(riid));
2239 return E_NOINTERFACE;
2242 static ULONG WINAPI AudioClock_AddRef(IAudioClock *iface)
2244 ACImpl *This = impl_from_IAudioClock(iface);
2245 return IAudioClient_AddRef(&This->IAudioClient_iface);
2248 static ULONG WINAPI AudioClock_Release(IAudioClock *iface)
2250 ACImpl *This = impl_from_IAudioClock(iface);
2251 return IAudioClient_Release(&This->IAudioClient_iface);
2254 static HRESULT WINAPI AudioClock_GetFrequency(IAudioClock *iface, UINT64 *freq)
2256 ACImpl *This = impl_from_IAudioClock(iface);
2258 TRACE("(%p)->(%p)\n", This, freq);
2260 *freq = This->fmt->nSamplesPerSec;
2265 static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos,
2268 ACImpl *This = impl_from_IAudioClock(iface);
2272 TRACE("(%p)->(%p, %p)\n", This, pos, qpctime);
2277 EnterCriticalSection(&This->lock);
2279 hr = IAudioClient_GetCurrentPadding(&This->IAudioClient_iface, &pad);
2281 LeaveCriticalSection(&This->lock);
2285 if(This->dataflow == eRender)
2286 *pos = This->written_frames - pad;
2287 else if(This->dataflow == eCapture)
2288 *pos = This->written_frames + pad;
2290 LeaveCriticalSection(&This->lock);
2293 LARGE_INTEGER stamp, freq;
2294 QueryPerformanceCounter(&stamp);
2295 QueryPerformanceFrequency(&freq);
2296 *qpctime = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
2302 static HRESULT WINAPI AudioClock_GetCharacteristics(IAudioClock *iface,
2305 ACImpl *This = impl_from_IAudioClock(iface);
2307 TRACE("(%p)->(%p)\n", This, chars);
2312 *chars = AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ;
2317 static const IAudioClockVtbl AudioClock_Vtbl =
2319 AudioClock_QueryInterface,
2322 AudioClock_GetFrequency,
2323 AudioClock_GetPosition,
2324 AudioClock_GetCharacteristics
2327 static HRESULT WINAPI AudioClock2_QueryInterface(IAudioClock2 *iface,
2328 REFIID riid, void **ppv)
2330 ACImpl *This = impl_from_IAudioClock2(iface);
2331 return IAudioClock_QueryInterface(&This->IAudioClock_iface, riid, ppv);
2334 static ULONG WINAPI AudioClock2_AddRef(IAudioClock2 *iface)
2336 ACImpl *This = impl_from_IAudioClock2(iface);
2337 return IAudioClient_AddRef(&This->IAudioClient_iface);
2340 static ULONG WINAPI AudioClock2_Release(IAudioClock2 *iface)
2342 ACImpl *This = impl_from_IAudioClock2(iface);
2343 return IAudioClient_Release(&This->IAudioClient_iface);
2346 static HRESULT WINAPI AudioClock2_GetDevicePosition(IAudioClock2 *iface,
2347 UINT64 *pos, UINT64 *qpctime)
2349 ACImpl *This = impl_from_IAudioClock2(iface);
2351 FIXME("(%p)->(%p, %p)\n", This, pos, qpctime);
2356 static const IAudioClock2Vtbl AudioClock2_Vtbl =
2358 AudioClock2_QueryInterface,
2360 AudioClock2_Release,
2361 AudioClock2_GetDevicePosition
2364 static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client)
2366 AudioSessionWrapper *ret;
2368 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2369 sizeof(AudioSessionWrapper));
2373 ret->IAudioSessionControl2_iface.lpVtbl = &AudioSessionControl2_Vtbl;
2374 ret->ISimpleAudioVolume_iface.lpVtbl = &SimpleAudioVolume_Vtbl;
2375 ret->IChannelAudioVolume_iface.lpVtbl = &ChannelAudioVolume_Vtbl;
2379 ret->client = client;
2381 ret->session = client->session;
2382 AudioClient_AddRef(&client->IAudioClient_iface);
2388 static HRESULT WINAPI AudioSessionControl_QueryInterface(
2389 IAudioSessionControl2 *iface, REFIID riid, void **ppv)
2391 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2397 if(IsEqualIID(riid, &IID_IUnknown) ||
2398 IsEqualIID(riid, &IID_IAudioSessionControl) ||
2399 IsEqualIID(riid, &IID_IAudioSessionControl2))
2402 IUnknown_AddRef((IUnknown*)*ppv);
2406 WARN("Unknown interface %s\n", debugstr_guid(riid));
2407 return E_NOINTERFACE;
2410 static ULONG WINAPI AudioSessionControl_AddRef(IAudioSessionControl2 *iface)
2412 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2414 ref = InterlockedIncrement(&This->ref);
2415 TRACE("(%p) Refcount now %u\n", This, ref);
2419 static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface)
2421 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2423 ref = InterlockedDecrement(&This->ref);
2424 TRACE("(%p) Refcount now %u\n", This, ref);
2427 EnterCriticalSection(&This->client->lock);
2428 This->client->session_wrapper = NULL;
2429 LeaveCriticalSection(&This->client->lock);
2430 AudioClient_Release(&This->client->IAudioClient_iface);
2432 HeapFree(GetProcessHeap(), 0, This);
2437 static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface,
2438 AudioSessionState *state)
2440 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2443 TRACE("(%p)->(%p)\n", This, state);
2446 return NULL_PTR_ERR;
2448 EnterCriticalSection(&g_sessions_lock);
2450 if(list_empty(&This->session->clients)){
2451 *state = AudioSessionStateExpired;
2452 LeaveCriticalSection(&g_sessions_lock);
2456 LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry){
2457 EnterCriticalSection(&client->lock);
2458 if(client->started){
2459 *state = AudioSessionStateActive;
2460 LeaveCriticalSection(&client->lock);
2461 LeaveCriticalSection(&g_sessions_lock);
2464 LeaveCriticalSection(&client->lock);
2467 LeaveCriticalSection(&g_sessions_lock);
2469 *state = AudioSessionStateInactive;
2474 static HRESULT WINAPI AudioSessionControl_GetDisplayName(
2475 IAudioSessionControl2 *iface, WCHAR **name)
2477 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2479 FIXME("(%p)->(%p) - stub\n", This, name);
2484 static HRESULT WINAPI AudioSessionControl_SetDisplayName(
2485 IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session)
2487 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2489 FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session));
2494 static HRESULT WINAPI AudioSessionControl_GetIconPath(
2495 IAudioSessionControl2 *iface, WCHAR **path)
2497 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2499 FIXME("(%p)->(%p) - stub\n", This, path);
2504 static HRESULT WINAPI AudioSessionControl_SetIconPath(
2505 IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session)
2507 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2509 FIXME("(%p)->(%p, %s) - stub\n", This, path, debugstr_guid(session));
2514 static HRESULT WINAPI AudioSessionControl_GetGroupingParam(
2515 IAudioSessionControl2 *iface, GUID *group)
2517 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2519 FIXME("(%p)->(%p) - stub\n", This, group);
2524 static HRESULT WINAPI AudioSessionControl_SetGroupingParam(
2525 IAudioSessionControl2 *iface, const GUID *group, const GUID *session)
2527 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2529 FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group),
2530 debugstr_guid(session));
2535 static HRESULT WINAPI AudioSessionControl_RegisterAudioSessionNotification(
2536 IAudioSessionControl2 *iface, IAudioSessionEvents *events)
2538 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2540 FIXME("(%p)->(%p) - stub\n", This, events);
2545 static HRESULT WINAPI AudioSessionControl_UnregisterAudioSessionNotification(
2546 IAudioSessionControl2 *iface, IAudioSessionEvents *events)
2548 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2550 FIXME("(%p)->(%p) - stub\n", This, events);
2555 static HRESULT WINAPI AudioSessionControl_GetSessionIdentifier(
2556 IAudioSessionControl2 *iface, WCHAR **id)
2558 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2560 FIXME("(%p)->(%p) - stub\n", This, id);
2565 static HRESULT WINAPI AudioSessionControl_GetSessionInstanceIdentifier(
2566 IAudioSessionControl2 *iface, WCHAR **id)
2568 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2570 FIXME("(%p)->(%p) - stub\n", This, id);
2575 static HRESULT WINAPI AudioSessionControl_GetProcessId(
2576 IAudioSessionControl2 *iface, DWORD *pid)
2578 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2580 TRACE("(%p)->(%p)\n", This, pid);
2585 *pid = GetCurrentProcessId();
2590 static HRESULT WINAPI AudioSessionControl_IsSystemSoundsSession(
2591 IAudioSessionControl2 *iface)
2593 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2595 TRACE("(%p)\n", This);
2600 static HRESULT WINAPI AudioSessionControl_SetDuckingPreference(
2601 IAudioSessionControl2 *iface, BOOL optout)
2603 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2605 TRACE("(%p)->(%d)\n", This, optout);
2610 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl =
2612 AudioSessionControl_QueryInterface,
2613 AudioSessionControl_AddRef,
2614 AudioSessionControl_Release,
2615 AudioSessionControl_GetState,
2616 AudioSessionControl_GetDisplayName,
2617 AudioSessionControl_SetDisplayName,
2618 AudioSessionControl_GetIconPath,
2619 AudioSessionControl_SetIconPath,
2620 AudioSessionControl_GetGroupingParam,
2621 AudioSessionControl_SetGroupingParam,
2622 AudioSessionControl_RegisterAudioSessionNotification,
2623 AudioSessionControl_UnregisterAudioSessionNotification,
2624 AudioSessionControl_GetSessionIdentifier,
2625 AudioSessionControl_GetSessionInstanceIdentifier,
2626 AudioSessionControl_GetProcessId,
2627 AudioSessionControl_IsSystemSoundsSession,
2628 AudioSessionControl_SetDuckingPreference
2631 static HRESULT WINAPI SimpleAudioVolume_QueryInterface(
2632 ISimpleAudioVolume *iface, REFIID riid, void **ppv)
2634 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2640 if(IsEqualIID(riid, &IID_IUnknown) ||
2641 IsEqualIID(riid, &IID_ISimpleAudioVolume))
2644 IUnknown_AddRef((IUnknown*)*ppv);
2648 WARN("Unknown interface %s\n", debugstr_guid(riid));
2649 return E_NOINTERFACE;
2652 static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface)
2654 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2655 return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface);
2658 static ULONG WINAPI SimpleAudioVolume_Release(ISimpleAudioVolume *iface)
2660 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2661 return AudioSessionControl_Release(&This->IAudioSessionControl2_iface);
2664 static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume(
2665 ISimpleAudioVolume *iface, float level, const GUID *context)
2667 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2668 AudioSession *session = This->session;
2670 TRACE("(%p)->(%f, %s)\n", session, level, wine_dbgstr_guid(context));
2672 if(level < 0.f || level > 1.f)
2673 return E_INVALIDARG;
2676 FIXME("Notifications not supported yet\n");
2678 TRACE("ALSA does not support volume control\n");
2680 EnterCriticalSection(&session->lock);
2682 session->master_vol = level;
2684 LeaveCriticalSection(&session->lock);
2689 static HRESULT WINAPI SimpleAudioVolume_GetMasterVolume(
2690 ISimpleAudioVolume *iface, float *level)
2692 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2693 AudioSession *session = This->session;
2695 TRACE("(%p)->(%p)\n", session, level);
2698 return NULL_PTR_ERR;
2700 *level = session->master_vol;
2705 static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface,
2706 BOOL mute, const GUID *context)
2708 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2709 AudioSession *session = This->session;
2711 TRACE("(%p)->(%u, %p)\n", session, mute, context);
2714 FIXME("Notifications not supported yet\n");
2716 session->mute = mute;
2721 static HRESULT WINAPI SimpleAudioVolume_GetMute(ISimpleAudioVolume *iface,
2724 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2725 AudioSession *session = This->session;
2727 TRACE("(%p)->(%p)\n", session, mute);
2730 return NULL_PTR_ERR;
2732 *mute = session->mute;
2737 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl =
2739 SimpleAudioVolume_QueryInterface,
2740 SimpleAudioVolume_AddRef,
2741 SimpleAudioVolume_Release,
2742 SimpleAudioVolume_SetMasterVolume,
2743 SimpleAudioVolume_GetMasterVolume,
2744 SimpleAudioVolume_SetMute,
2745 SimpleAudioVolume_GetMute
2748 static HRESULT WINAPI AudioStreamVolume_QueryInterface(
2749 IAudioStreamVolume *iface, REFIID riid, void **ppv)
2751 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2757 if(IsEqualIID(riid, &IID_IUnknown) ||
2758 IsEqualIID(riid, &IID_IAudioStreamVolume))
2761 IUnknown_AddRef((IUnknown*)*ppv);
2765 WARN("Unknown interface %s\n", debugstr_guid(riid));
2766 return E_NOINTERFACE;
2769 static ULONG WINAPI AudioStreamVolume_AddRef(IAudioStreamVolume *iface)
2771 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2772 return IAudioClient_AddRef(&This->IAudioClient_iface);
2775 static ULONG WINAPI AudioStreamVolume_Release(IAudioStreamVolume *iface)
2777 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2778 return IAudioClient_Release(&This->IAudioClient_iface);
2781 static HRESULT WINAPI AudioStreamVolume_GetChannelCount(
2782 IAudioStreamVolume *iface, UINT32 *out)
2784 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2786 TRACE("(%p)->(%p)\n", This, out);
2791 *out = This->fmt->nChannels;
2796 static HRESULT WINAPI AudioStreamVolume_SetChannelVolume(
2797 IAudioStreamVolume *iface, UINT32 index, float level)
2799 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2801 TRACE("(%p)->(%d, %f)\n", This, index, level);
2803 if(level < 0.f || level > 1.f)
2804 return E_INVALIDARG;
2806 if(index >= This->fmt->nChannels)
2807 return E_INVALIDARG;
2809 TRACE("ALSA does not support volume control\n");
2811 EnterCriticalSection(&This->lock);
2813 This->vols[index] = level;
2815 LeaveCriticalSection(&This->lock);
2820 static HRESULT WINAPI AudioStreamVolume_GetChannelVolume(
2821 IAudioStreamVolume *iface, UINT32 index, float *level)
2823 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2825 TRACE("(%p)->(%d, %p)\n", This, index, level);
2830 if(index >= This->fmt->nChannels)
2831 return E_INVALIDARG;
2833 *level = This->vols[index];
2838 static HRESULT WINAPI AudioStreamVolume_SetAllVolumes(
2839 IAudioStreamVolume *iface, UINT32 count, const float *levels)
2841 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2844 TRACE("(%p)->(%d, %p)\n", This, count, levels);
2849 if(count != This->fmt->nChannels)
2850 return E_INVALIDARG;
2852 TRACE("ALSA does not support volume control\n");
2854 EnterCriticalSection(&This->lock);
2856 for(i = 0; i < count; ++i)
2857 This->vols[i] = levels[i];
2859 LeaveCriticalSection(&This->lock);
2864 static HRESULT WINAPI AudioStreamVolume_GetAllVolumes(
2865 IAudioStreamVolume *iface, UINT32 count, float *levels)
2867 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2870 TRACE("(%p)->(%d, %p)\n", This, count, levels);
2875 if(count != This->fmt->nChannels)
2876 return E_INVALIDARG;
2878 EnterCriticalSection(&This->lock);
2880 for(i = 0; i < count; ++i)
2881 levels[i] = This->vols[i];
2883 LeaveCriticalSection(&This->lock);
2888 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl =
2890 AudioStreamVolume_QueryInterface,
2891 AudioStreamVolume_AddRef,
2892 AudioStreamVolume_Release,
2893 AudioStreamVolume_GetChannelCount,
2894 AudioStreamVolume_SetChannelVolume,
2895 AudioStreamVolume_GetChannelVolume,
2896 AudioStreamVolume_SetAllVolumes,
2897 AudioStreamVolume_GetAllVolumes
2900 static HRESULT WINAPI ChannelAudioVolume_QueryInterface(
2901 IChannelAudioVolume *iface, REFIID riid, void **ppv)
2903 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2909 if(IsEqualIID(riid, &IID_IUnknown) ||
2910 IsEqualIID(riid, &IID_IChannelAudioVolume))
2913 IUnknown_AddRef((IUnknown*)*ppv);
2917 WARN("Unknown interface %s\n", debugstr_guid(riid));
2918 return E_NOINTERFACE;
2921 static ULONG WINAPI ChannelAudioVolume_AddRef(IChannelAudioVolume *iface)
2923 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2924 return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface);
2927 static ULONG WINAPI ChannelAudioVolume_Release(IChannelAudioVolume *iface)
2929 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2930 return AudioSessionControl_Release(&This->IAudioSessionControl2_iface);
2933 static HRESULT WINAPI ChannelAudioVolume_GetChannelCount(
2934 IChannelAudioVolume *iface, UINT32 *out)
2936 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2937 AudioSession *session = This->session;
2939 TRACE("(%p)->(%p)\n", session, out);
2942 return NULL_PTR_ERR;
2944 *out = session->channel_count;
2949 static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume(
2950 IChannelAudioVolume *iface, UINT32 index, float level,
2951 const GUID *context)
2953 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2954 AudioSession *session = This->session;
2956 TRACE("(%p)->(%d, %f, %s)\n", session, index, level,
2957 wine_dbgstr_guid(context));
2959 if(level < 0.f || level > 1.f)
2960 return E_INVALIDARG;
2962 if(index >= session->channel_count)
2963 return E_INVALIDARG;
2966 FIXME("Notifications not supported yet\n");
2968 TRACE("ALSA does not support volume control\n");
2970 EnterCriticalSection(&session->lock);
2972 session->channel_vols[index] = level;
2974 LeaveCriticalSection(&session->lock);
2979 static HRESULT WINAPI ChannelAudioVolume_GetChannelVolume(
2980 IChannelAudioVolume *iface, UINT32 index, float *level)
2982 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2983 AudioSession *session = This->session;
2985 TRACE("(%p)->(%d, %p)\n", session, index, level);
2988 return NULL_PTR_ERR;
2990 if(index >= session->channel_count)
2991 return E_INVALIDARG;
2993 *level = session->channel_vols[index];
2998 static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes(
2999 IChannelAudioVolume *iface, UINT32 count, const float *levels,
3000 const GUID *context)
3002 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
3003 AudioSession *session = This->session;
3006 TRACE("(%p)->(%d, %p, %s)\n", session, count, levels,
3007 wine_dbgstr_guid(context));
3010 return NULL_PTR_ERR;
3012 if(count != session->channel_count)
3013 return E_INVALIDARG;
3016 FIXME("Notifications not supported yet\n");
3018 TRACE("ALSA does not support volume control\n");
3020 EnterCriticalSection(&session->lock);
3022 for(i = 0; i < count; ++i)
3023 session->channel_vols[i] = levels[i];
3025 LeaveCriticalSection(&session->lock);
3030 static HRESULT WINAPI ChannelAudioVolume_GetAllVolumes(
3031 IChannelAudioVolume *iface, UINT32 count, float *levels)
3033 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
3034 AudioSession *session = This->session;
3037 TRACE("(%p)->(%d, %p)\n", session, count, levels);
3040 return NULL_PTR_ERR;
3042 if(count != session->channel_count)
3043 return E_INVALIDARG;
3045 for(i = 0; i < count; ++i)
3046 levels[i] = session->channel_vols[i];
3051 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl =
3053 ChannelAudioVolume_QueryInterface,
3054 ChannelAudioVolume_AddRef,
3055 ChannelAudioVolume_Release,
3056 ChannelAudioVolume_GetChannelCount,
3057 ChannelAudioVolume_SetChannelVolume,
3058 ChannelAudioVolume_GetChannelVolume,
3059 ChannelAudioVolume_SetAllVolumes,
3060 ChannelAudioVolume_GetAllVolumes
3063 static HRESULT WINAPI AudioSessionManager_QueryInterface(IAudioSessionManager2 *iface,
3064 REFIID riid, void **ppv)
3066 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
3072 if(IsEqualIID(riid, &IID_IUnknown) ||
3073 IsEqualIID(riid, &IID_IAudioSessionManager) ||
3074 IsEqualIID(riid, &IID_IAudioSessionManager2))
3077 IUnknown_AddRef((IUnknown*)*ppv);
3081 WARN("Unknown interface %s\n", debugstr_guid(riid));
3082 return E_NOINTERFACE;
3085 static ULONG WINAPI AudioSessionManager_AddRef(IAudioSessionManager2 *iface)
3087 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3089 ref = InterlockedIncrement(&This->ref);
3090 TRACE("(%p) Refcount now %u\n", This, ref);
3094 static ULONG WINAPI AudioSessionManager_Release(IAudioSessionManager2 *iface)
3096 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3098 ref = InterlockedDecrement(&This->ref);
3099 TRACE("(%p) Refcount now %u\n", This, ref);
3101 HeapFree(GetProcessHeap(), 0, This);
3105 static HRESULT WINAPI AudioSessionManager_GetAudioSessionControl(
3106 IAudioSessionManager2 *iface, const GUID *session_guid, DWORD flags,
3107 IAudioSessionControl **out)
3109 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3110 AudioSession *session;
3111 AudioSessionWrapper *wrapper;
3114 TRACE("(%p)->(%s, %x, %p)\n", This, debugstr_guid(session_guid),
3117 hr = get_audio_session(session_guid, This->device, 0, &session);
3121 wrapper = AudioSessionWrapper_Create(NULL);
3123 return E_OUTOFMEMORY;
3125 wrapper->session = session;
3127 *out = (IAudioSessionControl*)&wrapper->IAudioSessionControl2_iface;
3132 static HRESULT WINAPI AudioSessionManager_GetSimpleAudioVolume(
3133 IAudioSessionManager2 *iface, const GUID *session_guid, DWORD flags,
3134 ISimpleAudioVolume **out)
3136 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3137 AudioSession *session;
3138 AudioSessionWrapper *wrapper;
3141 TRACE("(%p)->(%s, %x, %p)\n", This, debugstr_guid(session_guid),
3144 hr = get_audio_session(session_guid, This->device, 0, &session);
3148 wrapper = AudioSessionWrapper_Create(NULL);
3150 return E_OUTOFMEMORY;
3152 wrapper->session = session;
3154 *out = &wrapper->ISimpleAudioVolume_iface;
3159 static HRESULT WINAPI AudioSessionManager_GetSessionEnumerator(
3160 IAudioSessionManager2 *iface, IAudioSessionEnumerator **out)
3162 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3163 FIXME("(%p)->(%p) - stub\n", This, out);
3167 static HRESULT WINAPI AudioSessionManager_RegisterSessionNotification(
3168 IAudioSessionManager2 *iface, IAudioSessionNotification *notification)
3170 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3171 FIXME("(%p)->(%p) - stub\n", This, notification);
3175 static HRESULT WINAPI AudioSessionManager_UnregisterSessionNotification(
3176 IAudioSessionManager2 *iface, IAudioSessionNotification *notification)
3178 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3179 FIXME("(%p)->(%p) - stub\n", This, notification);
3183 static HRESULT WINAPI AudioSessionManager_RegisterDuckNotification(
3184 IAudioSessionManager2 *iface, const WCHAR *session_id,
3185 IAudioVolumeDuckNotification *notification)
3187 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3188 FIXME("(%p)->(%p) - stub\n", This, notification);
3192 static HRESULT WINAPI AudioSessionManager_UnregisterDuckNotification(
3193 IAudioSessionManager2 *iface,
3194 IAudioVolumeDuckNotification *notification)
3196 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3197 FIXME("(%p)->(%p) - stub\n", This, notification);
3201 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl =
3203 AudioSessionManager_QueryInterface,
3204 AudioSessionManager_AddRef,
3205 AudioSessionManager_Release,
3206 AudioSessionManager_GetAudioSessionControl,
3207 AudioSessionManager_GetSimpleAudioVolume,
3208 AudioSessionManager_GetSessionEnumerator,
3209 AudioSessionManager_RegisterSessionNotification,
3210 AudioSessionManager_UnregisterSessionNotification,
3211 AudioSessionManager_RegisterDuckNotification,
3212 AudioSessionManager_UnregisterDuckNotification
3215 HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device,
3216 IAudioSessionManager2 **out)
3220 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SessionMgr));
3222 return E_OUTOFMEMORY;
3224 This->IAudioSessionManager2_iface.lpVtbl = &AudioSessionManager2_Vtbl;
3225 This->device = device;
3228 *out = &This->IAudioSessionManager2_iface;