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"
40 #include "endpointvolume.h"
43 #include "audioclient.h"
44 #include "audiopolicy.h"
47 #include <alsa/asoundlib.h>
49 WINE_DEFAULT_DEBUG_CHANNEL(alsa);
50 WINE_DECLARE_DEBUG_CHANNEL(winediag);
52 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
54 static const REFERENCE_TIME DefaultPeriod = 200000;
55 static const REFERENCE_TIME MinimumPeriod = 100000;
58 typedef struct ACImpl ACImpl;
60 typedef struct _AudioSession {
71 CRITICAL_SECTION lock;
76 typedef struct _AudioSessionWrapper {
77 IAudioSessionControl2 IAudioSessionControl2_iface;
78 IChannelAudioVolume IChannelAudioVolume_iface;
79 ISimpleAudioVolume ISimpleAudioVolume_iface;
84 AudioSession *session;
85 } AudioSessionWrapper;
88 IAudioClient IAudioClient_iface;
89 IAudioRenderClient IAudioRenderClient_iface;
90 IAudioCaptureClient IAudioCaptureClient_iface;
91 IAudioClock IAudioClock_iface;
92 IAudioClock2 IAudioClock2_iface;
93 IAudioStreamVolume IAudioStreamVolume_iface;
97 snd_pcm_t *pcm_handle;
98 snd_pcm_uframes_t period_alsa, bufsize_alsa;
99 snd_pcm_hw_params_t *hw_params; /* does not hold state between calls */
100 snd_pcm_format_t alsa_format;
107 AUDCLNT_SHAREMODE share;
111 BOOL initted, started;
112 UINT64 written_frames;
113 UINT32 bufsize_frames, held_frames, tmp_buffer_frames, period_us;
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 int wine_snd_pcm_recover(snd_pcm_t *pcm, int err, int silent);
162 static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
164 static inline ACImpl *impl_from_IAudioClient(IAudioClient *iface)
166 return CONTAINING_RECORD(iface, ACImpl, IAudioClient_iface);
169 static inline ACImpl *impl_from_IAudioRenderClient(IAudioRenderClient *iface)
171 return CONTAINING_RECORD(iface, ACImpl, IAudioRenderClient_iface);
174 static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface)
176 return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface);
179 static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface)
181 return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface);
184 static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface)
186 return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface);
189 static inline AudioSessionWrapper *impl_from_IChannelAudioVolume(IChannelAudioVolume *iface)
191 return CONTAINING_RECORD(iface, AudioSessionWrapper, IChannelAudioVolume_iface);
194 static inline ACImpl *impl_from_IAudioClock(IAudioClock *iface)
196 return CONTAINING_RECORD(iface, ACImpl, IAudioClock_iface);
199 static inline ACImpl *impl_from_IAudioClock2(IAudioClock2 *iface)
201 return CONTAINING_RECORD(iface, ACImpl, IAudioClock2_iface);
204 static inline ACImpl *impl_from_IAudioStreamVolume(IAudioStreamVolume *iface)
206 return CONTAINING_RECORD(iface, ACImpl, IAudioStreamVolume_iface);
209 static inline SessionMgr *impl_from_IAudioSessionManager2(IAudioSessionManager2 *iface)
211 return CONTAINING_RECORD(iface, SessionMgr, IAudioSessionManager2_iface);
214 BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved)
216 if(reason == DLL_PROCESS_ATTACH){
217 g_timer_q = CreateTimerQueue();
221 InitializeCriticalSection(&g_sessions_lock);
227 /* From <dlls/mmdevapi/mmdevapi.h> */
228 enum DriverPriority {
229 Priority_Unavailable = 0,
235 int WINAPI AUDDRV_GetPriority(void)
237 return Priority_Neutral;
240 static HRESULT alsa_get_card_devices(EDataFlow flow, WCHAR **ids, char **keys,
241 UINT *num, snd_ctl_t *ctl, int card, const WCHAR *cardnameW,
244 static const WCHAR dashW[] = {' ','-',' ',0};
246 snd_pcm_info_t *info;
247 snd_pcm_stream_t stream = (flow == eRender ? SND_PCM_STREAM_PLAYBACK :
248 SND_PCM_STREAM_CAPTURE);
250 info = HeapAlloc(GetProcessHeap(), 0, snd_pcm_info_sizeof());
252 return E_OUTOFMEMORY;
254 snd_pcm_info_set_subdevice(info, 0);
255 snd_pcm_info_set_stream(info, stream);
258 for(err = snd_ctl_pcm_next_device(ctl, &device); device != -1 && err >= 0;
259 err = snd_ctl_pcm_next_device(ctl, &device)){
264 snd_pcm_info_set_device(info, device);
266 if((err = snd_ctl_pcm_info(ctl, info)) < 0){
268 /* This device doesn't have the right stream direction */
271 WARN("Failed to get info for card %d, device %d: %d (%s)\n",
272 card, device, err, snd_strerror(err));
276 sprintf(devnode, "hw:%d,%d", card, device);
277 if((err = snd_pcm_open(&handle, devnode, stream, SND_PCM_NONBLOCK)) < 0){
278 WARN("The device \"%s\" failed to open, pretending it doesn't exist: %d (%s)\n",
279 devnode, err, snd_strerror(err));
285 snd_pcm_close(handle);
290 devname = snd_pcm_info_get_name(info);
292 WARN("Unable to get device name for card %d, device %d\n", card,
297 cardlen = lstrlenW(cardnameW);
298 len = MultiByteToWideChar(CP_UNIXCP, 0, devname, -1, NULL, 0);
299 len += lstrlenW(dashW);
301 ids[*num] = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
303 HeapFree(GetProcessHeap(), 0, info);
304 return E_OUTOFMEMORY;
306 memcpy(ids[*num], cardnameW, cardlen * sizeof(WCHAR));
307 memcpy(ids[*num] + cardlen, dashW, lstrlenW(dashW) * sizeof(WCHAR));
308 cardlen += lstrlenW(dashW);
309 MultiByteToWideChar(CP_UNIXCP, 0, devname, -1, ids[*num] + cardlen,
312 keys[*num] = HeapAlloc(GetProcessHeap(), 0, 32);
314 HeapFree(GetProcessHeap(), 0, info);
315 HeapFree(GetProcessHeap(), 0, ids[*num]);
316 return E_OUTOFMEMORY;
318 memcpy(keys[*num], devnode, sizeof(devnode));
324 HeapFree(GetProcessHeap(), 0, info);
327 WARN("Got a failure during device enumeration on card %d: %d (%s)\n",
328 card, err, snd_strerror(err));
333 static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR **ids, char **keys,
334 UINT *num, BOOL count_failed)
340 for(err = snd_card_next(&card); card != -1 && err >= 0;
341 err = snd_card_next(&card)){
343 const char *cardname;
348 sprintf(cardpath, "hw:%u", card);
350 if((err = snd_ctl_open(&ctl, cardpath, 0)) < 0){
351 WARN("Unable to open ctl for ALSA device %s: %d (%s)\n", cardpath,
352 err, snd_strerror(err));
356 if((err = snd_card_get_name(card, (char **)&cardname)) < 0){
357 WARN("Unable to get card name for ALSA device %s: %d (%s)\n",
358 cardpath, err, snd_strerror(err));
359 /* FIXME: Should be localized */
360 cardname = "Unknown soundcard";
363 len = MultiByteToWideChar(CP_UNIXCP, 0, cardname, -1, NULL, 0);
364 cardnameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
367 return E_OUTOFMEMORY;
369 MultiByteToWideChar(CP_UNIXCP, 0, cardname, -1, cardnameW, len);
371 alsa_get_card_devices(flow, ids, keys, num, ctl, card, cardnameW,
374 HeapFree(GetProcessHeap(), 0, cardnameW);
380 WARN("Got a failure during card enumeration: %d (%s)\n",
381 err, snd_strerror(err));
386 HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, char ***keys,
387 UINT *num, UINT *def_index)
391 TRACE("%d %p %p %p %p\n", flow, ids, keys, num, def_index);
393 hr = alsa_enum_devices(flow, NULL, NULL, num, TRUE);
404 *ids = HeapAlloc(GetProcessHeap(), 0, (*num + 1) * sizeof(WCHAR *));
405 *keys = HeapAlloc(GetProcessHeap(), 0, (*num + 1) * sizeof(char *));
407 HeapFree(GetProcessHeap(), 0, *ids);
408 HeapFree(GetProcessHeap(), 0, *keys);
409 return E_OUTOFMEMORY;
412 (*ids)[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW));
413 memcpy((*ids)[0], defaultW, sizeof(defaultW));
414 (*keys)[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(defname));
415 memcpy((*keys)[0], defname, sizeof(defname));
418 hr = alsa_enum_devices(flow, (*ids) + 1, (*keys) + 1, num, FALSE);
421 for(i = 0; i < *num; ++i){
422 HeapFree(GetProcessHeap(), 0, (*ids)[i]);
423 HeapFree(GetProcessHeap(), 0, (*keys)[i]);
425 HeapFree(GetProcessHeap(), 0, *ids);
426 HeapFree(GetProcessHeap(), 0, *keys);
427 return E_OUTOFMEMORY;
430 ++(*num); /* for default device */
435 /* Using the pulse PCM device from alsa-plugins 1.0.24 triggers a bug
436 * which causes audio to cease playing after a few minutes of playback.
437 * Setting handle_underrun=1 on pulse-backed ALSA devices seems to work
438 * around this issue. */
439 static snd_config_t *make_handle_underrun_config(const char *name)
441 snd_config_t *lconf, *dev_node, *hu_node, *type_node;
442 char dev_node_name[64];
443 const char *type_str;
448 if((err = snd_config_copy(&lconf, snd_config)) < 0){
449 WARN("snd_config_copy failed: %d (%s)\n", err, snd_strerror(err));
453 sprintf(dev_node_name, "pcm.%s", name);
454 err = snd_config_search(lconf, dev_node_name, &dev_node);
456 snd_config_delete(lconf);
460 snd_config_delete(lconf);
461 WARN("snd_config_search failed: %d (%s)\n", err, snd_strerror(err));
465 /* ALSA is extremely fragile. If it runs into a config setting it doesn't
466 * recognize, it tends to fail or assert. So we only want to inject
467 * handle_underrun=1 on devices that we know will recognize it. */
468 err = snd_config_search(dev_node, "type", &type_node);
470 snd_config_delete(lconf);
474 snd_config_delete(lconf);
475 WARN("snd_config_search failed: %d (%s)\n", err, snd_strerror(err));
479 if((err = snd_config_get_string(type_node, &type_str)) < 0){
480 snd_config_delete(lconf);
484 if(strcmp(type_str, "pulse") != 0){
485 snd_config_delete(lconf);
489 err = snd_config_search(dev_node, "handle_underrun", &hu_node);
491 /* user already has an explicit handle_underrun setting, so don't
492 * use a local config */
493 snd_config_delete(lconf);
497 snd_config_delete(lconf);
498 WARN("snd_config_search failed: %d (%s)\n", err, snd_strerror(err));
502 if((err = snd_config_imake_integer(&hu_node, "handle_underrun", 1)) < 0){
503 snd_config_delete(lconf);
504 WARN("snd_config_imake_integer failed: %d (%s)\n", err,
509 if((err = snd_config_add(dev_node, hu_node)) < 0){
510 snd_config_delete(lconf);
511 WARN("snd_config_add failed: %d (%s)\n", err, snd_strerror(err));
518 HRESULT WINAPI AUDDRV_GetAudioEndpoint(const char *key, IMMDevice *dev,
519 EDataFlow dataflow, IAudioClient **out)
523 snd_pcm_stream_t stream;
525 static int handle_underrun = 1;
527 TRACE("\"%s\" %p %d %p\n", key, dev, dataflow, out);
529 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACImpl));
531 return E_OUTOFMEMORY;
533 This->IAudioClient_iface.lpVtbl = &AudioClient_Vtbl;
534 This->IAudioRenderClient_iface.lpVtbl = &AudioRenderClient_Vtbl;
535 This->IAudioCaptureClient_iface.lpVtbl = &AudioCaptureClient_Vtbl;
536 This->IAudioClock_iface.lpVtbl = &AudioClock_Vtbl;
537 This->IAudioClock2_iface.lpVtbl = &AudioClock2_Vtbl;
538 This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl;
540 if(dataflow == eRender)
541 stream = SND_PCM_STREAM_PLAYBACK;
542 else if(dataflow == eCapture)
543 stream = SND_PCM_STREAM_CAPTURE;
545 HeapFree(GetProcessHeap(), 0, This);
549 This->dataflow = dataflow;
550 if(handle_underrun && ((lconf = make_handle_underrun_config(key)))){
551 err = snd_pcm_open_lconf(&This->pcm_handle, key, stream, SND_PCM_NONBLOCK, lconf);
552 TRACE("Opening PCM device \"%s\" with handle_underrun: %d\n", key, err);
553 snd_config_delete(lconf);
554 /* Pulse <= 2010 returns EINVAL, it does not know handle_underrun. */
556 ERR_(winediag)("PulseAudio \"%s\" %d without handle_underrun. Audio may hang."
557 " Please upgrade to alsa_plugins >= 1.0.24\n", key, err);
563 err = snd_pcm_open(&This->pcm_handle, key, stream, SND_PCM_NONBLOCK);
566 HeapFree(GetProcessHeap(), 0, This);
567 WARN("Unable to open PCM \"%s\": %d (%s)\n", key, err, snd_strerror(err));
571 This->hw_params = HeapAlloc(GetProcessHeap(), 0,
572 snd_pcm_hw_params_sizeof());
573 if(!This->hw_params){
574 HeapFree(GetProcessHeap(), 0, This);
575 snd_pcm_close(This->pcm_handle);
576 return E_OUTOFMEMORY;
579 InitializeCriticalSection(&This->lock);
582 IMMDevice_AddRef(This->parent);
584 *out = &This->IAudioClient_iface;
585 IAudioClient_AddRef(&This->IAudioClient_iface);
590 static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient *iface,
591 REFIID riid, void **ppv)
593 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
598 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClient))
601 IUnknown_AddRef((IUnknown*)*ppv);
604 WARN("Unknown interface %s\n", debugstr_guid(riid));
605 return E_NOINTERFACE;
608 static ULONG WINAPI AudioClient_AddRef(IAudioClient *iface)
610 ACImpl *This = impl_from_IAudioClient(iface);
612 ref = InterlockedIncrement(&This->ref);
613 TRACE("(%p) Refcount now %u\n", This, ref);
617 static ULONG WINAPI AudioClient_Release(IAudioClient *iface)
619 ACImpl *This = impl_from_IAudioClient(iface);
621 ref = InterlockedDecrement(&This->ref);
622 TRACE("(%p) Refcount now %u\n", This, ref);
624 IAudioClient_Stop(iface);
625 IMMDevice_Release(This->parent);
626 DeleteCriticalSection(&This->lock);
627 snd_pcm_drop(This->pcm_handle);
628 snd_pcm_close(This->pcm_handle);
630 EnterCriticalSection(&g_sessions_lock);
631 list_remove(&This->entry);
632 LeaveCriticalSection(&g_sessions_lock);
634 HeapFree(GetProcessHeap(), 0, This->vols);
635 HeapFree(GetProcessHeap(), 0, This->local_buffer);
636 HeapFree(GetProcessHeap(), 0, This->tmp_buffer);
637 HeapFree(GetProcessHeap(), 0, This->hw_params);
638 CoTaskMemFree(This->fmt);
639 HeapFree(GetProcessHeap(), 0, This);
644 static void dump_fmt(const WAVEFORMATEX *fmt)
646 TRACE("wFormatTag: 0x%x (", fmt->wFormatTag);
647 switch(fmt->wFormatTag){
648 case WAVE_FORMAT_PCM:
649 TRACE("WAVE_FORMAT_PCM");
651 case WAVE_FORMAT_IEEE_FLOAT:
652 TRACE("WAVE_FORMAT_IEEE_FLOAT");
654 case WAVE_FORMAT_EXTENSIBLE:
655 TRACE("WAVE_FORMAT_EXTENSIBLE");
663 TRACE("nChannels: %u\n", fmt->nChannels);
664 TRACE("nSamplesPerSec: %u\n", fmt->nSamplesPerSec);
665 TRACE("nAvgBytesPerSec: %u\n", fmt->nAvgBytesPerSec);
666 TRACE("nBlockAlign: %u\n", fmt->nBlockAlign);
667 TRACE("wBitsPerSample: %u\n", fmt->wBitsPerSample);
668 TRACE("cbSize: %u\n", fmt->cbSize);
670 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE){
671 WAVEFORMATEXTENSIBLE *fmtex = (void*)fmt;
672 TRACE("dwChannelMask: %08x\n", fmtex->dwChannelMask);
673 TRACE("Samples: %04x\n", fmtex->Samples.wReserved);
674 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex->SubFormat));
678 static WAVEFORMATEX *clone_format(const WAVEFORMATEX *fmt)
683 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
684 size = sizeof(WAVEFORMATEXTENSIBLE);
686 size = sizeof(WAVEFORMATEX);
688 ret = CoTaskMemAlloc(size);
692 memcpy(ret, fmt, size);
694 ret->cbSize = size - sizeof(WAVEFORMATEX);
699 static void session_init_vols(AudioSession *session, UINT channels)
701 if(session->channel_count < channels){
704 if(session->channel_vols)
705 session->channel_vols = HeapReAlloc(GetProcessHeap(), 0,
706 session->channel_vols, sizeof(float) * channels);
708 session->channel_vols = HeapAlloc(GetProcessHeap(), 0,
709 sizeof(float) * channels);
710 if(!session->channel_vols)
713 for(i = session->channel_count; i < channels; ++i)
714 session->channel_vols[i] = 1.f;
716 session->channel_count = channels;
720 static AudioSession *create_session(const GUID *guid, IMMDevice *device,
725 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AudioSession));
729 memcpy(&ret->guid, guid, sizeof(GUID));
731 ret->device = device;
733 list_init(&ret->clients);
735 list_add_head(&g_sessions, &ret->entry);
737 InitializeCriticalSection(&ret->lock);
739 session_init_vols(ret, num_channels);
741 ret->master_vol = 1.f;
746 /* if channels == 0, then this will return or create a session with
747 * matching dataflow and GUID. otherwise, channels must also match */
748 static HRESULT get_audio_session(const GUID *sessionguid,
749 IMMDevice *device, UINT channels, AudioSession **out)
751 AudioSession *session;
753 if(!sessionguid || IsEqualGUID(sessionguid, &GUID_NULL)){
754 *out = create_session(&GUID_NULL, device, channels);
756 return E_OUTOFMEMORY;
762 LIST_FOR_EACH_ENTRY(session, &g_sessions, AudioSession, entry){
763 if(session->device == device &&
764 IsEqualGUID(sessionguid, &session->guid)){
765 session_init_vols(session, channels);
772 *out = create_session(sessionguid, device, channels);
774 return E_OUTOFMEMORY;
780 static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface,
781 AUDCLNT_SHAREMODE mode, DWORD flags, REFERENCE_TIME duration,
782 REFERENCE_TIME period, const WAVEFORMATEX *fmt,
783 const GUID *sessionguid)
785 ACImpl *This = impl_from_IAudioClient(iface);
786 snd_pcm_sw_params_t *sw_params = NULL;
787 snd_pcm_format_t format;
788 snd_pcm_uframes_t boundary;
789 const WAVEFORMATEXTENSIBLE *fmtex = (const WAVEFORMATEXTENSIBLE *)fmt;
790 unsigned int time_us, rate;
794 TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This, mode, flags,
795 wine_dbgstr_longlong(duration), wine_dbgstr_longlong(period), fmt, debugstr_guid(sessionguid));
800 if(mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE)
801 return AUDCLNT_E_NOT_INITIALIZED;
803 if(flags & ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS |
804 AUDCLNT_STREAMFLAGS_LOOPBACK |
805 AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
806 AUDCLNT_STREAMFLAGS_NOPERSIST |
807 AUDCLNT_STREAMFLAGS_RATEADJUST |
808 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED |
809 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE |
810 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED)){
811 TRACE("Unknown flags: %08x\n", flags);
815 EnterCriticalSection(&This->lock);
818 LeaveCriticalSection(&This->lock);
819 return AUDCLNT_E_ALREADY_INITIALIZED;
824 if((err = snd_pcm_hw_params_any(This->pcm_handle, This->hw_params)) < 0){
825 WARN("Unable to get hw_params: %d (%s)\n", err, snd_strerror(err));
830 if((err = snd_pcm_hw_params_set_access(This->pcm_handle, This->hw_params,
831 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0){
832 WARN("Unable to set access: %d (%s)\n", err, snd_strerror(err));
837 if(fmt->wFormatTag == WAVE_FORMAT_PCM ||
838 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
839 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))){
840 if(fmt->wBitsPerSample == 8)
841 format = SND_PCM_FORMAT_U8;
842 else if(fmt->wBitsPerSample == 16)
843 format = SND_PCM_FORMAT_S16_LE;
844 else if(fmt->wBitsPerSample == 24)
845 format = SND_PCM_FORMAT_S24_3LE;
846 else if(fmt->wBitsPerSample == 32)
847 format = SND_PCM_FORMAT_S32_LE;
849 WARN("Unsupported bit depth: %u\n", fmt->wBitsPerSample);
850 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
853 }else if(fmt->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
854 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
855 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))){
856 if(fmt->wBitsPerSample == 32)
857 format = SND_PCM_FORMAT_FLOAT_LE;
858 else if(fmt->wBitsPerSample == 64)
859 format = SND_PCM_FORMAT_FLOAT64_LE;
861 WARN("Unsupported float size: %u\n", fmt->wBitsPerSample);
862 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
866 WARN("Unknown wave format: %04x\n", fmt->wFormatTag);
867 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
871 if((err = snd_pcm_hw_params_set_format(This->pcm_handle, This->hw_params,
873 WARN("Unable to set ALSA format to %u: %d (%s)\n", format, err,
879 This->alsa_format = format;
881 rate = fmt->nSamplesPerSec;
882 if((err = snd_pcm_hw_params_set_rate_near(This->pcm_handle, This->hw_params,
884 WARN("Unable to set rate to %u: %d (%s)\n", rate, err,
890 if((err = snd_pcm_hw_params_set_channels(This->pcm_handle, This->hw_params,
891 fmt->nChannels)) < 0){
892 WARN("Unable to set channels to %u: %d (%s)\n", fmt->nChannels, err,
898 time_us = MinimumPeriod / 10;
899 if((err = snd_pcm_hw_params_set_period_time_near(This->pcm_handle,
900 This->hw_params, &time_us, NULL)) < 0){
901 WARN("Unable to set max period time to %u: %d (%s)\n", time_us,
902 err, snd_strerror(err));
907 if((err = snd_pcm_hw_params(This->pcm_handle, This->hw_params)) < 0){
908 WARN("Unable to set hw params: %d (%s)\n", err, snd_strerror(err));
913 sw_params = HeapAlloc(GetProcessHeap(), 0, snd_pcm_sw_params_sizeof());
919 if((err = snd_pcm_sw_params_current(This->pcm_handle, sw_params)) < 0){
920 WARN("Unable to get sw_params: %d (%s)\n", err, snd_strerror(err));
926 duration = 300000; /* 0.03s */
927 This->bufsize_frames = ceil((duration / 10000000.) * fmt->nSamplesPerSec);
928 This->local_buffer = HeapAlloc(GetProcessHeap(), 0,
929 This->bufsize_frames * fmt->nBlockAlign);
930 if(!This->local_buffer){
934 if (fmt->wBitsPerSample == 8)
935 memset(This->local_buffer, 128, This->bufsize_frames * fmt->nBlockAlign);
937 memset(This->local_buffer, 0, This->bufsize_frames * fmt->nBlockAlign);
939 if((err = snd_pcm_sw_params_get_boundary(sw_params, &boundary)) < 0){
940 WARN("Unable to get boundary: %d (%s)\n", err, snd_strerror(err));
945 if((err = snd_pcm_sw_params_set_start_threshold(This->pcm_handle,
946 sw_params, boundary)) < 0){
947 WARN("Unable to set start threshold to %lx: %d (%s)\n", boundary, err,
953 if((err = snd_pcm_sw_params_set_stop_threshold(This->pcm_handle,
954 sw_params, boundary)) < 0){
955 WARN("Unable to set stop threshold to %lx: %d (%s)\n", boundary, err,
961 if((err = snd_pcm_sw_params_set_avail_min(This->pcm_handle,
963 WARN("Unable to set avail min to 0: %d (%s)\n", err, snd_strerror(err));
968 if((err = snd_pcm_sw_params_set_silence_size(This->pcm_handle,
969 sw_params, boundary)) < 0){
970 WARN("Unable to set silence size to %lx: %d (%s)\n", boundary, err,
976 if((err = snd_pcm_sw_params(This->pcm_handle, sw_params)) < 0){
977 WARN("Unable to set sw params: %d (%s)\n", err, snd_strerror(err));
982 if((err = snd_pcm_prepare(This->pcm_handle)) < 0){
983 WARN("Unable to prepare device: %d (%s)\n", err, snd_strerror(err));
988 if((err = snd_pcm_hw_params_get_buffer_size(This->hw_params,
989 &This->bufsize_alsa)) < 0){
990 WARN("Unable to get buffer size: %d (%s)\n", err, snd_strerror(err));
995 if((err = snd_pcm_hw_params_get_period_size(This->hw_params,
996 &This->period_alsa, NULL)) < 0){
997 WARN("Unable to get period size: %d (%s)\n", err, snd_strerror(err));
1002 if((err = snd_pcm_hw_params_get_period_time(This->hw_params,
1003 &This->period_us, NULL)) < 0){
1004 WARN("Unable to get period time: %d (%s)\n", err, snd_strerror(err));
1009 This->fmt = clone_format(fmt);
1015 This->vols = HeapAlloc(GetProcessHeap(), 0, fmt->nChannels * sizeof(float));
1021 for(i = 0; i < fmt->nChannels; ++i)
1022 This->vols[i] = 1.f;
1025 This->flags = flags;
1027 EnterCriticalSection(&g_sessions_lock);
1029 hr = get_audio_session(sessionguid, This->parent, fmt->nChannels,
1032 LeaveCriticalSection(&g_sessions_lock);
1036 list_add_tail(&This->session->clients, &This->entry);
1038 LeaveCriticalSection(&g_sessions_lock);
1040 This->initted = TRUE;
1043 HeapFree(GetProcessHeap(), 0, sw_params);
1045 if(This->local_buffer){
1046 HeapFree(GetProcessHeap(), 0, This->local_buffer);
1047 This->local_buffer = NULL;
1050 CoTaskMemFree(This->fmt);
1054 HeapFree(GetProcessHeap(), 0, This->vols);
1059 LeaveCriticalSection(&This->lock);
1064 static HRESULT WINAPI AudioClient_GetBufferSize(IAudioClient *iface,
1067 ACImpl *This = impl_from_IAudioClient(iface);
1069 TRACE("(%p)->(%p)\n", This, out);
1074 EnterCriticalSection(&This->lock);
1077 LeaveCriticalSection(&This->lock);
1078 return AUDCLNT_E_NOT_INITIALIZED;
1081 *out = This->bufsize_frames;
1083 LeaveCriticalSection(&This->lock);
1088 static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient *iface,
1089 REFERENCE_TIME *latency)
1091 ACImpl *This = impl_from_IAudioClient(iface);
1093 TRACE("(%p)->(%p)\n", This, latency);
1098 EnterCriticalSection(&This->lock);
1101 LeaveCriticalSection(&This->lock);
1102 return AUDCLNT_E_NOT_INITIALIZED;
1105 LeaveCriticalSection(&This->lock);
1112 static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient *iface,
1115 ACImpl *This = impl_from_IAudioClient(iface);
1117 TRACE("(%p)->(%p)\n", This, out);
1122 EnterCriticalSection(&This->lock);
1125 LeaveCriticalSection(&This->lock);
1126 return AUDCLNT_E_NOT_INITIALIZED;
1129 if(This->dataflow == eRender){
1130 snd_pcm_sframes_t avail_frames;
1132 avail_frames = snd_pcm_avail_update(This->pcm_handle);
1134 if(This->bufsize_alsa < avail_frames){
1135 WARN("Xrun detected\n");
1136 *out = This->held_frames;
1138 *out = This->bufsize_alsa - avail_frames + This->held_frames;
1139 }else if(This->dataflow == eCapture){
1140 *out = This->held_frames;
1142 LeaveCriticalSection(&This->lock);
1143 return E_UNEXPECTED;
1146 LeaveCriticalSection(&This->lock);
1151 static DWORD get_channel_mask(unsigned int channels)
1157 return KSAUDIO_SPEAKER_MONO;
1159 return KSAUDIO_SPEAKER_STEREO;
1161 return KSAUDIO_SPEAKER_STEREO | SPEAKER_LOW_FREQUENCY;
1163 return KSAUDIO_SPEAKER_QUAD; /* not _SURROUND */
1165 return KSAUDIO_SPEAKER_QUAD | SPEAKER_LOW_FREQUENCY;
1167 return KSAUDIO_SPEAKER_5POINT1; /* not 5POINT1_SURROUND */
1169 return KSAUDIO_SPEAKER_5POINT1 | SPEAKER_BACK_CENTER;
1171 return KSAUDIO_SPEAKER_7POINT1; /* not 7POINT1_SURROUND */
1173 FIXME("Unknown speaker configuration: %u\n", channels);
1177 static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient *iface,
1178 AUDCLNT_SHAREMODE mode, const WAVEFORMATEX *fmt,
1181 ACImpl *This = impl_from_IAudioClient(iface);
1182 snd_pcm_format_mask_t *formats = NULL;
1184 WAVEFORMATEX *closest = NULL;
1185 const WAVEFORMATEXTENSIBLE *fmtex = (const WAVEFORMATEXTENSIBLE *)fmt;
1186 unsigned int max = 0, min = 0;
1189 TRACE("(%p)->(%x, %p, %p)\n", This, mode, fmt, out);
1191 if(!fmt || (mode == AUDCLNT_SHAREMODE_SHARED && !out))
1194 if(mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE)
1195 return E_INVALIDARG;
1197 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1198 fmt->cbSize < sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))
1199 return E_INVALIDARG;
1206 EnterCriticalSection(&This->lock);
1208 if((err = snd_pcm_hw_params_any(This->pcm_handle, This->hw_params)) < 0){
1213 formats = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1214 snd_pcm_format_mask_sizeof());
1220 snd_pcm_hw_params_get_format_mask(This->hw_params, formats);
1222 if(fmt->wFormatTag == WAVE_FORMAT_PCM ||
1223 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1224 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))){
1225 switch(fmt->wBitsPerSample){
1227 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_U8)){
1228 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1233 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S16_LE)){
1234 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1239 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S24_3LE)){
1240 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1245 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S32_LE)){
1246 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1251 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1254 }else if(fmt->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
1255 (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1256 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))){
1257 switch(fmt->wBitsPerSample){
1259 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_FLOAT_LE)){
1260 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1265 if(!snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_FLOAT64_LE)){
1266 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1271 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1275 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1279 closest = clone_format(fmt);
1285 if((err = snd_pcm_hw_params_get_rate_min(This->hw_params, &min, NULL)) < 0){
1287 WARN("Unable to get min rate: %d (%s)\n", err, snd_strerror(err));
1291 if((err = snd_pcm_hw_params_get_rate_max(This->hw_params, &max, NULL)) < 0){
1293 WARN("Unable to get max rate: %d (%s)\n", err, snd_strerror(err));
1297 if(fmt->nSamplesPerSec < min || fmt->nSamplesPerSec > max){
1298 hr = AUDCLNT_E_UNSUPPORTED_FORMAT;
1302 if((err = snd_pcm_hw_params_get_channels_min(This->hw_params, &min)) < 0){
1304 WARN("Unable to get min channels: %d (%s)\n", err, snd_strerror(err));
1308 if((err = snd_pcm_hw_params_get_channels_max(This->hw_params, &max)) < 0){
1310 WARN("Unable to get max channels: %d (%s)\n", err, snd_strerror(err));
1315 if(fmt->nChannels > max){
1317 closest->nChannels = max;
1318 }else if(fmt->nChannels < min){
1320 closest->nChannels = min;
1323 if(closest->wFormatTag == WAVE_FORMAT_EXTENSIBLE){
1324 DWORD mask = get_channel_mask(closest->nChannels);
1326 ((WAVEFORMATEXTENSIBLE*)closest)->dwChannelMask = mask;
1328 if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
1329 fmtex->dwChannelMask != mask)
1334 LeaveCriticalSection(&This->lock);
1335 HeapFree(GetProcessHeap(), 0, formats);
1337 if(hr == S_FALSE && out) {
1338 closest->nBlockAlign =
1339 closest->nChannels * closest->wBitsPerSample / 8;
1340 closest->nAvgBytesPerSec =
1341 closest->nBlockAlign * closest->nSamplesPerSec;
1344 CoTaskMemFree(closest);
1346 TRACE("returning: %08x\n", hr);
1350 static HRESULT WINAPI AudioClient_GetMixFormat(IAudioClient *iface,
1351 WAVEFORMATEX **pwfx)
1353 ACImpl *This = impl_from_IAudioClient(iface);
1354 WAVEFORMATEXTENSIBLE *fmt;
1355 snd_pcm_format_mask_t *formats;
1356 unsigned int max_rate, max_channels;
1360 TRACE("(%p)->(%p)\n", This, pwfx);
1366 fmt = CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE));
1368 return E_OUTOFMEMORY;
1370 formats = HeapAlloc(GetProcessHeap(), 0, snd_pcm_format_mask_sizeof());
1373 return E_OUTOFMEMORY;
1376 EnterCriticalSection(&This->lock);
1378 if((err = snd_pcm_hw_params_any(This->pcm_handle, This->hw_params)) < 0){
1379 WARN("Unable to get hw_params: %d (%s)\n", err, snd_strerror(err));
1384 snd_pcm_hw_params_get_format_mask(This->hw_params, formats);
1386 fmt->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
1387 if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_FLOAT_LE)){
1388 fmt->Format.wBitsPerSample = 32;
1389 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
1390 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S16_LE)){
1391 fmt->Format.wBitsPerSample = 16;
1392 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1393 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_U8)){
1394 fmt->Format.wBitsPerSample = 8;
1395 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1396 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S32_LE)){
1397 fmt->Format.wBitsPerSample = 32;
1398 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1399 }else if(snd_pcm_format_mask_test(formats, SND_PCM_FORMAT_S24_3LE)){
1400 fmt->Format.wBitsPerSample = 24;
1401 fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1403 ERR("Didn't recognize any available ALSA formats\n");
1408 if((err = snd_pcm_hw_params_get_channels_max(This->hw_params,
1409 &max_channels)) < 0){
1410 WARN("Unable to get max channels: %d (%s)\n", err, snd_strerror(err));
1415 if(max_channels > 2){
1416 FIXME("Don't know what to do with %u channels, pretending there's "
1417 "only 2 channels\n", max_channels);
1418 fmt->Format.nChannels = 2;
1420 fmt->Format.nChannels = max_channels;
1422 fmt->dwChannelMask = get_channel_mask(fmt->Format.nChannels);
1424 if((err = snd_pcm_hw_params_get_rate_max(This->hw_params, &max_rate,
1426 WARN("Unable to get max rate: %d (%s)\n", err, snd_strerror(err));
1431 if(max_rate >= 48000)
1432 fmt->Format.nSamplesPerSec = 48000;
1433 else if(max_rate >= 44100)
1434 fmt->Format.nSamplesPerSec = 44100;
1435 else if(max_rate >= 22050)
1436 fmt->Format.nSamplesPerSec = 22050;
1437 else if(max_rate >= 11025)
1438 fmt->Format.nSamplesPerSec = 11025;
1439 else if(max_rate >= 8000)
1440 fmt->Format.nSamplesPerSec = 8000;
1442 ERR("Unknown max rate: %u\n", max_rate);
1447 fmt->Format.nBlockAlign = (fmt->Format.wBitsPerSample *
1448 fmt->Format.nChannels) / 8;
1449 fmt->Format.nAvgBytesPerSec = fmt->Format.nSamplesPerSec *
1450 fmt->Format.nBlockAlign;
1452 fmt->Samples.wValidBitsPerSample = fmt->Format.wBitsPerSample;
1453 fmt->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
1455 dump_fmt((WAVEFORMATEX*)fmt);
1456 *pwfx = (WAVEFORMATEX*)fmt;
1459 LeaveCriticalSection(&This->lock);
1462 HeapFree(GetProcessHeap(), 0, formats);
1467 static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient *iface,
1468 REFERENCE_TIME *defperiod, REFERENCE_TIME *minperiod)
1470 ACImpl *This = impl_from_IAudioClient(iface);
1472 TRACE("(%p)->(%p, %p)\n", This, defperiod, minperiod);
1474 if(!defperiod && !minperiod)
1478 *defperiod = DefaultPeriod;
1480 *minperiod = MinimumPeriod;
1485 static snd_pcm_sframes_t alsa_write_best_effort(snd_pcm_t *handle, BYTE *buf,
1486 snd_pcm_uframes_t frames, ACImpl *This)
1488 snd_pcm_sframes_t written;
1490 if(This->session->mute){
1492 if((err = snd_pcm_format_set_silence(This->alsa_format, buf,
1493 frames * This->fmt->nChannels)) < 0)
1494 WARN("Setting buffer to silence failed: %d (%s)\n", err,
1498 written = snd_pcm_writei(handle, buf, frames);
1502 if(written == -EAGAIN)
1506 WARN("writei failed, recovering: %ld (%s)\n", written,
1507 snd_strerror(written));
1509 ret = wine_snd_pcm_recover(handle, written, 0);
1511 WARN("Could not recover: %d (%s)\n", ret, snd_strerror(ret));
1515 written = snd_pcm_writei(handle, buf, frames);
1521 static void alsa_write_data(ACImpl *This)
1523 snd_pcm_sframes_t written;
1524 snd_pcm_uframes_t to_write;
1526 This->local_buffer + (This->lcl_offs_frames * This->fmt->nBlockAlign);
1528 if(This->lcl_offs_frames + This->held_frames > This->bufsize_frames)
1529 to_write = This->bufsize_frames - This->lcl_offs_frames;
1531 to_write = This->held_frames;
1533 written = alsa_write_best_effort(This->pcm_handle, buf, to_write, This);
1535 WARN("Couldn't write: %ld (%s)\n", written, snd_strerror(written));
1539 This->lcl_offs_frames += written;
1540 This->lcl_offs_frames %= This->bufsize_frames;
1541 This->held_frames -= written;
1543 if(written < to_write){
1544 /* ALSA buffer probably full */
1548 if(This->held_frames){
1549 /* wrapped and have some data back at the start to write */
1550 written = alsa_write_best_effort(This->pcm_handle, This->local_buffer,
1551 This->held_frames, 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;
1563 static void alsa_read_data(ACImpl *This)
1565 snd_pcm_sframes_t pos, readable, nread;
1567 pos = (This->held_frames + This->lcl_offs_frames) % This->bufsize_frames;
1568 readable = This->bufsize_frames - pos;
1570 nread = snd_pcm_readi(This->pcm_handle,
1571 This->local_buffer + pos * This->fmt->nBlockAlign, readable);
1575 WARN("read failed, recovering: %ld (%s)\n", nread, snd_strerror(nread));
1577 ret = wine_snd_pcm_recover(This->pcm_handle, nread, 0);
1579 WARN("Recover failed: %d (%s)\n", ret, snd_strerror(ret));
1583 nread = snd_pcm_readi(This->pcm_handle,
1584 This->local_buffer + pos * This->fmt->nBlockAlign, readable);
1586 WARN("read failed: %ld (%s)\n", nread, snd_strerror(nread));
1591 if(This->session->mute){
1593 if((err = snd_pcm_format_set_silence(This->alsa_format,
1594 This->local_buffer + pos * This->fmt->nBlockAlign,
1596 WARN("Setting buffer to silence failed: %d (%s)\n", err,
1600 This->held_frames += nread;
1602 if(This->held_frames > This->bufsize_frames){
1603 WARN("Overflow of unread data\n");
1604 This->lcl_offs_frames += This->held_frames;
1605 This->lcl_offs_frames %= This->bufsize_frames;
1606 This->held_frames = This->bufsize_frames;
1610 static void CALLBACK alsa_push_buffer_data(void *user, BOOLEAN timer)
1612 ACImpl *This = user;
1614 EnterCriticalSection(&This->lock);
1617 if(This->dataflow == eRender && This->held_frames)
1618 alsa_write_data(This);
1619 else if(This->dataflow == eCapture)
1620 alsa_read_data(This);
1623 SetEvent(This->event);
1626 LeaveCriticalSection(&This->lock);
1629 static HRESULT alsa_consider_start(ACImpl *This)
1631 snd_pcm_sframes_t avail;
1634 avail = snd_pcm_avail_update(This->pcm_handle);
1636 WARN("Unable to get avail_update: %ld (%s)\n", avail,
1637 snd_strerror(avail));
1641 if(This->period_alsa < This->bufsize_alsa - avail){
1642 if((err = snd_pcm_start(This->pcm_handle)) < 0){
1643 WARN("Start failed: %d (%s), state: %d\n", err, snd_strerror(err),
1644 snd_pcm_state(This->pcm_handle));
1654 static HRESULT WINAPI AudioClient_Start(IAudioClient *iface)
1656 ACImpl *This = impl_from_IAudioClient(iface);
1660 TRACE("(%p)\n", This);
1662 EnterCriticalSection(&This->lock);
1665 LeaveCriticalSection(&This->lock);
1666 return AUDCLNT_E_NOT_INITIALIZED;
1669 if((This->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && !This->event){
1670 LeaveCriticalSection(&This->lock);
1671 return AUDCLNT_E_EVENTHANDLE_NOT_SET;
1675 LeaveCriticalSection(&This->lock);
1676 return AUDCLNT_E_NOT_STOPPED;
1679 hr = alsa_consider_start(This);
1681 LeaveCriticalSection(&This->lock);
1685 period_ms = This->period_us / 1000;
1689 if(This->dataflow == eCapture){
1690 /* dump any data that might be leftover in the ALSA capture buffer */
1691 snd_pcm_readi(This->pcm_handle, This->local_buffer,
1692 This->bufsize_frames);
1695 if(!CreateTimerQueueTimer(&This->timer, g_timer_q, alsa_push_buffer_data,
1696 This, 0, period_ms, WT_EXECUTEINTIMERTHREAD)){
1697 LeaveCriticalSection(&This->lock);
1698 WARN("Unable to create timer: %u\n", GetLastError());
1702 This->started = TRUE;
1704 LeaveCriticalSection(&This->lock);
1709 static HRESULT WINAPI AudioClient_Stop(IAudioClient *iface)
1711 ACImpl *This = impl_from_IAudioClient(iface);
1716 TRACE("(%p)\n", This);
1718 EnterCriticalSection(&This->lock);
1721 LeaveCriticalSection(&This->lock);
1722 return AUDCLNT_E_NOT_INITIALIZED;
1726 LeaveCriticalSection(&This->lock);
1730 event = CreateEventW(NULL, TRUE, FALSE, NULL);
1731 wait = !DeleteTimerQueueTimer(g_timer_q, This->timer, event);
1733 WARN("DeleteTimerQueueTimer error %u\n", GetLastError());
1734 wait = wait && GetLastError() == ERROR_IO_PENDING;
1736 if((err = snd_pcm_drop(This->pcm_handle)) < 0){
1737 LeaveCriticalSection(&This->lock);
1738 WARN("Drop failed: %d (%s)\n", err, snd_strerror(err));
1742 if((err = snd_pcm_prepare(This->pcm_handle)) < 0){
1743 LeaveCriticalSection(&This->lock);
1744 WARN("Prepare failed: %d (%s)\n", err, snd_strerror(err));
1748 This->started = FALSE;
1750 LeaveCriticalSection(&This->lock);
1753 WaitForSingleObject(event, INFINITE);
1759 static HRESULT WINAPI AudioClient_Reset(IAudioClient *iface)
1761 ACImpl *This = impl_from_IAudioClient(iface);
1763 TRACE("(%p)\n", This);
1765 EnterCriticalSection(&This->lock);
1768 LeaveCriticalSection(&This->lock);
1769 return AUDCLNT_E_NOT_INITIALIZED;
1773 LeaveCriticalSection(&This->lock);
1774 return AUDCLNT_E_NOT_STOPPED;
1777 if(This->buf_state != NOT_LOCKED){
1778 LeaveCriticalSection(&This->lock);
1779 return AUDCLNT_E_BUFFER_OPERATION_PENDING;
1782 This->held_frames = 0;
1783 This->written_frames = 0;
1784 This->lcl_offs_frames = 0;
1786 LeaveCriticalSection(&This->lock);
1791 static HRESULT WINAPI AudioClient_SetEventHandle(IAudioClient *iface,
1794 ACImpl *This = impl_from_IAudioClient(iface);
1796 TRACE("(%p)->(%p)\n", This, event);
1799 return E_INVALIDARG;
1801 EnterCriticalSection(&This->lock);
1804 LeaveCriticalSection(&This->lock);
1805 return AUDCLNT_E_NOT_INITIALIZED;
1808 if(!(This->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK)){
1809 LeaveCriticalSection(&This->lock);
1810 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED;
1813 This->event = event;
1815 LeaveCriticalSection(&This->lock);
1820 static HRESULT WINAPI AudioClient_GetService(IAudioClient *iface, REFIID riid,
1823 ACImpl *This = impl_from_IAudioClient(iface);
1825 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1831 EnterCriticalSection(&This->lock);
1834 LeaveCriticalSection(&This->lock);
1835 return AUDCLNT_E_NOT_INITIALIZED;
1838 if(IsEqualIID(riid, &IID_IAudioRenderClient)){
1839 if(This->dataflow != eRender){
1840 LeaveCriticalSection(&This->lock);
1841 return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
1843 IAudioRenderClient_AddRef(&This->IAudioRenderClient_iface);
1844 *ppv = &This->IAudioRenderClient_iface;
1845 }else if(IsEqualIID(riid, &IID_IAudioCaptureClient)){
1846 if(This->dataflow != eCapture){
1847 LeaveCriticalSection(&This->lock);
1848 return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
1850 IAudioCaptureClient_AddRef(&This->IAudioCaptureClient_iface);
1851 *ppv = &This->IAudioCaptureClient_iface;
1852 }else if(IsEqualIID(riid, &IID_IAudioClock)){
1853 IAudioClock_AddRef(&This->IAudioClock_iface);
1854 *ppv = &This->IAudioClock_iface;
1855 }else if(IsEqualIID(riid, &IID_IAudioStreamVolume)){
1856 IAudioStreamVolume_AddRef(&This->IAudioStreamVolume_iface);
1857 *ppv = &This->IAudioStreamVolume_iface;
1858 }else if(IsEqualIID(riid, &IID_IAudioSessionControl)){
1859 if(!This->session_wrapper){
1860 This->session_wrapper = AudioSessionWrapper_Create(This);
1861 if(!This->session_wrapper){
1862 LeaveCriticalSection(&This->lock);
1863 return E_OUTOFMEMORY;
1866 IAudioSessionControl2_AddRef(&This->session_wrapper->IAudioSessionControl2_iface);
1868 *ppv = &This->session_wrapper->IAudioSessionControl2_iface;
1869 }else if(IsEqualIID(riid, &IID_IChannelAudioVolume)){
1870 if(!This->session_wrapper){
1871 This->session_wrapper = AudioSessionWrapper_Create(This);
1872 if(!This->session_wrapper){
1873 LeaveCriticalSection(&This->lock);
1874 return E_OUTOFMEMORY;
1877 IChannelAudioVolume_AddRef(&This->session_wrapper->IChannelAudioVolume_iface);
1879 *ppv = &This->session_wrapper->IChannelAudioVolume_iface;
1880 }else if(IsEqualIID(riid, &IID_ISimpleAudioVolume)){
1881 if(!This->session_wrapper){
1882 This->session_wrapper = AudioSessionWrapper_Create(This);
1883 if(!This->session_wrapper){
1884 LeaveCriticalSection(&This->lock);
1885 return E_OUTOFMEMORY;
1888 ISimpleAudioVolume_AddRef(&This->session_wrapper->ISimpleAudioVolume_iface);
1890 *ppv = &This->session_wrapper->ISimpleAudioVolume_iface;
1894 LeaveCriticalSection(&This->lock);
1898 LeaveCriticalSection(&This->lock);
1900 FIXME("stub %s\n", debugstr_guid(riid));
1901 return E_NOINTERFACE;
1904 static const IAudioClientVtbl AudioClient_Vtbl =
1906 AudioClient_QueryInterface,
1908 AudioClient_Release,
1909 AudioClient_Initialize,
1910 AudioClient_GetBufferSize,
1911 AudioClient_GetStreamLatency,
1912 AudioClient_GetCurrentPadding,
1913 AudioClient_IsFormatSupported,
1914 AudioClient_GetMixFormat,
1915 AudioClient_GetDevicePeriod,
1919 AudioClient_SetEventHandle,
1920 AudioClient_GetService
1923 static HRESULT WINAPI AudioRenderClient_QueryInterface(
1924 IAudioRenderClient *iface, REFIID riid, void **ppv)
1926 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
1932 if(IsEqualIID(riid, &IID_IUnknown) ||
1933 IsEqualIID(riid, &IID_IAudioRenderClient))
1936 IUnknown_AddRef((IUnknown*)*ppv);
1940 WARN("Unknown interface %s\n", debugstr_guid(riid));
1941 return E_NOINTERFACE;
1944 static ULONG WINAPI AudioRenderClient_AddRef(IAudioRenderClient *iface)
1946 ACImpl *This = impl_from_IAudioRenderClient(iface);
1947 return AudioClient_AddRef(&This->IAudioClient_iface);
1950 static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
1952 ACImpl *This = impl_from_IAudioRenderClient(iface);
1953 return AudioClient_Release(&This->IAudioClient_iface);
1956 static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
1957 UINT32 frames, BYTE **data)
1959 ACImpl *This = impl_from_IAudioRenderClient(iface);
1964 TRACE("(%p)->(%u, %p)\n", This, frames, data);
1969 EnterCriticalSection(&This->lock);
1971 if(This->buf_state != NOT_LOCKED){
1972 LeaveCriticalSection(&This->lock);
1973 return AUDCLNT_E_OUT_OF_ORDER;
1977 This->buf_state = LOCKED_NORMAL;
1978 LeaveCriticalSection(&This->lock);
1982 hr = IAudioClient_GetCurrentPadding(&This->IAudioClient_iface, &pad);
1984 LeaveCriticalSection(&This->lock);
1988 if(pad + frames > This->bufsize_frames){
1989 LeaveCriticalSection(&This->lock);
1990 return AUDCLNT_E_BUFFER_TOO_LARGE;
1994 (This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
1995 if(write_pos + frames > This->bufsize_frames){
1996 if(This->tmp_buffer_frames < frames){
1997 if(This->tmp_buffer)
1998 This->tmp_buffer = HeapReAlloc(GetProcessHeap(), 0,
1999 This->tmp_buffer, frames * This->fmt->nBlockAlign);
2001 This->tmp_buffer = HeapAlloc(GetProcessHeap(), 0,
2002 frames * This->fmt->nBlockAlign);
2003 if(!This->tmp_buffer){
2004 LeaveCriticalSection(&This->lock);
2005 return E_OUTOFMEMORY;
2007 This->tmp_buffer_frames = frames;
2009 *data = This->tmp_buffer;
2010 This->buf_state = LOCKED_WRAPPED;
2012 *data = This->local_buffer + write_pos * This->fmt->nBlockAlign;
2013 This->buf_state = LOCKED_NORMAL;
2016 LeaveCriticalSection(&This->lock);
2021 static void alsa_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_frames)
2023 snd_pcm_uframes_t write_offs_frames =
2024 (This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
2025 UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign;
2026 snd_pcm_uframes_t chunk_frames = This->bufsize_frames - write_offs_frames;
2027 UINT32 chunk_bytes = chunk_frames * This->fmt->nBlockAlign;
2028 UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
2030 if(written_bytes <= chunk_bytes){
2031 memcpy(This->local_buffer + write_offs_bytes, buffer, written_bytes);
2033 memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes);
2034 memcpy(This->local_buffer, buffer + chunk_bytes,
2035 written_bytes - chunk_bytes);
2039 static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
2040 IAudioRenderClient *iface, UINT32 written_frames, DWORD flags)
2042 ACImpl *This = impl_from_IAudioRenderClient(iface);
2046 TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
2048 EnterCriticalSection(&This->lock);
2050 if(This->buf_state == NOT_LOCKED || !written_frames){
2051 This->buf_state = NOT_LOCKED;
2052 LeaveCriticalSection(&This->lock);
2053 return written_frames ? AUDCLNT_E_OUT_OF_ORDER : S_OK;
2056 if(This->buf_state == LOCKED_NORMAL)
2057 buffer = This->local_buffer + This->fmt->nBlockAlign *
2058 ((This->lcl_offs_frames + This->held_frames) % This->bufsize_frames);
2060 buffer = This->tmp_buffer;
2062 if(flags & AUDCLNT_BUFFERFLAGS_SILENT){
2063 WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)This->fmt;
2064 if((This->fmt->wFormatTag == WAVE_FORMAT_PCM ||
2065 (This->fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
2066 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) &&
2067 This->fmt->wBitsPerSample == 8)
2068 memset(buffer, 128, written_frames * This->fmt->nBlockAlign);
2070 memset(buffer, 0, written_frames * This->fmt->nBlockAlign);
2073 if(This->held_frames){
2074 if(This->buf_state == LOCKED_WRAPPED)
2075 alsa_wrap_buffer(This, buffer, written_frames);
2077 This->held_frames += written_frames;
2079 snd_pcm_sframes_t written;
2081 written = alsa_write_best_effort(This->pcm_handle, buffer,
2082 written_frames, This);
2084 LeaveCriticalSection(&This->lock);
2085 WARN("write failed: %ld (%s)\n", written, snd_strerror(written));
2089 if(written < written_frames){
2090 if(This->buf_state == LOCKED_WRAPPED)
2091 alsa_wrap_buffer(This,
2092 This->tmp_buffer + written * This->fmt->nBlockAlign,
2093 written_frames - written);
2095 This->held_frames = written_frames - written;
2100 snd_pcm_state(This->pcm_handle) == SND_PCM_STATE_PREPARED){
2101 hr = alsa_consider_start(This);
2103 LeaveCriticalSection(&This->lock);
2108 This->written_frames += written_frames;
2109 This->buf_state = NOT_LOCKED;
2111 LeaveCriticalSection(&This->lock);
2116 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = {
2117 AudioRenderClient_QueryInterface,
2118 AudioRenderClient_AddRef,
2119 AudioRenderClient_Release,
2120 AudioRenderClient_GetBuffer,
2121 AudioRenderClient_ReleaseBuffer
2124 static HRESULT WINAPI AudioCaptureClient_QueryInterface(
2125 IAudioCaptureClient *iface, REFIID riid, void **ppv)
2127 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2133 if(IsEqualIID(riid, &IID_IUnknown) ||
2134 IsEqualIID(riid, &IID_IAudioCaptureClient))
2137 IUnknown_AddRef((IUnknown*)*ppv);
2141 WARN("Unknown interface %s\n", debugstr_guid(riid));
2142 return E_NOINTERFACE;
2145 static ULONG WINAPI AudioCaptureClient_AddRef(IAudioCaptureClient *iface)
2147 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2148 return IAudioClient_AddRef(&This->IAudioClient_iface);
2151 static ULONG WINAPI AudioCaptureClient_Release(IAudioCaptureClient *iface)
2153 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2154 return IAudioClient_Release(&This->IAudioClient_iface);
2157 static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
2158 BYTE **data, UINT32 *frames, DWORD *flags, UINT64 *devpos,
2161 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2164 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This, data, frames, flags,
2167 if(!data || !frames || !flags)
2170 EnterCriticalSection(&This->lock);
2172 if(This->buf_state != NOT_LOCKED){
2173 LeaveCriticalSection(&This->lock);
2174 return AUDCLNT_E_OUT_OF_ORDER;
2177 hr = IAudioCaptureClient_GetNextPacketSize(iface, frames);
2179 LeaveCriticalSection(&This->lock);
2185 if(This->lcl_offs_frames + *frames > This->bufsize_frames){
2186 UINT32 chunk_bytes, offs_bytes, frames_bytes;
2187 if(This->tmp_buffer_frames < *frames){
2188 if(This->tmp_buffer)
2189 This->tmp_buffer = HeapReAlloc(GetProcessHeap(), 0,
2190 This->tmp_buffer, *frames * This->fmt->nBlockAlign);
2192 This->tmp_buffer = HeapAlloc(GetProcessHeap(), 0,
2193 *frames * This->fmt->nBlockAlign);
2194 if(!This->tmp_buffer){
2195 LeaveCriticalSection(&This->lock);
2196 return E_OUTOFMEMORY;
2198 This->tmp_buffer_frames = *frames;
2201 *data = This->tmp_buffer;
2202 chunk_bytes = (This->bufsize_frames - This->lcl_offs_frames) *
2203 This->fmt->nBlockAlign;
2204 offs_bytes = This->lcl_offs_frames * This->fmt->nBlockAlign;
2205 frames_bytes = *frames * This->fmt->nBlockAlign;
2206 memcpy(This->tmp_buffer, This->local_buffer + offs_bytes, chunk_bytes);
2207 memcpy(This->tmp_buffer + chunk_bytes, This->local_buffer,
2208 frames_bytes - chunk_bytes);
2210 *data = This->local_buffer +
2211 This->lcl_offs_frames * This->fmt->nBlockAlign;
2213 This->buf_state = LOCKED_NORMAL;
2215 if(devpos || qpcpos)
2216 IAudioClock_GetPosition(&This->IAudioClock_iface, devpos, qpcpos);
2218 LeaveCriticalSection(&This->lock);
2220 return *frames ? S_OK : AUDCLNT_S_BUFFER_EMPTY;
2223 static HRESULT WINAPI AudioCaptureClient_ReleaseBuffer(
2224 IAudioCaptureClient *iface, UINT32 done)
2226 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2228 TRACE("(%p)->(%u)\n", This, done);
2230 EnterCriticalSection(&This->lock);
2232 if(This->buf_state == NOT_LOCKED){
2233 LeaveCriticalSection(&This->lock);
2234 return AUDCLNT_E_OUT_OF_ORDER;
2237 This->held_frames -= done;
2238 This->lcl_offs_frames += done;
2239 This->lcl_offs_frames %= This->bufsize_frames;
2241 This->buf_state = NOT_LOCKED;
2243 LeaveCriticalSection(&This->lock);
2248 static HRESULT WINAPI AudioCaptureClient_GetNextPacketSize(
2249 IAudioCaptureClient *iface, UINT32 *frames)
2251 ACImpl *This = impl_from_IAudioCaptureClient(iface);
2253 TRACE("(%p)->(%p)\n", This, frames);
2255 return AudioClient_GetCurrentPadding(&This->IAudioClient_iface, frames);
2258 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl =
2260 AudioCaptureClient_QueryInterface,
2261 AudioCaptureClient_AddRef,
2262 AudioCaptureClient_Release,
2263 AudioCaptureClient_GetBuffer,
2264 AudioCaptureClient_ReleaseBuffer,
2265 AudioCaptureClient_GetNextPacketSize
2268 static HRESULT WINAPI AudioClock_QueryInterface(IAudioClock *iface,
2269 REFIID riid, void **ppv)
2271 ACImpl *This = impl_from_IAudioClock(iface);
2273 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2279 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClock))
2281 else if(IsEqualIID(riid, &IID_IAudioClock2))
2282 *ppv = &This->IAudioClock2_iface;
2284 IUnknown_AddRef((IUnknown*)*ppv);
2288 WARN("Unknown interface %s\n", debugstr_guid(riid));
2289 return E_NOINTERFACE;
2292 static ULONG WINAPI AudioClock_AddRef(IAudioClock *iface)
2294 ACImpl *This = impl_from_IAudioClock(iface);
2295 return IAudioClient_AddRef(&This->IAudioClient_iface);
2298 static ULONG WINAPI AudioClock_Release(IAudioClock *iface)
2300 ACImpl *This = impl_from_IAudioClock(iface);
2301 return IAudioClient_Release(&This->IAudioClient_iface);
2304 static HRESULT WINAPI AudioClock_GetFrequency(IAudioClock *iface, UINT64 *freq)
2306 ACImpl *This = impl_from_IAudioClock(iface);
2308 TRACE("(%p)->(%p)\n", This, freq);
2310 *freq = This->fmt->nSamplesPerSec;
2315 static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos,
2318 ACImpl *This = impl_from_IAudioClock(iface);
2322 TRACE("(%p)->(%p, %p)\n", This, pos, qpctime);
2327 EnterCriticalSection(&This->lock);
2329 hr = IAudioClient_GetCurrentPadding(&This->IAudioClient_iface, &pad);
2331 LeaveCriticalSection(&This->lock);
2335 if(This->dataflow == eRender)
2336 *pos = This->written_frames - pad;
2337 else if(This->dataflow == eCapture)
2338 *pos = This->written_frames + pad;
2340 LeaveCriticalSection(&This->lock);
2343 LARGE_INTEGER stamp, freq;
2344 QueryPerformanceCounter(&stamp);
2345 QueryPerformanceFrequency(&freq);
2346 *qpctime = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
2352 static HRESULT WINAPI AudioClock_GetCharacteristics(IAudioClock *iface,
2355 ACImpl *This = impl_from_IAudioClock(iface);
2357 TRACE("(%p)->(%p)\n", This, chars);
2362 *chars = AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ;
2367 static const IAudioClockVtbl AudioClock_Vtbl =
2369 AudioClock_QueryInterface,
2372 AudioClock_GetFrequency,
2373 AudioClock_GetPosition,
2374 AudioClock_GetCharacteristics
2377 static HRESULT WINAPI AudioClock2_QueryInterface(IAudioClock2 *iface,
2378 REFIID riid, void **ppv)
2380 ACImpl *This = impl_from_IAudioClock2(iface);
2381 return IAudioClock_QueryInterface(&This->IAudioClock_iface, riid, ppv);
2384 static ULONG WINAPI AudioClock2_AddRef(IAudioClock2 *iface)
2386 ACImpl *This = impl_from_IAudioClock2(iface);
2387 return IAudioClient_AddRef(&This->IAudioClient_iface);
2390 static ULONG WINAPI AudioClock2_Release(IAudioClock2 *iface)
2392 ACImpl *This = impl_from_IAudioClock2(iface);
2393 return IAudioClient_Release(&This->IAudioClient_iface);
2396 static HRESULT WINAPI AudioClock2_GetDevicePosition(IAudioClock2 *iface,
2397 UINT64 *pos, UINT64 *qpctime)
2399 ACImpl *This = impl_from_IAudioClock2(iface);
2401 FIXME("(%p)->(%p, %p)\n", This, pos, qpctime);
2406 static const IAudioClock2Vtbl AudioClock2_Vtbl =
2408 AudioClock2_QueryInterface,
2410 AudioClock2_Release,
2411 AudioClock2_GetDevicePosition
2414 static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client)
2416 AudioSessionWrapper *ret;
2418 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2419 sizeof(AudioSessionWrapper));
2423 ret->IAudioSessionControl2_iface.lpVtbl = &AudioSessionControl2_Vtbl;
2424 ret->ISimpleAudioVolume_iface.lpVtbl = &SimpleAudioVolume_Vtbl;
2425 ret->IChannelAudioVolume_iface.lpVtbl = &ChannelAudioVolume_Vtbl;
2429 ret->client = client;
2431 ret->session = client->session;
2432 AudioClient_AddRef(&client->IAudioClient_iface);
2438 static HRESULT WINAPI AudioSessionControl_QueryInterface(
2439 IAudioSessionControl2 *iface, REFIID riid, void **ppv)
2441 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2447 if(IsEqualIID(riid, &IID_IUnknown) ||
2448 IsEqualIID(riid, &IID_IAudioSessionControl) ||
2449 IsEqualIID(riid, &IID_IAudioSessionControl2))
2452 IUnknown_AddRef((IUnknown*)*ppv);
2456 WARN("Unknown interface %s\n", debugstr_guid(riid));
2457 return E_NOINTERFACE;
2460 static ULONG WINAPI AudioSessionControl_AddRef(IAudioSessionControl2 *iface)
2462 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2464 ref = InterlockedIncrement(&This->ref);
2465 TRACE("(%p) Refcount now %u\n", This, ref);
2469 static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface)
2471 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2473 ref = InterlockedDecrement(&This->ref);
2474 TRACE("(%p) Refcount now %u\n", This, ref);
2477 EnterCriticalSection(&This->client->lock);
2478 This->client->session_wrapper = NULL;
2479 LeaveCriticalSection(&This->client->lock);
2480 AudioClient_Release(&This->client->IAudioClient_iface);
2482 HeapFree(GetProcessHeap(), 0, This);
2487 static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface,
2488 AudioSessionState *state)
2490 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2493 TRACE("(%p)->(%p)\n", This, state);
2496 return NULL_PTR_ERR;
2498 EnterCriticalSection(&g_sessions_lock);
2500 if(list_empty(&This->session->clients)){
2501 *state = AudioSessionStateExpired;
2502 LeaveCriticalSection(&g_sessions_lock);
2506 LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry){
2507 EnterCriticalSection(&client->lock);
2508 if(client->started){
2509 *state = AudioSessionStateActive;
2510 LeaveCriticalSection(&client->lock);
2511 LeaveCriticalSection(&g_sessions_lock);
2514 LeaveCriticalSection(&client->lock);
2517 LeaveCriticalSection(&g_sessions_lock);
2519 *state = AudioSessionStateInactive;
2524 static HRESULT WINAPI AudioSessionControl_GetDisplayName(
2525 IAudioSessionControl2 *iface, WCHAR **name)
2527 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2529 FIXME("(%p)->(%p) - stub\n", This, name);
2534 static HRESULT WINAPI AudioSessionControl_SetDisplayName(
2535 IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session)
2537 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2539 FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session));
2544 static HRESULT WINAPI AudioSessionControl_GetIconPath(
2545 IAudioSessionControl2 *iface, WCHAR **path)
2547 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2549 FIXME("(%p)->(%p) - stub\n", This, path);
2554 static HRESULT WINAPI AudioSessionControl_SetIconPath(
2555 IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session)
2557 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2559 FIXME("(%p)->(%p, %s) - stub\n", This, path, debugstr_guid(session));
2564 static HRESULT WINAPI AudioSessionControl_GetGroupingParam(
2565 IAudioSessionControl2 *iface, GUID *group)
2567 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2569 FIXME("(%p)->(%p) - stub\n", This, group);
2574 static HRESULT WINAPI AudioSessionControl_SetGroupingParam(
2575 IAudioSessionControl2 *iface, const GUID *group, const GUID *session)
2577 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2579 FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group),
2580 debugstr_guid(session));
2585 static HRESULT WINAPI AudioSessionControl_RegisterAudioSessionNotification(
2586 IAudioSessionControl2 *iface, IAudioSessionEvents *events)
2588 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2590 FIXME("(%p)->(%p) - stub\n", This, events);
2595 static HRESULT WINAPI AudioSessionControl_UnregisterAudioSessionNotification(
2596 IAudioSessionControl2 *iface, IAudioSessionEvents *events)
2598 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2600 FIXME("(%p)->(%p) - stub\n", This, events);
2605 static HRESULT WINAPI AudioSessionControl_GetSessionIdentifier(
2606 IAudioSessionControl2 *iface, WCHAR **id)
2608 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2610 FIXME("(%p)->(%p) - stub\n", This, id);
2615 static HRESULT WINAPI AudioSessionControl_GetSessionInstanceIdentifier(
2616 IAudioSessionControl2 *iface, WCHAR **id)
2618 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2620 FIXME("(%p)->(%p) - stub\n", This, id);
2625 static HRESULT WINAPI AudioSessionControl_GetProcessId(
2626 IAudioSessionControl2 *iface, DWORD *pid)
2628 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2630 TRACE("(%p)->(%p)\n", This, pid);
2635 *pid = GetCurrentProcessId();
2640 static HRESULT WINAPI AudioSessionControl_IsSystemSoundsSession(
2641 IAudioSessionControl2 *iface)
2643 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2645 TRACE("(%p)\n", This);
2650 static HRESULT WINAPI AudioSessionControl_SetDuckingPreference(
2651 IAudioSessionControl2 *iface, BOOL optout)
2653 AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
2655 TRACE("(%p)->(%d)\n", This, optout);
2660 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl =
2662 AudioSessionControl_QueryInterface,
2663 AudioSessionControl_AddRef,
2664 AudioSessionControl_Release,
2665 AudioSessionControl_GetState,
2666 AudioSessionControl_GetDisplayName,
2667 AudioSessionControl_SetDisplayName,
2668 AudioSessionControl_GetIconPath,
2669 AudioSessionControl_SetIconPath,
2670 AudioSessionControl_GetGroupingParam,
2671 AudioSessionControl_SetGroupingParam,
2672 AudioSessionControl_RegisterAudioSessionNotification,
2673 AudioSessionControl_UnregisterAudioSessionNotification,
2674 AudioSessionControl_GetSessionIdentifier,
2675 AudioSessionControl_GetSessionInstanceIdentifier,
2676 AudioSessionControl_GetProcessId,
2677 AudioSessionControl_IsSystemSoundsSession,
2678 AudioSessionControl_SetDuckingPreference
2681 static HRESULT WINAPI SimpleAudioVolume_QueryInterface(
2682 ISimpleAudioVolume *iface, REFIID riid, void **ppv)
2684 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2690 if(IsEqualIID(riid, &IID_IUnknown) ||
2691 IsEqualIID(riid, &IID_ISimpleAudioVolume))
2694 IUnknown_AddRef((IUnknown*)*ppv);
2698 WARN("Unknown interface %s\n", debugstr_guid(riid));
2699 return E_NOINTERFACE;
2702 static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface)
2704 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2705 return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface);
2708 static ULONG WINAPI SimpleAudioVolume_Release(ISimpleAudioVolume *iface)
2710 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2711 return AudioSessionControl_Release(&This->IAudioSessionControl2_iface);
2714 static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume(
2715 ISimpleAudioVolume *iface, float level, const GUID *context)
2717 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2718 AudioSession *session = This->session;
2720 TRACE("(%p)->(%f, %s)\n", session, level, wine_dbgstr_guid(context));
2722 if(level < 0.f || level > 1.f)
2723 return E_INVALIDARG;
2726 FIXME("Notifications not supported yet\n");
2728 TRACE("ALSA does not support volume control\n");
2730 EnterCriticalSection(&session->lock);
2732 session->master_vol = level;
2734 LeaveCriticalSection(&session->lock);
2739 static HRESULT WINAPI SimpleAudioVolume_GetMasterVolume(
2740 ISimpleAudioVolume *iface, float *level)
2742 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2743 AudioSession *session = This->session;
2745 TRACE("(%p)->(%p)\n", session, level);
2748 return NULL_PTR_ERR;
2750 *level = session->master_vol;
2755 static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface,
2756 BOOL mute, const GUID *context)
2758 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2759 AudioSession *session = This->session;
2761 TRACE("(%p)->(%u, %p)\n", session, mute, context);
2764 FIXME("Notifications not supported yet\n");
2766 session->mute = mute;
2771 static HRESULT WINAPI SimpleAudioVolume_GetMute(ISimpleAudioVolume *iface,
2774 AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
2775 AudioSession *session = This->session;
2777 TRACE("(%p)->(%p)\n", session, mute);
2780 return NULL_PTR_ERR;
2782 *mute = session->mute;
2787 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl =
2789 SimpleAudioVolume_QueryInterface,
2790 SimpleAudioVolume_AddRef,
2791 SimpleAudioVolume_Release,
2792 SimpleAudioVolume_SetMasterVolume,
2793 SimpleAudioVolume_GetMasterVolume,
2794 SimpleAudioVolume_SetMute,
2795 SimpleAudioVolume_GetMute
2798 static HRESULT WINAPI AudioStreamVolume_QueryInterface(
2799 IAudioStreamVolume *iface, REFIID riid, void **ppv)
2801 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2807 if(IsEqualIID(riid, &IID_IUnknown) ||
2808 IsEqualIID(riid, &IID_IAudioStreamVolume))
2811 IUnknown_AddRef((IUnknown*)*ppv);
2815 WARN("Unknown interface %s\n", debugstr_guid(riid));
2816 return E_NOINTERFACE;
2819 static ULONG WINAPI AudioStreamVolume_AddRef(IAudioStreamVolume *iface)
2821 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2822 return IAudioClient_AddRef(&This->IAudioClient_iface);
2825 static ULONG WINAPI AudioStreamVolume_Release(IAudioStreamVolume *iface)
2827 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2828 return IAudioClient_Release(&This->IAudioClient_iface);
2831 static HRESULT WINAPI AudioStreamVolume_GetChannelCount(
2832 IAudioStreamVolume *iface, UINT32 *out)
2834 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2836 TRACE("(%p)->(%p)\n", This, out);
2841 *out = This->fmt->nChannels;
2846 static HRESULT WINAPI AudioStreamVolume_SetChannelVolume(
2847 IAudioStreamVolume *iface, UINT32 index, float level)
2849 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2851 TRACE("(%p)->(%d, %f)\n", This, index, level);
2853 if(level < 0.f || level > 1.f)
2854 return E_INVALIDARG;
2856 if(index >= This->fmt->nChannels)
2857 return E_INVALIDARG;
2859 TRACE("ALSA does not support volume control\n");
2861 EnterCriticalSection(&This->lock);
2863 This->vols[index] = level;
2865 LeaveCriticalSection(&This->lock);
2870 static HRESULT WINAPI AudioStreamVolume_GetChannelVolume(
2871 IAudioStreamVolume *iface, UINT32 index, float *level)
2873 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2875 TRACE("(%p)->(%d, %p)\n", This, index, level);
2880 if(index >= This->fmt->nChannels)
2881 return E_INVALIDARG;
2883 *level = This->vols[index];
2888 static HRESULT WINAPI AudioStreamVolume_SetAllVolumes(
2889 IAudioStreamVolume *iface, UINT32 count, const float *levels)
2891 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2894 TRACE("(%p)->(%d, %p)\n", This, count, levels);
2899 if(count != This->fmt->nChannels)
2900 return E_INVALIDARG;
2902 TRACE("ALSA does not support volume control\n");
2904 EnterCriticalSection(&This->lock);
2906 for(i = 0; i < count; ++i)
2907 This->vols[i] = levels[i];
2909 LeaveCriticalSection(&This->lock);
2914 static HRESULT WINAPI AudioStreamVolume_GetAllVolumes(
2915 IAudioStreamVolume *iface, UINT32 count, float *levels)
2917 ACImpl *This = impl_from_IAudioStreamVolume(iface);
2920 TRACE("(%p)->(%d, %p)\n", This, count, levels);
2925 if(count != This->fmt->nChannels)
2926 return E_INVALIDARG;
2928 EnterCriticalSection(&This->lock);
2930 for(i = 0; i < count; ++i)
2931 levels[i] = This->vols[i];
2933 LeaveCriticalSection(&This->lock);
2938 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl =
2940 AudioStreamVolume_QueryInterface,
2941 AudioStreamVolume_AddRef,
2942 AudioStreamVolume_Release,
2943 AudioStreamVolume_GetChannelCount,
2944 AudioStreamVolume_SetChannelVolume,
2945 AudioStreamVolume_GetChannelVolume,
2946 AudioStreamVolume_SetAllVolumes,
2947 AudioStreamVolume_GetAllVolumes
2950 static HRESULT WINAPI ChannelAudioVolume_QueryInterface(
2951 IChannelAudioVolume *iface, REFIID riid, void **ppv)
2953 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2959 if(IsEqualIID(riid, &IID_IUnknown) ||
2960 IsEqualIID(riid, &IID_IChannelAudioVolume))
2963 IUnknown_AddRef((IUnknown*)*ppv);
2967 WARN("Unknown interface %s\n", debugstr_guid(riid));
2968 return E_NOINTERFACE;
2971 static ULONG WINAPI ChannelAudioVolume_AddRef(IChannelAudioVolume *iface)
2973 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2974 return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface);
2977 static ULONG WINAPI ChannelAudioVolume_Release(IChannelAudioVolume *iface)
2979 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2980 return AudioSessionControl_Release(&This->IAudioSessionControl2_iface);
2983 static HRESULT WINAPI ChannelAudioVolume_GetChannelCount(
2984 IChannelAudioVolume *iface, UINT32 *out)
2986 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
2987 AudioSession *session = This->session;
2989 TRACE("(%p)->(%p)\n", session, out);
2992 return NULL_PTR_ERR;
2994 *out = session->channel_count;
2999 static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume(
3000 IChannelAudioVolume *iface, UINT32 index, float level,
3001 const GUID *context)
3003 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
3004 AudioSession *session = This->session;
3006 TRACE("(%p)->(%d, %f, %s)\n", session, index, level,
3007 wine_dbgstr_guid(context));
3009 if(level < 0.f || level > 1.f)
3010 return E_INVALIDARG;
3012 if(index >= 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 session->channel_vols[index] = level;
3024 LeaveCriticalSection(&session->lock);
3029 static HRESULT WINAPI ChannelAudioVolume_GetChannelVolume(
3030 IChannelAudioVolume *iface, UINT32 index, float *level)
3032 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
3033 AudioSession *session = This->session;
3035 TRACE("(%p)->(%d, %p)\n", session, index, level);
3038 return NULL_PTR_ERR;
3040 if(index >= session->channel_count)
3041 return E_INVALIDARG;
3043 *level = session->channel_vols[index];
3048 static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes(
3049 IChannelAudioVolume *iface, UINT32 count, const float *levels,
3050 const GUID *context)
3052 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
3053 AudioSession *session = This->session;
3056 TRACE("(%p)->(%d, %p, %s)\n", session, count, levels,
3057 wine_dbgstr_guid(context));
3060 return NULL_PTR_ERR;
3062 if(count != session->channel_count)
3063 return E_INVALIDARG;
3066 FIXME("Notifications not supported yet\n");
3068 TRACE("ALSA does not support volume control\n");
3070 EnterCriticalSection(&session->lock);
3072 for(i = 0; i < count; ++i)
3073 session->channel_vols[i] = levels[i];
3075 LeaveCriticalSection(&session->lock);
3080 static HRESULT WINAPI ChannelAudioVolume_GetAllVolumes(
3081 IChannelAudioVolume *iface, UINT32 count, float *levels)
3083 AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
3084 AudioSession *session = This->session;
3087 TRACE("(%p)->(%d, %p)\n", session, count, levels);
3090 return NULL_PTR_ERR;
3092 if(count != session->channel_count)
3093 return E_INVALIDARG;
3095 for(i = 0; i < count; ++i)
3096 levels[i] = session->channel_vols[i];
3101 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl =
3103 ChannelAudioVolume_QueryInterface,
3104 ChannelAudioVolume_AddRef,
3105 ChannelAudioVolume_Release,
3106 ChannelAudioVolume_GetChannelCount,
3107 ChannelAudioVolume_SetChannelVolume,
3108 ChannelAudioVolume_GetChannelVolume,
3109 ChannelAudioVolume_SetAllVolumes,
3110 ChannelAudioVolume_GetAllVolumes
3113 static HRESULT WINAPI AudioSessionManager_QueryInterface(IAudioSessionManager2 *iface,
3114 REFIID riid, void **ppv)
3116 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
3122 if(IsEqualIID(riid, &IID_IUnknown) ||
3123 IsEqualIID(riid, &IID_IAudioSessionManager) ||
3124 IsEqualIID(riid, &IID_IAudioSessionManager2))
3127 IUnknown_AddRef((IUnknown*)*ppv);
3131 WARN("Unknown interface %s\n", debugstr_guid(riid));
3132 return E_NOINTERFACE;
3135 static ULONG WINAPI AudioSessionManager_AddRef(IAudioSessionManager2 *iface)
3137 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3139 ref = InterlockedIncrement(&This->ref);
3140 TRACE("(%p) Refcount now %u\n", This, ref);
3144 static ULONG WINAPI AudioSessionManager_Release(IAudioSessionManager2 *iface)
3146 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3148 ref = InterlockedDecrement(&This->ref);
3149 TRACE("(%p) Refcount now %u\n", This, ref);
3151 HeapFree(GetProcessHeap(), 0, This);
3155 static HRESULT WINAPI AudioSessionManager_GetAudioSessionControl(
3156 IAudioSessionManager2 *iface, const GUID *session_guid, DWORD flags,
3157 IAudioSessionControl **out)
3159 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3160 AudioSession *session;
3161 AudioSessionWrapper *wrapper;
3164 TRACE("(%p)->(%s, %x, %p)\n", This, debugstr_guid(session_guid),
3167 hr = get_audio_session(session_guid, This->device, 0, &session);
3171 wrapper = AudioSessionWrapper_Create(NULL);
3173 return E_OUTOFMEMORY;
3175 wrapper->session = session;
3177 *out = (IAudioSessionControl*)&wrapper->IAudioSessionControl2_iface;
3182 static HRESULT WINAPI AudioSessionManager_GetSimpleAudioVolume(
3183 IAudioSessionManager2 *iface, const GUID *session_guid, DWORD flags,
3184 ISimpleAudioVolume **out)
3186 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3187 AudioSession *session;
3188 AudioSessionWrapper *wrapper;
3191 TRACE("(%p)->(%s, %x, %p)\n", This, debugstr_guid(session_guid),
3194 hr = get_audio_session(session_guid, This->device, 0, &session);
3198 wrapper = AudioSessionWrapper_Create(NULL);
3200 return E_OUTOFMEMORY;
3202 wrapper->session = session;
3204 *out = &wrapper->ISimpleAudioVolume_iface;
3209 static HRESULT WINAPI AudioSessionManager_GetSessionEnumerator(
3210 IAudioSessionManager2 *iface, IAudioSessionEnumerator **out)
3212 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3213 FIXME("(%p)->(%p) - stub\n", This, out);
3217 static HRESULT WINAPI AudioSessionManager_RegisterSessionNotification(
3218 IAudioSessionManager2 *iface, IAudioSessionNotification *notification)
3220 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3221 FIXME("(%p)->(%p) - stub\n", This, notification);
3225 static HRESULT WINAPI AudioSessionManager_UnregisterSessionNotification(
3226 IAudioSessionManager2 *iface, IAudioSessionNotification *notification)
3228 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3229 FIXME("(%p)->(%p) - stub\n", This, notification);
3233 static HRESULT WINAPI AudioSessionManager_RegisterDuckNotification(
3234 IAudioSessionManager2 *iface, const WCHAR *session_id,
3235 IAudioVolumeDuckNotification *notification)
3237 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3238 FIXME("(%p)->(%p) - stub\n", This, notification);
3242 static HRESULT WINAPI AudioSessionManager_UnregisterDuckNotification(
3243 IAudioSessionManager2 *iface,
3244 IAudioVolumeDuckNotification *notification)
3246 SessionMgr *This = impl_from_IAudioSessionManager2(iface);
3247 FIXME("(%p)->(%p) - stub\n", This, notification);
3251 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl =
3253 AudioSessionManager_QueryInterface,
3254 AudioSessionManager_AddRef,
3255 AudioSessionManager_Release,
3256 AudioSessionManager_GetAudioSessionControl,
3257 AudioSessionManager_GetSimpleAudioVolume,
3258 AudioSessionManager_GetSessionEnumerator,
3259 AudioSessionManager_RegisterSessionNotification,
3260 AudioSessionManager_UnregisterSessionNotification,
3261 AudioSessionManager_RegisterDuckNotification,
3262 AudioSessionManager_UnregisterDuckNotification
3265 HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device,
3266 IAudioSessionManager2 **out)
3270 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SessionMgr));
3272 return E_OUTOFMEMORY;
3274 This->IAudioSessionManager2_iface.lpVtbl = &AudioSessionManager2_Vtbl;
3275 This->device = device;
3278 *out = &This->IAudioSessionManager2_iface;