2009-12-15 15:35:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Maarten Lankhorst
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define CINTERFACE
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "mmdeviceapi.h"
|
|
|
|
|
|
|
|
#include "mmdevapi.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
|
|
|
|
|
2009-12-14 16:04:04 +01:00
|
|
|
typedef struct MMDevEnumImpl
|
|
|
|
{
|
2010-01-04 22:38:04 +01:00
|
|
|
const IMMDeviceEnumeratorVtbl *lpVtbl;
|
2009-12-14 16:04:04 +01:00
|
|
|
LONG ref;
|
|
|
|
} MMDevEnumImpl;
|
|
|
|
|
|
|
|
static MMDevEnumImpl *MMDevEnumerator;
|
2010-01-04 22:38:04 +01:00
|
|
|
static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl;
|
2009-12-14 16:04:04 +01:00
|
|
|
|
2009-12-14 18:03:56 +01:00
|
|
|
typedef struct MMDevColImpl
|
|
|
|
{
|
|
|
|
const IMMDeviceCollectionVtbl *lpVtbl;
|
|
|
|
LONG ref;
|
|
|
|
MMDevEnumImpl *parent;
|
|
|
|
EDataFlow flow;
|
|
|
|
DWORD state;
|
|
|
|
} MMDevColImpl;
|
|
|
|
static const IMMDeviceCollectionVtbl MMDevColVtbl;
|
|
|
|
|
|
|
|
static HRESULT MMDevCol_Create(IMMDeviceCollection **ppv, MMDevEnumImpl *parent, EDataFlow flow, DWORD state)
|
|
|
|
{
|
|
|
|
MMDevColImpl *This;
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
*ppv = NULL;
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
This->lpVtbl = &MMDevColVtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
This->parent = parent;
|
|
|
|
This->flow = flow;
|
|
|
|
This->state = state;
|
|
|
|
*ppv = (IMMDeviceCollection*)This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MMDevCol_Destroy(MMDevColImpl *This)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevCol_QueryInterface(IMMDeviceCollection *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
MMDevColImpl *This = (MMDevColImpl*)iface;
|
|
|
|
|
|
|
|
if (!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualIID(riid, &IID_IMMDeviceCollection))
|
|
|
|
*ppv = This;
|
|
|
|
else
|
|
|
|
*ppv = NULL;
|
|
|
|
if (!*ppv)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MMDevCol_AddRef(IMMDeviceCollection *iface)
|
|
|
|
{
|
|
|
|
MMDevColImpl *This = (MMDevColImpl*)iface;
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("Refcount now %i\n", ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MMDevCol_Release(IMMDeviceCollection *iface)
|
|
|
|
{
|
|
|
|
MMDevColImpl *This = (MMDevColImpl*)iface;
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
TRACE("Refcount now %i\n", ref);
|
|
|
|
if (!ref)
|
|
|
|
MMDevCol_Destroy(This);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevCol_GetCount(IMMDeviceCollection *iface, UINT *numdevs)
|
|
|
|
{
|
|
|
|
MMDevColImpl *This = (MMDevColImpl*)iface;
|
|
|
|
TRACE("(%p)->(%p)\n", This, numdevs);
|
|
|
|
if (!numdevs)
|
|
|
|
return E_POINTER;
|
|
|
|
*numdevs = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevCol_Item(IMMDeviceCollection *iface, UINT i, IMMDevice **dev)
|
|
|
|
{
|
|
|
|
MMDevColImpl *This = (MMDevColImpl*)iface;
|
|
|
|
TRACE("(%p)->(%u, %p)\n", This, i, dev);
|
|
|
|
if (!dev)
|
|
|
|
return E_POINTER;
|
|
|
|
*dev = NULL;
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMMDeviceCollectionVtbl MMDevColVtbl =
|
|
|
|
{
|
|
|
|
MMDevCol_QueryInterface,
|
|
|
|
MMDevCol_AddRef,
|
|
|
|
MMDevCol_Release,
|
|
|
|
MMDevCol_GetCount,
|
|
|
|
MMDevCol_Item
|
|
|
|
};
|
|
|
|
|
2009-12-15 15:35:18 +01:00
|
|
|
HRESULT MMDevEnum_Create(REFIID riid, void **ppv)
|
|
|
|
{
|
2009-12-14 16:04:04 +01:00
|
|
|
MMDevEnumImpl *This = MMDevEnumerator;
|
|
|
|
|
|
|
|
if (!This)
|
|
|
|
{
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
*ppv = NULL;
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
This->ref = 1;
|
|
|
|
This->lpVtbl = &MMDevEnumVtbl;
|
|
|
|
MMDevEnumerator = This;
|
|
|
|
}
|
|
|
|
return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MMDevEnum_Free(void)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, MMDevEnumerator);
|
|
|
|
MMDevEnumerator = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevEnum_QueryInterface(IMMDeviceEnumerator *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
|
|
|
|
if (!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualIID(riid, &IID_IMMDeviceEnumerator))
|
|
|
|
*ppv = This;
|
|
|
|
else
|
|
|
|
*ppv = NULL;
|
|
|
|
if (!*ppv)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MMDevEnum_AddRef(IMMDeviceEnumerator *iface)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("Refcount now %i\n", ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MMDevEnum_Release(IMMDeviceEnumerator *iface)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (!ref)
|
|
|
|
MMDevEnum_Free();
|
|
|
|
TRACE("Refcount now %i\n", ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator *iface, EDataFlow flow, DWORD mask, IMMDeviceCollection **devices)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
TRACE("(%p)->(%u,%u,%p)\n", This, flow, mask, devices);
|
|
|
|
if (!devices)
|
|
|
|
return E_POINTER;
|
|
|
|
*devices = NULL;
|
|
|
|
if (flow >= EDataFlow_enum_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (mask & ~DEVICE_STATEMASK_ALL)
|
|
|
|
return E_INVALIDARG;
|
2009-12-14 18:03:56 +01:00
|
|
|
return MMDevCol_Create(devices, This, flow, mask);
|
2009-12-14 16:04:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator *iface, EDataFlow flow, ERole role, IMMDevice **device)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
TRACE("(%p)->(%u,%u,%p)\n", This, flow, role, device);
|
2009-12-15 15:35:18 +01:00
|
|
|
FIXME("stub\n");
|
2009-12-14 16:04:04 +01:00
|
|
|
return E_NOTFOUND;
|
2009-12-15 15:35:18 +01:00
|
|
|
}
|
2009-12-14 16:04:04 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevEnum_GetDevice(IMMDeviceEnumerator *iface, const WCHAR *name, IMMDevice **device)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), device);
|
|
|
|
FIXME("stub\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator *iface, IMMNotificationClient *client)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
TRACE("(%p)->(%p)\n", This, client);
|
|
|
|
FIXME("stub\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator *iface, IMMNotificationClient *client)
|
|
|
|
{
|
|
|
|
MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
|
|
|
|
TRACE("(%p)->(%p)\n", This, client);
|
|
|
|
FIXME("stub\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-01-04 22:38:04 +01:00
|
|
|
static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl =
|
2009-12-14 16:04:04 +01:00
|
|
|
{
|
|
|
|
MMDevEnum_QueryInterface,
|
|
|
|
MMDevEnum_AddRef,
|
|
|
|
MMDevEnum_Release,
|
|
|
|
MMDevEnum_EnumAudioEndpoints,
|
|
|
|
MMDevEnum_GetDefaultAudioEndpoint,
|
|
|
|
MMDevEnum_GetDevice,
|
|
|
|
MMDevEnum_RegisterEndpointNotificationCallback,
|
|
|
|
MMDevEnum_UnregisterEndpointNotificationCallback
|
|
|
|
};
|