1999-09-22 18:52:47 +02:00
|
|
|
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
/*
|
2008-05-06 20:01:59 +02:00
|
|
|
* MMSYSTEM low level drivers handling functions
|
1999-09-22 18:52:47 +02:00
|
|
|
*
|
|
|
|
* Copyright 1999 Eric Pouech
|
2002-03-10 00:29:33 +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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-09-22 18:52:47 +02:00
|
|
|
*/
|
|
|
|
|
2006-02-07 16:31:21 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2011-08-31 22:04:23 +02:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
#define COBJMACROS
|
1999-09-22 18:52:47 +02:00
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-05-22 21:19:50 +02:00
|
|
|
#include <stdio.h>
|
1999-09-22 18:52:47 +02:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2001-05-22 21:19:50 +02:00
|
|
|
#include "winreg.h"
|
2011-08-31 22:04:23 +02:00
|
|
|
#include "winnls.h"
|
1999-09-22 18:52:47 +02:00
|
|
|
#include "winemm.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2005-07-15 11:56:17 +02:00
|
|
|
#include "wine/exception.h"
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2011-08-31 22:04:23 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "devpkey.h"
|
|
|
|
#include "mmdeviceapi.h"
|
|
|
|
|
2002-10-29 22:55:25 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winmm);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
/* each known type of driver has an instance of this structure */
|
|
|
|
typedef struct tagWINE_LLTYPE {
|
2002-06-01 01:06:46 +02:00
|
|
|
/* those attributes depend on the specification of the type */
|
2003-10-06 23:03:32 +02:00
|
|
|
LPCSTR typestr; /* name (for debugging) */
|
1999-09-22 18:52:47 +02:00
|
|
|
/* those attributes reflect the loaded/current situation for the type */
|
2005-07-15 11:56:17 +02:00
|
|
|
UINT wMaxId; /* number of loaded devices (sum across all loaded drivers) */
|
1999-09-22 18:52:47 +02:00
|
|
|
LPWINE_MLD lpMlds; /* "static" mlds to access the part though device IDs */
|
|
|
|
int nMapper; /* index to mapper */
|
|
|
|
} WINE_LLTYPE;
|
|
|
|
|
2010-03-31 21:13:33 +02:00
|
|
|
static WINE_LLTYPE llTypes[MMDRV_MAX] = {
|
|
|
|
{ "Aux", 0, 0, -1 },
|
|
|
|
{ "Mixer", 0, 0, -1 },
|
|
|
|
{ "MidiIn", 0, 0, -1 },
|
|
|
|
{ "MidiOut", 0, 0, -1 },
|
|
|
|
{ "WaveIn", 0, 0, -1 },
|
|
|
|
{ "WaveOut", 0, 0, -1 }
|
|
|
|
};
|
|
|
|
|
2010-03-31 20:19:35 +02:00
|
|
|
static int drivers_loaded, MMDrvsHi;
|
2004-05-05 03:00:54 +02:00
|
|
|
static WINE_MM_DRIVER MMDrvs[8];
|
2000-12-21 21:17:23 +01:00
|
|
|
static LPWINE_MLD MM_MLDrvs[40];
|
|
|
|
#define MAX_MM_MLDRVS (sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]))
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2010-03-31 20:19:35 +02:00
|
|
|
static void MMDRV_Init(void);
|
|
|
|
|
|
|
|
static void MMDRV_InitSingleType(UINT type) {
|
|
|
|
if (!drivers_loaded) {
|
|
|
|
drivers_loaded = 1;
|
|
|
|
MMDRV_Init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-22 18:52:47 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_GetNum [internal]
|
|
|
|
*/
|
|
|
|
UINT MMDRV_GetNum(UINT type)
|
|
|
|
{
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%04x)\n", type);
|
1999-09-22 18:52:47 +02:00
|
|
|
assert(type < MMDRV_MAX);
|
2010-03-31 20:19:35 +02:00
|
|
|
MMDRV_InitSingleType(type);
|
1999-09-22 18:52:47 +02:00
|
|
|
return llTypes[type].wMaxId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-12-12 23:26:01 +01:00
|
|
|
* MMDRV_Message [internal]
|
1999-09-22 18:52:47 +02:00
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
DWORD MMDRV_Message(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1,
|
2009-10-22 22:10:32 +02:00
|
|
|
DWORD_PTR dwParam2)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
|
|
|
LPWINE_MM_DRIVER lpDrv;
|
|
|
|
DWORD ret;
|
|
|
|
WINE_MM_DRIVER_PART* part;
|
|
|
|
WINE_LLTYPE* llType = &llTypes[mld->type];
|
|
|
|
|
2010-03-09 21:47:52 +01:00
|
|
|
TRACE("(%s %d %u 0x%08lx 0x%08lx 0x%08lx)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
llTypes[mld->type].typestr, mld->uDeviceID, wMsg,
|
2009-10-22 22:10:32 +02:00
|
|
|
mld->dwDriverInstance, dwParam1, dwParam2);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2010-03-09 21:47:52 +01:00
|
|
|
if ((UINT16)mld->uDeviceID == (UINT16)-1) {
|
2010-03-31 21:13:33 +02:00
|
|
|
if (llType->nMapper == -1) {
|
|
|
|
WARN("uDev=-1 requested on non-mapped ll type %s\n",
|
2001-05-22 21:19:50 +02:00
|
|
|
llTypes[mld->type].typestr);
|
1999-09-22 18:52:47 +02:00
|
|
|
return MMSYSERR_BADDEVICEID;
|
2010-03-31 21:13:33 +02:00
|
|
|
}
|
1999-09-22 18:52:47 +02:00
|
|
|
} else {
|
|
|
|
if (mld->uDeviceID >= llType->wMaxId) {
|
|
|
|
WARN("uDev(%u) requested >= max (%d)\n", mld->uDeviceID, llType->wMaxId);
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lpDrv = &MMDrvs[mld->mmdIndex];
|
|
|
|
part = &lpDrv->parts[mld->type];
|
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
assert(part->fnMessage32);
|
|
|
|
|
2010-03-09 21:47:52 +01:00
|
|
|
TRACE("Calling message(dev=%d msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx)\n",
|
2009-10-22 22:11:15 +02:00
|
|
|
mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
|
|
|
|
ret = part->fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
|
|
|
|
TRACE("=> %s\n", WINMM_ErrorToString(ret));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-09-22 18:52:47 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_Alloc [internal]
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
|
2009-10-22 22:10:32 +02:00
|
|
|
DWORD_PTR* dwCallback, DWORD_PTR* dwInstance)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
|
|
|
LPWINE_MLD mld;
|
2009-05-20 17:50:54 +02:00
|
|
|
UINT_PTR i;
|
2009-10-22 22:10:32 +02:00
|
|
|
TRACE("(%d, %04x, %p, %p, %p, %p)\n",
|
|
|
|
size, type, hndl, dwFlags, dwCallback, dwInstance);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2000-12-21 21:17:23 +01:00
|
|
|
mld = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
1999-09-22 18:52:47 +02:00
|
|
|
if (!mld) return NULL;
|
2000-12-21 21:17:23 +01:00
|
|
|
|
|
|
|
/* find an empty slot in MM_MLDrvs table */
|
2003-01-23 22:32:35 +01:00
|
|
|
for (i = 0; i < MAX_MM_MLDRVS; i++) if (!MM_MLDrvs[i]) break;
|
|
|
|
|
|
|
|
if (i == MAX_MM_MLDRVS) {
|
2000-12-21 21:17:23 +01:00
|
|
|
/* the MM_MLDrvs table could be made growable in the future if needed */
|
|
|
|
ERR("Too many open drivers\n");
|
2005-03-15 16:38:48 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, mld);
|
2000-12-21 21:17:23 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-01-23 22:32:35 +01:00
|
|
|
MM_MLDrvs[i] = mld;
|
|
|
|
*hndl = (HANDLE)(i | 0x8000);
|
2000-12-21 21:17:23 +01:00
|
|
|
|
1999-09-22 18:52:47 +02:00
|
|
|
mld->type = type;
|
2009-05-20 17:50:54 +02:00
|
|
|
if ((UINT_PTR)*hndl < MMDRV_GetNum(type) || ((UINT_PTR)*hndl >> 16)) {
|
1999-09-22 18:52:47 +02:00
|
|
|
/* FIXME: those conditions must be fulfilled so that:
|
|
|
|
* - we can distinguish between device IDs and handles
|
|
|
|
* - we can use handles as 16 or 32 bit entities
|
|
|
|
*/
|
|
|
|
ERR("Shouldn't happen. Bad allocation scheme\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
mld->dwFlags = HIWORD(*dwFlags);
|
|
|
|
mld->dwCallback = *dwCallback;
|
|
|
|
mld->dwClientInstance = *dwInstance;
|
|
|
|
|
|
|
|
return mld;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_Free [internal]
|
|
|
|
*/
|
|
|
|
void MMDRV_Free(HANDLE hndl, LPWINE_MLD mld)
|
|
|
|
{
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%p, %p)\n", hndl, mld);
|
|
|
|
|
2009-05-20 17:50:54 +02:00
|
|
|
if ((UINT_PTR)hndl & 0x8000) {
|
|
|
|
UINT_PTR idx = (UINT_PTR)hndl & ~0x8000;
|
2000-12-21 21:17:23 +01:00
|
|
|
if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
|
|
|
|
MM_MLDrvs[idx] = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, mld);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-10-31 02:02:41 +01:00
|
|
|
ERR("Bad Handle %p at %p (not freed)\n", hndl, mld);
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_Open [internal]
|
|
|
|
*/
|
2009-05-20 17:50:54 +02:00
|
|
|
DWORD MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1, DWORD dwFlags)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
|
|
|
DWORD dwRet = MMSYSERR_BADDEVICEID;
|
2009-05-20 17:50:54 +02:00
|
|
|
DWORD_PTR dwInstance;
|
1999-09-22 18:52:47 +02:00
|
|
|
WINE_LLTYPE* llType = &llTypes[mld->type];
|
2009-05-20 17:50:54 +02:00
|
|
|
TRACE("(%p, %04x, 0x%08lx, 0x%08x)\n", mld, wMsg, dwParam1, dwFlags);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2009-05-20 17:50:54 +02:00
|
|
|
mld->dwDriverInstance = (DWORD_PTR)&dwInstance;
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2000-01-04 02:04:48 +01:00
|
|
|
if (mld->uDeviceID == (UINT)-1 || mld->uDeviceID == (UINT16)-1) {
|
2010-03-31 21:13:33 +02:00
|
|
|
TRACE("MAPPER mode requested !\n");
|
|
|
|
if (llType->nMapper == -1) {
|
|
|
|
WARN("Mapper not supported for type %s\n", llTypes[mld->type].typestr);
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
mld->mmdIndex = llType->lpMlds[-1].mmdIndex;
|
|
|
|
TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
|
|
|
|
dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags);
|
1999-09-22 18:52:47 +02:00
|
|
|
} else {
|
|
|
|
if (mld->uDeviceID < llType->wMaxId) {
|
|
|
|
mld->mmdIndex = llType->lpMlds[mld->uDeviceID].mmdIndex;
|
|
|
|
TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
|
2009-10-22 22:10:32 +02:00
|
|
|
dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags);
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dwRet == MMSYSERR_NOERROR)
|
|
|
|
mld->dwDriverInstance = dwInstance;
|
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_Close [internal]
|
|
|
|
*/
|
|
|
|
DWORD MMDRV_Close(LPWINE_MLD mld, UINT wMsg)
|
|
|
|
{
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%p, %04x)\n", mld, wMsg);
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(mld, wMsg, 0L, 0L);
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
1999-11-21 01:51:05 +01:00
|
|
|
* MMDRV_GetByID [internal]
|
1999-09-22 18:52:47 +02:00
|
|
|
*/
|
2005-06-22 13:59:43 +02:00
|
|
|
static LPWINE_MLD MMDRV_GetByID(UINT uDevID, UINT type)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%04x, %04x)\n", uDevID, type);
|
1999-11-21 01:51:05 +01:00
|
|
|
if (uDevID < llTypes[type].wMaxId)
|
|
|
|
return &llTypes[type].lpMlds[uDevID];
|
|
|
|
if ((uDevID == (UINT16)-1 || uDevID == (UINT)-1) && llTypes[type].nMapper != -1)
|
|
|
|
return &llTypes[type].lpMlds[-1];
|
|
|
|
return NULL;
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_Get [internal]
|
|
|
|
*/
|
2002-10-31 02:02:41 +01:00
|
|
|
LPWINE_MLD MMDRV_Get(HANDLE _hndl, UINT type, BOOL bCanBeID)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
|
|
|
LPWINE_MLD mld = NULL;
|
2009-05-20 17:50:54 +02:00
|
|
|
UINT_PTR hndl = (UINT_PTR)_hndl;
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%p, %04x, %c)\n", _hndl, type, bCanBeID ? 'Y' : 'N');
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
assert(type < MMDRV_MAX);
|
2010-03-31 20:19:35 +02:00
|
|
|
MMDRV_InitSingleType(type);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
if (hndl >= llTypes[type].wMaxId &&
|
2001-05-22 21:19:50 +02:00
|
|
|
hndl != (UINT16)-1 && hndl != (UINT)-1) {
|
2002-10-31 02:02:41 +01:00
|
|
|
if (hndl & 0x8000) {
|
2005-09-08 20:59:52 +02:00
|
|
|
UINT idx = hndl & ~0x8000;
|
|
|
|
if (idx < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0])) {
|
2005-07-15 11:56:17 +02:00
|
|
|
__TRY
|
|
|
|
{
|
2005-09-08 20:59:52 +02:00
|
|
|
mld = MM_MLDrvs[idx];
|
2005-07-15 11:56:17 +02:00
|
|
|
if (mld && mld->type != type) mld = NULL;
|
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2005-07-15 11:56:17 +02:00
|
|
|
{
|
|
|
|
mld = NULL;
|
|
|
|
}
|
|
|
|
__ENDTRY;
|
2000-12-21 21:17:23 +01:00
|
|
|
}
|
|
|
|
}
|
1999-11-21 01:51:05 +01:00
|
|
|
}
|
|
|
|
if (mld == NULL && bCanBeID) {
|
2002-10-31 02:02:41 +01:00
|
|
|
mld = MMDRV_GetByID(hndl, type);
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
|
|
|
return mld;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_GetRelated [internal]
|
|
|
|
*/
|
|
|
|
LPWINE_MLD MMDRV_GetRelated(HANDLE hndl, UINT srcType,
|
|
|
|
BOOL bSrcCanBeID, UINT dstType)
|
|
|
|
{
|
|
|
|
LPWINE_MLD mld;
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%p, %04x, %c, %04x)\n",
|
|
|
|
hndl, srcType, bSrcCanBeID ? 'Y' : 'N', dstType);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
if ((mld = MMDRV_Get(hndl, srcType, bSrcCanBeID)) != NULL) {
|
|
|
|
WINE_MM_DRIVER_PART* part = &MMDrvs[mld->mmdIndex].parts[dstType];
|
|
|
|
if (part->nIDMin < part->nIDMax)
|
|
|
|
return MMDRV_GetByID(part->nIDMin, dstType);
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
1999-09-22 18:52:47 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_PhysicalFeatures [internal]
|
|
|
|
*/
|
2008-08-10 07:51:14 +02:00
|
|
|
UINT MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg,
|
|
|
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
|
|
|
WINE_MM_DRIVER* lpDrv = &MMDrvs[mld->mmdIndex];
|
|
|
|
|
2008-08-10 07:51:14 +02:00
|
|
|
TRACE("(%p, %04x, %08lx, %08lx)\n", mld, uMsg, dwParam1, dwParam2);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
/* all those function calls are undocumented */
|
|
|
|
switch (uMsg) {
|
2001-01-04 20:53:51 +01:00
|
|
|
case DRV_QUERYDRVENTRY:
|
2003-12-01 23:38:19 +01:00
|
|
|
lstrcpynA((LPSTR)dwParam1, lpDrv->drvname, LOWORD(dwParam2));
|
1999-09-22 18:52:47 +02:00
|
|
|
break;
|
2001-01-04 20:53:51 +01:00
|
|
|
case DRV_QUERYDEVNODE:
|
2003-12-01 23:38:19 +01:00
|
|
|
*(LPDWORD)dwParam1 = 0L; /* should be DevNode */
|
1999-09-22 18:52:47 +02:00
|
|
|
break;
|
2001-01-04 20:53:51 +01:00
|
|
|
case DRV_QUERYNAME:
|
|
|
|
WARN("NIY QueryName\n");
|
1999-09-22 18:52:47 +02:00
|
|
|
break;
|
2001-01-04 20:53:51 +01:00
|
|
|
case DRV_QUERYDRIVERIDS:
|
1999-09-22 18:52:47 +02:00
|
|
|
WARN("NIY call VxD\n");
|
|
|
|
/* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
|
2003-06-18 21:45:22 +02:00
|
|
|
* dwParam1 is buffer and dwParam2 is sizeof(buffer)
|
1999-09-22 18:52:47 +02:00
|
|
|
* I don't know where the result is stored though
|
|
|
|
*/
|
|
|
|
break;
|
2001-01-04 20:53:51 +01:00
|
|
|
case DRV_QUERYMAPPABLE:
|
1999-09-22 18:52:47 +02:00
|
|
|
return (lpDrv->bIsMapper) ? 2 : 0;
|
2000-06-24 14:55:33 +02:00
|
|
|
|
2003-10-28 01:15:16 +01:00
|
|
|
case DRVM_MAPPER_PREFERRED_GET:
|
|
|
|
/* FIXME: get from registry someday */
|
2003-12-01 23:38:19 +01:00
|
|
|
*((LPDWORD)dwParam1) = -1; /* No preferred device */
|
2004-12-17 20:04:28 +01:00
|
|
|
*((LPDWORD)dwParam2) = 0;
|
2003-12-01 23:38:19 +01:00
|
|
|
break;
|
2003-10-28 01:15:16 +01:00
|
|
|
|
|
|
|
case DRV_QUERYDEVICEINTERFACE:
|
|
|
|
case DRV_QUERYDEVICEINTERFACESIZE:
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(mld, uMsg, dwParam1, dwParam2);
|
2003-10-28 01:15:16 +01:00
|
|
|
|
1999-09-22 18:52:47 +02:00
|
|
|
default:
|
|
|
|
WARN("Unknown call %04x\n", uMsg);
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_InitPerType [internal]
|
|
|
|
*/
|
2001-05-22 21:19:50 +02:00
|
|
|
static BOOL MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv, UINT type, UINT wMsg)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
|
|
|
WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
|
1999-09-27 15:34:21 +02:00
|
|
|
DWORD ret;
|
|
|
|
UINT count = 0;
|
|
|
|
int i, k;
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%p, %04x, %04x)\n", lpDrv, type, wMsg);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
part->nIDMin = part->nIDMax = 0;
|
|
|
|
|
|
|
|
/* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
|
|
|
|
/* the DRVM_ENABLE is only required when the PnP node is non zero */
|
2009-10-22 22:11:15 +02:00
|
|
|
if (part->fnMessage32) {
|
|
|
|
ret = part->fnMessage32(0, DRVM_INIT, 0L, 0L, 0L);
|
|
|
|
TRACE("DRVM_INIT => %s\n", WINMM_ErrorToString(ret));
|
1999-09-22 18:52:47 +02:00
|
|
|
#if 0
|
2009-10-22 22:11:15 +02:00
|
|
|
ret = part->fnMessage32(0, DRVM_ENABLE, 0L, 0L, 0L);
|
|
|
|
TRACE("DRVM_ENABLE => %08lx\n", ret);
|
1999-09-22 18:52:47 +02:00
|
|
|
#endif
|
2009-10-22 22:11:15 +02:00
|
|
|
count = part->fnMessage32(0, wMsg, 0L, 0L, 0L);
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
2009-10-22 22:11:15 +02:00
|
|
|
else return FALSE;
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2001-05-22 21:19:50 +02:00
|
|
|
TRACE("Got %u dev for (%s:%s)\n", count, lpDrv->drvname, llTypes[type].typestr);
|
2004-12-01 16:32:19 +01:00
|
|
|
|
|
|
|
if (HIWORD(count))
|
|
|
|
return FALSE;
|
1999-09-27 15:34:21 +02:00
|
|
|
|
|
|
|
/* got some drivers */
|
|
|
|
if (lpDrv->bIsMapper) {
|
2010-03-31 21:13:33 +02:00
|
|
|
llTypes[type].nMapper = MMDrvsHi;
|
1999-09-27 15:34:21 +02:00
|
|
|
} else {
|
2001-01-04 20:27:49 +01:00
|
|
|
if (count == 0)
|
|
|
|
return FALSE;
|
1999-09-27 15:34:21 +02:00
|
|
|
part->nIDMin = llTypes[type].wMaxId;
|
|
|
|
llTypes[type].wMaxId += count;
|
|
|
|
part->nIDMax = llTypes[type].wMaxId;
|
|
|
|
}
|
|
|
|
TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
part->nIDMin, part->nIDMax, llTypes[type].wMaxId,
|
2001-05-22 21:19:50 +02:00
|
|
|
lpDrv->drvname, llTypes[type].typestr);
|
1999-09-27 15:34:21 +02:00
|
|
|
/* realloc translation table */
|
2003-10-15 23:01:05 +02:00
|
|
|
if (llTypes[type].lpMlds)
|
|
|
|
llTypes[type].lpMlds = (LPWINE_MLD)
|
|
|
|
HeapReAlloc(GetProcessHeap(), 0, llTypes[type].lpMlds - 1,
|
1999-09-27 15:34:21 +02:00
|
|
|
sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
|
2003-10-15 23:01:05 +02:00
|
|
|
else
|
|
|
|
llTypes[type].lpMlds = (LPWINE_MLD)
|
|
|
|
HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
|
|
|
|
|
1999-09-27 15:34:21 +02:00
|
|
|
/* re-build the translation table */
|
2010-03-31 21:13:33 +02:00
|
|
|
if (lpDrv->bIsMapper) {
|
2001-05-22 21:19:50 +02:00
|
|
|
TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, -1, MMDrvs[llTypes[type].nMapper].drvname);
|
2010-03-09 21:47:52 +01:00
|
|
|
llTypes[type].lpMlds[-1].uDeviceID = (UINT)-1;
|
1999-09-27 15:34:21 +02:00
|
|
|
llTypes[type].lpMlds[-1].type = type;
|
|
|
|
llTypes[type].lpMlds[-1].mmdIndex = llTypes[type].nMapper;
|
|
|
|
llTypes[type].lpMlds[-1].dwDriverInstance = 0;
|
|
|
|
}
|
2001-05-22 21:19:50 +02:00
|
|
|
for (i = k = 0; i <= MMDrvsHi; i++) {
|
1999-09-27 15:34:21 +02:00
|
|
|
while (MMDrvs[i].parts[type].nIDMin <= k && k < MMDrvs[i].parts[type].nIDMax) {
|
2001-05-22 21:19:50 +02:00
|
|
|
TRACE("%s:Trans[%d] -> %s\n", llTypes[type].typestr, k, MMDrvs[i].drvname);
|
1999-09-27 15:34:21 +02:00
|
|
|
llTypes[type].lpMlds[k].uDeviceID = k;
|
|
|
|
llTypes[type].lpMlds[k].type = type;
|
|
|
|
llTypes[type].lpMlds[k].mmdIndex = i;
|
|
|
|
llTypes[type].lpMlds[k].dwDriverInstance = 0;
|
|
|
|
k++;
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
|
|
|
}
|
1999-09-27 15:34:21 +02:00
|
|
|
return TRUE;
|
1999-09-22 18:52:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMDRV_Install [internal]
|
|
|
|
*/
|
2001-05-22 21:19:50 +02:00
|
|
|
static BOOL MMDRV_Install(LPCSTR drvRegName, LPCSTR drvFileName, BOOL bIsMapper)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
2001-05-22 21:19:50 +02:00
|
|
|
int i, count = 0;
|
|
|
|
LPWINE_MM_DRIVER lpDrv = &MMDrvs[MMDrvsHi];
|
2000-12-13 03:07:40 +01:00
|
|
|
LPWINE_DRIVER d;
|
2009-10-22 22:11:15 +02:00
|
|
|
WINEMM_msgFunc32 func;
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2001-05-22 21:19:50 +02:00
|
|
|
TRACE("('%s', '%s', mapper=%c);\n", drvRegName, drvFileName, bIsMapper ? 'Y' : 'N');
|
|
|
|
|
|
|
|
for (i = 0; i < MMDrvsHi; i++) {
|
2004-05-05 03:00:54 +02:00
|
|
|
if (!strcmp(drvRegName, MMDrvs[i].drvname)) return FALSE;
|
2001-05-22 21:19:50 +02:00
|
|
|
}
|
|
|
|
|
2004-05-05 03:00:54 +02:00
|
|
|
/* Be sure that size of MMDrvs matches the max number of loadable
|
|
|
|
* drivers !!
|
|
|
|
* If not just increase size of MMDrvs
|
|
|
|
*/
|
|
|
|
assert(MMDrvsHi <= sizeof(MMDrvs)/sizeof(MMDrvs[0]));
|
|
|
|
|
1999-09-22 18:52:47 +02:00
|
|
|
memset(lpDrv, 0, sizeof(*lpDrv));
|
|
|
|
|
2001-05-22 21:19:50 +02:00
|
|
|
if (!(lpDrv->hDriver = OpenDriverA(drvFileName, 0, 0))) {
|
|
|
|
WARN("Couldn't open driver '%s'\n", drvFileName);
|
1999-09-22 18:52:47 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
d = DRIVER_FindFromHDrvr(lpDrv->hDriver);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
/* Then look for xxxMessage functions */
|
2000-12-13 03:07:40 +01:00
|
|
|
#define AA(_h,_w,_x,_y,_z) \
|
|
|
|
func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
|
1999-09-22 18:52:47 +02:00
|
|
|
if (func != NULL) \
|
2009-10-22 22:11:15 +02:00
|
|
|
{ lpDrv->parts[_w].fnMessage##_y = func; count++; \
|
1999-09-22 18:52:47 +02:00
|
|
|
TRACE("Got %d bit func '%s'\n", _y, #_x); }
|
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
if (d->hModule) {
|
|
|
|
#define A(_x,_y) AA(d->hModule,_x,_y,32,GetProcAddress)
|
1999-09-22 18:52:47 +02:00
|
|
|
A(MMDRV_AUX, auxMessage);
|
2002-12-23 03:05:30 +01:00
|
|
|
A(MMDRV_MIXER, mxdMessage);
|
1999-09-22 18:52:47 +02:00
|
|
|
A(MMDRV_MIDIIN, midMessage);
|
|
|
|
A(MMDRV_MIDIOUT, modMessage);
|
|
|
|
A(MMDRV_WAVEIN, widMessage);
|
|
|
|
A(MMDRV_WAVEOUT, wodMessage);
|
|
|
|
#undef A
|
|
|
|
}
|
2002-10-29 22:55:25 +01:00
|
|
|
#undef AA
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
if (!count) {
|
2000-12-13 03:07:40 +01:00
|
|
|
CloseDriver(lpDrv->hDriver, 0, 0);
|
1999-09-22 18:52:47 +02:00
|
|
|
WARN("No message functions found\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: being a mapper or not should be known by another way */
|
|
|
|
/* it's known for NE drvs (the description is of the form '*mapper: *'
|
|
|
|
* I don't have any clue for PE drvs
|
|
|
|
*/
|
|
|
|
lpDrv->bIsMapper = bIsMapper;
|
2001-05-22 21:19:50 +02:00
|
|
|
lpDrv->drvname = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName) + 1), drvRegName);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
|
|
|
/* Finish init and get the count of the devices */
|
2003-09-22 21:25:11 +02:00
|
|
|
i = 0;
|
|
|
|
if (MMDRV_InitPerType(lpDrv, MMDRV_AUX, AUXDM_GETNUMDEVS)) i = 1;
|
|
|
|
if (MMDRV_InitPerType(lpDrv, MMDRV_MIXER, MXDM_GETNUMDEVS)) i = 1;
|
|
|
|
if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIIN, MIDM_GETNUMDEVS)) i = 1;
|
|
|
|
if (MMDRV_InitPerType(lpDrv, MMDRV_MIDIOUT, MODM_GETNUMDEVS)) i = 1;
|
|
|
|
if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEIN, WIDM_GETNUMDEVS)) i = 1;
|
|
|
|
if (MMDRV_InitPerType(lpDrv, MMDRV_WAVEOUT, WODM_GETNUMDEVS)) i = 1;
|
|
|
|
/* if all those func calls return FALSE, then the driver must be unloaded */
|
|
|
|
if (!i) {
|
|
|
|
CloseDriver(lpDrv->hDriver, 0, 0);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpDrv->drvname);
|
|
|
|
WARN("Driver initialization failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-05-22 21:19:50 +02:00
|
|
|
|
|
|
|
MMDrvsHi++;
|
|
|
|
|
1999-09-22 18:52:47 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2005-03-17 11:25:25 +01:00
|
|
|
* MMDRV_Init
|
1999-09-22 18:52:47 +02:00
|
|
|
*/
|
2010-03-31 20:19:35 +02:00
|
|
|
static void MMDRV_Init(void)
|
1999-09-22 18:52:47 +02:00
|
|
|
{
|
2011-08-31 22:04:23 +02:00
|
|
|
IMMDeviceEnumerator *devenum;
|
|
|
|
IMMDevice *device;
|
|
|
|
IPropertyStore *ps;
|
|
|
|
PROPVARIANT pv;
|
|
|
|
DWORD size;
|
|
|
|
char *drvA;
|
|
|
|
HRESULT init_hr, hr;
|
|
|
|
|
|
|
|
static const WCHAR wine_info_deviceW[] = {'W','i','n','e',' ',
|
|
|
|
'i','n','f','o',' ','d','e','v','i','c','e',0};
|
|
|
|
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("()\n");
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2012-01-16 17:44:02 +01:00
|
|
|
init_hr = CoInitialize(NULL);
|
1999-09-22 18:52:47 +02:00
|
|
|
|
2011-08-31 22:04:23 +02:00
|
|
|
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
ERR("CoCreateInstance failed: %08x\n", hr);
|
|
|
|
goto exit;
|
2005-06-20 20:35:57 +02:00
|
|
|
}
|
|
|
|
|
2011-08-31 22:04:23 +02:00
|
|
|
hr = IMMDeviceEnumerator_GetDevice(devenum, wine_info_deviceW, &device);
|
|
|
|
IMMDeviceEnumerator_Release(devenum);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
ERR("GetDevice failed: %08x\n", hr);
|
|
|
|
goto exit;
|
2005-06-20 20:35:57 +02:00
|
|
|
}
|
|
|
|
|
2011-08-31 22:04:23 +02:00
|
|
|
hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
ERR("OpenPropertyStore failed: %08x\n", hr);
|
|
|
|
IMMDevice_Release(device);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IPropertyStore_GetValue(ps,
|
|
|
|
(const PROPERTYKEY *)&DEVPKEY_Device_Driver, &pv);
|
|
|
|
IPropertyStore_Release(ps);
|
|
|
|
IMMDevice_Release(device);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
ERR("GetValue failed: %08x\n", hr);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = WideCharToMultiByte(CP_ACP, 0, pv.u.pwszVal, -1,
|
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
drvA = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, pv.u.pwszVal, -1, drvA, size, NULL, NULL);
|
|
|
|
|
|
|
|
MMDRV_Install(drvA, drvA, FALSE);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, drvA);
|
|
|
|
PropVariantClear(&pv);
|
|
|
|
|
2010-03-31 20:33:45 +02:00
|
|
|
MMDRV_Install("wavemapper", "msacm32.drv", TRUE);
|
|
|
|
MMDRV_Install("midimapper", "midimap.dll", TRUE);
|
2011-08-31 22:04:23 +02:00
|
|
|
|
|
|
|
exit:
|
|
|
|
if(SUCCEEDED(init_hr))
|
|
|
|
CoUninitialize();
|
2001-05-22 21:19:50 +02:00
|
|
|
}
|
2002-11-11 20:53:01 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ExitPerType
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL MMDRV_ExitPerType(LPWINE_MM_DRIVER lpDrv, UINT type)
|
|
|
|
{
|
|
|
|
WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
|
|
|
|
DWORD ret;
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("(%p, %04x)\n", lpDrv, type);
|
2002-11-11 20:53:01 +01:00
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
if (part->fnMessage32) {
|
2002-11-11 20:53:01 +01:00
|
|
|
#if 0
|
2009-10-22 22:11:15 +02:00
|
|
|
ret = part->fnMessage32(0, DRVM_DISABLE, 0L, 0L, 0L);
|
|
|
|
TRACE("DRVM_DISABLE => %08lx\n", ret);
|
2002-11-11 20:53:01 +01:00
|
|
|
#endif
|
2009-10-22 22:11:15 +02:00
|
|
|
ret = part->fnMessage32(0, DRVM_EXIT, 0L, 0L, 0L);
|
|
|
|
TRACE("DRVM_EXIT => %s\n", WINMM_ErrorToString(ret));
|
2002-11-11 20:53:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* Exit
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2010-03-31 20:19:35 +02:00
|
|
|
void MMDRV_Exit(void)
|
2002-11-11 20:53:01 +01:00
|
|
|
{
|
2008-12-12 21:22:03 +01:00
|
|
|
unsigned int i;
|
2004-05-27 22:05:08 +02:00
|
|
|
TRACE("()\n");
|
2002-11-11 20:53:01 +01:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(MM_MLDrvs) / sizeof(MM_MLDrvs[0]); i++)
|
|
|
|
{
|
|
|
|
if (MM_MLDrvs[i] != NULL)
|
|
|
|
{
|
|
|
|
FIXME("Closing while ll-driver open\n");
|
|
|
|
#if 0
|
|
|
|
/* FIXME: should generate a message depending on type */
|
|
|
|
MMDRV_Free((HANDLE)(i | 0x8000), MM_MLDrvs[i]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unload driver, in reverse order of loading */
|
2008-12-12 21:22:03 +01:00
|
|
|
i = sizeof(MMDrvs) / sizeof(MMDrvs[0]);
|
|
|
|
while (i-- > 0)
|
2002-11-11 20:53:01 +01:00
|
|
|
{
|
|
|
|
MMDRV_ExitPerType(&MMDrvs[i], MMDRV_AUX);
|
|
|
|
MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIXER);
|
|
|
|
MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIIN);
|
|
|
|
MMDRV_ExitPerType(&MMDrvs[i], MMDRV_MIDIOUT);
|
|
|
|
MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEIN);
|
|
|
|
MMDRV_ExitPerType(&MMDrvs[i], MMDRV_WAVEOUT);
|
|
|
|
CloseDriver(MMDrvs[i].hDriver, 0, 0);
|
|
|
|
}
|
2008-05-22 20:39:40 +02:00
|
|
|
if (llTypes[MMDRV_AUX].lpMlds)
|
|
|
|
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_AUX].lpMlds - 1);
|
|
|
|
if (llTypes[MMDRV_MIXER].lpMlds)
|
|
|
|
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIXER].lpMlds - 1);
|
|
|
|
if (llTypes[MMDRV_MIDIIN].lpMlds)
|
|
|
|
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIIN].lpMlds - 1);
|
|
|
|
if (llTypes[MMDRV_MIDIOUT].lpMlds)
|
|
|
|
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIOUT].lpMlds - 1);
|
|
|
|
if (llTypes[MMDRV_WAVEIN].lpMlds)
|
|
|
|
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEIN].lpMlds - 1);
|
|
|
|
if (llTypes[MMDRV_WAVEOUT].lpMlds)
|
|
|
|
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEOUT].lpMlds - 1);
|
2002-11-11 20:53:01 +01:00
|
|
|
}
|