[MMDEVAPI] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / mmdevapi / audiovolume.c
index 845241a..76f9f4e 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#define COBJMACROS
+#include "config.h"
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winnls.h"
+#include "winreg.h"
+#include "wine/debug.h"
+#include "wine/unicode.h"
+
+#include "ole2.h"
+#include "mmdeviceapi.h"
+#include "mmsystem.h"
+#include "dsound.h"
+#include "audioclient.h"
+#include "endpointvolume.h"
+#include "audiopolicy.h"
+
 #include "mmdevapi.h"
 
-static const IAudioEndpointVolumeExVtbl AEVImpl_Vtbl;
+WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
 
 typedef struct AEVImpl {
     IAudioEndpointVolumeEx IAudioEndpointVolumeEx_iface;
     LONG ref;
+    float master_vol;
+    BOOL mute;
 } AEVImpl;
 
 static inline AEVImpl *impl_from_IAudioEndpointVolumeEx(IAudioEndpointVolumeEx *iface)
@@ -30,18 +52,6 @@ static inline AEVImpl *impl_from_IAudioEndpointVolumeEx(IAudioEndpointVolumeEx *
     return CONTAINING_RECORD(iface, AEVImpl, IAudioEndpointVolumeEx_iface);
 }
 
-HRESULT AudioEndpointVolume_Create(MMDevice *parent, IAudioEndpointVolume **ppv)
-{
-    AEVImpl *This;
-    This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
-    *ppv = (IAudioEndpointVolume*)This;
-    if (!This)
-        return E_OUTOFMEMORY;
-    This->IAudioEndpointVolumeEx_iface.lpVtbl = &AEVImpl_Vtbl;
-    This->ref = 1;
-    return S_OK;
-}
-
 static void AudioEndpointVolume_Destroy(AEVImpl *This)
 {
     HeapFree(GetProcessHeap(), 0, This);
@@ -57,7 +67,7 @@ static HRESULT WINAPI AEV_QueryInterface(IAudioEndpointVolumeEx *iface, REFIID r
     if (IsEqualIID(riid, &IID_IUnknown) ||
         IsEqualIID(riid, &IID_IAudioEndpointVolume) ||
         IsEqualIID(riid, &IID_IAudioEndpointVolumeEx)) {
-        *ppv = This;
+        *ppv = &This->IAudioEndpointVolumeEx_iface;
     }
     else
         return E_NOINTERFACE;
@@ -112,9 +122,16 @@ static HRESULT WINAPI AEV_GetChannelCount(IAudioEndpointVolumeEx *iface, UINT *c
 
 static HRESULT WINAPI AEV_SetMasterVolumeLevel(IAudioEndpointVolumeEx *iface, float leveldb, const GUID *ctx)
 {
+    AEVImpl *This = impl_from_IAudioEndpointVolumeEx(iface);
+
     TRACE("(%p)->(%f,%s)\n", iface, leveldb, debugstr_guid(ctx));
-    FIXME("stub\n");
-    return E_NOTIMPL;
+
+    if(leveldb < -100.f || leveldb > 0.f)
+        return E_INVALIDARG;
+
+    This->master_vol = leveldb;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI AEV_SetMasterVolumeLevelScalar(IAudioEndpointVolumeEx *iface, float level, const GUID *ctx)
@@ -126,11 +143,16 @@ static HRESULT WINAPI AEV_SetMasterVolumeLevelScalar(IAudioEndpointVolumeEx *ifa
 
 static HRESULT WINAPI AEV_GetMasterVolumeLevel(IAudioEndpointVolumeEx *iface, float *leveldb)
 {
+    AEVImpl *This = impl_from_IAudioEndpointVolumeEx(iface);
+
     TRACE("(%p)->(%p)\n", iface, leveldb);
+
     if (!leveldb)
         return E_POINTER;
-    FIXME("stub\n");
-    return E_NOTIMPL;
+
+    *leveldb = This->master_vol;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI AEV_GetMasterVolumeLevelScalar(IAudioEndpointVolumeEx *iface, float *level)
@@ -176,18 +198,30 @@ static HRESULT WINAPI AEV_GetChannelVolumeLevelScalar(IAudioEndpointVolumeEx *if
 
 static HRESULT WINAPI AEV_SetMute(IAudioEndpointVolumeEx *iface, BOOL mute, const GUID *ctx)
 {
+    AEVImpl *This = impl_from_IAudioEndpointVolumeEx(iface);
+    HRESULT ret;
+
     TRACE("(%p)->(%u,%s)\n", iface, mute, debugstr_guid(ctx));
-    FIXME("stub\n");
-    return E_NOTIMPL;
+
+    ret = This->mute == mute ? S_FALSE : S_OK;
+
+    This->mute = mute;
+
+    return ret;
 }
 
 static HRESULT WINAPI AEV_GetMute(IAudioEndpointVolumeEx *iface, BOOL *mute)
 {
+    AEVImpl *This = impl_from_IAudioEndpointVolumeEx(iface);
+
     TRACE("(%p)->(%p)\n", iface, mute);
+
     if (!mute)
         return E_POINTER;
-    FIXME("stub\n");
-    return E_NOTIMPL;
+
+    *mute = This->mute;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI AEV_GetVolumeStepInfo(IAudioEndpointVolumeEx *iface, UINT *stepsize, UINT *stepcount)
@@ -225,10 +259,15 @@ static HRESULT WINAPI AEV_QueryHardwareSupport(IAudioEndpointVolumeEx *iface, DW
 static HRESULT WINAPI AEV_GetVolumeRange(IAudioEndpointVolumeEx *iface, float *mindb, float *maxdb, float *inc)
 {
     TRACE("(%p)->(%p,%p,%p)\n", iface, mindb, maxdb, inc);
+
     if (!mindb || !maxdb || !inc)
         return E_POINTER;
-    FIXME("stub\n");
-    return E_NOTIMPL;
+
+    *mindb = -100.f;
+    *maxdb = 0.f;
+    *inc = 1.f;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI AEV_GetVolumeRangeChannel(IAudioEndpointVolumeEx *iface, UINT chan, float *mindb, float *maxdb, float *inc)
@@ -264,3 +303,18 @@ static const IAudioEndpointVolumeExVtbl AEVImpl_Vtbl = {
     AEV_GetVolumeRange,
     AEV_GetVolumeRangeChannel
 };
+
+HRESULT AudioEndpointVolume_Create(MMDevice *parent, IAudioEndpointVolumeEx **ppv)
+{
+    AEVImpl *This;
+
+    *ppv = NULL;
+    This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
+    if (!This)
+        return E_OUTOFMEMORY;
+    This->IAudioEndpointVolumeEx_iface.lpVtbl = &AEVImpl_Vtbl;
+    This->ref = 1;
+
+    *ppv = &This->IAudioEndpointVolumeEx_iface;
+    return S_OK;
+}