2009-12-09 15:38:43 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Maarten Lankhorst
|
2011-04-22 22:25:14 +02:00
|
|
|
* Copyright 2011 Andrew Eikum for CodeWeavers
|
2009-12-09 15:38:43 +01:00
|
|
|
*
|
|
|
|
* 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"
|
2010-02-21 14:48:39 +01:00
|
|
|
#include "wine/port.h"
|
2009-12-09 15:38:43 +01:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2009-12-15 15:35:18 +01:00
|
|
|
#define COBJMACROS
|
2009-12-09 15:38:43 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2010-02-21 13:50:42 +01:00
|
|
|
#include "wingdi.h"
|
2010-02-21 14:48:39 +01:00
|
|
|
#include "wine/library.h"
|
2009-12-09 15:38:43 +01:00
|
|
|
|
|
|
|
#include "ole2.h"
|
2010-03-17 22:02:44 +01:00
|
|
|
#include "olectl.h"
|
2010-12-07 13:30:55 +01:00
|
|
|
#include "rpcproxy.h"
|
2010-07-17 17:22:00 +02:00
|
|
|
#include "propsys.h"
|
2010-03-17 22:02:44 +01:00
|
|
|
#include "initguid.h"
|
2010-07-17 17:22:00 +02:00
|
|
|
#include "propkeydef.h"
|
2009-12-09 15:38:43 +01:00
|
|
|
#include "mmdeviceapi.h"
|
2010-02-21 13:50:42 +01:00
|
|
|
#include "dshow.h"
|
|
|
|
#include "dsound.h"
|
|
|
|
#include "audioclient.h"
|
|
|
|
#include "endpointvolume.h"
|
|
|
|
#include "audiopolicy.h"
|
|
|
|
#include "devpkey.h"
|
2011-04-22 22:25:14 +02:00
|
|
|
#include "winreg.h"
|
2009-12-09 15:38:43 +01:00
|
|
|
|
2009-12-15 15:35:18 +01:00
|
|
|
#include "mmdevapi.h"
|
2010-02-21 14:48:39 +01:00
|
|
|
#include "wine/debug.h"
|
2011-07-26 14:58:43 +02:00
|
|
|
#include "wine/unicode.h"
|
2009-12-15 15:35:18 +01:00
|
|
|
|
2009-12-09 15:38:43 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
|
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
static HINSTANCE instance;
|
2010-02-21 14:48:39 +01:00
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
DriverFuncs drvs;
|
2010-02-21 14:48:39 +01:00
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
static BOOL load_driver(const WCHAR *name)
|
2010-02-21 14:48:39 +01:00
|
|
|
{
|
2011-04-22 22:25:14 +02:00
|
|
|
WCHAR driver_module[264];
|
|
|
|
static const WCHAR wineW[] = {'w','i','n','e',0};
|
|
|
|
static const WCHAR dotdrvW[] = {'.','d','r','v',0};
|
2010-02-21 14:48:39 +01:00
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
lstrcpyW(driver_module, wineW);
|
|
|
|
lstrcatW(driver_module, name);
|
|
|
|
lstrcatW(driver_module, dotdrvW);
|
2010-05-04 21:30:07 +02:00
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
TRACE("Attempting to load %s\n", wine_dbgstr_w(driver_module));
|
2010-02-21 14:48:39 +01:00
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
drvs.module = LoadLibraryW(driver_module);
|
|
|
|
if(!drvs.module){
|
|
|
|
TRACE("Unable to load %s: %u\n", wine_dbgstr_w(driver_module),
|
|
|
|
GetLastError());
|
|
|
|
return FALSE;
|
2010-02-21 14:48:39 +01:00
|
|
|
}
|
2011-04-22 22:25:14 +02:00
|
|
|
|
|
|
|
#define LDFC(n) do { drvs.p##n = (void*)GetProcAddress(drvs.module, #n);\
|
2011-05-18 14:17:48 +02:00
|
|
|
if(!drvs.p##n) { FreeLibrary(drvs.module); return FALSE; } } while(0)
|
2011-04-22 22:25:14 +02:00
|
|
|
LDFC(GetEndpointIDs);
|
|
|
|
LDFC(GetAudioEndpoint);
|
2011-06-06 15:49:48 +02:00
|
|
|
LDFC(GetAudioSessionManager);
|
2011-04-22 22:25:14 +02:00
|
|
|
#undef LDFC
|
|
|
|
|
|
|
|
TRACE("Successfully loaded %s\n", wine_dbgstr_w(driver_module));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL init_driver(void)
|
|
|
|
{
|
|
|
|
static const WCHAR alsaW[] = {'a','l','s','a',0};
|
|
|
|
static const WCHAR ossW[] = {'o','s','s',0};
|
|
|
|
static const WCHAR coreaudioW[] = {'c','o','r','e','a','u','d','i','o',0};
|
|
|
|
static const WCHAR *default_drivers[] = { alsaW, coreaudioW, ossW };
|
|
|
|
static const WCHAR drv_key[] = {'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'W','i','n','e','\\','D','r','i','v','e','r','s',0};
|
|
|
|
static const WCHAR drv_value[] = {'A','u','d','i','o',0};
|
|
|
|
HKEY key;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if(drvs.module)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if(RegOpenKeyW(HKEY_CURRENT_USER, drv_key, &key) == ERROR_SUCCESS){
|
2011-07-26 14:58:43 +02:00
|
|
|
WCHAR driver_name[256], *p, *next;
|
2011-04-22 22:25:14 +02:00
|
|
|
DWORD size = sizeof(driver_name);
|
|
|
|
|
|
|
|
if(RegQueryValueExW(key, drv_value, 0, NULL, (BYTE*)driver_name,
|
2011-08-22 21:16:04 +02:00
|
|
|
&size) == ERROR_SUCCESS){
|
2011-04-22 22:25:14 +02:00
|
|
|
RegCloseKey(key);
|
2011-07-26 14:58:43 +02:00
|
|
|
|
2011-08-22 21:16:04 +02:00
|
|
|
if(driver_name[0] == '\0')
|
|
|
|
return TRUE;
|
|
|
|
|
2011-07-26 14:58:43 +02:00
|
|
|
for(next = p = driver_name; next; p = next + 1){
|
|
|
|
next = strchrW(p, ',');
|
|
|
|
if(next)
|
|
|
|
*next = '\0';
|
|
|
|
|
|
|
|
if(load_driver(p))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
TRACE("Failed to load driver: %s\n", wine_dbgstr_w(driver_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("No drivers in the registry loaded successfully!\n");
|
|
|
|
return FALSE;
|
2010-02-21 14:48:39 +01:00
|
|
|
}
|
2011-04-22 22:25:14 +02:00
|
|
|
|
|
|
|
RegCloseKey(key);
|
2010-02-21 14:48:39 +01:00
|
|
|
}
|
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
for(i = 0; i < sizeof(default_drivers)/sizeof(*default_drivers); ++i)
|
|
|
|
if(load_driver(default_drivers[i]))
|
|
|
|
return TRUE;
|
2010-02-21 14:48:39 +01:00
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-12-07 13:30:55 +01:00
|
|
|
|
2009-12-09 15:38:43 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
|
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2010-12-07 13:30:55 +01:00
|
|
|
instance = hinstDLL;
|
2009-12-09 15:38:43 +01:00
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
2009-12-14 16:04:04 +01:00
|
|
|
MMDevEnum_Free();
|
2009-12-09 15:38:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:35:18 +01:00
|
|
|
typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
|
|
|
|
|
|
|
|
typedef struct {
|
2010-12-05 15:16:39 +01:00
|
|
|
IClassFactory IClassFactory_iface;
|
2009-12-15 15:35:18 +01:00
|
|
|
REFCLSID rclsid;
|
|
|
|
FnCreateInstance pfnCreateInstance;
|
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
2010-12-05 15:16:39 +01:00
|
|
|
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:35:18 +01:00
|
|
|
static HRESULT WINAPI
|
|
|
|
MMCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
|
2009-12-09 15:38:43 +01:00
|
|
|
{
|
2010-12-05 15:16:39 +01:00
|
|
|
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2009-12-15 15:35:18 +01:00
|
|
|
TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
|
|
|
|
if (ppobj == NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IClassFactory))
|
|
|
|
{
|
|
|
|
*ppobj = iface;
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
*ppobj = NULL;
|
2009-12-09 15:38:43 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2009-12-15 15:35:18 +01:00
|
|
|
|
|
|
|
static ULONG WINAPI MMCF_AddRef(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MMCF_Release(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
/* static class, won't be freed */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMCF_CreateInstance(
|
|
|
|
LPCLASSFACTORY iface,
|
|
|
|
LPUNKNOWN pOuter,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppobj)
|
|
|
|
{
|
2010-12-05 15:16:39 +01:00
|
|
|
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2009-12-15 15:35:18 +01:00
|
|
|
TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
|
|
|
|
|
|
|
|
if (pOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
if (ppobj == NULL) {
|
|
|
|
WARN("invalid parameter\n");
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
*ppobj = NULL;
|
|
|
|
return This->pfnCreateInstance(riid, ppobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MMCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
|
|
|
|
{
|
2010-12-05 15:16:39 +01:00
|
|
|
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2009-12-15 15:35:18 +01:00
|
|
|
FIXME("(%p, %d) stub!\n", This, dolock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IClassFactoryVtbl MMCF_Vtbl = {
|
|
|
|
MMCF_QueryInterface,
|
|
|
|
MMCF_AddRef,
|
|
|
|
MMCF_Release,
|
|
|
|
MMCF_CreateInstance,
|
|
|
|
MMCF_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
static IClassFactoryImpl MMDEVAPI_CF[] = {
|
2010-12-05 15:16:39 +01:00
|
|
|
{ { &MMCF_Vtbl }, &CLSID_MMDeviceEnumerator, (FnCreateInstance)MMDevEnum_Create }
|
2009-12-15 15:35:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
|
|
|
|
2011-04-22 22:25:14 +02:00
|
|
|
if(!init_driver()){
|
|
|
|
ERR("Driver initialization failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:35:18 +01:00
|
|
|
if (ppv == NULL) {
|
|
|
|
WARN("invalid parameter\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (!IsEqualIID(riid, &IID_IClassFactory) &&
|
|
|
|
!IsEqualIID(riid, &IID_IUnknown)) {
|
|
|
|
WARN("no interface for %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(MMDEVAPI_CF)/sizeof(MMDEVAPI_CF[0]); ++i)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(rclsid, MMDEVAPI_CF[i].rclsid)) {
|
2010-12-05 15:16:39 +01:00
|
|
|
IUnknown_AddRef(&MMDEVAPI_CF[i].IClassFactory_iface);
|
2009-12-15 15:35:18 +01:00
|
|
|
*ppv = &MMDEVAPI_CF[i];
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
|
|
|
|
debugstr_guid(riid), ppv);
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|
2010-12-07 13:30:55 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (MMDEVAPI.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllRegisterServer(void)
|
|
|
|
{
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_register_resources( instance );
|
2010-12-07 13:30:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllUnregisterServer (MMDEVAPI.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllUnregisterServer(void)
|
|
|
|
{
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_unregister_resources( instance );
|
2010-12-07 13:30:55 +01:00
|
|
|
}
|