/* * 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 #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); typedef struct MMDevEnumImpl { const IMMDeviceEnumeratorVtbl *lpVtbl; LONG ref; } MMDevEnumImpl; static MMDevEnumImpl *MMDevEnumerator; static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl; 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 }; HRESULT MMDevEnum_Create(REFIID riid, void **ppv) { 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; return MMDevCol_Create(devices, This, flow, mask); } 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); FIXME("stub\n"); return E_NOTFOUND; } 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; } static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl = { MMDevEnum_QueryInterface, MMDevEnum_AddRef, MMDevEnum_Release, MMDevEnum_EnumAudioEndpoints, MMDevEnum_GetDefaultAudioEndpoint, MMDevEnum_GetDevice, MMDevEnum_RegisterEndpointNotificationCallback, MMDevEnum_UnregisterEndpointNotificationCallback };