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
);
51 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
53 static const REFERENCE_TIME DefaultPeriod
= 200000;
54 static const REFERENCE_TIME MinimumPeriod
= 100000;
57 typedef struct ACImpl ACImpl
;
59 typedef struct _AudioSession
{
69 CRITICAL_SECTION lock
;
74 typedef struct _AudioSessionWrapper
{
75 IAudioSessionControl2 IAudioSessionControl2_iface
;
76 IChannelAudioVolume IChannelAudioVolume_iface
;
77 ISimpleAudioVolume ISimpleAudioVolume_iface
;
82 AudioSession
*session
;
83 } AudioSessionWrapper
;
86 IAudioClient IAudioClient_iface
;
87 IAudioRenderClient IAudioRenderClient_iface
;
88 IAudioCaptureClient IAudioCaptureClient_iface
;
89 IAudioClock IAudioClock_iface
;
90 IAudioClock2 IAudioClock2_iface
;
91 IAudioStreamVolume IAudioStreamVolume_iface
;
95 snd_pcm_t
*pcm_handle
;
96 snd_pcm_uframes_t period_alsa
, bufsize_alsa
;
97 snd_pcm_hw_params_t
*hw_params
; /* does not hold state between calls */
104 AUDCLNT_SHAREMODE share
;
108 BOOL initted
, started
;
109 UINT64 written_frames
, held_frames
, tmp_buffer_frames
;
110 UINT32 bufsize_frames
, period_us
;
111 UINT32 lcl_offs_frames
; /* offs into local_buffer where valid data starts */
114 BYTE
*local_buffer
, *tmp_buffer
;
117 CRITICAL_SECTION lock
;
119 AudioSession
*session
;
120 AudioSessionWrapper
*session_wrapper
;
127 LOCKED_NORMAL
, /* public buffer piece is from local_buffer */
128 LOCKED_WRAPPED
/* public buffer piece is wrapped around, in tmp_buffer */
131 typedef struct _SessionMgr
{
132 IAudioSessionManager2 IAudioSessionManager2_iface
;
139 static HANDLE g_timer_q
;
141 static CRITICAL_SECTION g_sessions_lock
;
142 static struct list g_sessions
= LIST_INIT(g_sessions
);
144 static const WCHAR defaultW
[] = {'d','e','f','a','u','l','t',0};
145 static const char defname
[] = "default";
147 static const IAudioClientVtbl AudioClient_Vtbl
;
148 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
;
149 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
;
150 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
;
151 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
;
152 static const IAudioClockVtbl AudioClock_Vtbl
;
153 static const IAudioClock2Vtbl AudioClock2_Vtbl
;
154 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
;
155 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
;
156 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
;
158 int wine_snd_pcm_recover(snd_pcm_t
*pcm
, int err
, int silent
);
159 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
);
161 static inline ACImpl
*impl_from_IAudioClient(IAudioClient
*iface
)
163 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClient_iface
);
166 static inline ACImpl
*impl_from_IAudioRenderClient(IAudioRenderClient
*iface
)
168 return CONTAINING_RECORD(iface
, ACImpl
, IAudioRenderClient_iface
);
171 static inline ACImpl
*impl_from_IAudioCaptureClient(IAudioCaptureClient
*iface
)
173 return CONTAINING_RECORD(iface
, ACImpl
, IAudioCaptureClient_iface
);
176 static inline AudioSessionWrapper
*impl_from_IAudioSessionControl2(IAudioSessionControl2
*iface
)
178 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IAudioSessionControl2_iface
);
181 static inline AudioSessionWrapper
*impl_from_ISimpleAudioVolume(ISimpleAudioVolume
*iface
)
183 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, ISimpleAudioVolume_iface
);
186 static inline AudioSessionWrapper
*impl_from_IChannelAudioVolume(IChannelAudioVolume
*iface
)
188 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IChannelAudioVolume_iface
);
191 static inline ACImpl
*impl_from_IAudioClock(IAudioClock
*iface
)
193 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock_iface
);
196 static inline ACImpl
*impl_from_IAudioClock2(IAudioClock2
*iface
)
198 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock2_iface
);
201 static inline ACImpl
*impl_from_IAudioStreamVolume(IAudioStreamVolume
*iface
)
203 return CONTAINING_RECORD(iface
, ACImpl
, IAudioStreamVolume_iface
);
206 static inline SessionMgr
*impl_from_IAudioSessionManager2(IAudioSessionManager2
*iface
)
208 return CONTAINING_RECORD(iface
, SessionMgr
, IAudioSessionManager2_iface
);
211 BOOL WINAPI
DllMain(HINSTANCE dll
, DWORD reason
, void *reserved
)
213 if(reason
== DLL_PROCESS_ATTACH
){
214 g_timer_q
= CreateTimerQueue();
218 InitializeCriticalSection(&g_sessions_lock
);
224 static HRESULT
alsa_get_card_devices(EDataFlow flow
, WCHAR
**ids
, char **keys
,
225 UINT
*num
, snd_ctl_t
*ctl
, int card
, const WCHAR
*cardnameW
)
227 static const WCHAR dashW
[] = {' ','-',' ',0};
229 snd_pcm_info_t
*info
;
231 info
= HeapAlloc(GetProcessHeap(), 0, snd_pcm_info_sizeof());
233 return E_OUTOFMEMORY
;
235 snd_pcm_info_set_subdevice(info
, 0);
236 snd_pcm_info_set_stream(info
,
237 flow
== eRender
? SND_PCM_STREAM_PLAYBACK
: SND_PCM_STREAM_CAPTURE
);
240 for(err
= snd_ctl_pcm_next_device(ctl
, &device
); device
!= -1 && err
>= 0;
241 err
= snd_ctl_pcm_next_device(ctl
, &device
)){
244 snd_pcm_info_set_device(info
, device
);
246 if((err
= snd_ctl_pcm_info(ctl
, info
)) < 0){
248 /* This device doesn't have the right stream direction */
251 WARN("Failed to get info for card %d, device %d: %d (%s)\n",
252 card
, device
, err
, snd_strerror(err
));
259 devname
= snd_pcm_info_get_name(info
);
261 WARN("Unable to get device name for card %d, device %d\n", card
,
266 cardlen
= lstrlenW(cardnameW
);
267 len
= MultiByteToWideChar(CP_UNIXCP
, 0, devname
, -1, NULL
, 0);
268 len
+= lstrlenW(dashW
);
270 ids
[*num
] = HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
272 HeapFree(GetProcessHeap(), 0, info
);
273 return E_OUTOFMEMORY
;
275 memcpy(ids
[*num
], cardnameW
, cardlen
* sizeof(WCHAR
));
276 memcpy(ids
[*num
] + cardlen
, dashW
, lstrlenW(dashW
) * sizeof(WCHAR
));
277 cardlen
+= lstrlenW(dashW
);
278 MultiByteToWideChar(CP_UNIXCP
, 0, devname
, -1, ids
[*num
] + cardlen
,
281 keys
[*num
] = HeapAlloc(GetProcessHeap(), 0, 32);
283 HeapFree(GetProcessHeap(), 0, info
);
284 HeapFree(GetProcessHeap(), 0, ids
[*num
]);
285 return E_OUTOFMEMORY
;
287 sprintf(keys
[*num
], "hw:%d,%d", card
, device
);
293 HeapFree(GetProcessHeap(), 0, info
);
296 WARN("Got a failure during device enumeration on card %d: %d (%s)\n",
297 card
, err
, snd_strerror(err
));
302 static HRESULT
alsa_enum_devices(EDataFlow flow
, WCHAR
**ids
, char **keys
,
309 for(err
= snd_card_next(&card
); card
!= -1 && err
>= 0;
310 err
= snd_card_next(&card
)){
312 const char *cardname
;
317 sprintf(cardpath
, "hw:%u", card
);
319 if((err
= snd_ctl_open(&ctl
, cardpath
, 0)) < 0){
320 WARN("Unable to open ctl for ALSA device %s: %d (%s)\n", cardpath
,
321 err
, snd_strerror(err
));
325 if((err
= snd_card_get_name(card
, (char **)&cardname
)) < 0){
326 WARN("Unable to get card name for ALSA device %s: %d (%s)\n",
327 cardpath
, err
, snd_strerror(err
));
328 /* FIXME: Should be localized */
329 cardname
= "Unknown soundcard";
332 len
= MultiByteToWideChar(CP_UNIXCP
, 0, cardname
, -1, NULL
, 0);
333 cardnameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
336 return E_OUTOFMEMORY
;
338 MultiByteToWideChar(CP_UNIXCP
, 0, cardname
, -1, cardnameW
, len
);
340 alsa_get_card_devices(flow
, ids
, keys
, num
, ctl
, card
, cardnameW
);
342 HeapFree(GetProcessHeap(), 0, cardnameW
);
348 WARN("Got a failure during card enumeration: %d (%s)\n",
349 err
, snd_strerror(err
));
354 HRESULT WINAPI
AUDDRV_GetEndpointIDs(EDataFlow flow
, WCHAR
***ids
, char ***keys
,
355 UINT
*num
, UINT
*def_index
)
359 TRACE("%d %p %p %p %p\n", flow
, ids
, keys
, num
, def_index
);
361 hr
= alsa_enum_devices(flow
, NULL
, NULL
, num
);
365 *ids
= HeapAlloc(GetProcessHeap(), 0, (*num
+ 1) * sizeof(WCHAR
*));
366 *keys
= HeapAlloc(GetProcessHeap(), 0, (*num
+ 1) * sizeof(char *));
368 HeapFree(GetProcessHeap(), 0, *ids
);
369 HeapFree(GetProcessHeap(), 0, *keys
);
370 return E_OUTOFMEMORY
;
373 (*ids
)[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW
));
374 memcpy((*ids
)[0], defaultW
, sizeof(defaultW
));
375 (*keys
)[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(defname
));
376 memcpy((*keys
)[0], defname
, sizeof(defname
));
379 hr
= alsa_enum_devices(flow
, (*ids
) + 1, (*keys
) + 1, num
);
382 for(i
= 0; i
< *num
; ++i
){
383 HeapFree(GetProcessHeap(), 0, (*ids
)[i
]);
384 HeapFree(GetProcessHeap(), 0, (*keys
)[i
]);
386 HeapFree(GetProcessHeap(), 0, *ids
);
387 HeapFree(GetProcessHeap(), 0, *keys
);
388 return E_OUTOFMEMORY
;
391 ++(*num
); /* for default device */
396 HRESULT WINAPI
AUDDRV_GetAudioEndpoint(const char *key
, IMMDevice
*dev
,
397 EDataFlow dataflow
, IAudioClient
**out
)
401 snd_pcm_stream_t stream
;
403 TRACE("\"%s\" %p %d %p\n", key
, dev
, dataflow
, out
);
405 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ACImpl
));
407 return E_OUTOFMEMORY
;
409 This
->IAudioClient_iface
.lpVtbl
= &AudioClient_Vtbl
;
410 This
->IAudioRenderClient_iface
.lpVtbl
= &AudioRenderClient_Vtbl
;
411 This
->IAudioCaptureClient_iface
.lpVtbl
= &AudioCaptureClient_Vtbl
;
412 This
->IAudioClock_iface
.lpVtbl
= &AudioClock_Vtbl
;
413 This
->IAudioClock2_iface
.lpVtbl
= &AudioClock2_Vtbl
;
414 This
->IAudioStreamVolume_iface
.lpVtbl
= &AudioStreamVolume_Vtbl
;
416 if(dataflow
== eRender
)
417 stream
= SND_PCM_STREAM_PLAYBACK
;
418 else if(dataflow
== eCapture
)
419 stream
= SND_PCM_STREAM_CAPTURE
;
421 HeapFree(GetProcessHeap(), 0, This
);
425 This
->dataflow
= dataflow
;
426 if((err
= snd_pcm_open(&This
->pcm_handle
, key
, stream
,
427 SND_PCM_NONBLOCK
)) < 0){
428 HeapFree(GetProcessHeap(), 0, This
);
429 WARN("Unable to open PCM \"%s\": %d (%s)\n", key
, err
,
434 This
->hw_params
= HeapAlloc(GetProcessHeap(), 0,
435 snd_pcm_hw_params_sizeof());
436 if(!This
->hw_params
){
437 HeapFree(GetProcessHeap(), 0, This
);
438 snd_pcm_close(This
->pcm_handle
);
439 return E_OUTOFMEMORY
;
442 InitializeCriticalSection(&This
->lock
);
445 IMMDevice_AddRef(This
->parent
);
447 *out
= &This
->IAudioClient_iface
;
448 IAudioClient_AddRef(&This
->IAudioClient_iface
);
453 static HRESULT WINAPI
AudioClient_QueryInterface(IAudioClient
*iface
,
454 REFIID riid
, void **ppv
)
456 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
461 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClient
))
464 IUnknown_AddRef((IUnknown
*)*ppv
);
467 WARN("Unknown interface %s\n", debugstr_guid(riid
));
468 return E_NOINTERFACE
;
471 static ULONG WINAPI
AudioClient_AddRef(IAudioClient
*iface
)
473 ACImpl
*This
= impl_from_IAudioClient(iface
);
475 ref
= InterlockedIncrement(&This
->ref
);
476 TRACE("(%p) Refcount now %u\n", This
, ref
);
480 static ULONG WINAPI
AudioClient_Release(IAudioClient
*iface
)
482 ACImpl
*This
= impl_from_IAudioClient(iface
);
484 ref
= InterlockedDecrement(&This
->ref
);
485 TRACE("(%p) Refcount now %u\n", This
, ref
);
487 IAudioClient_Stop(iface
);
488 IMMDevice_Release(This
->parent
);
489 DeleteCriticalSection(&This
->lock
);
490 snd_pcm_drop(This
->pcm_handle
);
491 snd_pcm_close(This
->pcm_handle
);
493 EnterCriticalSection(&g_sessions_lock
);
494 list_remove(&This
->entry
);
495 LeaveCriticalSection(&g_sessions_lock
);
497 HeapFree(GetProcessHeap(), 0, This
->vols
);
498 HeapFree(GetProcessHeap(), 0, This
->local_buffer
);
499 HeapFree(GetProcessHeap(), 0, This
->hw_params
);
500 CoTaskMemFree(This
->fmt
);
501 HeapFree(GetProcessHeap(), 0, This
);
506 static void dump_fmt(const WAVEFORMATEX
*fmt
)
508 TRACE("wFormatTag: 0x%x (", fmt
->wFormatTag
);
509 switch(fmt
->wFormatTag
){
510 case WAVE_FORMAT_PCM
:
511 TRACE("WAVE_FORMAT_PCM");
513 case WAVE_FORMAT_IEEE_FLOAT
:
514 TRACE("WAVE_FORMAT_IEEE_FLOAT");
516 case WAVE_FORMAT_EXTENSIBLE
:
517 TRACE("WAVE_FORMAT_EXTENSIBLE");
525 TRACE("nChannels: %u\n", fmt
->nChannels
);
526 TRACE("nSamplesPerSec: %u\n", fmt
->nSamplesPerSec
);
527 TRACE("nAvgBytesPerSec: %u\n", fmt
->nAvgBytesPerSec
);
528 TRACE("nBlockAlign: %u\n", fmt
->nBlockAlign
);
529 TRACE("wBitsPerSample: %u\n", fmt
->wBitsPerSample
);
530 TRACE("cbSize: %u\n", fmt
->cbSize
);
532 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
533 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
534 TRACE("dwChannelMask: %08x\n", fmtex
->dwChannelMask
);
535 TRACE("Samples: %04x\n", fmtex
->Samples
.wReserved
);
536 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex
->SubFormat
));
540 static WAVEFORMATEX
*clone_format(const WAVEFORMATEX
*fmt
)
545 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
546 size
= sizeof(WAVEFORMATEXTENSIBLE
);
548 size
= sizeof(WAVEFORMATEX
);
550 ret
= CoTaskMemAlloc(size
);
554 memcpy(ret
, fmt
, size
);
556 ret
->cbSize
= size
- sizeof(WAVEFORMATEX
);
561 static void session_init_vols(AudioSession
*session
, UINT channels
)
563 session
->channel_vols
= HeapAlloc(GetProcessHeap(), 0,
564 sizeof(float) * channels
);
565 if(!session
->channel_vols
)
568 session
->channel_count
= channels
;
570 for(; channels
> 0; --channels
)
571 session
->channel_vols
[channels
- 1] = 1.f
;
574 static AudioSession
*create_session(const GUID
*guid
, EDataFlow flow
,
579 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(AudioSession
));
583 memcpy(&ret
->guid
, guid
, sizeof(GUID
));
585 ret
->dataflow
= flow
;
587 list_init(&ret
->clients
);
589 list_add_head(&g_sessions
, &ret
->entry
);
591 InitializeCriticalSection(&ret
->lock
);
594 session_init_vols(ret
, num_channels
);
596 ret
->master_vol
= 1.f
;
601 /* if channels == 0, then this will return or create a session with
602 * matching dataflow and GUID. otherwise, channels must also match */
603 static HRESULT
get_audio_session(const GUID
*sessionguid
,
604 EDataFlow flow
, UINT channels
, AudioSession
**out
)
606 AudioSession
*session
;
608 if(!sessionguid
|| IsEqualGUID(sessionguid
, &GUID_NULL
)){
609 *out
= create_session(&GUID_NULL
, flow
, channels
);
611 return E_OUTOFMEMORY
;
617 LIST_FOR_EACH_ENTRY(session
, &g_sessions
, AudioSession
, entry
){
618 if(IsEqualGUID(sessionguid
, &session
->guid
) &&
619 session
->dataflow
== flow
){
620 if(session
->channel_count
> 0){
621 if(channels
> 0 && session
->channel_count
!= channels
)
623 }else if(channels
> 0)
624 session_init_vols(session
, channels
);
631 *out
= create_session(sessionguid
, flow
, channels
);
633 return E_OUTOFMEMORY
;
639 static HRESULT WINAPI
AudioClient_Initialize(IAudioClient
*iface
,
640 AUDCLNT_SHAREMODE mode
, DWORD flags
, REFERENCE_TIME duration
,
641 REFERENCE_TIME period
, const WAVEFORMATEX
*fmt
,
642 const GUID
*sessionguid
)
644 ACImpl
*This
= impl_from_IAudioClient(iface
);
645 snd_pcm_sw_params_t
*sw_params
= NULL
;
646 snd_pcm_format_t format
;
647 snd_pcm_uframes_t boundary
;
648 const WAVEFORMATEXTENSIBLE
*fmtex
= (const WAVEFORMATEXTENSIBLE
*)fmt
;
649 unsigned int time_us
, rate
;
653 TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This
, mode
, flags
,
654 wine_dbgstr_longlong(duration
), wine_dbgstr_longlong(period
), fmt
, debugstr_guid(sessionguid
));
659 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
660 return AUDCLNT_E_NOT_INITIALIZED
;
662 if(flags
& ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS
|
663 AUDCLNT_STREAMFLAGS_LOOPBACK
|
664 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
|
665 AUDCLNT_STREAMFLAGS_NOPERSIST
|
666 AUDCLNT_STREAMFLAGS_RATEADJUST
|
667 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED
|
668 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE
|
669 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED
)){
670 TRACE("Unknown flags: %08x\n", flags
);
674 EnterCriticalSection(&This
->lock
);
677 LeaveCriticalSection(&This
->lock
);
678 return AUDCLNT_E_ALREADY_INITIALIZED
;
683 if((err
= snd_pcm_hw_params_any(This
->pcm_handle
, This
->hw_params
)) < 0){
684 WARN("Unable to get hw_params: %d (%s)\n", err
, snd_strerror(err
));
689 if((err
= snd_pcm_hw_params_set_access(This
->pcm_handle
, This
->hw_params
,
690 SND_PCM_ACCESS_RW_INTERLEAVED
)) < 0){
691 WARN("Unable to set access: %d (%s)\n", err
, snd_strerror(err
));
696 if(fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
697 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
698 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
699 if(fmt
->wBitsPerSample
== 8)
700 format
= SND_PCM_FORMAT_U8
;
701 else if(fmt
->wBitsPerSample
== 16)
702 format
= SND_PCM_FORMAT_S16_LE
;
703 else if(fmt
->wBitsPerSample
== 24)
704 format
= SND_PCM_FORMAT_S24_3LE
;
705 else if(fmt
->wBitsPerSample
== 32)
706 format
= SND_PCM_FORMAT_S32_LE
;
708 WARN("Unsupported bit depth: %u\n", fmt
->wBitsPerSample
);
709 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
712 }else if(fmt
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
713 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
714 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))){
715 if(fmt
->wBitsPerSample
== 32)
716 format
= SND_PCM_FORMAT_FLOAT_LE
;
717 else if(fmt
->wBitsPerSample
== 64)
718 format
= SND_PCM_FORMAT_FLOAT64_LE
;
720 WARN("Unsupported float size: %u\n", fmt
->wBitsPerSample
);
721 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
725 WARN("Unknown wave format: %04x\n", fmt
->wFormatTag
);
726 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
730 if((err
= snd_pcm_hw_params_set_format(This
->pcm_handle
, This
->hw_params
,
732 WARN("Unable to set ALSA format to %u: %d (%s)\n", format
, err
,
738 rate
= fmt
->nSamplesPerSec
;
739 if((err
= snd_pcm_hw_params_set_rate_near(This
->pcm_handle
, This
->hw_params
,
741 WARN("Unable to set rate to %u: %d (%s)\n", rate
, err
,
747 if((err
= snd_pcm_hw_params_set_channels(This
->pcm_handle
, This
->hw_params
,
748 fmt
->nChannels
)) < 0){
749 WARN("Unable to set channels to %u: %d (%s)\n", fmt
->nChannels
, err
,
755 time_us
= MinimumPeriod
/ 10;
756 if((err
= snd_pcm_hw_params_set_period_time_near(This
->pcm_handle
,
757 This
->hw_params
, &time_us
, NULL
)) < 0){
758 WARN("Unable to set max period time to %u: %d (%s)\n", time_us
,
759 err
, snd_strerror(err
));
764 if((err
= snd_pcm_hw_params(This
->pcm_handle
, This
->hw_params
)) < 0){
765 WARN("Unable to set hw params: %d (%s)\n", err
, snd_strerror(err
));
770 sw_params
= HeapAlloc(GetProcessHeap(), 0, snd_pcm_sw_params_sizeof());
776 if((err
= snd_pcm_sw_params_current(This
->pcm_handle
, sw_params
)) < 0){
777 WARN("Unable to get sw_params: %d (%s)\n", err
, snd_strerror(err
));
782 This
->bufsize_frames
= ceil((duration
/ 10000000.) * fmt
->nSamplesPerSec
);
783 This
->local_buffer
= HeapAlloc(GetProcessHeap(), 0,
784 This
->bufsize_frames
* fmt
->nBlockAlign
);
785 if(!This
->local_buffer
){
789 if (fmt
->wBitsPerSample
== 8)
790 memset(This
->local_buffer
, 128, This
->bufsize_frames
* fmt
->nBlockAlign
);
792 memset(This
->local_buffer
, 0, This
->bufsize_frames
* fmt
->nBlockAlign
);
794 if((err
= snd_pcm_sw_params_get_boundary(sw_params
, &boundary
)) < 0){
795 WARN("Unable to get boundary: %d (%s)\n", err
, snd_strerror(err
));
800 if((err
= snd_pcm_sw_params_set_start_threshold(This
->pcm_handle
,
801 sw_params
, boundary
)) < 0){
802 WARN("Unable to set start threshold to %lx: %d (%s)\n", boundary
, err
,
808 if((err
= snd_pcm_sw_params_set_stop_threshold(This
->pcm_handle
,
809 sw_params
, boundary
)) < 0){
810 WARN("Unable to set stop threshold to %lx: %d (%s)\n", boundary
, err
,
816 if((err
= snd_pcm_sw_params_set_avail_min(This
->pcm_handle
,
818 WARN("Unable to set avail min to 0: %d (%s)\n", err
, snd_strerror(err
));
823 if((err
= snd_pcm_sw_params(This
->pcm_handle
, sw_params
)) < 0){
824 WARN("Unable to set sw params: %d (%s)\n", err
, snd_strerror(err
));
829 if((err
= snd_pcm_prepare(This
->pcm_handle
)) < 0){
830 WARN("Unable to prepare device: %d (%s)\n", err
, snd_strerror(err
));
835 if((err
= snd_pcm_hw_params_get_buffer_size(This
->hw_params
,
836 &This
->bufsize_alsa
)) < 0){
837 WARN("Unable to get buffer size: %d (%s)\n", err
, snd_strerror(err
));
842 if((err
= snd_pcm_hw_params_get_period_size(This
->hw_params
,
843 &This
->period_alsa
, NULL
)) < 0){
844 WARN("Unable to get period size: %d (%s)\n", err
, snd_strerror(err
));
849 if((err
= snd_pcm_hw_params_get_period_time(This
->hw_params
,
850 &This
->period_us
, NULL
)) < 0){
851 WARN("Unable to get period time: %d (%s)\n", err
, snd_strerror(err
));
856 This
->fmt
= clone_format(fmt
);
862 This
->vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
868 for(i
= 0; i
< fmt
->nChannels
; ++i
)
874 EnterCriticalSection(&g_sessions_lock
);
876 hr
= get_audio_session(sessionguid
, This
->dataflow
, fmt
->nChannels
,
879 LeaveCriticalSection(&g_sessions_lock
);
883 list_add_tail(&This
->session
->clients
, &This
->entry
);
885 LeaveCriticalSection(&g_sessions_lock
);
887 This
->initted
= TRUE
;
890 HeapFree(GetProcessHeap(), 0, sw_params
);
892 if(This
->local_buffer
){
893 HeapFree(GetProcessHeap(), 0, This
->local_buffer
);
894 This
->local_buffer
= NULL
;
897 HeapFree(GetProcessHeap(), 0, This
->fmt
);
901 HeapFree(GetProcessHeap(), 0, This
->vols
);
906 LeaveCriticalSection(&This
->lock
);
911 static HRESULT WINAPI
AudioClient_GetBufferSize(IAudioClient
*iface
,
914 ACImpl
*This
= impl_from_IAudioClient(iface
);
916 TRACE("(%p)->(%p)\n", This
, out
);
921 EnterCriticalSection(&This
->lock
);
924 LeaveCriticalSection(&This
->lock
);
925 return AUDCLNT_E_NOT_INITIALIZED
;
928 *out
= This
->bufsize_frames
;
930 LeaveCriticalSection(&This
->lock
);
935 static HRESULT WINAPI
AudioClient_GetStreamLatency(IAudioClient
*iface
,
936 REFERENCE_TIME
*latency
)
938 ACImpl
*This
= impl_from_IAudioClient(iface
);
940 TRACE("(%p)->(%p)\n", This
, latency
);
945 EnterCriticalSection(&This
->lock
);
948 LeaveCriticalSection(&This
->lock
);
949 return AUDCLNT_E_NOT_INITIALIZED
;
952 LeaveCriticalSection(&This
->lock
);
959 static HRESULT WINAPI
AudioClient_GetCurrentPadding(IAudioClient
*iface
,
962 ACImpl
*This
= impl_from_IAudioClient(iface
);
964 TRACE("(%p)->(%p)\n", This
, out
);
969 EnterCriticalSection(&This
->lock
);
972 LeaveCriticalSection(&This
->lock
);
973 return AUDCLNT_E_NOT_INITIALIZED
;
976 if(This
->dataflow
== eRender
){
977 snd_pcm_sframes_t avail_frames
;
979 avail_frames
= snd_pcm_avail_update(This
->pcm_handle
);
981 if(This
->bufsize_alsa
< avail_frames
){
982 WARN("Xrun detected\n");
983 *out
= This
->held_frames
;
985 *out
= This
->bufsize_alsa
- avail_frames
+ This
->held_frames
;
986 }else if(This
->dataflow
== eCapture
){
987 *out
= This
->held_frames
;
989 LeaveCriticalSection(&This
->lock
);
993 LeaveCriticalSection(&This
->lock
);
998 static DWORD
get_channel_mask(unsigned int channels
)
1004 return SPEAKER_FRONT_CENTER
;
1006 return SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
;
1008 return SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
|
1009 SPEAKER_LOW_FREQUENCY
;
1011 return SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
| SPEAKER_BACK_LEFT
|
1014 return SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
| SPEAKER_BACK_LEFT
|
1015 SPEAKER_BACK_RIGHT
| SPEAKER_LOW_FREQUENCY
;
1017 return SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
| SPEAKER_BACK_LEFT
|
1018 SPEAKER_BACK_RIGHT
| SPEAKER_LOW_FREQUENCY
| SPEAKER_FRONT_CENTER
;
1020 return SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
| SPEAKER_BACK_LEFT
|
1021 SPEAKER_BACK_RIGHT
| SPEAKER_LOW_FREQUENCY
| SPEAKER_FRONT_CENTER
|
1022 SPEAKER_BACK_CENTER
;
1024 FIXME("Unknown speaker configuration: %u\n", channels
);
1028 static HRESULT WINAPI
AudioClient_IsFormatSupported(IAudioClient
*iface
,
1029 AUDCLNT_SHAREMODE mode
, const WAVEFORMATEX
*fmt
,
1032 ACImpl
*This
= impl_from_IAudioClient(iface
);
1033 snd_pcm_format_mask_t
*formats
= NULL
;
1035 WAVEFORMATEX
*closest
= NULL
;
1036 const WAVEFORMATEXTENSIBLE
*fmtex
= (const WAVEFORMATEXTENSIBLE
*)fmt
;
1037 unsigned int max
= 0, min
= 0;
1040 TRACE("(%p)->(%x, %p, %p)\n", This
, mode
, fmt
, out
);
1042 if(!fmt
|| (mode
== AUDCLNT_SHAREMODE_SHARED
&& !out
))
1045 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
1046 return E_INVALIDARG
;
1048 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1049 fmt
->cbSize
< sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
))
1050 return E_INVALIDARG
;
1054 EnterCriticalSection(&This
->lock
);
1056 if((err
= snd_pcm_hw_params_any(This
->pcm_handle
, This
->hw_params
)) < 0){
1061 formats
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1062 snd_pcm_format_mask_sizeof());
1068 snd_pcm_hw_params_get_format_mask(This
->hw_params
, formats
);
1070 if(fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
1071 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1072 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
1073 switch(fmt
->wBitsPerSample
){
1075 if(!snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_U8
)){
1076 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1081 if(!snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_S16_LE
)){
1082 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1087 if(!snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_S24_3LE
)){
1088 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1093 if(!snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_S32_LE
)){
1094 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1099 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1102 }else if(fmt
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
1103 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1104 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))){
1105 switch(fmt
->wBitsPerSample
){
1107 if(!snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_FLOAT_LE
)){
1108 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1113 if(!snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_FLOAT64_LE
)){
1114 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1119 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1123 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1127 closest
= clone_format(fmt
);
1133 if((err
= snd_pcm_hw_params_get_rate_min(This
->hw_params
, &min
, NULL
)) < 0){
1135 WARN("Unable to get min rate: %d (%s)\n", err
, snd_strerror(err
));
1139 if((err
= snd_pcm_hw_params_get_rate_max(This
->hw_params
, &max
, NULL
)) < 0){
1141 WARN("Unable to get max rate: %d (%s)\n", err
, snd_strerror(err
));
1145 if(fmt
->nSamplesPerSec
< min
|| fmt
->nSamplesPerSec
> max
||
1146 (fmt
->nSamplesPerSec
!= 48000 &&
1147 fmt
->nSamplesPerSec
!= 44100 &&
1148 fmt
->nSamplesPerSec
!= 22050 &&
1149 fmt
->nSamplesPerSec
!= 11025 &&
1150 fmt
->nSamplesPerSec
!= 8000)){
1151 hr
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
1155 if((err
= snd_pcm_hw_params_get_channels_min(This
->hw_params
, &min
)) < 0){
1157 WARN("Unable to get min channels: %d (%s)\n", err
, snd_strerror(err
));
1161 if((err
= snd_pcm_hw_params_get_channels_max(This
->hw_params
, &max
)) < 0){
1163 WARN("Unable to get max channels: %d (%s)\n", err
, snd_strerror(err
));
1168 if(fmt
->nChannels
> max
){
1170 closest
->nChannels
= max
;
1171 }else if(fmt
->nChannels
< min
){
1173 closest
->nChannels
= min
;
1176 if(closest
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
1177 DWORD mask
= get_channel_mask(closest
->nChannels
);
1179 ((WAVEFORMATEXTENSIBLE
*)closest
)->dwChannelMask
= mask
;
1181 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1182 fmtex
->dwChannelMask
!= mask
)
1187 LeaveCriticalSection(&This
->lock
);
1188 HeapFree(GetProcessHeap(), 0, formats
);
1190 if(hr
== S_OK
|| !out
){
1191 CoTaskMemFree(closest
);
1195 closest
->nBlockAlign
=
1196 closest
->nChannels
* closest
->wBitsPerSample
/ 8;
1197 closest
->nAvgBytesPerSec
=
1198 closest
->nBlockAlign
* closest
->nSamplesPerSec
;
1202 TRACE("returning: %08x\n", hr
);
1206 static HRESULT WINAPI
AudioClient_GetMixFormat(IAudioClient
*iface
,
1207 WAVEFORMATEX
**pwfx
)
1209 ACImpl
*This
= impl_from_IAudioClient(iface
);
1210 WAVEFORMATEXTENSIBLE
*fmt
;
1211 snd_pcm_format_mask_t
*formats
;
1212 unsigned int max_rate
, max_channels
;
1216 TRACE("(%p)->(%p)\n", This
, pwfx
);
1222 fmt
= CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE
));
1224 return E_OUTOFMEMORY
;
1226 formats
= HeapAlloc(GetProcessHeap(), 0, snd_pcm_format_mask_sizeof());
1229 return E_OUTOFMEMORY
;
1232 EnterCriticalSection(&This
->lock
);
1234 if((err
= snd_pcm_hw_params_any(This
->pcm_handle
, This
->hw_params
)) < 0){
1235 WARN("Unable to get hw_params: %d (%s)\n", err
, snd_strerror(err
));
1240 snd_pcm_hw_params_get_format_mask(This
->hw_params
, formats
);
1242 fmt
->Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1243 if(snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_FLOAT_LE
)){
1244 fmt
->Format
.wBitsPerSample
= 32;
1245 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1246 }else if(snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_S16_LE
)){
1247 fmt
->Format
.wBitsPerSample
= 16;
1248 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1249 }else if(snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_U8
)){
1250 fmt
->Format
.wBitsPerSample
= 8;
1251 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1252 }else if(snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_S32_LE
)){
1253 fmt
->Format
.wBitsPerSample
= 32;
1254 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1255 }else if(snd_pcm_format_mask_test(formats
, SND_PCM_FORMAT_S24_3LE
)){
1256 fmt
->Format
.wBitsPerSample
= 24;
1257 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1259 ERR("Didn't recognize any available ALSA formats\n");
1264 if((err
= snd_pcm_hw_params_get_channels_max(This
->hw_params
,
1265 &max_channels
)) < 0){
1266 WARN("Unable to get max channels: %d (%s)\n", err
, snd_strerror(err
));
1271 if(max_channels
> 2){
1272 FIXME("Don't know what to do with %u channels, pretending there's "
1273 "only 2 channels\n", max_channels
);
1274 fmt
->Format
.nChannels
= 2;
1276 fmt
->Format
.nChannels
= max_channels
;
1278 fmt
->dwChannelMask
= get_channel_mask(fmt
->Format
.nChannels
);
1280 if((err
= snd_pcm_hw_params_get_rate_max(This
->hw_params
, &max_rate
,
1282 WARN("Unable to get max rate: %d (%s)\n", err
, snd_strerror(err
));
1287 if(max_rate
>= 48000)
1288 fmt
->Format
.nSamplesPerSec
= 48000;
1289 else if(max_rate
>= 44100)
1290 fmt
->Format
.nSamplesPerSec
= 44100;
1291 else if(max_rate
>= 22050)
1292 fmt
->Format
.nSamplesPerSec
= 22050;
1293 else if(max_rate
>= 11025)
1294 fmt
->Format
.nSamplesPerSec
= 11025;
1295 else if(max_rate
>= 8000)
1296 fmt
->Format
.nSamplesPerSec
= 8000;
1298 ERR("Unknown max rate: %u\n", max_rate
);
1303 fmt
->Format
.nBlockAlign
= (fmt
->Format
.wBitsPerSample
*
1304 fmt
->Format
.nChannels
) / 8;
1305 fmt
->Format
.nAvgBytesPerSec
= fmt
->Format
.nSamplesPerSec
*
1306 fmt
->Format
.nBlockAlign
;
1308 fmt
->Samples
.wValidBitsPerSample
= fmt
->Format
.wBitsPerSample
;
1309 fmt
->Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1311 dump_fmt((WAVEFORMATEX
*)fmt
);
1312 *pwfx
= (WAVEFORMATEX
*)fmt
;
1315 LeaveCriticalSection(&This
->lock
);
1318 HeapFree(GetProcessHeap(), 0, formats
);
1323 static HRESULT WINAPI
AudioClient_GetDevicePeriod(IAudioClient
*iface
,
1324 REFERENCE_TIME
*defperiod
, REFERENCE_TIME
*minperiod
)
1326 ACImpl
*This
= impl_from_IAudioClient(iface
);
1328 TRACE("(%p)->(%p, %p)\n", This
, defperiod
, minperiod
);
1330 if(!defperiod
&& !minperiod
)
1334 *defperiod
= DefaultPeriod
;
1336 *minperiod
= MinimumPeriod
;
1341 static snd_pcm_sframes_t
alsa_write_best_effort(snd_pcm_t
*handle
, BYTE
*buf
,
1342 snd_pcm_uframes_t frames
)
1344 snd_pcm_sframes_t written
;
1346 written
= snd_pcm_writei(handle
, buf
, frames
);
1350 if(written
== -EAGAIN
)
1354 WARN("writei failed, recovering: %ld (%s)\n", written
,
1355 snd_strerror(written
));
1357 ret
= wine_snd_pcm_recover(handle
, written
, 0);
1359 WARN("Could not recover: %d (%s)\n", ret
, snd_strerror(ret
));
1363 written
= snd_pcm_writei(handle
, buf
, frames
);
1369 static void alsa_write_data(ACImpl
*This
)
1371 snd_pcm_sframes_t written
;
1372 snd_pcm_uframes_t to_write
;
1374 This
->local_buffer
+ (This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
);
1376 if(This
->lcl_offs_frames
+ This
->held_frames
> This
->bufsize_frames
)
1377 to_write
= This
->bufsize_frames
- This
->lcl_offs_frames
;
1379 to_write
= This
->held_frames
;
1381 written
= alsa_write_best_effort(This
->pcm_handle
, buf
, to_write
);
1383 WARN("Couldn't write: %ld (%s)\n", written
, snd_strerror(written
));
1387 This
->lcl_offs_frames
+= written
;
1388 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1389 This
->held_frames
-= written
;
1391 if(written
< to_write
){
1392 /* ALSA buffer probably full */
1396 if(This
->held_frames
){
1397 /* wrapped and have some data back at the start to write */
1398 written
= alsa_write_best_effort(This
->pcm_handle
, This
->local_buffer
,
1401 WARN("Couldn't write: %ld (%s)\n", written
, snd_strerror(written
));
1405 This
->lcl_offs_frames
+= written
;
1406 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1407 This
->held_frames
-= written
;
1411 static void alsa_read_data(ACImpl
*This
)
1413 snd_pcm_sframes_t pos
, readable
, nread
;
1415 pos
= (This
->held_frames
+ This
->lcl_offs_frames
) % This
->bufsize_frames
;
1416 readable
= This
->bufsize_frames
- pos
;
1418 nread
= snd_pcm_readi(This
->pcm_handle
,
1419 This
->local_buffer
+ pos
* This
->fmt
->nBlockAlign
, readable
);
1423 WARN("read failed, recovering: %ld (%s)\n", nread
, snd_strerror(nread
));
1425 ret
= wine_snd_pcm_recover(This
->pcm_handle
, nread
, 0);
1427 WARN("Recover failed: %d (%s)\n", ret
, snd_strerror(ret
));
1431 nread
= snd_pcm_readi(This
->pcm_handle
,
1432 This
->local_buffer
+ pos
* This
->fmt
->nBlockAlign
, readable
);
1434 WARN("read failed: %ld (%s)\n", nread
, snd_strerror(nread
));
1439 This
->held_frames
+= nread
;
1441 if(This
->held_frames
> This
->bufsize_frames
){
1442 WARN("Overflow of unread data\n");
1443 This
->lcl_offs_frames
+= This
->held_frames
;
1444 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1445 This
->held_frames
= This
->bufsize_frames
;
1449 static void CALLBACK
alsa_push_buffer_data(void *user
, BOOLEAN timer
)
1451 ACImpl
*This
= user
;
1453 EnterCriticalSection(&This
->lock
);
1455 if(This
->dataflow
== eRender
&& This
->held_frames
)
1456 alsa_write_data(This
);
1457 else if(This
->dataflow
== eCapture
)
1458 alsa_read_data(This
);
1461 SetEvent(This
->event
);
1463 LeaveCriticalSection(&This
->lock
);
1466 static HRESULT
alsa_consider_start(ACImpl
*This
)
1468 snd_pcm_sframes_t avail
;
1471 avail
= snd_pcm_avail_update(This
->pcm_handle
);
1473 WARN("Unable to get avail_update: %ld (%s)\n", avail
,
1474 snd_strerror(avail
));
1478 if(This
->period_alsa
< This
->bufsize_alsa
- avail
){
1479 if((err
= snd_pcm_start(This
->pcm_handle
)) < 0){
1480 WARN("Start failed: %d (%s), state: %d\n", err
, snd_strerror(err
),
1481 snd_pcm_state(This
->pcm_handle
));
1491 static HRESULT WINAPI
AudioClient_Start(IAudioClient
*iface
)
1493 ACImpl
*This
= impl_from_IAudioClient(iface
);
1497 TRACE("(%p)\n", This
);
1499 EnterCriticalSection(&This
->lock
);
1502 LeaveCriticalSection(&This
->lock
);
1503 return AUDCLNT_E_NOT_INITIALIZED
;
1506 if((This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
) && !This
->event
){
1507 LeaveCriticalSection(&This
->lock
);
1508 return AUDCLNT_E_EVENTHANDLE_NOT_SET
;
1512 LeaveCriticalSection(&This
->lock
);
1513 return AUDCLNT_E_NOT_STOPPED
;
1516 hr
= alsa_consider_start(This
);
1518 LeaveCriticalSection(&This
->lock
);
1522 period_ms
= This
->period_us
/ 1000;
1526 if(This
->dataflow
== eCapture
){
1527 /* dump any data that might be leftover in the ALSA capture buffer */
1528 snd_pcm_readi(This
->pcm_handle
, This
->local_buffer
,
1529 This
->bufsize_frames
);
1532 if(!CreateTimerQueueTimer(&This
->timer
, g_timer_q
, alsa_push_buffer_data
,
1533 This
, 0, period_ms
, WT_EXECUTEINTIMERTHREAD
)){
1534 LeaveCriticalSection(&This
->lock
);
1535 WARN("Unable to create timer: %u\n", GetLastError());
1539 This
->started
= TRUE
;
1541 LeaveCriticalSection(&This
->lock
);
1546 static HRESULT WINAPI
AudioClient_Stop(IAudioClient
*iface
)
1548 ACImpl
*This
= impl_from_IAudioClient(iface
);
1551 TRACE("(%p)\n", This
);
1553 EnterCriticalSection(&This
->lock
);
1556 LeaveCriticalSection(&This
->lock
);
1557 return AUDCLNT_E_NOT_INITIALIZED
;
1561 LeaveCriticalSection(&This
->lock
);
1565 DeleteTimerQueueTimer(g_timer_q
, This
->timer
, INVALID_HANDLE_VALUE
);
1567 if((err
= snd_pcm_drop(This
->pcm_handle
)) < 0){
1568 LeaveCriticalSection(&This
->lock
);
1569 WARN("Drop failed: %d (%s)\n", err
, snd_strerror(err
));
1573 if((err
= snd_pcm_prepare(This
->pcm_handle
)) < 0){
1574 LeaveCriticalSection(&This
->lock
);
1575 WARN("Prepare failed: %d (%s)\n", err
, snd_strerror(err
));
1579 This
->started
= FALSE
;
1581 LeaveCriticalSection(&This
->lock
);
1586 static HRESULT WINAPI
AudioClient_Reset(IAudioClient
*iface
)
1588 ACImpl
*This
= impl_from_IAudioClient(iface
);
1590 TRACE("(%p)\n", This
);
1592 EnterCriticalSection(&This
->lock
);
1595 LeaveCriticalSection(&This
->lock
);
1596 return AUDCLNT_E_NOT_INITIALIZED
;
1600 LeaveCriticalSection(&This
->lock
);
1601 return AUDCLNT_E_NOT_STOPPED
;
1604 This
->held_frames
= 0;
1605 This
->written_frames
= 0;
1606 This
->lcl_offs_frames
= 0;
1608 LeaveCriticalSection(&This
->lock
);
1613 static HRESULT WINAPI
AudioClient_SetEventHandle(IAudioClient
*iface
,
1616 ACImpl
*This
= impl_from_IAudioClient(iface
);
1618 TRACE("(%p)->(%p)\n", This
, event
);
1621 return E_INVALIDARG
;
1623 EnterCriticalSection(&This
->lock
);
1626 LeaveCriticalSection(&This
->lock
);
1627 return AUDCLNT_E_NOT_INITIALIZED
;
1630 if(!(This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
)){
1631 LeaveCriticalSection(&This
->lock
);
1632 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED
;
1635 This
->event
= event
;
1637 LeaveCriticalSection(&This
->lock
);
1642 static HRESULT WINAPI
AudioClient_GetService(IAudioClient
*iface
, REFIID riid
,
1645 ACImpl
*This
= impl_from_IAudioClient(iface
);
1647 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1653 EnterCriticalSection(&This
->lock
);
1656 LeaveCriticalSection(&This
->lock
);
1657 return AUDCLNT_E_NOT_INITIALIZED
;
1660 if(IsEqualIID(riid
, &IID_IAudioRenderClient
)){
1661 if(This
->dataflow
!= eRender
){
1662 LeaveCriticalSection(&This
->lock
);
1663 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1665 *ppv
= &This
->IAudioRenderClient_iface
;
1666 }else if(IsEqualIID(riid
, &IID_IAudioCaptureClient
)){
1667 if(This
->dataflow
!= eCapture
){
1668 LeaveCriticalSection(&This
->lock
);
1669 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1671 *ppv
= &This
->IAudioCaptureClient_iface
;
1672 }else if(IsEqualIID(riid
, &IID_IAudioClock
)){
1673 *ppv
= &This
->IAudioClock_iface
;
1674 }else if(IsEqualIID(riid
, &IID_IAudioStreamVolume
)){
1675 *ppv
= &This
->IAudioStreamVolume_iface
;
1676 }else if(IsEqualIID(riid
, &IID_IAudioSessionControl
)){
1677 if(!This
->session_wrapper
){
1678 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1679 if(!This
->session_wrapper
){
1680 LeaveCriticalSection(&This
->lock
);
1681 return E_OUTOFMEMORY
;
1685 *ppv
= &This
->session_wrapper
->IAudioSessionControl2_iface
;
1686 }else if(IsEqualIID(riid
, &IID_IChannelAudioVolume
)){
1687 if(!This
->session_wrapper
){
1688 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1689 if(!This
->session_wrapper
){
1690 LeaveCriticalSection(&This
->lock
);
1691 return E_OUTOFMEMORY
;
1695 *ppv
= &This
->session_wrapper
->IChannelAudioVolume_iface
;
1696 }else if(IsEqualIID(riid
, &IID_ISimpleAudioVolume
)){
1697 if(!This
->session_wrapper
){
1698 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1699 if(!This
->session_wrapper
){
1700 LeaveCriticalSection(&This
->lock
);
1701 return E_OUTOFMEMORY
;
1705 *ppv
= &This
->session_wrapper
->ISimpleAudioVolume_iface
;
1709 IUnknown_AddRef((IUnknown
*)*ppv
);
1710 LeaveCriticalSection(&This
->lock
);
1714 LeaveCriticalSection(&This
->lock
);
1716 FIXME("stub %s\n", debugstr_guid(riid
));
1717 return E_NOINTERFACE
;
1720 static const IAudioClientVtbl AudioClient_Vtbl
=
1722 AudioClient_QueryInterface
,
1724 AudioClient_Release
,
1725 AudioClient_Initialize
,
1726 AudioClient_GetBufferSize
,
1727 AudioClient_GetStreamLatency
,
1728 AudioClient_GetCurrentPadding
,
1729 AudioClient_IsFormatSupported
,
1730 AudioClient_GetMixFormat
,
1731 AudioClient_GetDevicePeriod
,
1735 AudioClient_SetEventHandle
,
1736 AudioClient_GetService
1739 static HRESULT WINAPI
AudioRenderClient_QueryInterface(
1740 IAudioRenderClient
*iface
, REFIID riid
, void **ppv
)
1742 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1748 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1749 IsEqualIID(riid
, &IID_IAudioRenderClient
))
1752 IUnknown_AddRef((IUnknown
*)*ppv
);
1756 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1757 return E_NOINTERFACE
;
1760 static ULONG WINAPI
AudioRenderClient_AddRef(IAudioRenderClient
*iface
)
1762 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1763 return AudioClient_AddRef(&This
->IAudioClient_iface
);
1766 static ULONG WINAPI
AudioRenderClient_Release(IAudioRenderClient
*iface
)
1768 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1769 return AudioClient_Release(&This
->IAudioClient_iface
);
1772 static HRESULT WINAPI
AudioRenderClient_GetBuffer(IAudioRenderClient
*iface
,
1773 UINT32 frames
, BYTE
**data
)
1775 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1780 TRACE("(%p)->(%u, %p)\n", This
, frames
, data
);
1785 EnterCriticalSection(&This
->lock
);
1787 if(This
->buf_state
!= NOT_LOCKED
){
1788 LeaveCriticalSection(&This
->lock
);
1789 return AUDCLNT_E_OUT_OF_ORDER
;
1793 This
->buf_state
= LOCKED_NORMAL
;
1794 LeaveCriticalSection(&This
->lock
);
1798 hr
= IAudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, &pad
);
1800 LeaveCriticalSection(&This
->lock
);
1804 if(pad
+ frames
> This
->bufsize_frames
){
1805 LeaveCriticalSection(&This
->lock
);
1806 return AUDCLNT_E_BUFFER_TOO_LARGE
;
1810 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1811 if(write_pos
+ frames
> This
->bufsize_frames
){
1812 if(This
->tmp_buffer_frames
< frames
){
1813 if(This
->tmp_buffer
)
1814 This
->tmp_buffer
= HeapReAlloc(GetProcessHeap(), 0,
1815 This
->tmp_buffer
, frames
* This
->fmt
->nBlockAlign
);
1817 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1818 frames
* This
->fmt
->nBlockAlign
);
1819 if(!This
->tmp_buffer
){
1820 LeaveCriticalSection(&This
->lock
);
1821 return E_OUTOFMEMORY
;
1823 This
->tmp_buffer_frames
= frames
;
1825 *data
= This
->tmp_buffer
;
1826 This
->buf_state
= LOCKED_WRAPPED
;
1828 *data
= This
->local_buffer
+
1829 This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1830 This
->buf_state
= LOCKED_NORMAL
;
1833 LeaveCriticalSection(&This
->lock
);
1838 static void alsa_wrap_buffer(ACImpl
*This
, BYTE
*buffer
, UINT32 written_bytes
)
1840 snd_pcm_uframes_t write_offs_frames
=
1841 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1842 UINT32 write_offs_bytes
= write_offs_frames
* This
->fmt
->nBlockAlign
;
1843 snd_pcm_uframes_t chunk_frames
= This
->bufsize_frames
- write_offs_frames
;
1844 UINT32 chunk_bytes
= chunk_frames
* This
->fmt
->nBlockAlign
;
1846 if(written_bytes
< chunk_bytes
){
1847 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, written_bytes
);
1849 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, chunk_bytes
);
1850 memcpy(This
->local_buffer
, buffer
+ chunk_bytes
,
1851 written_bytes
- chunk_bytes
);
1855 static HRESULT WINAPI
AudioRenderClient_ReleaseBuffer(
1856 IAudioRenderClient
*iface
, UINT32 written_frames
, DWORD flags
)
1858 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1859 UINT32 written_bytes
= written_frames
* This
->fmt
->nBlockAlign
;
1863 TRACE("(%p)->(%u, %x)\n", This
, written_frames
, flags
);
1865 EnterCriticalSection(&This
->lock
);
1867 if(This
->buf_state
== NOT_LOCKED
|| !written_frames
){
1868 This
->buf_state
= NOT_LOCKED
;
1869 LeaveCriticalSection(&This
->lock
);
1870 return written_frames
? AUDCLNT_E_OUT_OF_ORDER
: S_OK
;
1873 if(This
->buf_state
== LOCKED_NORMAL
)
1874 buffer
= This
->local_buffer
+
1875 This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1877 buffer
= This
->tmp_buffer
;
1879 if(flags
& AUDCLNT_BUFFERFLAGS_SILENT
){
1880 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)This
->fmt
;
1881 if((This
->fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
1882 (This
->fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1883 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))) &&
1884 This
->fmt
->wBitsPerSample
== 8)
1885 memset(buffer
, 128, written_frames
* This
->fmt
->nBlockAlign
);
1887 memset(buffer
, 0, written_frames
* This
->fmt
->nBlockAlign
);
1890 if(This
->held_frames
){
1891 if(This
->buf_state
== LOCKED_WRAPPED
)
1892 alsa_wrap_buffer(This
, buffer
, written_bytes
);
1894 This
->held_frames
+= written_frames
;
1896 snd_pcm_sframes_t written
;
1898 written
= alsa_write_best_effort(This
->pcm_handle
, buffer
,
1901 LeaveCriticalSection(&This
->lock
);
1902 WARN("write failed: %ld (%s)\n", written
, snd_strerror(written
));
1906 if(written
< written_frames
){
1907 if(This
->buf_state
== LOCKED_WRAPPED
)
1908 alsa_wrap_buffer(This
,
1909 This
->tmp_buffer
+ written
* This
->fmt
->nBlockAlign
,
1910 written_frames
- written
);
1912 This
->held_frames
= written_frames
- written
;
1917 snd_pcm_state(This
->pcm_handle
) == SND_PCM_STATE_PREPARED
){
1918 hr
= alsa_consider_start(This
);
1920 LeaveCriticalSection(&This
->lock
);
1925 This
->written_frames
+= written_frames
;
1926 This
->buf_state
= NOT_LOCKED
;
1928 LeaveCriticalSection(&This
->lock
);
1933 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
= {
1934 AudioRenderClient_QueryInterface
,
1935 AudioRenderClient_AddRef
,
1936 AudioRenderClient_Release
,
1937 AudioRenderClient_GetBuffer
,
1938 AudioRenderClient_ReleaseBuffer
1941 static HRESULT WINAPI
AudioCaptureClient_QueryInterface(
1942 IAudioCaptureClient
*iface
, REFIID riid
, void **ppv
)
1944 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1950 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1951 IsEqualIID(riid
, &IID_IAudioCaptureClient
))
1954 IUnknown_AddRef((IUnknown
*)*ppv
);
1958 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1959 return E_NOINTERFACE
;
1962 static ULONG WINAPI
AudioCaptureClient_AddRef(IAudioCaptureClient
*iface
)
1964 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1965 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1968 static ULONG WINAPI
AudioCaptureClient_Release(IAudioCaptureClient
*iface
)
1970 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1971 return IAudioClient_Release(&This
->IAudioClient_iface
);
1974 static HRESULT WINAPI
AudioCaptureClient_GetBuffer(IAudioCaptureClient
*iface
,
1975 BYTE
**data
, UINT32
*frames
, DWORD
*flags
, UINT64
*devpos
,
1978 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1981 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This
, data
, frames
, flags
,
1984 if(!data
|| !frames
|| !flags
)
1987 EnterCriticalSection(&This
->lock
);
1989 if(This
->buf_state
!= NOT_LOCKED
){
1990 LeaveCriticalSection(&This
->lock
);
1991 return AUDCLNT_E_OUT_OF_ORDER
;
1994 hr
= IAudioCaptureClient_GetNextPacketSize(iface
, frames
);
1996 LeaveCriticalSection(&This
->lock
);
2002 if(This
->lcl_offs_frames
+ *frames
> This
->bufsize_frames
){
2003 UINT32 chunk_bytes
, offs_bytes
, frames_bytes
;
2004 if(This
->tmp_buffer_frames
< *frames
){
2005 if(This
->tmp_buffer
)
2006 This
->tmp_buffer
= HeapReAlloc(GetProcessHeap(), 0,
2007 This
->tmp_buffer
, *frames
* This
->fmt
->nBlockAlign
);
2009 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
2010 *frames
* This
->fmt
->nBlockAlign
);
2011 if(!This
->tmp_buffer
){
2012 LeaveCriticalSection(&This
->lock
);
2013 return E_OUTOFMEMORY
;
2015 This
->tmp_buffer_frames
= *frames
;
2018 *data
= This
->tmp_buffer
;
2019 chunk_bytes
= (This
->bufsize_frames
- This
->lcl_offs_frames
) *
2020 This
->fmt
->nBlockAlign
;
2021 offs_bytes
= This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
2022 frames_bytes
= *frames
* This
->fmt
->nBlockAlign
;
2023 memcpy(This
->tmp_buffer
, This
->local_buffer
+ offs_bytes
, chunk_bytes
);
2024 memcpy(This
->tmp_buffer
+ chunk_bytes
, This
->local_buffer
,
2025 frames_bytes
- chunk_bytes
);
2027 *data
= This
->local_buffer
+
2028 This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
2030 This
->buf_state
= LOCKED_NORMAL
;
2032 if(devpos
|| qpcpos
)
2033 IAudioClock_GetPosition(&This
->IAudioClock_iface
, devpos
, qpcpos
);
2035 LeaveCriticalSection(&This
->lock
);
2037 return *frames
? S_OK
: AUDCLNT_S_BUFFER_EMPTY
;
2040 static HRESULT WINAPI
AudioCaptureClient_ReleaseBuffer(
2041 IAudioCaptureClient
*iface
, UINT32 done
)
2043 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
2045 TRACE("(%p)->(%u)\n", This
, done
);
2047 EnterCriticalSection(&This
->lock
);
2049 if(This
->buf_state
== NOT_LOCKED
){
2050 LeaveCriticalSection(&This
->lock
);
2051 return AUDCLNT_E_OUT_OF_ORDER
;
2054 This
->held_frames
-= done
;
2055 This
->lcl_offs_frames
+= done
;
2056 This
->lcl_offs_frames
%= This
->bufsize_frames
;
2058 This
->buf_state
= NOT_LOCKED
;
2060 LeaveCriticalSection(&This
->lock
);
2065 static HRESULT WINAPI
AudioCaptureClient_GetNextPacketSize(
2066 IAudioCaptureClient
*iface
, UINT32
*frames
)
2068 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
2070 TRACE("(%p)->(%p)\n", This
, frames
);
2072 return AudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, frames
);
2075 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
=
2077 AudioCaptureClient_QueryInterface
,
2078 AudioCaptureClient_AddRef
,
2079 AudioCaptureClient_Release
,
2080 AudioCaptureClient_GetBuffer
,
2081 AudioCaptureClient_ReleaseBuffer
,
2082 AudioCaptureClient_GetNextPacketSize
2085 static HRESULT WINAPI
AudioClock_QueryInterface(IAudioClock
*iface
,
2086 REFIID riid
, void **ppv
)
2088 ACImpl
*This
= impl_from_IAudioClock(iface
);
2090 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2096 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClock
))
2098 else if(IsEqualIID(riid
, &IID_IAudioClock2
))
2099 *ppv
= &This
->IAudioClock2_iface
;
2101 IUnknown_AddRef((IUnknown
*)*ppv
);
2105 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2106 return E_NOINTERFACE
;
2109 static ULONG WINAPI
AudioClock_AddRef(IAudioClock
*iface
)
2111 ACImpl
*This
= impl_from_IAudioClock(iface
);
2112 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2115 static ULONG WINAPI
AudioClock_Release(IAudioClock
*iface
)
2117 ACImpl
*This
= impl_from_IAudioClock(iface
);
2118 return IAudioClient_Release(&This
->IAudioClient_iface
);
2121 static HRESULT WINAPI
AudioClock_GetFrequency(IAudioClock
*iface
, UINT64
*freq
)
2123 ACImpl
*This
= impl_from_IAudioClock(iface
);
2125 TRACE("(%p)->(%p)\n", This
, freq
);
2127 *freq
= This
->fmt
->nSamplesPerSec
;
2132 static HRESULT WINAPI
AudioClock_GetPosition(IAudioClock
*iface
, UINT64
*pos
,
2135 ACImpl
*This
= impl_from_IAudioClock(iface
);
2139 TRACE("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
2144 EnterCriticalSection(&This
->lock
);
2146 hr
= IAudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, &pad
);
2148 LeaveCriticalSection(&This
->lock
);
2152 if(This
->dataflow
== eRender
)
2153 *pos
= This
->written_frames
- pad
;
2154 else if(This
->dataflow
== eCapture
)
2155 *pos
= This
->written_frames
+ pad
;
2157 LeaveCriticalSection(&This
->lock
);
2160 LARGE_INTEGER stamp
, freq
;
2161 QueryPerformanceCounter(&stamp
);
2162 QueryPerformanceFrequency(&freq
);
2163 *qpctime
= (stamp
.QuadPart
* (INT64
)10000000) / freq
.QuadPart
;
2169 static HRESULT WINAPI
AudioClock_GetCharacteristics(IAudioClock
*iface
,
2172 ACImpl
*This
= impl_from_IAudioClock(iface
);
2174 TRACE("(%p)->(%p)\n", This
, chars
);
2179 *chars
= AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ
;
2184 static const IAudioClockVtbl AudioClock_Vtbl
=
2186 AudioClock_QueryInterface
,
2189 AudioClock_GetFrequency
,
2190 AudioClock_GetPosition
,
2191 AudioClock_GetCharacteristics
2194 static HRESULT WINAPI
AudioClock2_QueryInterface(IAudioClock2
*iface
,
2195 REFIID riid
, void **ppv
)
2197 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2198 return IAudioClock_QueryInterface(&This
->IAudioClock_iface
, riid
, ppv
);
2201 static ULONG WINAPI
AudioClock2_AddRef(IAudioClock2
*iface
)
2203 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2204 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2207 static ULONG WINAPI
AudioClock2_Release(IAudioClock2
*iface
)
2209 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2210 return IAudioClient_Release(&This
->IAudioClient_iface
);
2213 static HRESULT WINAPI
AudioClock2_GetDevicePosition(IAudioClock2
*iface
,
2214 UINT64
*pos
, UINT64
*qpctime
)
2216 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2218 FIXME("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
2223 static const IAudioClock2Vtbl AudioClock2_Vtbl
=
2225 AudioClock2_QueryInterface
,
2227 AudioClock2_Release
,
2228 AudioClock2_GetDevicePosition
2231 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
)
2233 AudioSessionWrapper
*ret
;
2235 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2236 sizeof(AudioSessionWrapper
));
2240 ret
->IAudioSessionControl2_iface
.lpVtbl
= &AudioSessionControl2_Vtbl
;
2241 ret
->ISimpleAudioVolume_iface
.lpVtbl
= &SimpleAudioVolume_Vtbl
;
2242 ret
->IChannelAudioVolume_iface
.lpVtbl
= &ChannelAudioVolume_Vtbl
;
2244 ret
->client
= client
;
2246 ret
->session
= client
->session
;
2247 AudioClient_AddRef(&client
->IAudioClient_iface
);
2253 static HRESULT WINAPI
AudioSessionControl_QueryInterface(
2254 IAudioSessionControl2
*iface
, REFIID riid
, void **ppv
)
2256 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2262 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2263 IsEqualIID(riid
, &IID_IAudioSessionControl
) ||
2264 IsEqualIID(riid
, &IID_IAudioSessionControl2
))
2267 IUnknown_AddRef((IUnknown
*)*ppv
);
2271 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2272 return E_NOINTERFACE
;
2275 static ULONG WINAPI
AudioSessionControl_AddRef(IAudioSessionControl2
*iface
)
2277 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2279 ref
= InterlockedIncrement(&This
->ref
);
2280 TRACE("(%p) Refcount now %u\n", This
, ref
);
2284 static ULONG WINAPI
AudioSessionControl_Release(IAudioSessionControl2
*iface
)
2286 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2288 ref
= InterlockedDecrement(&This
->ref
);
2289 TRACE("(%p) Refcount now %u\n", This
, ref
);
2292 EnterCriticalSection(&This
->client
->lock
);
2293 This
->client
->session_wrapper
= NULL
;
2294 LeaveCriticalSection(&This
->client
->lock
);
2295 AudioClient_Release(&This
->client
->IAudioClient_iface
);
2297 HeapFree(GetProcessHeap(), 0, This
);
2302 static HRESULT WINAPI
AudioSessionControl_GetState(IAudioSessionControl2
*iface
,
2303 AudioSessionState
*state
)
2305 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2308 TRACE("(%p)->(%p)\n", This
, state
);
2311 return NULL_PTR_ERR
;
2313 EnterCriticalSection(&g_sessions_lock
);
2315 if(list_empty(&This
->session
->clients
)){
2316 *state
= AudioSessionStateExpired
;
2317 LeaveCriticalSection(&g_sessions_lock
);
2321 LIST_FOR_EACH_ENTRY(client
, &This
->session
->clients
, ACImpl
, entry
){
2322 EnterCriticalSection(&client
->lock
);
2323 if(client
->started
){
2324 *state
= AudioSessionStateActive
;
2325 LeaveCriticalSection(&client
->lock
);
2326 LeaveCriticalSection(&g_sessions_lock
);
2329 LeaveCriticalSection(&client
->lock
);
2332 LeaveCriticalSection(&g_sessions_lock
);
2334 *state
= AudioSessionStateInactive
;
2339 static HRESULT WINAPI
AudioSessionControl_GetDisplayName(
2340 IAudioSessionControl2
*iface
, WCHAR
**name
)
2342 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2344 FIXME("(%p)->(%p) - stub\n", This
, name
);
2349 static HRESULT WINAPI
AudioSessionControl_SetDisplayName(
2350 IAudioSessionControl2
*iface
, const WCHAR
*name
, const GUID
*session
)
2352 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2354 FIXME("(%p)->(%p, %s) - stub\n", This
, name
, debugstr_guid(session
));
2359 static HRESULT WINAPI
AudioSessionControl_GetIconPath(
2360 IAudioSessionControl2
*iface
, WCHAR
**path
)
2362 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2364 FIXME("(%p)->(%p) - stub\n", This
, path
);
2369 static HRESULT WINAPI
AudioSessionControl_SetIconPath(
2370 IAudioSessionControl2
*iface
, const WCHAR
*path
, const GUID
*session
)
2372 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2374 FIXME("(%p)->(%p, %s) - stub\n", This
, path
, debugstr_guid(session
));
2379 static HRESULT WINAPI
AudioSessionControl_GetGroupingParam(
2380 IAudioSessionControl2
*iface
, GUID
*group
)
2382 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2384 FIXME("(%p)->(%p) - stub\n", This
, group
);
2389 static HRESULT WINAPI
AudioSessionControl_SetGroupingParam(
2390 IAudioSessionControl2
*iface
, GUID
*group
, const GUID
*session
)
2392 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2394 FIXME("(%p)->(%s, %s) - stub\n", This
, debugstr_guid(group
),
2395 debugstr_guid(session
));
2400 static HRESULT WINAPI
AudioSessionControl_RegisterAudioSessionNotification(
2401 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2403 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2405 FIXME("(%p)->(%p) - stub\n", This
, events
);
2410 static HRESULT WINAPI
AudioSessionControl_UnregisterAudioSessionNotification(
2411 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2413 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2415 FIXME("(%p)->(%p) - stub\n", This
, events
);
2420 static HRESULT WINAPI
AudioSessionControl_GetSessionIdentifier(
2421 IAudioSessionControl2
*iface
, WCHAR
**id
)
2423 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2425 FIXME("(%p)->(%p) - stub\n", This
, id
);
2430 static HRESULT WINAPI
AudioSessionControl_GetSessionInstanceIdentifier(
2431 IAudioSessionControl2
*iface
, WCHAR
**id
)
2433 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2435 FIXME("(%p)->(%p) - stub\n", This
, id
);
2440 static HRESULT WINAPI
AudioSessionControl_GetProcessId(
2441 IAudioSessionControl2
*iface
, DWORD
*pid
)
2443 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2445 TRACE("(%p)->(%p)\n", This
, pid
);
2450 *pid
= GetCurrentProcessId();
2455 static HRESULT WINAPI
AudioSessionControl_IsSystemSoundsSession(
2456 IAudioSessionControl2
*iface
)
2458 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2460 TRACE("(%p)\n", This
);
2465 static HRESULT WINAPI
AudioSessionControl_SetDuckingPreference(
2466 IAudioSessionControl2
*iface
, BOOL optout
)
2468 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2470 TRACE("(%p)->(%d)\n", This
, optout
);
2475 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
=
2477 AudioSessionControl_QueryInterface
,
2478 AudioSessionControl_AddRef
,
2479 AudioSessionControl_Release
,
2480 AudioSessionControl_GetState
,
2481 AudioSessionControl_GetDisplayName
,
2482 AudioSessionControl_SetDisplayName
,
2483 AudioSessionControl_GetIconPath
,
2484 AudioSessionControl_SetIconPath
,
2485 AudioSessionControl_GetGroupingParam
,
2486 AudioSessionControl_SetGroupingParam
,
2487 AudioSessionControl_RegisterAudioSessionNotification
,
2488 AudioSessionControl_UnregisterAudioSessionNotification
,
2489 AudioSessionControl_GetSessionIdentifier
,
2490 AudioSessionControl_GetSessionInstanceIdentifier
,
2491 AudioSessionControl_GetProcessId
,
2492 AudioSessionControl_IsSystemSoundsSession
,
2493 AudioSessionControl_SetDuckingPreference
2496 static HRESULT WINAPI
SimpleAudioVolume_QueryInterface(
2497 ISimpleAudioVolume
*iface
, REFIID riid
, void **ppv
)
2499 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2505 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2506 IsEqualIID(riid
, &IID_ISimpleAudioVolume
))
2509 IUnknown_AddRef((IUnknown
*)*ppv
);
2513 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2514 return E_NOINTERFACE
;
2517 static ULONG WINAPI
SimpleAudioVolume_AddRef(ISimpleAudioVolume
*iface
)
2519 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2520 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2523 static ULONG WINAPI
SimpleAudioVolume_Release(ISimpleAudioVolume
*iface
)
2525 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2526 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2529 static HRESULT WINAPI
SimpleAudioVolume_SetMasterVolume(
2530 ISimpleAudioVolume
*iface
, float level
, const GUID
*context
)
2532 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2533 AudioSession
*session
= This
->session
;
2535 TRACE("(%p)->(%f, %s)\n", session
, level
, wine_dbgstr_guid(context
));
2537 if(level
< 0.f
|| level
> 1.f
)
2538 return E_INVALIDARG
;
2541 FIXME("Notifications not supported yet\n");
2543 TRACE("ALSA does not support volume control\n");
2545 EnterCriticalSection(&session
->lock
);
2547 session
->master_vol
= level
;
2549 LeaveCriticalSection(&session
->lock
);
2554 static HRESULT WINAPI
SimpleAudioVolume_GetMasterVolume(
2555 ISimpleAudioVolume
*iface
, float *level
)
2557 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2558 AudioSession
*session
= This
->session
;
2560 TRACE("(%p)->(%p)\n", session
, level
);
2563 return NULL_PTR_ERR
;
2565 *level
= session
->master_vol
;
2570 static HRESULT WINAPI
SimpleAudioVolume_SetMute(ISimpleAudioVolume
*iface
,
2571 BOOL mute
, const GUID
*context
)
2573 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2574 AudioSession
*session
= This
->session
;
2576 FIXME("(%p)->(%u, %p) - stub\n", session
, mute
, context
);
2581 static HRESULT WINAPI
SimpleAudioVolume_GetMute(ISimpleAudioVolume
*iface
,
2584 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2585 AudioSession
*session
= This
->session
;
2587 FIXME("(%p)->(%p) - stub\n", session
, mute
);
2590 return NULL_PTR_ERR
;
2595 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
=
2597 SimpleAudioVolume_QueryInterface
,
2598 SimpleAudioVolume_AddRef
,
2599 SimpleAudioVolume_Release
,
2600 SimpleAudioVolume_SetMasterVolume
,
2601 SimpleAudioVolume_GetMasterVolume
,
2602 SimpleAudioVolume_SetMute
,
2603 SimpleAudioVolume_GetMute
2606 static HRESULT WINAPI
AudioStreamVolume_QueryInterface(
2607 IAudioStreamVolume
*iface
, REFIID riid
, void **ppv
)
2609 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2615 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2616 IsEqualIID(riid
, &IID_IAudioStreamVolume
))
2619 IUnknown_AddRef((IUnknown
*)*ppv
);
2623 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2624 return E_NOINTERFACE
;
2627 static ULONG WINAPI
AudioStreamVolume_AddRef(IAudioStreamVolume
*iface
)
2629 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2630 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2633 static ULONG WINAPI
AudioStreamVolume_Release(IAudioStreamVolume
*iface
)
2635 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2636 return IAudioClient_Release(&This
->IAudioClient_iface
);
2639 static HRESULT WINAPI
AudioStreamVolume_GetChannelCount(
2640 IAudioStreamVolume
*iface
, UINT32
*out
)
2642 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2644 TRACE("(%p)->(%p)\n", This
, out
);
2649 *out
= This
->fmt
->nChannels
;
2654 static HRESULT WINAPI
AudioStreamVolume_SetChannelVolume(
2655 IAudioStreamVolume
*iface
, UINT32 index
, float level
)
2657 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2659 TRACE("(%p)->(%d, %f)\n", This
, index
, level
);
2661 if(level
< 0.f
|| level
> 1.f
)
2662 return E_INVALIDARG
;
2664 if(index
>= This
->fmt
->nChannels
)
2665 return E_INVALIDARG
;
2667 TRACE("ALSA does not support volume control\n");
2669 EnterCriticalSection(&This
->lock
);
2671 This
->vols
[index
] = level
;
2673 LeaveCriticalSection(&This
->lock
);
2678 static HRESULT WINAPI
AudioStreamVolume_GetChannelVolume(
2679 IAudioStreamVolume
*iface
, UINT32 index
, float *level
)
2681 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2683 TRACE("(%p)->(%d, %p)\n", This
, index
, level
);
2688 if(index
>= This
->fmt
->nChannels
)
2689 return E_INVALIDARG
;
2691 *level
= This
->vols
[index
];
2696 static HRESULT WINAPI
AudioStreamVolume_SetAllVolumes(
2697 IAudioStreamVolume
*iface
, UINT32 count
, const float *levels
)
2699 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2702 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2707 if(count
!= This
->fmt
->nChannels
)
2708 return E_INVALIDARG
;
2710 TRACE("ALSA does not support volume control\n");
2712 EnterCriticalSection(&This
->lock
);
2714 for(i
= 0; i
< count
; ++i
)
2715 This
->vols
[i
] = levels
[i
];
2717 LeaveCriticalSection(&This
->lock
);
2722 static HRESULT WINAPI
AudioStreamVolume_GetAllVolumes(
2723 IAudioStreamVolume
*iface
, UINT32 count
, float *levels
)
2725 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2728 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2733 if(count
!= This
->fmt
->nChannels
)
2734 return E_INVALIDARG
;
2736 EnterCriticalSection(&This
->lock
);
2738 for(i
= 0; i
< count
; ++i
)
2739 levels
[i
] = This
->vols
[i
];
2741 LeaveCriticalSection(&This
->lock
);
2746 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
=
2748 AudioStreamVolume_QueryInterface
,
2749 AudioStreamVolume_AddRef
,
2750 AudioStreamVolume_Release
,
2751 AudioStreamVolume_GetChannelCount
,
2752 AudioStreamVolume_SetChannelVolume
,
2753 AudioStreamVolume_GetChannelVolume
,
2754 AudioStreamVolume_SetAllVolumes
,
2755 AudioStreamVolume_GetAllVolumes
2758 static HRESULT WINAPI
ChannelAudioVolume_QueryInterface(
2759 IChannelAudioVolume
*iface
, REFIID riid
, void **ppv
)
2761 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2767 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2768 IsEqualIID(riid
, &IID_IChannelAudioVolume
))
2771 IUnknown_AddRef((IUnknown
*)*ppv
);
2775 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2776 return E_NOINTERFACE
;
2779 static ULONG WINAPI
ChannelAudioVolume_AddRef(IChannelAudioVolume
*iface
)
2781 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2782 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2785 static ULONG WINAPI
ChannelAudioVolume_Release(IChannelAudioVolume
*iface
)
2787 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2788 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2791 static HRESULT WINAPI
ChannelAudioVolume_GetChannelCount(
2792 IChannelAudioVolume
*iface
, UINT32
*out
)
2794 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2795 AudioSession
*session
= This
->session
;
2797 TRACE("(%p)->(%p)\n", session
, out
);
2800 return NULL_PTR_ERR
;
2802 *out
= session
->channel_count
;
2807 static HRESULT WINAPI
ChannelAudioVolume_SetChannelVolume(
2808 IChannelAudioVolume
*iface
, UINT32 index
, float level
,
2809 const GUID
*context
)
2811 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2812 AudioSession
*session
= This
->session
;
2814 TRACE("(%p)->(%d, %f, %s)\n", session
, index
, level
,
2815 wine_dbgstr_guid(context
));
2817 if(level
< 0.f
|| level
> 1.f
)
2818 return E_INVALIDARG
;
2820 if(index
>= session
->channel_count
)
2821 return E_INVALIDARG
;
2824 FIXME("Notifications not supported yet\n");
2826 TRACE("ALSA does not support volume control\n");
2828 EnterCriticalSection(&session
->lock
);
2830 session
->channel_vols
[index
] = level
;
2832 LeaveCriticalSection(&session
->lock
);
2837 static HRESULT WINAPI
ChannelAudioVolume_GetChannelVolume(
2838 IChannelAudioVolume
*iface
, UINT32 index
, float *level
)
2840 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2841 AudioSession
*session
= This
->session
;
2843 TRACE("(%p)->(%d, %p)\n", session
, index
, level
);
2846 return NULL_PTR_ERR
;
2848 if(index
>= session
->channel_count
)
2849 return E_INVALIDARG
;
2851 *level
= session
->channel_vols
[index
];
2856 static HRESULT WINAPI
ChannelAudioVolume_SetAllVolumes(
2857 IChannelAudioVolume
*iface
, UINT32 count
, const float *levels
,
2858 const GUID
*context
)
2860 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2861 AudioSession
*session
= This
->session
;
2864 TRACE("(%p)->(%d, %p, %s)\n", session
, count
, levels
,
2865 wine_dbgstr_guid(context
));
2868 return NULL_PTR_ERR
;
2870 if(count
!= session
->channel_count
)
2871 return E_INVALIDARG
;
2874 FIXME("Notifications not supported yet\n");
2876 TRACE("ALSA does not support volume control\n");
2878 EnterCriticalSection(&session
->lock
);
2880 for(i
= 0; i
< count
; ++i
)
2881 session
->channel_vols
[i
] = levels
[i
];
2883 LeaveCriticalSection(&session
->lock
);
2888 static HRESULT WINAPI
ChannelAudioVolume_GetAllVolumes(
2889 IChannelAudioVolume
*iface
, UINT32 count
, float *levels
)
2891 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2892 AudioSession
*session
= This
->session
;
2895 TRACE("(%p)->(%d, %p)\n", session
, count
, levels
);
2898 return NULL_PTR_ERR
;
2900 if(count
!= session
->channel_count
)
2901 return E_INVALIDARG
;
2903 for(i
= 0; i
< count
; ++i
)
2904 levels
[i
] = session
->channel_vols
[i
];
2909 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
=
2911 ChannelAudioVolume_QueryInterface
,
2912 ChannelAudioVolume_AddRef
,
2913 ChannelAudioVolume_Release
,
2914 ChannelAudioVolume_GetChannelCount
,
2915 ChannelAudioVolume_SetChannelVolume
,
2916 ChannelAudioVolume_GetChannelVolume
,
2917 ChannelAudioVolume_SetAllVolumes
,
2918 ChannelAudioVolume_GetAllVolumes
2921 HRESULT WINAPI
AudioSessionManager_QueryInterface(IAudioSessionManager2
*iface
,
2922 REFIID riid
, void **ppv
)
2924 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2930 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2931 IsEqualIID(riid
, &IID_IAudioSessionManager
) ||
2932 IsEqualIID(riid
, &IID_IAudioSessionManager2
))
2935 IUnknown_AddRef((IUnknown
*)*ppv
);
2939 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2940 return E_NOINTERFACE
;
2943 ULONG WINAPI
AudioSessionManager_AddRef(IAudioSessionManager2
*iface
)
2945 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2947 ref
= InterlockedIncrement(&This
->ref
);
2948 TRACE("(%p) Refcount now %u\n", This
, ref
);
2952 ULONG WINAPI
AudioSessionManager_Release(IAudioSessionManager2
*iface
)
2954 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2956 ref
= InterlockedDecrement(&This
->ref
);
2957 TRACE("(%p) Refcount now %u\n", This
, ref
);
2959 HeapFree(GetProcessHeap(), 0, This
);
2963 HRESULT WINAPI
AudioSessionManager_GetAudioSessionControl(
2964 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2965 IAudioSessionControl
**out
)
2967 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2968 AudioSession
*session
;
2969 AudioSessionWrapper
*wrapper
;
2972 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
2975 hr
= get_audio_session(session_guid
, This
->flow
, 0, &session
);
2979 wrapper
= AudioSessionWrapper_Create(NULL
);
2981 return E_OUTOFMEMORY
;
2983 wrapper
->session
= session
;
2985 *out
= (IAudioSessionControl
*)&wrapper
->IAudioSessionControl2_iface
;
2990 HRESULT WINAPI
AudioSessionManager_GetSimpleAudioVolume(
2991 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2992 ISimpleAudioVolume
**out
)
2994 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2995 AudioSession
*session
;
2996 AudioSessionWrapper
*wrapper
;
2999 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
3002 hr
= get_audio_session(session_guid
, This
->flow
, 0, &session
);
3006 wrapper
= AudioSessionWrapper_Create(NULL
);
3008 return E_OUTOFMEMORY
;
3010 wrapper
->session
= session
;
3012 *out
= &wrapper
->ISimpleAudioVolume_iface
;
3017 HRESULT WINAPI
AudioSessionManager_GetSessionEnumerator(
3018 IAudioSessionManager2
*iface
, IAudioSessionEnumerator
**out
)
3020 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3021 FIXME("(%p)->(%p) - stub\n", This
, out
);
3025 HRESULT WINAPI
AudioSessionManager_RegisterSessionNotification(
3026 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
3028 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3029 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3033 HRESULT WINAPI
AudioSessionManager_UnregisterSessionNotification(
3034 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
3036 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3037 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3041 HRESULT WINAPI
AudioSessionManager_RegisterDuckNotification(
3042 IAudioSessionManager2
*iface
, const WCHAR
*session_id
,
3043 IAudioVolumeDuckNotification
*notification
)
3045 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3046 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3050 HRESULT WINAPI
AudioSessionManager_UnregisterDuckNotification(
3051 IAudioSessionManager2
*iface
,
3052 IAudioVolumeDuckNotification
*notification
)
3054 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3055 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3059 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
=
3061 AudioSessionManager_QueryInterface
,
3062 AudioSessionManager_AddRef
,
3063 AudioSessionManager_Release
,
3064 AudioSessionManager_GetAudioSessionControl
,
3065 AudioSessionManager_GetSimpleAudioVolume
,
3066 AudioSessionManager_GetSessionEnumerator
,
3067 AudioSessionManager_RegisterSessionNotification
,
3068 AudioSessionManager_UnregisterSessionNotification
,
3069 AudioSessionManager_RegisterDuckNotification
,
3070 AudioSessionManager_UnregisterDuckNotification
3073 HRESULT WINAPI
AUDDRV_GetAudioSessionManager(EDataFlow dataflow
,
3074 IAudioSessionManager2
**out
)
3078 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SessionMgr
));
3080 return E_OUTOFMEMORY
;
3082 This
->IAudioSessionManager2_iface
.lpVtbl
= &AudioSessionManager2_Vtbl
;
3083 This
->flow
= dataflow
;
3086 *out
= &This
->IAudioSessionManager2_iface
;