2 * Copyright 2010 Maarten Lankhorst for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
30 #include "mmdeviceapi.h"
33 #include "audioclient.h"
34 #include "endpointvolume.h"
35 #include "audiopolicy.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
41 typedef struct AEVImpl
{
42 IAudioEndpointVolumeEx IAudioEndpointVolumeEx_iface
;
48 static inline AEVImpl
*impl_from_IAudioEndpointVolumeEx(IAudioEndpointVolumeEx
*iface
)
50 return CONTAINING_RECORD(iface
, AEVImpl
, IAudioEndpointVolumeEx_iface
);
53 static void AudioEndpointVolume_Destroy(AEVImpl
*This
)
55 HeapFree(GetProcessHeap(), 0, This
);
58 static HRESULT WINAPI
AEV_QueryInterface(IAudioEndpointVolumeEx
*iface
, REFIID riid
, void **ppv
)
60 AEVImpl
*This
= impl_from_IAudioEndpointVolumeEx(iface
);
61 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppv
);
65 if (IsEqualIID(riid
, &IID_IUnknown
) ||
66 IsEqualIID(riid
, &IID_IAudioEndpointVolume
) ||
67 IsEqualIID(riid
, &IID_IAudioEndpointVolumeEx
)) {
68 *ppv
= &This
->IAudioEndpointVolumeEx_iface
;
72 IUnknown_AddRef((IUnknown
*)*ppv
);
76 static ULONG WINAPI
AEV_AddRef(IAudioEndpointVolumeEx
*iface
)
78 AEVImpl
*This
= impl_from_IAudioEndpointVolumeEx(iface
);
79 ULONG ref
= InterlockedIncrement(&This
->ref
);
80 TRACE("(%p) new ref %u\n", This
, ref
);
84 static ULONG WINAPI
AEV_Release(IAudioEndpointVolumeEx
*iface
)
86 AEVImpl
*This
= impl_from_IAudioEndpointVolumeEx(iface
);
87 ULONG ref
= InterlockedDecrement(&This
->ref
);
88 TRACE("(%p) new ref %u\n", This
, ref
);
90 AudioEndpointVolume_Destroy(This
);
94 static HRESULT WINAPI
AEV_RegisterControlChangeNotify(IAudioEndpointVolumeEx
*iface
, IAudioEndpointVolumeCallback
*notify
)
96 TRACE("(%p)->(%p)\n", iface
, notify
);
103 static HRESULT WINAPI
AEV_UnregisterControlChangeNotify(IAudioEndpointVolumeEx
*iface
, IAudioEndpointVolumeCallback
*notify
)
105 TRACE("(%p)->(%p)\n", iface
, notify
);
112 static HRESULT WINAPI
AEV_GetChannelCount(IAudioEndpointVolumeEx
*iface
, UINT
*count
)
114 TRACE("(%p)->(%p)\n", iface
, count
);
121 static HRESULT WINAPI
AEV_SetMasterVolumeLevel(IAudioEndpointVolumeEx
*iface
, float leveldb
, const GUID
*ctx
)
123 AEVImpl
*This
= impl_from_IAudioEndpointVolumeEx(iface
);
125 TRACE("(%p)->(%f,%s)\n", iface
, leveldb
, debugstr_guid(ctx
));
127 if(leveldb
< -100.f
|| leveldb
> 0.f
)
130 This
->master_vol
= leveldb
;
135 static HRESULT WINAPI
AEV_SetMasterVolumeLevelScalar(IAudioEndpointVolumeEx
*iface
, float level
, const GUID
*ctx
)
137 TRACE("(%p)->(%f,%s)\n", iface
, level
, debugstr_guid(ctx
));
142 static HRESULT WINAPI
AEV_GetMasterVolumeLevel(IAudioEndpointVolumeEx
*iface
, float *leveldb
)
144 AEVImpl
*This
= impl_from_IAudioEndpointVolumeEx(iface
);
146 TRACE("(%p)->(%p)\n", iface
, leveldb
);
151 *leveldb
= This
->master_vol
;
156 static HRESULT WINAPI
AEV_GetMasterVolumeLevelScalar(IAudioEndpointVolumeEx
*iface
, float *level
)
158 TRACE("(%p)->(%p)\n", iface
, level
);
166 static HRESULT WINAPI
AEV_SetChannelVolumeLevel(IAudioEndpointVolumeEx
*iface
, UINT chan
, float leveldb
, const GUID
*ctx
)
168 TRACE("(%p)->(%f,%s)\n", iface
, leveldb
, debugstr_guid(ctx
));
173 static HRESULT WINAPI
AEV_SetChannelVolumeLevelScalar(IAudioEndpointVolumeEx
*iface
, UINT chan
, float level
, const GUID
*ctx
)
175 TRACE("(%p)->(%u,%f,%s)\n", iface
, chan
, level
, debugstr_guid(ctx
));
180 static HRESULT WINAPI
AEV_GetChannelVolumeLevel(IAudioEndpointVolumeEx
*iface
, UINT chan
, float *leveldb
)
182 TRACE("(%p)->(%u,%p)\n", iface
, chan
, leveldb
);
189 static HRESULT WINAPI
AEV_GetChannelVolumeLevelScalar(IAudioEndpointVolumeEx
*iface
, UINT chan
, float *level
)
191 TRACE("(%p)->(%u,%p)\n", iface
, chan
, level
);
198 static HRESULT WINAPI
AEV_SetMute(IAudioEndpointVolumeEx
*iface
, BOOL mute
, const GUID
*ctx
)
200 AEVImpl
*This
= impl_from_IAudioEndpointVolumeEx(iface
);
203 TRACE("(%p)->(%u,%s)\n", iface
, mute
, debugstr_guid(ctx
));
205 ret
= This
->mute
== mute
? S_FALSE
: S_OK
;
212 static HRESULT WINAPI
AEV_GetMute(IAudioEndpointVolumeEx
*iface
, BOOL
*mute
)
214 AEVImpl
*This
= impl_from_IAudioEndpointVolumeEx(iface
);
216 TRACE("(%p)->(%p)\n", iface
, mute
);
226 static HRESULT WINAPI
AEV_GetVolumeStepInfo(IAudioEndpointVolumeEx
*iface
, UINT
*stepsize
, UINT
*stepcount
)
228 TRACE("(%p)->(%p,%p)\n", iface
, stepsize
, stepcount
);
229 if (!stepsize
&& !stepcount
)
235 static HRESULT WINAPI
AEV_VolumeStepUp(IAudioEndpointVolumeEx
*iface
, const GUID
*ctx
)
237 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(ctx
));
242 static HRESULT WINAPI
AEV_VolumeStepDown(IAudioEndpointVolumeEx
*iface
, const GUID
*ctx
)
244 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(ctx
));
249 static HRESULT WINAPI
AEV_QueryHardwareSupport(IAudioEndpointVolumeEx
*iface
, DWORD
*mask
)
251 TRACE("(%p)->(%p)\n", iface
, mask
);
258 static HRESULT WINAPI
AEV_GetVolumeRange(IAudioEndpointVolumeEx
*iface
, float *mindb
, float *maxdb
, float *inc
)
260 TRACE("(%p)->(%p,%p,%p)\n", iface
, mindb
, maxdb
, inc
);
262 if (!mindb
|| !maxdb
|| !inc
)
272 static HRESULT WINAPI
AEV_GetVolumeRangeChannel(IAudioEndpointVolumeEx
*iface
, UINT chan
, float *mindb
, float *maxdb
, float *inc
)
274 TRACE("(%p)->(%p,%p,%p)\n", iface
, mindb
, maxdb
, inc
);
275 if (!mindb
|| !maxdb
|| !inc
)
281 static const IAudioEndpointVolumeExVtbl AEVImpl_Vtbl
= {
285 AEV_RegisterControlChangeNotify
,
286 AEV_UnregisterControlChangeNotify
,
288 AEV_SetMasterVolumeLevel
,
289 AEV_SetMasterVolumeLevelScalar
,
290 AEV_GetMasterVolumeLevel
,
291 AEV_GetMasterVolumeLevelScalar
,
292 AEV_SetChannelVolumeLevel
,
293 AEV_SetChannelVolumeLevelScalar
,
294 AEV_GetChannelVolumeLevel
,
295 AEV_GetChannelVolumeLevelScalar
,
298 AEV_GetVolumeStepInfo
,
301 AEV_QueryHardwareSupport
,
303 AEV_GetVolumeRangeChannel
306 HRESULT
AudioEndpointVolume_Create(MMDevice
*parent
, IAudioEndpointVolumeEx
**ppv
)
311 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*This
));
313 return E_OUTOFMEMORY
;
314 This
->IAudioEndpointVolumeEx_iface
.lpVtbl
= &AEVImpl_Vtbl
;
317 *ppv
= &This
->IAudioEndpointVolumeEx_iface
;