2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <audiopolicy.h>
20 #include <mmdeviceapi.h>
22 #include <wine/debug.h>
23 #include <wine/list.h>
25 #include "mmdevapi_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
29 extern HRESULT
get_audio_session_wrapper(const GUID
*guid
, IMMDevice
*device
,
30 struct audio_session_wrapper
**out
);
32 static CRITICAL_SECTION g_sessions_lock
;
33 static CRITICAL_SECTION_DEBUG g_sessions_lock_debug
=
35 0, 0, &g_sessions_lock
,
36 { &g_sessions_lock_debug
.ProcessLocksList
, &g_sessions_lock_debug
.ProcessLocksList
},
37 0, 0, { (DWORD_PTR
)(__FILE__
": g_sessions_lock") }
39 static CRITICAL_SECTION g_sessions_lock
= { &g_sessions_lock_debug
, -1, 0, 0, 0, 0 };
41 void sessions_lock(void)
43 EnterCriticalSection(&g_sessions_lock
);
46 void sessions_unlock(void)
48 LeaveCriticalSection(&g_sessions_lock
);
51 static inline struct session_mgr
*impl_from_IAudioSessionManager2(IAudioSessionManager2
*iface
)
53 return CONTAINING_RECORD(iface
, struct session_mgr
, IAudioSessionManager2_iface
);
56 static HRESULT WINAPI
ASM_QueryInterface(IAudioSessionManager2
*iface
, REFIID riid
, void **ppv
)
58 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
59 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
64 if (IsEqualIID(riid
, &IID_IUnknown
) ||
65 IsEqualIID(riid
, &IID_IAudioSessionManager
) ||
66 IsEqualIID(riid
, &IID_IAudioSessionManager2
))
67 *ppv
= &This
->IAudioSessionManager2_iface
;
73 IUnknown_AddRef((IUnknown
*)*ppv
);
78 static ULONG WINAPI
ASM_AddRef(IAudioSessionManager2
*iface
)
80 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
81 ULONG ref
= InterlockedIncrement(&This
->ref
);
82 TRACE("(%p) new ref %lu\n", This
, ref
);
86 static ULONG WINAPI
ASM_Release(IAudioSessionManager2
*iface
)
88 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
89 ULONG ref
= InterlockedDecrement(&This
->ref
);
90 TRACE("(%p) new ref %lu\n", This
, ref
);
98 static HRESULT WINAPI
ASM_GetAudioSessionControl(IAudioSessionManager2
*iface
,
99 const GUID
*guid
, DWORD flags
,
100 IAudioSessionControl
**out
)
102 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
103 AudioSessionWrapper
*wrapper
;
106 TRACE("(%p)->(%s, %lx, %p)\n", This
, debugstr_guid(guid
), flags
, out
);
108 hr
= get_audio_session_wrapper(guid
, This
->device
, &wrapper
);
112 *out
= (IAudioSessionControl
*)&wrapper
->IAudioSessionControl2_iface
;
117 static HRESULT WINAPI
ASM_GetSimpleAudioVolume(IAudioSessionManager2
*iface
,
118 const GUID
*guid
, DWORD flags
,
119 ISimpleAudioVolume
**out
)
121 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
122 AudioSessionWrapper
*wrapper
;
125 TRACE("(%p)->(%s, %lx, %p)\n", This
, debugstr_guid(guid
), flags
, out
);
127 hr
= get_audio_session_wrapper(guid
, This
->device
, &wrapper
);
131 *out
= &wrapper
->ISimpleAudioVolume_iface
;
136 static HRESULT WINAPI
ASM_GetSessionEnumerator(IAudioSessionManager2
*iface
,
137 IAudioSessionEnumerator
**out
)
139 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
140 FIXME("(%p)->(%p) - stub\n", This
, out
);
144 static HRESULT WINAPI
ASM_RegisterSessionNotification(IAudioSessionManager2
*iface
,
145 IAudioSessionNotification
*notification
)
147 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
148 FIXME("(%p)->(%p) - stub\n", This
, notification
);
152 static HRESULT WINAPI
ASM_UnregisterSessionNotification(IAudioSessionManager2
*iface
,
153 IAudioSessionNotification
*notification
)
155 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
156 FIXME("(%p)->(%p) - stub\n", This
, notification
);
160 static HRESULT WINAPI
ASM_RegisterDuckNotification(IAudioSessionManager2
*iface
,
161 const WCHAR
*session_id
,
162 IAudioVolumeDuckNotification
*notification
)
164 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
165 FIXME("(%p)->(%s, %p) - stub\n", This
, debugstr_w(session_id
), notification
);
169 static HRESULT WINAPI
ASM_UnregisterDuckNotification(IAudioSessionManager2
*iface
,
170 IAudioVolumeDuckNotification
*notification
)
172 struct session_mgr
*This
= impl_from_IAudioSessionManager2(iface
);
173 FIXME("(%p)->(%p) - stub\n", This
, notification
);
177 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
=
182 ASM_GetAudioSessionControl
,
183 ASM_GetSimpleAudioVolume
,
184 ASM_GetSessionEnumerator
,
185 ASM_RegisterSessionNotification
,
186 ASM_UnregisterSessionNotification
,
187 ASM_RegisterDuckNotification
,
188 ASM_UnregisterDuckNotification
191 HRESULT
AudioSessionManager_Create(IMMDevice
*device
, IAudioSessionManager2
**ppv
)
193 struct session_mgr
*This
;
195 This
= calloc(1, sizeof(*This
));
197 return E_OUTOFMEMORY
;
199 This
->IAudioSessionManager2_iface
.lpVtbl
= &AudioSessionManager2_Vtbl
;
200 This
->device
= device
;
203 *ppv
= &This
->IAudioSessionManager2_iface
;