2 * 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
30 #include "mmdeviceapi.h"
36 #include "endpointvolume.h"
37 #include "audiopolicy.h"
38 #include "audioclient.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
42 #include "wine/unixlib.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(oss
);
48 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
50 unixlib_handle_t oss_handle
= 0;
52 static const REFERENCE_TIME DefaultPeriod
= 100000;
53 static const REFERENCE_TIME MinimumPeriod
= 50000;
56 typedef struct ACImpl ACImpl
;
58 typedef struct _AudioSession
{
72 typedef struct _AudioSessionWrapper
{
73 IAudioSessionControl2 IAudioSessionControl2_iface
;
74 IChannelAudioVolume IChannelAudioVolume_iface
;
75 ISimpleAudioVolume ISimpleAudioVolume_iface
;
80 AudioSession
*session
;
81 } AudioSessionWrapper
;
84 IAudioClient3 IAudioClient3_iface
;
85 IAudioRenderClient IAudioRenderClient_iface
;
86 IAudioCaptureClient IAudioCaptureClient_iface
;
87 IAudioClock IAudioClock_iface
;
88 IAudioClock2 IAudioClock2_iface
;
89 IAudioStreamVolume IAudioStreamVolume_iface
;
94 IUnknown
*pUnkFTMarshal
;
103 AudioSession
*session
;
104 AudioSessionWrapper
*session_wrapper
;
112 typedef struct _SessionMgr
{
113 IAudioSessionManager2 IAudioSessionManager2_iface
;
120 typedef struct _OSSDevice
{
127 static struct list g_devices
= LIST_INIT(g_devices
);
129 static const WCHAR drv_key_devicesW
[] = {'S','o','f','t','w','a','r','e','\\',
130 'W','i','n','e','\\','D','r','i','v','e','r','s','\\',
131 'w','i','n','e','o','s','s','.','d','r','v','\\','d','e','v','i','c','e','s',0};
132 static const WCHAR guidW
[] = {'g','u','i','d',0};
134 static CRITICAL_SECTION g_sessions_lock
;
135 static CRITICAL_SECTION_DEBUG g_sessions_lock_debug
=
137 0, 0, &g_sessions_lock
,
138 { &g_sessions_lock_debug
.ProcessLocksList
, &g_sessions_lock_debug
.ProcessLocksList
},
139 0, 0, { (DWORD_PTR
)(__FILE__
": g_sessions_lock") }
141 static CRITICAL_SECTION g_sessions_lock
= { &g_sessions_lock_debug
, -1, 0, 0, 0, 0 };
142 static struct list g_sessions
= LIST_INIT(g_sessions
);
144 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
);
146 static const IAudioClient3Vtbl AudioClient3_Vtbl
;
147 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
;
148 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
;
149 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
;
150 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
;
151 static const IAudioClockVtbl AudioClock_Vtbl
;
152 static const IAudioClock2Vtbl AudioClock2_Vtbl
;
153 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
;
154 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
;
155 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
;
157 static inline ACImpl
*impl_from_IAudioClient3(IAudioClient3
*iface
)
159 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClient3_iface
);
162 static inline ACImpl
*impl_from_IAudioRenderClient(IAudioRenderClient
*iface
)
164 return CONTAINING_RECORD(iface
, ACImpl
, IAudioRenderClient_iface
);
167 static inline ACImpl
*impl_from_IAudioCaptureClient(IAudioCaptureClient
*iface
)
169 return CONTAINING_RECORD(iface
, ACImpl
, IAudioCaptureClient_iface
);
172 static inline AudioSessionWrapper
*impl_from_IAudioSessionControl2(IAudioSessionControl2
*iface
)
174 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IAudioSessionControl2_iface
);
177 static inline AudioSessionWrapper
*impl_from_ISimpleAudioVolume(ISimpleAudioVolume
*iface
)
179 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, ISimpleAudioVolume_iface
);
182 static inline AudioSessionWrapper
*impl_from_IChannelAudioVolume(IChannelAudioVolume
*iface
)
184 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IChannelAudioVolume_iface
);
187 static inline ACImpl
*impl_from_IAudioClock(IAudioClock
*iface
)
189 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock_iface
);
192 static inline ACImpl
*impl_from_IAudioClock2(IAudioClock2
*iface
)
194 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock2_iface
);
197 static inline ACImpl
*impl_from_IAudioStreamVolume(IAudioStreamVolume
*iface
)
199 return CONTAINING_RECORD(iface
, ACImpl
, IAudioStreamVolume_iface
);
202 static inline SessionMgr
*impl_from_IAudioSessionManager2(IAudioSessionManager2
*iface
)
204 return CONTAINING_RECORD(iface
, SessionMgr
, IAudioSessionManager2_iface
);
207 BOOL WINAPI
DllMain(HINSTANCE dll
, DWORD reason
, void *reserved
)
211 case DLL_PROCESS_ATTACH
:
212 if(NtQueryVirtualMemory(GetCurrentProcess(), dll
, MemoryWineUnixFuncs
,
213 &oss_handle
, sizeof(oss_handle
), NULL
))
217 case DLL_PROCESS_DETACH
:
220 OSSDevice
*iter
, *iter2
;
222 DeleteCriticalSection(&g_sessions_lock
);
224 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter2
, &g_devices
, OSSDevice
, entry
){
225 HeapFree(GetProcessHeap(), 0, iter
);
233 int WINAPI
AUDDRV_GetPriority(void)
235 struct test_connect_params params
;
239 OSS_CALL(test_connect
, ¶ms
);
241 return params
.priority
;
244 static HRESULT
stream_release(stream_handle stream
, HANDLE timer_thread
)
246 struct release_stream_params params
;
248 params
.stream
= stream
;
249 params
.timer_thread
= timer_thread
;
250 OSS_CALL(release_stream
, ¶ms
);
252 return params
.result
;
255 static DWORD WINAPI
timer_thread(void *user
)
257 struct timer_loop_params params
;
258 struct ACImpl
*This
= user
;
260 params
.stream
= This
->stream
;
261 OSS_CALL(timer_loop
, ¶ms
);
266 static void set_device_guid(EDataFlow flow
, HKEY drv_key
, const WCHAR
*key_name
,
274 lr
= RegCreateKeyExW(HKEY_CURRENT_USER
, drv_key_devicesW
, 0, NULL
, 0, KEY_WRITE
,
275 NULL
, &drv_key
, NULL
);
276 if(lr
!= ERROR_SUCCESS
){
277 ERR("RegCreateKeyEx(drv_key) failed: %lu\n", lr
);
283 lr
= RegCreateKeyExW(drv_key
, key_name
, 0, NULL
, 0, KEY_WRITE
,
285 if(lr
!= ERROR_SUCCESS
){
286 ERR("RegCreateKeyEx(%s) failed: %lu\n", wine_dbgstr_w(key_name
), lr
);
290 lr
= RegSetValueExW(key
, guidW
, 0, REG_BINARY
, (BYTE
*)guid
,
292 if(lr
!= ERROR_SUCCESS
)
293 ERR("RegSetValueEx(%s\\guid) failed: %lu\n", wine_dbgstr_w(key_name
), lr
);
298 RegCloseKey(drv_key
);
301 static void get_device_guid(EDataFlow flow
, const char *device
, GUID
*guid
)
303 HKEY key
= NULL
, dev_key
;
304 DWORD type
, size
= sizeof(*guid
);
312 MultiByteToWideChar(CP_UNIXCP
, 0, device
, -1, key_name
+ 2, ARRAY_SIZE(key_name
) - 2);
314 if(RegOpenKeyExW(HKEY_CURRENT_USER
, drv_key_devicesW
, 0, KEY_WRITE
|KEY_READ
, &key
) == ERROR_SUCCESS
){
315 if(RegOpenKeyExW(key
, key_name
, 0, KEY_READ
, &dev_key
) == ERROR_SUCCESS
){
316 if(RegQueryValueExW(dev_key
, guidW
, 0, &type
,
317 (BYTE
*)guid
, &size
) == ERROR_SUCCESS
){
318 if(type
== REG_BINARY
){
319 RegCloseKey(dev_key
);
323 ERR("Invalid type for device %s GUID: %lu; ignoring and overwriting\n",
324 wine_dbgstr_w(key_name
), type
);
326 RegCloseKey(dev_key
);
332 set_device_guid(flow
, key
, key_name
, guid
);
338 static void set_stream_volumes(ACImpl
*This
)
340 struct set_volumes_params params
;
342 params
.stream
= This
->stream
;
343 params
.master_volume
= (This
->session
->mute
? 0.0f
: This
->session
->master_vol
);
344 params
.volumes
= This
->vols
;
345 params
.session_volumes
= This
->session
->channel_vols
;
346 OSS_CALL(set_volumes
, ¶ms
);
349 static const OSSDevice
*get_ossdevice_from_guid(const GUID
*guid
)
352 LIST_FOR_EACH_ENTRY(dev_item
, &g_devices
, OSSDevice
, entry
)
353 if(IsEqualGUID(guid
, &dev_item
->guid
))
358 static void device_add(OSSDevice
*oss_dev
)
360 if(get_ossdevice_from_guid(&oss_dev
->guid
)) /* already in list */
361 HeapFree(GetProcessHeap(), 0, oss_dev
);
363 list_add_tail(&g_devices
, &oss_dev
->entry
);
366 HRESULT WINAPI
AUDDRV_GetEndpointIDs(EDataFlow flow
, WCHAR
***ids_out
, GUID
**guids_out
,
367 UINT
*num
, UINT
*def_index
)
369 struct get_endpoint_ids_params params
;
374 TRACE("%d %p %p %p %p\n", flow
, ids
, guids
, num
, def_index
);
378 params
.endpoints
= NULL
;
380 HeapFree(GetProcessHeap(), 0, params
.endpoints
);
381 params
.endpoints
= HeapAlloc(GetProcessHeap(), 0, params
.size
);
382 OSS_CALL(get_endpoint_ids
, ¶ms
);
383 }while(params
.result
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
));
385 if(FAILED(params
.result
)) goto end
;
387 ids
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, params
.num
* sizeof(*ids
));
388 guids
= HeapAlloc(GetProcessHeap(), 0, params
.num
* sizeof(*guids
));
390 params
.result
= E_OUTOFMEMORY
;
394 for(i
= 0; i
< params
.num
; i
++){
395 WCHAR
*name
= (WCHAR
*)((char *)params
.endpoints
+ params
.endpoints
[i
].name
);
396 char *device
= (char *)params
.endpoints
+ params
.endpoints
[i
].device
;
397 unsigned int name_size
= (wcslen(name
) + 1) * sizeof(WCHAR
);
398 unsigned int dev_size
= strlen(device
) + 1;
401 ids
[i
] = HeapAlloc(GetProcessHeap(), 0, name_size
);
402 oss_dev
= HeapAlloc(GetProcessHeap(), 0, offsetof(OSSDevice
, devnode
[dev_size
]));
403 if(!ids
[i
] || !oss_dev
){
404 HeapFree(GetProcessHeap(), 0, oss_dev
);
405 params
.result
= E_OUTOFMEMORY
;
408 memcpy(ids
[i
], name
, name_size
);
409 get_device_guid(flow
, device
, guids
+ i
);
411 oss_dev
->flow
= flow
;
412 oss_dev
->guid
= guids
[i
];
413 memcpy(oss_dev
->devnode
, device
, dev_size
);
416 *def_index
= params
.default_idx
;
419 HeapFree(GetProcessHeap(), 0, params
.endpoints
);
420 if(FAILED(params
.result
)){
421 HeapFree(GetProcessHeap(), 0, guids
);
423 for(i
= 0; i
< params
.num
; i
++)
424 HeapFree(GetProcessHeap(), 0, ids
[i
]);
425 HeapFree(GetProcessHeap(), 0, ids
);
433 return params
.result
;
436 HRESULT WINAPI
AUDDRV_GetAudioEndpoint(GUID
*guid
, IMMDevice
*dev
,
440 const OSSDevice
*oss_dev
;
444 TRACE("%s %p %p\n", debugstr_guid(guid
), dev
, out
);
446 oss_dev
= get_ossdevice_from_guid(guid
);
448 WARN("Unknown GUID: %s\n", debugstr_guid(guid
));
449 return AUDCLNT_E_DEVICE_INVALIDATED
;
451 len
= strlen(oss_dev
->devnode
);
452 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, offsetof(ACImpl
, devnode
[len
+ 1]));
454 return E_OUTOFMEMORY
;
456 hr
= CoCreateFreeThreadedMarshaler((IUnknown
*)&This
->IAudioClient3_iface
, &This
->pUnkFTMarshal
);
458 HeapFree(GetProcessHeap(), 0, This
);
462 This
->dataflow
= oss_dev
->flow
;
463 strcpy(This
->devnode
, oss_dev
->devnode
);
465 This
->IAudioClient3_iface
.lpVtbl
= &AudioClient3_Vtbl
;
466 This
->IAudioRenderClient_iface
.lpVtbl
= &AudioRenderClient_Vtbl
;
467 This
->IAudioCaptureClient_iface
.lpVtbl
= &AudioCaptureClient_Vtbl
;
468 This
->IAudioClock_iface
.lpVtbl
= &AudioClock_Vtbl
;
469 This
->IAudioClock2_iface
.lpVtbl
= &AudioClock2_Vtbl
;
470 This
->IAudioStreamVolume_iface
.lpVtbl
= &AudioStreamVolume_Vtbl
;
473 IMMDevice_AddRef(This
->parent
);
475 *out
= (IAudioClient
*)&This
->IAudioClient3_iface
;
476 IAudioClient3_AddRef(&This
->IAudioClient3_iface
);
481 static HRESULT WINAPI
AudioClient_QueryInterface(IAudioClient3
*iface
,
482 REFIID riid
, void **ppv
)
484 ACImpl
*This
= impl_from_IAudioClient3(iface
);
485 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
490 if(IsEqualIID(riid
, &IID_IUnknown
) ||
491 IsEqualIID(riid
, &IID_IAudioClient
) ||
492 IsEqualIID(riid
, &IID_IAudioClient2
) ||
493 IsEqualIID(riid
, &IID_IAudioClient3
))
495 else if(IsEqualIID(riid
, &IID_IMarshal
))
496 return IUnknown_QueryInterface(This
->pUnkFTMarshal
, riid
, ppv
);
498 IUnknown_AddRef((IUnknown
*)*ppv
);
501 WARN("Unknown interface %s\n", debugstr_guid(riid
));
502 return E_NOINTERFACE
;
505 static ULONG WINAPI
AudioClient_AddRef(IAudioClient3
*iface
)
507 ACImpl
*This
= impl_from_IAudioClient3(iface
);
509 ref
= InterlockedIncrement(&This
->ref
);
510 TRACE("(%p) Refcount now %lu\n", This
, ref
);
514 static ULONG WINAPI
AudioClient_Release(IAudioClient3
*iface
)
516 ACImpl
*This
= impl_from_IAudioClient3(iface
);
519 ref
= InterlockedDecrement(&This
->ref
);
520 TRACE("(%p) Refcount now %lu\n", This
, ref
);
522 IAudioClient3_Stop(iface
);
523 IMMDevice_Release(This
->parent
);
524 IUnknown_Release(This
->pUnkFTMarshal
);
526 EnterCriticalSection(&g_sessions_lock
);
527 list_remove(&This
->entry
);
528 LeaveCriticalSection(&g_sessions_lock
);
530 HeapFree(GetProcessHeap(), 0, This
->vols
);
532 stream_release(This
->stream
, This
->timer_thread
);
533 HeapFree(GetProcessHeap(), 0, This
);
538 static void dump_fmt(const WAVEFORMATEX
*fmt
)
540 TRACE("wFormatTag: 0x%x (", fmt
->wFormatTag
);
541 switch(fmt
->wFormatTag
){
542 case WAVE_FORMAT_PCM
:
543 TRACE("WAVE_FORMAT_PCM");
545 case WAVE_FORMAT_IEEE_FLOAT
:
546 TRACE("WAVE_FORMAT_IEEE_FLOAT");
548 case WAVE_FORMAT_EXTENSIBLE
:
549 TRACE("WAVE_FORMAT_EXTENSIBLE");
557 TRACE("nChannels: %u\n", fmt
->nChannels
);
558 TRACE("nSamplesPerSec: %lu\n", fmt
->nSamplesPerSec
);
559 TRACE("nAvgBytesPerSec: %lu\n", fmt
->nAvgBytesPerSec
);
560 TRACE("nBlockAlign: %u\n", fmt
->nBlockAlign
);
561 TRACE("wBitsPerSample: %u\n", fmt
->wBitsPerSample
);
562 TRACE("cbSize: %u\n", fmt
->cbSize
);
564 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
565 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
566 TRACE("dwChannelMask: %08lx\n", fmtex
->dwChannelMask
);
567 TRACE("Samples: %04x\n", fmtex
->Samples
.wReserved
);
568 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex
->SubFormat
));
572 static void session_init_vols(AudioSession
*session
, UINT channels
)
574 if(session
->channel_count
< channels
){
577 if(session
->channel_vols
)
578 session
->channel_vols
= HeapReAlloc(GetProcessHeap(), 0,
579 session
->channel_vols
, sizeof(float) * channels
);
581 session
->channel_vols
= HeapAlloc(GetProcessHeap(), 0,
582 sizeof(float) * channels
);
583 if(!session
->channel_vols
)
586 for(i
= session
->channel_count
; i
< channels
; ++i
)
587 session
->channel_vols
[i
] = 1.f
;
589 session
->channel_count
= channels
;
593 static AudioSession
*create_session(const GUID
*guid
, IMMDevice
*device
,
598 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(AudioSession
));
602 memcpy(&ret
->guid
, guid
, sizeof(GUID
));
604 ret
->device
= device
;
606 list_init(&ret
->clients
);
608 list_add_head(&g_sessions
, &ret
->entry
);
610 session_init_vols(ret
, num_channels
);
612 ret
->master_vol
= 1.f
;
617 /* if channels == 0, then this will return or create a session with
618 * matching dataflow and GUID. otherwise, channels must also match */
619 static HRESULT
get_audio_session(const GUID
*sessionguid
,
620 IMMDevice
*device
, UINT channels
, AudioSession
**out
)
622 AudioSession
*session
;
624 if(!sessionguid
|| IsEqualGUID(sessionguid
, &GUID_NULL
)){
625 *out
= create_session(&GUID_NULL
, device
, channels
);
627 return E_OUTOFMEMORY
;
633 LIST_FOR_EACH_ENTRY(session
, &g_sessions
, AudioSession
, entry
){
634 if(session
->device
== device
&&
635 IsEqualGUID(sessionguid
, &session
->guid
)){
636 session_init_vols(session
, channels
);
643 *out
= create_session(sessionguid
, device
, channels
);
645 return E_OUTOFMEMORY
;
651 static HRESULT WINAPI
AudioClient_Initialize(IAudioClient3
*iface
,
652 AUDCLNT_SHAREMODE mode
, DWORD flags
, REFERENCE_TIME duration
,
653 REFERENCE_TIME period
, const WAVEFORMATEX
*fmt
,
654 const GUID
*sessionguid
)
656 ACImpl
*This
= impl_from_IAudioClient3(iface
);
657 struct create_stream_params params
;
658 stream_handle stream
;
661 TRACE("(%p)->(%x, %lx, %s, %s, %p, %s)\n", This
, mode
, flags
,
662 wine_dbgstr_longlong(duration
), wine_dbgstr_longlong(period
), fmt
, debugstr_guid(sessionguid
));
669 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
672 if(flags
& ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS
|
673 AUDCLNT_STREAMFLAGS_LOOPBACK
|
674 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
|
675 AUDCLNT_STREAMFLAGS_NOPERSIST
|
676 AUDCLNT_STREAMFLAGS_RATEADJUST
|
677 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED
|
678 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE
|
679 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED
|
680 AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY
|
681 AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM
)){
682 FIXME("Unknown flags: %08lx\n", flags
);
686 if(mode
== AUDCLNT_SHAREMODE_SHARED
){
687 period
= DefaultPeriod
;
688 if( duration
< 3 * period
)
689 duration
= 3 * period
;
692 period
= DefaultPeriod
; /* not minimum */
693 if(period
< MinimumPeriod
|| period
> 5000000)
694 return AUDCLNT_E_INVALID_DEVICE_PERIOD
;
695 if(duration
> 20000000) /* the smaller the period, the lower this limit */
696 return AUDCLNT_E_BUFFER_SIZE_ERROR
;
697 if(flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
){
698 if(duration
!= period
)
699 return AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL
;
700 FIXME("EXCLUSIVE mode with EVENTCALLBACK\n");
701 return AUDCLNT_E_DEVICE_IN_USE
;
703 if( duration
< 8 * period
)
704 duration
= 8 * period
; /* may grow above 2s */
708 EnterCriticalSection(&g_sessions_lock
);
711 LeaveCriticalSection(&g_sessions_lock
);
712 return AUDCLNT_E_ALREADY_INITIALIZED
;
716 params
.device
= This
->devnode
;
717 params
.flow
= This
->dataflow
;
719 params
.flags
= flags
;
720 params
.duration
= duration
;
721 params
.period
= period
;
723 params
.channel_count
= NULL
;
724 params
.stream
= &stream
;
726 OSS_CALL(create_stream
, ¶ms
);
727 if(FAILED(params
.result
)){
728 LeaveCriticalSection(&g_sessions_lock
);
729 return params
.result
;
732 This
->channel_count
= fmt
->nChannels
;
733 This
->vols
= HeapAlloc(GetProcessHeap(), 0, This
->channel_count
* sizeof(float));
735 params
.result
= E_OUTOFMEMORY
;
738 for(i
= 0; i
< This
->channel_count
; ++i
)
741 params
.result
= get_audio_session(sessionguid
, This
->parent
, This
->channel_count
,
745 if(FAILED(params
.result
)){
746 stream_release(stream
, NULL
);
747 HeapFree(GetProcessHeap(), 0, This
->vols
);
750 list_add_tail(&This
->session
->clients
, &This
->entry
);
751 This
->stream
= stream
;
752 set_stream_volumes(This
);
755 LeaveCriticalSection(&g_sessions_lock
);
757 return params
.result
;
760 static HRESULT WINAPI
AudioClient_GetBufferSize(IAudioClient3
*iface
,
763 ACImpl
*This
= impl_from_IAudioClient3(iface
);
764 struct get_buffer_size_params params
;
766 TRACE("(%p)->(%p)\n", This
, frames
);
772 return AUDCLNT_E_NOT_INITIALIZED
;
774 params
.stream
= This
->stream
;
775 params
.size
= frames
;
777 OSS_CALL(get_buffer_size
, ¶ms
);
778 TRACE("buffer size: %u\n", *frames
);
780 return params
.result
;
783 static HRESULT WINAPI
AudioClient_GetStreamLatency(IAudioClient3
*iface
,
784 REFERENCE_TIME
*latency
)
786 ACImpl
*This
= impl_from_IAudioClient3(iface
);
787 struct get_latency_params params
;
789 TRACE("(%p)->(%p)\n", This
, latency
);
795 return AUDCLNT_E_NOT_INITIALIZED
;
797 params
.stream
= This
->stream
;
798 params
.latency
= latency
;
799 OSS_CALL(get_latency
, ¶ms
);
801 return params
.result
;
804 static HRESULT WINAPI
AudioClient_GetCurrentPadding(IAudioClient3
*iface
,
807 ACImpl
*This
= impl_from_IAudioClient3(iface
);
808 struct get_current_padding_params params
;
810 TRACE("(%p)->(%p)\n", This
, numpad
);
816 return AUDCLNT_E_NOT_INITIALIZED
;
818 params
.stream
= This
->stream
;
819 params
.padding
= numpad
;
820 OSS_CALL(get_current_padding
, ¶ms
);
821 TRACE("padding: %u\n", *numpad
);
823 return params
.result
;
826 static HRESULT WINAPI
AudioClient_IsFormatSupported(IAudioClient3
*iface
,
827 AUDCLNT_SHAREMODE mode
, const WAVEFORMATEX
*fmt
,
830 ACImpl
*This
= impl_from_IAudioClient3(iface
);
831 struct is_format_supported_params params
;
833 TRACE("(%p)->(%x, %p, %p)\n", This
, mode
, fmt
, out
);
834 if(fmt
) dump_fmt(fmt
);
836 params
.device
= This
->devnode
;
837 params
.flow
= This
->dataflow
;
840 params
.fmt_out
= NULL
;
844 if(mode
== AUDCLNT_SHAREMODE_SHARED
)
845 params
.fmt_out
= CoTaskMemAlloc(sizeof(*params
.fmt_out
));
847 OSS_CALL(is_format_supported
, ¶ms
);
849 if(params
.result
== S_FALSE
)
850 *out
= ¶ms
.fmt_out
->Format
;
852 CoTaskMemFree(params
.fmt_out
);
854 return params
.result
;
857 static HRESULT WINAPI
AudioClient_GetMixFormat(IAudioClient3
*iface
,
860 ACImpl
*This
= impl_from_IAudioClient3(iface
);
861 struct get_mix_format_params params
;
863 TRACE("(%p)->(%p)\n", This
, pwfx
);
869 params
.device
= This
->devnode
;
870 params
.flow
= This
->dataflow
;
871 params
.fmt
= CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE
));
873 return E_OUTOFMEMORY
;
875 OSS_CALL(get_mix_format
, ¶ms
);
877 if(SUCCEEDED(params
.result
)){
878 *pwfx
= ¶ms
.fmt
->Format
;
881 CoTaskMemFree(params
.fmt
);
883 return params
.result
;
886 static HRESULT WINAPI
AudioClient_GetDevicePeriod(IAudioClient3
*iface
,
887 REFERENCE_TIME
*defperiod
, REFERENCE_TIME
*minperiod
)
889 ACImpl
*This
= impl_from_IAudioClient3(iface
);
891 TRACE("(%p)->(%p, %p)\n", This
, defperiod
, minperiod
);
893 if(!defperiod
&& !minperiod
)
897 *defperiod
= DefaultPeriod
;
899 *minperiod
= MinimumPeriod
;
904 static HRESULT WINAPI
AudioClient_Start(IAudioClient3
*iface
)
906 ACImpl
*This
= impl_from_IAudioClient3(iface
);
907 struct start_params params
;
909 TRACE("(%p)\n", This
);
911 EnterCriticalSection(&g_sessions_lock
);
914 LeaveCriticalSection(&g_sessions_lock
);
915 return AUDCLNT_E_NOT_INITIALIZED
;
918 params
.stream
= This
->stream
;
919 OSS_CALL(start
, ¶ms
);
921 if(SUCCEEDED(params
.result
) && !This
->timer_thread
){
922 This
->timer_thread
= CreateThread(NULL
, 0, timer_thread
, This
, 0, NULL
);
923 SetThreadPriority(This
->timer_thread
, THREAD_PRIORITY_TIME_CRITICAL
);
926 LeaveCriticalSection(&g_sessions_lock
);
928 return params
.result
;
931 static HRESULT WINAPI
AudioClient_Stop(IAudioClient3
*iface
)
933 ACImpl
*This
= impl_from_IAudioClient3(iface
);
934 struct stop_params params
;
936 TRACE("(%p)\n", This
);
939 return AUDCLNT_E_NOT_INITIALIZED
;
941 params
.stream
= This
->stream
;
942 OSS_CALL(stop
, ¶ms
);
944 return params
.result
;
947 static HRESULT WINAPI
AudioClient_Reset(IAudioClient3
*iface
)
949 ACImpl
*This
= impl_from_IAudioClient3(iface
);
950 struct reset_params params
;
952 TRACE("(%p)\n", This
);
955 return AUDCLNT_E_NOT_INITIALIZED
;
957 params
.stream
= This
->stream
;
958 OSS_CALL(reset
, ¶ms
);
960 return params
.result
;
963 static HRESULT WINAPI
AudioClient_SetEventHandle(IAudioClient3
*iface
,
966 ACImpl
*This
= impl_from_IAudioClient3(iface
);
967 struct set_event_handle_params params
;
969 TRACE("(%p)->(%p)\n", This
, event
);
975 return AUDCLNT_E_NOT_INITIALIZED
;
977 params
.stream
= This
->stream
;
978 params
.event
= event
;
979 OSS_CALL(set_event_handle
, ¶ms
);
981 return params
.result
;
984 static HRESULT WINAPI
AudioClient_GetService(IAudioClient3
*iface
, REFIID riid
,
987 ACImpl
*This
= impl_from_IAudioClient3(iface
);
989 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
995 EnterCriticalSection(&g_sessions_lock
);
998 LeaveCriticalSection(&g_sessions_lock
);
999 return AUDCLNT_E_NOT_INITIALIZED
;
1002 if(IsEqualIID(riid
, &IID_IAudioRenderClient
)){
1003 if(This
->dataflow
!= eRender
){
1004 LeaveCriticalSection(&g_sessions_lock
);
1005 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1007 IAudioRenderClient_AddRef(&This
->IAudioRenderClient_iface
);
1008 *ppv
= &This
->IAudioRenderClient_iface
;
1009 }else if(IsEqualIID(riid
, &IID_IAudioCaptureClient
)){
1010 if(This
->dataflow
!= eCapture
){
1011 LeaveCriticalSection(&g_sessions_lock
);
1012 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1014 IAudioCaptureClient_AddRef(&This
->IAudioCaptureClient_iface
);
1015 *ppv
= &This
->IAudioCaptureClient_iface
;
1016 }else if(IsEqualIID(riid
, &IID_IAudioClock
)){
1017 IAudioClock_AddRef(&This
->IAudioClock_iface
);
1018 *ppv
= &This
->IAudioClock_iface
;
1019 }else if(IsEqualIID(riid
, &IID_IAudioStreamVolume
)){
1020 IAudioStreamVolume_AddRef(&This
->IAudioStreamVolume_iface
);
1021 *ppv
= &This
->IAudioStreamVolume_iface
;
1022 }else if(IsEqualIID(riid
, &IID_IAudioSessionControl
)){
1023 if(!This
->session_wrapper
){
1024 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1025 if(!This
->session_wrapper
){
1026 LeaveCriticalSection(&g_sessions_lock
);
1027 return E_OUTOFMEMORY
;
1030 IAudioSessionControl2_AddRef(&This
->session_wrapper
->IAudioSessionControl2_iface
);
1032 *ppv
= &This
->session_wrapper
->IAudioSessionControl2_iface
;
1033 }else if(IsEqualIID(riid
, &IID_IChannelAudioVolume
)){
1034 if(!This
->session_wrapper
){
1035 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1036 if(!This
->session_wrapper
){
1037 LeaveCriticalSection(&g_sessions_lock
);
1038 return E_OUTOFMEMORY
;
1041 IChannelAudioVolume_AddRef(&This
->session_wrapper
->IChannelAudioVolume_iface
);
1043 *ppv
= &This
->session_wrapper
->IChannelAudioVolume_iface
;
1044 }else if(IsEqualIID(riid
, &IID_ISimpleAudioVolume
)){
1045 if(!This
->session_wrapper
){
1046 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1047 if(!This
->session_wrapper
){
1048 LeaveCriticalSection(&g_sessions_lock
);
1049 return E_OUTOFMEMORY
;
1052 ISimpleAudioVolume_AddRef(&This
->session_wrapper
->ISimpleAudioVolume_iface
);
1054 *ppv
= &This
->session_wrapper
->ISimpleAudioVolume_iface
;
1058 LeaveCriticalSection(&g_sessions_lock
);
1062 LeaveCriticalSection(&g_sessions_lock
);
1064 FIXME("stub %s\n", debugstr_guid(riid
));
1065 return E_NOINTERFACE
;
1068 static HRESULT WINAPI
AudioClient_IsOffloadCapable(IAudioClient3
*iface
,
1069 AUDIO_STREAM_CATEGORY category
, BOOL
*offload_capable
)
1071 ACImpl
*This
= impl_from_IAudioClient3(iface
);
1073 TRACE("(%p)->(0x%x, %p)\n", This
, category
, offload_capable
);
1075 if(!offload_capable
)
1076 return E_INVALIDARG
;
1078 *offload_capable
= FALSE
;
1083 static HRESULT WINAPI
AudioClient_SetClientProperties(IAudioClient3
*iface
,
1084 const AudioClientProperties
*prop
)
1086 ACImpl
*This
= impl_from_IAudioClient3(iface
);
1087 const Win8AudioClientProperties
*legacy_prop
= (const Win8AudioClientProperties
*)prop
;
1089 TRACE("(%p)->(%p)\n", This
, prop
);
1094 if(legacy_prop
->cbSize
== sizeof(AudioClientProperties
)){
1095 TRACE("{ bIsOffload: %u, eCategory: 0x%x, Options: 0x%x }\n",
1096 legacy_prop
->bIsOffload
,
1097 legacy_prop
->eCategory
,
1099 }else if(legacy_prop
->cbSize
== sizeof(Win8AudioClientProperties
)){
1100 TRACE("{ bIsOffload: %u, eCategory: 0x%x }\n",
1101 legacy_prop
->bIsOffload
,
1102 legacy_prop
->eCategory
);
1104 WARN("Unsupported Size = %d\n", legacy_prop
->cbSize
);
1105 return E_INVALIDARG
;
1109 if(legacy_prop
->bIsOffload
)
1110 return AUDCLNT_E_ENDPOINT_OFFLOAD_NOT_CAPABLE
;
1115 static HRESULT WINAPI
AudioClient_GetBufferSizeLimits(IAudioClient3
*iface
,
1116 const WAVEFORMATEX
*format
, BOOL event_driven
, REFERENCE_TIME
*min_duration
,
1117 REFERENCE_TIME
*max_duration
)
1119 ACImpl
*This
= impl_from_IAudioClient3(iface
);
1121 FIXME("(%p)->(%p, %u, %p, %p)\n", This
, format
, event_driven
, min_duration
, max_duration
);
1126 static HRESULT WINAPI
AudioClient_GetSharedModeEnginePeriod(IAudioClient3
*iface
,
1127 const WAVEFORMATEX
*format
, UINT32
*default_period_frames
, UINT32
*unit_period_frames
,
1128 UINT32
*min_period_frames
, UINT32
*max_period_frames
)
1130 ACImpl
*This
= impl_from_IAudioClient3(iface
);
1132 FIXME("(%p)->(%p, %p, %p, %p, %p)\n", This
, format
, default_period_frames
, unit_period_frames
,
1133 min_period_frames
, max_period_frames
);
1138 static HRESULT WINAPI
AudioClient_GetCurrentSharedModeEnginePeriod(IAudioClient3
*iface
,
1139 WAVEFORMATEX
**cur_format
, UINT32
*cur_period_frames
)
1141 ACImpl
*This
= impl_from_IAudioClient3(iface
);
1143 FIXME("(%p)->(%p, %p)\n", This
, cur_format
, cur_period_frames
);
1148 static HRESULT WINAPI
AudioClient_InitializeSharedAudioStream(IAudioClient3
*iface
,
1149 DWORD flags
, UINT32 period_frames
, const WAVEFORMATEX
*format
,
1150 const GUID
*session_guid
)
1152 ACImpl
*This
= impl_from_IAudioClient3(iface
);
1154 FIXME("(%p)->(0x%lx, %u, %p, %s)\n", This
, flags
, period_frames
, format
, debugstr_guid(session_guid
));
1159 static const IAudioClient3Vtbl AudioClient3_Vtbl
=
1161 AudioClient_QueryInterface
,
1163 AudioClient_Release
,
1164 AudioClient_Initialize
,
1165 AudioClient_GetBufferSize
,
1166 AudioClient_GetStreamLatency
,
1167 AudioClient_GetCurrentPadding
,
1168 AudioClient_IsFormatSupported
,
1169 AudioClient_GetMixFormat
,
1170 AudioClient_GetDevicePeriod
,
1174 AudioClient_SetEventHandle
,
1175 AudioClient_GetService
,
1176 AudioClient_IsOffloadCapable
,
1177 AudioClient_SetClientProperties
,
1178 AudioClient_GetBufferSizeLimits
,
1179 AudioClient_GetSharedModeEnginePeriod
,
1180 AudioClient_GetCurrentSharedModeEnginePeriod
,
1181 AudioClient_InitializeSharedAudioStream
,
1184 static HRESULT WINAPI
AudioRenderClient_QueryInterface(
1185 IAudioRenderClient
*iface
, REFIID riid
, void **ppv
)
1187 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1188 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1194 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1195 IsEqualIID(riid
, &IID_IAudioRenderClient
))
1197 else if(IsEqualIID(riid
, &IID_IMarshal
))
1198 return IUnknown_QueryInterface(This
->pUnkFTMarshal
, riid
, ppv
);
1200 IUnknown_AddRef((IUnknown
*)*ppv
);
1204 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1205 return E_NOINTERFACE
;
1208 static ULONG WINAPI
AudioRenderClient_AddRef(IAudioRenderClient
*iface
)
1210 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1211 return AudioClient_AddRef(&This
->IAudioClient3_iface
);
1214 static ULONG WINAPI
AudioRenderClient_Release(IAudioRenderClient
*iface
)
1216 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1217 return AudioClient_Release(&This
->IAudioClient3_iface
);
1220 static HRESULT WINAPI
AudioRenderClient_GetBuffer(IAudioRenderClient
*iface
,
1221 UINT32 frames
, BYTE
**data
)
1223 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1224 struct get_render_buffer_params params
;
1226 TRACE("(%p)->(%u, %p)\n", This
, frames
, data
);
1233 params
.stream
= This
->stream
;
1234 params
.frames
= frames
;
1236 OSS_CALL(get_render_buffer
, ¶ms
);
1238 return params
.result
;
1241 static HRESULT WINAPI
AudioRenderClient_ReleaseBuffer(
1242 IAudioRenderClient
*iface
, UINT32 written_frames
, DWORD flags
)
1244 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1245 struct release_render_buffer_params params
;
1247 TRACE("(%p)->(%u, %lx)\n", This
, written_frames
, flags
);
1249 params
.stream
= This
->stream
;
1250 params
.written_frames
= written_frames
;
1251 params
.flags
= flags
;
1252 OSS_CALL(release_render_buffer
, ¶ms
);
1254 return params
.result
;
1257 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
= {
1258 AudioRenderClient_QueryInterface
,
1259 AudioRenderClient_AddRef
,
1260 AudioRenderClient_Release
,
1261 AudioRenderClient_GetBuffer
,
1262 AudioRenderClient_ReleaseBuffer
1265 static HRESULT WINAPI
AudioCaptureClient_QueryInterface(
1266 IAudioCaptureClient
*iface
, REFIID riid
, void **ppv
)
1268 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1269 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1275 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1276 IsEqualIID(riid
, &IID_IAudioCaptureClient
))
1278 else if(IsEqualIID(riid
, &IID_IMarshal
))
1279 return IUnknown_QueryInterface(This
->pUnkFTMarshal
, riid
, ppv
);
1281 IUnknown_AddRef((IUnknown
*)*ppv
);
1285 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1286 return E_NOINTERFACE
;
1289 static ULONG WINAPI
AudioCaptureClient_AddRef(IAudioCaptureClient
*iface
)
1291 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1292 return IAudioClient3_AddRef(&This
->IAudioClient3_iface
);
1295 static ULONG WINAPI
AudioCaptureClient_Release(IAudioCaptureClient
*iface
)
1297 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1298 return IAudioClient3_Release(&This
->IAudioClient3_iface
);
1301 static HRESULT WINAPI
AudioCaptureClient_GetBuffer(IAudioCaptureClient
*iface
,
1302 BYTE
**data
, UINT32
*frames
, DWORD
*flags
, UINT64
*devpos
,
1305 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1306 struct get_capture_buffer_params params
;
1308 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This
, data
, frames
, flags
,
1316 if(!frames
|| !flags
)
1319 params
.stream
= This
->stream
;
1321 params
.frames
= frames
;
1322 params
.flags
= (UINT
*)flags
;
1323 params
.devpos
= devpos
;
1324 params
.qpcpos
= qpcpos
;
1325 OSS_CALL(get_capture_buffer
, ¶ms
);
1327 return params
.result
;
1330 static HRESULT WINAPI
AudioCaptureClient_ReleaseBuffer(
1331 IAudioCaptureClient
*iface
, UINT32 done
)
1333 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1334 struct release_capture_buffer_params params
;
1336 TRACE("(%p)->(%u)\n", This
, done
);
1338 params
.stream
= This
->stream
;
1340 OSS_CALL(release_capture_buffer
, ¶ms
);
1342 return params
.result
;
1345 static HRESULT WINAPI
AudioCaptureClient_GetNextPacketSize(
1346 IAudioCaptureClient
*iface
, UINT32
*frames
)
1348 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1349 struct get_next_packet_size_params params
;
1351 TRACE("(%p)->(%p)\n", This
, frames
);
1356 params
.stream
= This
->stream
;
1357 params
.frames
= frames
;
1358 OSS_CALL(get_next_packet_size
, ¶ms
);
1360 return params
.result
;
1363 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
=
1365 AudioCaptureClient_QueryInterface
,
1366 AudioCaptureClient_AddRef
,
1367 AudioCaptureClient_Release
,
1368 AudioCaptureClient_GetBuffer
,
1369 AudioCaptureClient_ReleaseBuffer
,
1370 AudioCaptureClient_GetNextPacketSize
1373 static HRESULT WINAPI
AudioClock_QueryInterface(IAudioClock
*iface
,
1374 REFIID riid
, void **ppv
)
1376 ACImpl
*This
= impl_from_IAudioClock(iface
);
1378 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1384 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClock
))
1386 else if(IsEqualIID(riid
, &IID_IAudioClock2
))
1387 *ppv
= &This
->IAudioClock2_iface
;
1389 IUnknown_AddRef((IUnknown
*)*ppv
);
1393 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1394 return E_NOINTERFACE
;
1397 static ULONG WINAPI
AudioClock_AddRef(IAudioClock
*iface
)
1399 ACImpl
*This
= impl_from_IAudioClock(iface
);
1400 return IAudioClient3_AddRef(&This
->IAudioClient3_iface
);
1403 static ULONG WINAPI
AudioClock_Release(IAudioClock
*iface
)
1405 ACImpl
*This
= impl_from_IAudioClock(iface
);
1406 return IAudioClient3_Release(&This
->IAudioClient3_iface
);
1409 static HRESULT WINAPI
AudioClock_GetFrequency(IAudioClock
*iface
, UINT64
*freq
)
1411 ACImpl
*This
= impl_from_IAudioClock(iface
);
1412 struct get_frequency_params params
;
1414 TRACE("(%p)->(%p)\n", This
, freq
);
1416 params
.stream
= This
->stream
;
1418 OSS_CALL(get_frequency
, ¶ms
);
1420 return params
.result
;
1423 static HRESULT WINAPI
AudioClock_GetPosition(IAudioClock
*iface
, UINT64
*pos
,
1426 ACImpl
*This
= impl_from_IAudioClock(iface
);
1427 struct get_position_params params
;
1429 TRACE("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
1434 params
.stream
= This
->stream
;
1435 params
.device
= FALSE
;
1437 params
.qpctime
= qpctime
;
1438 OSS_CALL(get_position
, ¶ms
);
1440 return params
.result
;
1443 static HRESULT WINAPI
AudioClock_GetCharacteristics(IAudioClock
*iface
,
1446 ACImpl
*This
= impl_from_IAudioClock(iface
);
1448 TRACE("(%p)->(%p)\n", This
, chars
);
1453 *chars
= AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ
;
1458 static const IAudioClockVtbl AudioClock_Vtbl
=
1460 AudioClock_QueryInterface
,
1463 AudioClock_GetFrequency
,
1464 AudioClock_GetPosition
,
1465 AudioClock_GetCharacteristics
1468 static HRESULT WINAPI
AudioClock2_QueryInterface(IAudioClock2
*iface
,
1469 REFIID riid
, void **ppv
)
1471 ACImpl
*This
= impl_from_IAudioClock2(iface
);
1472 return IAudioClock_QueryInterface(&This
->IAudioClock_iface
, riid
, ppv
);
1475 static ULONG WINAPI
AudioClock2_AddRef(IAudioClock2
*iface
)
1477 ACImpl
*This
= impl_from_IAudioClock2(iface
);
1478 return IAudioClient3_AddRef(&This
->IAudioClient3_iface
);
1481 static ULONG WINAPI
AudioClock2_Release(IAudioClock2
*iface
)
1483 ACImpl
*This
= impl_from_IAudioClock2(iface
);
1484 return IAudioClient3_Release(&This
->IAudioClient3_iface
);
1487 static HRESULT WINAPI
AudioClock2_GetDevicePosition(IAudioClock2
*iface
,
1488 UINT64
*pos
, UINT64
*qpctime
)
1490 ACImpl
*This
= impl_from_IAudioClock2(iface
);
1492 FIXME("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
1497 static const IAudioClock2Vtbl AudioClock2_Vtbl
=
1499 AudioClock2_QueryInterface
,
1501 AudioClock2_Release
,
1502 AudioClock2_GetDevicePosition
1505 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
)
1507 AudioSessionWrapper
*ret
;
1509 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1510 sizeof(AudioSessionWrapper
));
1514 ret
->IAudioSessionControl2_iface
.lpVtbl
= &AudioSessionControl2_Vtbl
;
1515 ret
->ISimpleAudioVolume_iface
.lpVtbl
= &SimpleAudioVolume_Vtbl
;
1516 ret
->IChannelAudioVolume_iface
.lpVtbl
= &ChannelAudioVolume_Vtbl
;
1520 ret
->client
= client
;
1522 ret
->session
= client
->session
;
1523 AudioClient_AddRef(&client
->IAudioClient3_iface
);
1529 static HRESULT WINAPI
AudioSessionControl_QueryInterface(
1530 IAudioSessionControl2
*iface
, REFIID riid
, void **ppv
)
1532 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1538 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1539 IsEqualIID(riid
, &IID_IAudioSessionControl
) ||
1540 IsEqualIID(riid
, &IID_IAudioSessionControl2
))
1543 IUnknown_AddRef((IUnknown
*)*ppv
);
1547 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1548 return E_NOINTERFACE
;
1551 static ULONG WINAPI
AudioSessionControl_AddRef(IAudioSessionControl2
*iface
)
1553 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1555 ref
= InterlockedIncrement(&This
->ref
);
1556 TRACE("(%p) Refcount now %lu\n", This
, ref
);
1560 static ULONG WINAPI
AudioSessionControl_Release(IAudioSessionControl2
*iface
)
1562 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1564 ref
= InterlockedDecrement(&This
->ref
);
1565 TRACE("(%p) Refcount now %lu\n", This
, ref
);
1568 EnterCriticalSection(&g_sessions_lock
);
1569 This
->client
->session_wrapper
= NULL
;
1570 LeaveCriticalSection(&g_sessions_lock
);
1571 AudioClient_Release(&This
->client
->IAudioClient3_iface
);
1573 HeapFree(GetProcessHeap(), 0, This
);
1578 static HRESULT WINAPI
AudioSessionControl_GetState(IAudioSessionControl2
*iface
,
1579 AudioSessionState
*state
)
1581 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1582 struct is_started_params params
;
1585 TRACE("(%p)->(%p)\n", This
, state
);
1588 return NULL_PTR_ERR
;
1590 EnterCriticalSection(&g_sessions_lock
);
1592 if(list_empty(&This
->session
->clients
)){
1593 *state
= AudioSessionStateExpired
;
1594 LeaveCriticalSection(&g_sessions_lock
);
1598 LIST_FOR_EACH_ENTRY(client
, &This
->session
->clients
, ACImpl
, entry
){
1599 params
.stream
= client
->stream
;
1600 OSS_CALL(is_started
, ¶ms
);
1601 if(params
.result
== S_OK
){
1602 *state
= AudioSessionStateActive
;
1603 LeaveCriticalSection(&g_sessions_lock
);
1608 LeaveCriticalSection(&g_sessions_lock
);
1610 *state
= AudioSessionStateInactive
;
1615 static HRESULT WINAPI
AudioSessionControl_GetDisplayName(
1616 IAudioSessionControl2
*iface
, WCHAR
**name
)
1618 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1620 FIXME("(%p)->(%p) - stub\n", This
, name
);
1625 static HRESULT WINAPI
AudioSessionControl_SetDisplayName(
1626 IAudioSessionControl2
*iface
, const WCHAR
*name
, const GUID
*session
)
1628 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1630 FIXME("(%p)->(%p, %s) - stub\n", This
, name
, debugstr_guid(session
));
1635 static HRESULT WINAPI
AudioSessionControl_GetIconPath(
1636 IAudioSessionControl2
*iface
, WCHAR
**path
)
1638 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1640 FIXME("(%p)->(%p) - stub\n", This
, path
);
1645 static HRESULT WINAPI
AudioSessionControl_SetIconPath(
1646 IAudioSessionControl2
*iface
, const WCHAR
*path
, const GUID
*session
)
1648 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1650 FIXME("(%p)->(%p, %s) - stub\n", This
, path
, debugstr_guid(session
));
1655 static HRESULT WINAPI
AudioSessionControl_GetGroupingParam(
1656 IAudioSessionControl2
*iface
, GUID
*group
)
1658 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1660 FIXME("(%p)->(%p) - stub\n", This
, group
);
1665 static HRESULT WINAPI
AudioSessionControl_SetGroupingParam(
1666 IAudioSessionControl2
*iface
, const GUID
*group
, const GUID
*session
)
1668 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1670 FIXME("(%p)->(%s, %s) - stub\n", This
, debugstr_guid(group
),
1671 debugstr_guid(session
));
1676 static HRESULT WINAPI
AudioSessionControl_RegisterAudioSessionNotification(
1677 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
1679 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1681 FIXME("(%p)->(%p) - stub\n", This
, events
);
1686 static HRESULT WINAPI
AudioSessionControl_UnregisterAudioSessionNotification(
1687 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
1689 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1691 FIXME("(%p)->(%p) - stub\n", This
, events
);
1696 static HRESULT WINAPI
AudioSessionControl_GetSessionIdentifier(
1697 IAudioSessionControl2
*iface
, WCHAR
**id
)
1699 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1701 FIXME("(%p)->(%p) - stub\n", This
, id
);
1706 static HRESULT WINAPI
AudioSessionControl_GetSessionInstanceIdentifier(
1707 IAudioSessionControl2
*iface
, WCHAR
**id
)
1709 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1711 FIXME("(%p)->(%p) - stub\n", This
, id
);
1716 static HRESULT WINAPI
AudioSessionControl_GetProcessId(
1717 IAudioSessionControl2
*iface
, DWORD
*pid
)
1719 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1721 TRACE("(%p)->(%p)\n", This
, pid
);
1726 *pid
= GetCurrentProcessId();
1731 static HRESULT WINAPI
AudioSessionControl_IsSystemSoundsSession(
1732 IAudioSessionControl2
*iface
)
1734 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1736 TRACE("(%p)\n", This
);
1741 static HRESULT WINAPI
AudioSessionControl_SetDuckingPreference(
1742 IAudioSessionControl2
*iface
, BOOL optout
)
1744 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
1746 TRACE("(%p)->(%d)\n", This
, optout
);
1751 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
=
1753 AudioSessionControl_QueryInterface
,
1754 AudioSessionControl_AddRef
,
1755 AudioSessionControl_Release
,
1756 AudioSessionControl_GetState
,
1757 AudioSessionControl_GetDisplayName
,
1758 AudioSessionControl_SetDisplayName
,
1759 AudioSessionControl_GetIconPath
,
1760 AudioSessionControl_SetIconPath
,
1761 AudioSessionControl_GetGroupingParam
,
1762 AudioSessionControl_SetGroupingParam
,
1763 AudioSessionControl_RegisterAudioSessionNotification
,
1764 AudioSessionControl_UnregisterAudioSessionNotification
,
1765 AudioSessionControl_GetSessionIdentifier
,
1766 AudioSessionControl_GetSessionInstanceIdentifier
,
1767 AudioSessionControl_GetProcessId
,
1768 AudioSessionControl_IsSystemSoundsSession
,
1769 AudioSessionControl_SetDuckingPreference
1772 static HRESULT WINAPI
SimpleAudioVolume_QueryInterface(
1773 ISimpleAudioVolume
*iface
, REFIID riid
, void **ppv
)
1775 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1781 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1782 IsEqualIID(riid
, &IID_ISimpleAudioVolume
))
1785 IUnknown_AddRef((IUnknown
*)*ppv
);
1789 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1790 return E_NOINTERFACE
;
1793 static ULONG WINAPI
SimpleAudioVolume_AddRef(ISimpleAudioVolume
*iface
)
1795 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
1796 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
1799 static ULONG WINAPI
SimpleAudioVolume_Release(ISimpleAudioVolume
*iface
)
1801 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
1802 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
1805 static HRESULT WINAPI
SimpleAudioVolume_SetMasterVolume(
1806 ISimpleAudioVolume
*iface
, float level
, const GUID
*context
)
1808 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
1809 AudioSession
*session
= This
->session
;
1812 TRACE("(%p)->(%f, %s)\n", session
, level
, wine_dbgstr_guid(context
));
1814 if(level
< 0.f
|| level
> 1.f
)
1815 return E_INVALIDARG
;
1818 FIXME("Notifications not supported yet\n");
1820 EnterCriticalSection(&g_sessions_lock
);
1822 session
->master_vol
= level
;
1824 TRACE("OSS doesn't support setting volume\n");
1825 LIST_FOR_EACH_ENTRY(client
, &session
->clients
, ACImpl
, entry
)
1826 set_stream_volumes(client
);
1828 LeaveCriticalSection(&g_sessions_lock
);
1833 static HRESULT WINAPI
SimpleAudioVolume_GetMasterVolume(
1834 ISimpleAudioVolume
*iface
, float *level
)
1836 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
1837 AudioSession
*session
= This
->session
;
1839 TRACE("(%p)->(%p)\n", session
, level
);
1842 return NULL_PTR_ERR
;
1844 *level
= session
->master_vol
;
1849 static HRESULT WINAPI
SimpleAudioVolume_SetMute(ISimpleAudioVolume
*iface
,
1850 BOOL mute
, const GUID
*context
)
1852 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
1853 AudioSession
*session
= This
->session
;
1856 TRACE("(%p)->(%u, %s)\n", session
, mute
, debugstr_guid(context
));
1858 EnterCriticalSection(&g_sessions_lock
);
1860 session
->mute
= mute
;
1862 LIST_FOR_EACH_ENTRY(client
, &session
->clients
, ACImpl
, entry
)
1863 set_stream_volumes(client
);
1865 LeaveCriticalSection(&g_sessions_lock
);
1870 static HRESULT WINAPI
SimpleAudioVolume_GetMute(ISimpleAudioVolume
*iface
,
1873 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
1874 AudioSession
*session
= This
->session
;
1876 TRACE("(%p)->(%p)\n", session
, mute
);
1879 return NULL_PTR_ERR
;
1881 *mute
= This
->session
->mute
;
1886 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
=
1888 SimpleAudioVolume_QueryInterface
,
1889 SimpleAudioVolume_AddRef
,
1890 SimpleAudioVolume_Release
,
1891 SimpleAudioVolume_SetMasterVolume
,
1892 SimpleAudioVolume_GetMasterVolume
,
1893 SimpleAudioVolume_SetMute
,
1894 SimpleAudioVolume_GetMute
1897 static HRESULT WINAPI
AudioStreamVolume_QueryInterface(
1898 IAudioStreamVolume
*iface
, REFIID riid
, void **ppv
)
1900 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1906 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1907 IsEqualIID(riid
, &IID_IAudioStreamVolume
))
1910 IUnknown_AddRef((IUnknown
*)*ppv
);
1914 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1915 return E_NOINTERFACE
;
1918 static ULONG WINAPI
AudioStreamVolume_AddRef(IAudioStreamVolume
*iface
)
1920 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
1921 return IAudioClient3_AddRef(&This
->IAudioClient3_iface
);
1924 static ULONG WINAPI
AudioStreamVolume_Release(IAudioStreamVolume
*iface
)
1926 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
1927 return IAudioClient3_Release(&This
->IAudioClient3_iface
);
1930 static HRESULT WINAPI
AudioStreamVolume_GetChannelCount(
1931 IAudioStreamVolume
*iface
, UINT32
*out
)
1933 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
1935 TRACE("(%p)->(%p)\n", This
, out
);
1940 *out
= This
->channel_count
;
1945 static HRESULT WINAPI
AudioStreamVolume_SetChannelVolume(
1946 IAudioStreamVolume
*iface
, UINT32 index
, float level
)
1948 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
1950 TRACE("(%p)->(%d, %f)\n", This
, index
, level
);
1952 if(level
< 0.f
|| level
> 1.f
)
1953 return E_INVALIDARG
;
1955 if(index
>= This
->channel_count
)
1956 return E_INVALIDARG
;
1958 EnterCriticalSection(&g_sessions_lock
);
1960 This
->vols
[index
] = level
;
1962 TRACE("OSS doesn't support setting volume\n");
1963 set_stream_volumes(This
);
1965 LeaveCriticalSection(&g_sessions_lock
);
1970 static HRESULT WINAPI
AudioStreamVolume_GetChannelVolume(
1971 IAudioStreamVolume
*iface
, UINT32 index
, float *level
)
1973 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
1975 TRACE("(%p)->(%d, %p)\n", This
, index
, level
);
1980 if(index
>= This
->channel_count
)
1981 return E_INVALIDARG
;
1983 *level
= This
->vols
[index
];
1988 static HRESULT WINAPI
AudioStreamVolume_SetAllVolumes(
1989 IAudioStreamVolume
*iface
, UINT32 count
, const float *levels
)
1991 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
1994 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
1999 if(count
!= This
->channel_count
)
2000 return E_INVALIDARG
;
2002 EnterCriticalSection(&g_sessions_lock
);
2004 for(i
= 0; i
< count
; ++i
)
2005 This
->vols
[i
] = levels
[i
];
2007 TRACE("OSS doesn't support setting volume\n");
2008 set_stream_volumes(This
);
2010 LeaveCriticalSection(&g_sessions_lock
);
2015 static HRESULT WINAPI
AudioStreamVolume_GetAllVolumes(
2016 IAudioStreamVolume
*iface
, UINT32 count
, float *levels
)
2018 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2021 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2026 if(count
!= This
->channel_count
)
2027 return E_INVALIDARG
;
2029 EnterCriticalSection(&g_sessions_lock
);
2031 for(i
= 0; i
< count
; ++i
)
2032 levels
[i
] = This
->vols
[i
];
2034 LeaveCriticalSection(&g_sessions_lock
);
2039 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
=
2041 AudioStreamVolume_QueryInterface
,
2042 AudioStreamVolume_AddRef
,
2043 AudioStreamVolume_Release
,
2044 AudioStreamVolume_GetChannelCount
,
2045 AudioStreamVolume_SetChannelVolume
,
2046 AudioStreamVolume_GetChannelVolume
,
2047 AudioStreamVolume_SetAllVolumes
,
2048 AudioStreamVolume_GetAllVolumes
2051 static HRESULT WINAPI
ChannelAudioVolume_QueryInterface(
2052 IChannelAudioVolume
*iface
, REFIID riid
, void **ppv
)
2054 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2060 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2061 IsEqualIID(riid
, &IID_IChannelAudioVolume
))
2064 IUnknown_AddRef((IUnknown
*)*ppv
);
2068 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2069 return E_NOINTERFACE
;
2072 static ULONG WINAPI
ChannelAudioVolume_AddRef(IChannelAudioVolume
*iface
)
2074 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2075 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2078 static ULONG WINAPI
ChannelAudioVolume_Release(IChannelAudioVolume
*iface
)
2080 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2081 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2084 static HRESULT WINAPI
ChannelAudioVolume_GetChannelCount(
2085 IChannelAudioVolume
*iface
, UINT32
*out
)
2087 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2088 AudioSession
*session
= This
->session
;
2090 TRACE("(%p)->(%p)\n", session
, out
);
2093 return NULL_PTR_ERR
;
2095 *out
= session
->channel_count
;
2100 static HRESULT WINAPI
ChannelAudioVolume_SetChannelVolume(
2101 IChannelAudioVolume
*iface
, UINT32 index
, float level
,
2102 const GUID
*context
)
2104 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2105 AudioSession
*session
= This
->session
;
2108 TRACE("(%p)->(%d, %f, %s)\n", session
, index
, level
,
2109 wine_dbgstr_guid(context
));
2111 if(level
< 0.f
|| level
> 1.f
)
2112 return E_INVALIDARG
;
2114 if(index
>= session
->channel_count
)
2115 return E_INVALIDARG
;
2118 FIXME("Notifications not supported yet\n");
2120 EnterCriticalSection(&g_sessions_lock
);
2122 session
->channel_vols
[index
] = level
;
2124 TRACE("OSS doesn't support setting volume\n");
2125 LIST_FOR_EACH_ENTRY(client
, &session
->clients
, ACImpl
, entry
)
2126 set_stream_volumes(client
);
2128 LeaveCriticalSection(&g_sessions_lock
);
2133 static HRESULT WINAPI
ChannelAudioVolume_GetChannelVolume(
2134 IChannelAudioVolume
*iface
, UINT32 index
, float *level
)
2136 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2137 AudioSession
*session
= This
->session
;
2139 TRACE("(%p)->(%d, %p)\n", session
, index
, level
);
2142 return NULL_PTR_ERR
;
2144 if(index
>= session
->channel_count
)
2145 return E_INVALIDARG
;
2147 *level
= session
->channel_vols
[index
];
2152 static HRESULT WINAPI
ChannelAudioVolume_SetAllVolumes(
2153 IChannelAudioVolume
*iface
, UINT32 count
, const float *levels
,
2154 const GUID
*context
)
2156 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2157 AudioSession
*session
= This
->session
;
2161 TRACE("(%p)->(%d, %p, %s)\n", session
, count
, levels
,
2162 wine_dbgstr_guid(context
));
2165 return NULL_PTR_ERR
;
2167 if(count
!= session
->channel_count
)
2168 return E_INVALIDARG
;
2171 FIXME("Notifications not supported yet\n");
2173 EnterCriticalSection(&g_sessions_lock
);
2175 for(i
= 0; i
< count
; ++i
)
2176 session
->channel_vols
[i
] = levels
[i
];
2178 TRACE("OSS doesn't support setting volume\n");
2179 LIST_FOR_EACH_ENTRY(client
, &session
->clients
, ACImpl
, entry
)
2180 set_stream_volumes(client
);
2182 LeaveCriticalSection(&g_sessions_lock
);
2187 static HRESULT WINAPI
ChannelAudioVolume_GetAllVolumes(
2188 IChannelAudioVolume
*iface
, UINT32 count
, float *levels
)
2190 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2191 AudioSession
*session
= This
->session
;
2194 TRACE("(%p)->(%d, %p)\n", session
, count
, levels
);
2197 return NULL_PTR_ERR
;
2199 if(count
!= session
->channel_count
)
2200 return E_INVALIDARG
;
2202 for(i
= 0; i
< count
; ++i
)
2203 levels
[i
] = session
->channel_vols
[i
];
2208 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
=
2210 ChannelAudioVolume_QueryInterface
,
2211 ChannelAudioVolume_AddRef
,
2212 ChannelAudioVolume_Release
,
2213 ChannelAudioVolume_GetChannelCount
,
2214 ChannelAudioVolume_SetChannelVolume
,
2215 ChannelAudioVolume_GetChannelVolume
,
2216 ChannelAudioVolume_SetAllVolumes
,
2217 ChannelAudioVolume_GetAllVolumes
2220 static HRESULT WINAPI
AudioSessionManager_QueryInterface(IAudioSessionManager2
*iface
,
2221 REFIID riid
, void **ppv
)
2223 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2229 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2230 IsEqualIID(riid
, &IID_IAudioSessionManager
) ||
2231 IsEqualIID(riid
, &IID_IAudioSessionManager2
))
2234 IUnknown_AddRef((IUnknown
*)*ppv
);
2238 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2239 return E_NOINTERFACE
;
2242 static ULONG WINAPI
AudioSessionManager_AddRef(IAudioSessionManager2
*iface
)
2244 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2246 ref
= InterlockedIncrement(&This
->ref
);
2247 TRACE("(%p) Refcount now %lu\n", This
, ref
);
2251 static ULONG WINAPI
AudioSessionManager_Release(IAudioSessionManager2
*iface
)
2253 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2255 ref
= InterlockedDecrement(&This
->ref
);
2256 TRACE("(%p) Refcount now %lu\n", This
, ref
);
2258 HeapFree(GetProcessHeap(), 0, This
);
2262 static HRESULT WINAPI
AudioSessionManager_GetAudioSessionControl(
2263 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2264 IAudioSessionControl
**out
)
2266 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2267 AudioSession
*session
;
2268 AudioSessionWrapper
*wrapper
;
2271 TRACE("(%p)->(%s, %lx, %p)\n", This
, debugstr_guid(session_guid
),
2274 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2278 wrapper
= AudioSessionWrapper_Create(NULL
);
2280 return E_OUTOFMEMORY
;
2282 wrapper
->session
= session
;
2284 *out
= (IAudioSessionControl
*)&wrapper
->IAudioSessionControl2_iface
;
2289 static HRESULT WINAPI
AudioSessionManager_GetSimpleAudioVolume(
2290 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2291 ISimpleAudioVolume
**out
)
2293 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2294 AudioSession
*session
;
2295 AudioSessionWrapper
*wrapper
;
2298 TRACE("(%p)->(%s, %lx, %p)\n", This
, debugstr_guid(session_guid
),
2301 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2305 wrapper
= AudioSessionWrapper_Create(NULL
);
2307 return E_OUTOFMEMORY
;
2309 wrapper
->session
= session
;
2311 *out
= &wrapper
->ISimpleAudioVolume_iface
;
2316 static HRESULT WINAPI
AudioSessionManager_GetSessionEnumerator(
2317 IAudioSessionManager2
*iface
, IAudioSessionEnumerator
**out
)
2319 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2320 FIXME("(%p)->(%p) - stub\n", This
, out
);
2324 static HRESULT WINAPI
AudioSessionManager_RegisterSessionNotification(
2325 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2327 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2328 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2332 static HRESULT WINAPI
AudioSessionManager_UnregisterSessionNotification(
2333 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2335 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2336 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2340 static HRESULT WINAPI
AudioSessionManager_RegisterDuckNotification(
2341 IAudioSessionManager2
*iface
, const WCHAR
*session_id
,
2342 IAudioVolumeDuckNotification
*notification
)
2344 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2345 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2349 static HRESULT WINAPI
AudioSessionManager_UnregisterDuckNotification(
2350 IAudioSessionManager2
*iface
,
2351 IAudioVolumeDuckNotification
*notification
)
2353 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2354 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2358 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
=
2360 AudioSessionManager_QueryInterface
,
2361 AudioSessionManager_AddRef
,
2362 AudioSessionManager_Release
,
2363 AudioSessionManager_GetAudioSessionControl
,
2364 AudioSessionManager_GetSimpleAudioVolume
,
2365 AudioSessionManager_GetSessionEnumerator
,
2366 AudioSessionManager_RegisterSessionNotification
,
2367 AudioSessionManager_UnregisterSessionNotification
,
2368 AudioSessionManager_RegisterDuckNotification
,
2369 AudioSessionManager_UnregisterDuckNotification
2372 HRESULT WINAPI
AUDDRV_GetAudioSessionManager(IMMDevice
*device
,
2373 IAudioSessionManager2
**out
)
2377 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SessionMgr
));
2379 return E_OUTOFMEMORY
;
2381 This
->IAudioSessionManager2_iface
.lpVtbl
= &AudioSessionManager2_Vtbl
;
2382 This
->device
= device
;
2385 *out
= &This
->IAudioSessionManager2_iface
;