Simplify the global internal data handling.

This commit is contained in:
Eric Pouech 2002-10-25 19:00:12 +00:00 committed by Alexandre Julliard
parent fb8bad49d9
commit 1e3e87d430
7 changed files with 147 additions and 186 deletions

View File

@ -72,14 +72,13 @@ inline static LPSTR str_dup_upper( LPCSTR str )
LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
{
LPWINE_MCIDRIVER wmd = 0;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
EnterCriticalSection(&iData->cs);
for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
EnterCriticalSection(&WINMM_IData->cs);
for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
if (wmd->wDeviceID == wDevID)
break;
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
return wmd;
}
@ -89,7 +88,6 @@ LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
UINT MCI_GetDriverFromString(LPCSTR lpstrName)
{
LPWINE_MCIDRIVER wmd;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
UINT ret = 0;
if (!lpstrName)
@ -98,8 +96,8 @@ UINT MCI_GetDriverFromString(LPCSTR lpstrName)
if (!lstrcmpiA(lpstrName, "ALL"))
return MCI_ALL_DEVICE_ID;
EnterCriticalSection(&iData->cs);
for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
EnterCriticalSection(&WINMM_IData->cs);
for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
if (wmd->lpstrElementName && strcmp(wmd->lpstrElementName, lpstrName) == 0) {
ret = wmd->wDeviceID;
break;
@ -113,7 +111,7 @@ UINT MCI_GetDriverFromString(LPCSTR lpstrName)
break;
}
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
return ret;
}
@ -284,12 +282,12 @@ static BOOL MCI_DumpCommandTable(UINT uTbl)
return TRUE;
}
static UINT MCI_SetCommandTable(LPWINE_MM_IDATA iData, HANDLE hMem, UINT uDevType);
static UINT MCI_SetCommandTable(HANDLE hMem, UINT uDevType);
/**************************************************************************
* MCI_GetCommandTable [internal]
*/
static UINT MCI_GetCommandTable(LPWINE_MM_IDATA iData, UINT uDevType)
static UINT MCI_GetCommandTable(UINT uDevType)
{
UINT uTbl;
char buf[32];
@ -303,7 +301,7 @@ static UINT MCI_GetCommandTable(LPWINE_MM_IDATA iData, UINT uDevType)
/* well try to load id */
if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
if (LoadStringA(iData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
if (LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
str = buf;
}
} else if (uDevType == 0) {
@ -311,15 +309,15 @@ static UINT MCI_GetCommandTable(LPWINE_MM_IDATA iData, UINT uDevType)
}
uTbl = MCI_NO_COMMAND_TABLE;
if (str) {
HRSRC hRsrc = FindResourceA(iData->hWinMM32Instance, str, (LPCSTR)RT_RCDATAA);
HRSRC hRsrc = FindResourceA(WINMM_IData->hWinMM32Instance, str, (LPCSTR)RT_RCDATAA);
HANDLE hMem = 0;
if (hRsrc) hMem = LoadResource(iData->hWinMM32Instance, hRsrc);
if (hRsrc) hMem = LoadResource(WINMM_IData->hWinMM32Instance, hRsrc);
if (hMem) {
uTbl = MCI_SetCommandTable(iData, hMem, uDevType);
uTbl = MCI_SetCommandTable(hMem, uDevType);
} else {
WARN("No command table found in resource %04x[%s]\n",
iData->hWinMM32Instance, str);
WINMM_IData->hWinMM32Instance, str);
}
}
TRACE("=> %d\n", uTbl);
@ -329,8 +327,7 @@ static UINT MCI_GetCommandTable(LPWINE_MM_IDATA iData, UINT uDevType)
/**************************************************************************
* MCI_SetCommandTable [internal]
*/
static UINT MCI_SetCommandTable(LPWINE_MM_IDATA iData, HANDLE hMem,
UINT uDevType)
static UINT MCI_SetCommandTable(HANDLE hMem, UINT uDevType)
{
int uTbl;
static BOOL bInitDone = FALSE;
@ -345,7 +342,7 @@ static UINT MCI_SetCommandTable(LPWINE_MM_IDATA iData, HANDLE hMem,
for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
S_MciCmdTable[uTbl].hMem = 0;
}
MCI_GetCommandTable(iData, 0);
MCI_GetCommandTable(0);
}
for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
@ -415,7 +412,7 @@ static BOOL MCI_DeleteCommandTable(UINT uTbl)
/**************************************************************************
* MCI_UnLoadMciDriver [internal]
*/
static BOOL MCI_UnLoadMciDriver(LPWINE_MM_IDATA iData, LPWINE_MCIDRIVER wmd)
static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
{
LPWINE_MCIDRIVER* tmp;
@ -427,14 +424,14 @@ static BOOL MCI_UnLoadMciDriver(LPWINE_MM_IDATA iData, LPWINE_MCIDRIVER wmd)
if (wmd->dwPrivate != 0)
WARN("Unloading mci driver with non nul dwPrivate field\n");
EnterCriticalSection(&iData->cs);
for (tmp = &iData->lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
EnterCriticalSection(&WINMM_IData->cs);
for (tmp = &WINMM_IData->lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
if (*tmp == wmd) {
*tmp = wmd->lpNext;
break;
}
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
@ -483,8 +480,7 @@ static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCSTR drvTyp, LPARAM lp)
/**************************************************************************
* MCI_LoadMciDriver [internal]
*/
static DWORD MCI_LoadMciDriver(LPWINE_MM_IDATA iData, LPCSTR _strDevTyp,
LPWINE_MCIDRIVER* lpwmd)
static DWORD MCI_LoadMciDriver(LPCSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
{
LPSTR strDevTyp = str_dup_upper(_strDevTyp);
LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
@ -501,12 +497,12 @@ static DWORD MCI_LoadMciDriver(LPWINE_MM_IDATA iData, LPCSTR _strDevTyp,
wmd->hCreatorTask = GetCurrentTask();
wmd->CreatorThread = GetCurrentThreadId();
EnterCriticalSection(&iData->cs);
EnterCriticalSection(&WINMM_IData->cs);
/* wmd must be inserted in list before sending opening the driver, coz' it
* may want to lookup at wDevID
*/
wmd->lpNext = iData->lpMciDrvs;
iData->lpMciDrvs = wmd;
wmd->lpNext = WINMM_IData->lpMciDrvs;
WINMM_IData->lpMciDrvs = wmd;
for (modp.wDeviceID = MCI_MAGIC;
MCI_GetDriver(modp.wDeviceID) != 0;
@ -514,7 +510,7 @@ static DWORD MCI_LoadMciDriver(LPWINE_MM_IDATA iData, LPCSTR _strDevTyp,
wmd->wDeviceID = modp.wDeviceID;
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
TRACE("wDevID=%04X \n", modp.wDeviceID);
@ -555,7 +551,7 @@ static DWORD MCI_LoadMciDriver(LPWINE_MM_IDATA iData, LPCSTR _strDevTyp,
*lpwmd = wmd;
return 0;
errCleanUp:
MCI_UnLoadMciDriver(iData, wmd);
MCI_UnLoadMciDriver(wmd);
HeapFree(GetProcessHeap(), 0, strDevTyp);
*lpwmd = 0;
return dwRet;
@ -803,9 +799,8 @@ static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCSTR lpCmd,
/**************************************************************************
* MCI_HandleReturnValues [internal]
*/
static DWORD MCI_HandleReturnValues(LPWINE_MM_IDATA iData, DWORD dwRet,
LPWINE_MCIDRIVER wmd, LPCSTR lpCmd, LPDWORD data,
LPSTR lpstrRet, UINT uRetLen)
static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, LPCSTR lpCmd,
LPDWORD data, LPSTR lpstrRet, UINT uRetLen)
{
if (lpstrRet) {
switch (MCI_GetReturnType(lpCmd)) {
@ -820,7 +815,7 @@ static DWORD MCI_HandleReturnValues(LPWINE_MM_IDATA iData, DWORD dwRet,
case MCI_RESOURCE_RETURNED:
/* return string which ID is HIWORD(data[1]),
* string is loaded from mmsystem.dll */
LoadStringA(iData->hWinMM32Instance, HIWORD(data[1]),
LoadStringA(WINMM_IData->hWinMM32Instance, HIWORD(data[1]),
lpstrRet, uRetLen);
break;
case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
@ -882,7 +877,6 @@ DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
DWORD data[MCI_DATA_SIZE];
LPCSTR lpCmd = 0;
LPSTR devAlias = NULL;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
BOOL bAutoOpen = FALSE;
TRACE("('%s', %p, %d, %X)\n", lpstrCommand, lpstrRet, uRetLen, hwndCallback);
@ -961,10 +955,10 @@ DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
/* dwFlags |= MCI_OPEN_ALIAS; */
}
dwRet = MCI_LoadMciDriver(iData, devType, &wmd);
dwRet = MCI_LoadMciDriver(devType, &wmd);
HeapFree(GetProcessHeap(), 0, devType);
if (dwRet) {
MCI_UnLoadMciDriver(iData, wmd);
MCI_UnLoadMciDriver(wmd);
goto errCleanUp;
}
} else if (!(wmd = MCI_GetDriver(mciGetDeviceIDA(dev)))) {
@ -990,13 +984,13 @@ DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
if (!lpCmd) {
/* try the type specific command table */
if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
wmd->uTypeCmdTable = MCI_GetCommandTable(iData, wmd->wType);
wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
}
}
/* try core command table */
if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(iData, 0), verb);
if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
if (!lpCmd) {
TRACE("Command '%s' not found!\n", verb);
@ -1043,13 +1037,13 @@ DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
if (strcmp(verb, "open") == 0) {
if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSA)data, dwFlags)))
MCI_UnLoadMciDriver(iData, wmd);
MCI_UnLoadMciDriver(wmd);
/* FIXME: notification is not properly shared across two opens */
} else {
dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
}
TRACE("=> 1/ %lx (%s)\n", dwRet, lpstrRet);
dwRet = MCI_HandleReturnValues(iData, dwRet, wmd, lpCmd, data, lpstrRet, uRetLen);
dwRet = MCI_HandleReturnValues(dwRet, wmd, lpCmd, data, lpstrRet, uRetLen);
TRACE("=> 2/ %lx (%s)\n", dwRet, lpstrRet);
errCleanUp:
@ -1109,7 +1103,6 @@ UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
HRSRC hRsrc = 0;
HGLOBAL hMem;
UINT16 ret = MCI_NO_COMMAND_TABLE;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
TRACE("(%04x, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
@ -1134,7 +1127,7 @@ UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
if (!(hRsrc = FindResourceW(hInst, resNameW, (LPCWSTR)RT_RCDATAA))) {
WARN("No command table found in resource\n");
} else if ((hMem = LoadResource(hInst, hRsrc))) {
ret = MCI_SetCommandTable(iData, hMem, type);
ret = MCI_SetCommandTable(hMem, type);
} else {
WARN("Couldn't load resource.\n");
}
@ -2137,7 +2130,6 @@ static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
char strDevTyp[128];
DWORD dwRet;
LPWINE_MCIDRIVER wmd = NULL;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
TRACE("(%08lX, %p)\n", dwParam, lpParms);
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
@ -2159,7 +2151,7 @@ static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
if (uDevType < MCI_DEVTYPE_FIRST ||
uDevType > MCI_DEVTYPE_LAST ||
!LoadStringA(iData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
!LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
dwRet = MCIERR_BAD_INTEGER;
goto errCleanUp;
}
@ -2233,7 +2225,7 @@ static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
}
}
if ((dwRet = MCI_LoadMciDriver(iData, strDevTyp, &wmd))) {
if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
goto errCleanUp;
}
@ -2251,7 +2243,7 @@ static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
return 0;
errCleanUp:
if (wmd) MCI_UnLoadMciDriver(iData, wmd);
if (wmd) MCI_UnLoadMciDriver(wmd);
if (dwParam & MCI_NOTIFY)
mciDriverNotify(lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
@ -2265,24 +2257,23 @@ static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms
{
DWORD dwRet;
LPWINE_MCIDRIVER wmd;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
if (wDevID == MCI_ALL_DEVICE_ID) {
LPWINE_MCIDRIVER next;
EnterCriticalSection(&iData->cs);
EnterCriticalSection(&WINMM_IData->cs);
/* FIXME: shall I notify once after all is done, or for
* each of the open drivers ? if the latest, which notif
* to return when only one fails ?
*/
for (wmd = iData->lpMciDrvs; wmd; ) {
for (wmd = WINMM_IData->lpMciDrvs; wmd; ) {
next = wmd->lpNext;
MCI_Close(wmd->wDeviceID, dwParam, lpParms);
wmd = next;
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
return 0;
}
@ -2292,7 +2283,7 @@ static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms
dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
MCI_UnLoadMciDriver(iData, wmd);
MCI_UnLoadMciDriver(wmd);
if (dwParam & MCI_NOTIFY)
mciDriverNotify(lpParms->dwCallback, wDevID,
@ -2328,7 +2319,6 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParm
{
DWORD ret = MCIERR_INVALID_DEVICE_ID;
LPWINE_MCIDRIVER wmd;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
@ -2344,11 +2334,11 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParm
lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
if (dwFlags & MCI_SYSINFO_OPEN) {
TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
EnterCriticalSection(&iData->cs);
for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
EnterCriticalSection(&WINMM_IData->cs);
for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
cnt++;
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
} else {
TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
cnt = MCI_InstalledCount;
@ -2357,12 +2347,12 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParm
if (dwFlags & MCI_SYSINFO_OPEN) {
TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
lpParms->wDeviceType);
EnterCriticalSection(&iData->cs);
for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
EnterCriticalSection(&WINMM_IData->cs);
for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
if (wmd->wType == lpParms->wDeviceType)
cnt++;
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
} else {
TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
lpParms->wDeviceType);

View File

@ -352,12 +352,9 @@ static LRESULT send_message(struct IOProcList* ioProc, LPMMIOINFO mmioinfo,
switch (ioProc->type) {
case MMIO_PROC_16:
{
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
if (iData && iData->pFnMmioCallback16)
result = iData->pFnMmioCallback16((SEGPTR)ioProc->pIOProc,
mmioinfo, wMsg, lp1, lp2);
}
if (WINMM_IData && WINMM_IData->pFnMmioCallback16)
result = WINMM_IData->pFnMmioCallback16((SEGPTR)ioProc->pIOProc,
mmioinfo, wMsg, lp1, lp2);
break;
case MMIO_PROC_32A:
case MMIO_PROC_32W:
@ -434,18 +431,16 @@ static FOURCC MMIO_ParseExtA(LPCSTR szFileName)
*
* Retrieves the mmio object from current process
*/
LPWINE_MMIO MMIO_Get(LPWINE_MM_IDATA iData, HMMIO h)
LPWINE_MMIO MMIO_Get(HMMIO h)
{
LPWINE_MMIO wm = NULL;
if (!iData) iData = MULTIMEDIA_GetIData();
EnterCriticalSection(&iData->cs);
for (wm = iData->lpMMIO; wm; wm = wm->lpNext) {
EnterCriticalSection(&WINMM_IData->cs);
for (wm = WINMM_IData->lpMMIO; wm; wm = wm->lpNext) {
if (wm->info.hmmio == h)
break;
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
return wm;
}
@ -458,17 +453,16 @@ static LPWINE_MMIO MMIO_Create(void)
{
static WORD MMIO_counter = 0;
LPWINE_MMIO wm;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
wm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MMIO));
if (wm) {
EnterCriticalSection(&iData->cs);
EnterCriticalSection(&WINMM_IData->cs);
/* lookup next unallocated WORD handle, with a non NULL value */
while (++MMIO_counter == 0 || MMIO_Get(iData, HMMIO_32(MMIO_counter)));
while (++MMIO_counter == 0 || MMIO_Get(HMMIO_32(MMIO_counter)));
wm->info.hmmio = HMMIO_32(MMIO_counter);
wm->lpNext = iData->lpMMIO;
iData->lpMMIO = wm;
LeaveCriticalSection(&iData->cs);
wm->lpNext = WINMM_IData->lpMMIO;
WINMM_IData->lpMMIO = wm;
LeaveCriticalSection(&WINMM_IData->cs);
}
return wm;
}
@ -480,12 +474,11 @@ static LPWINE_MMIO MMIO_Create(void)
*/
static BOOL MMIO_Destroy(LPWINE_MMIO wm)
{
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
LPWINE_MMIO* m;
EnterCriticalSection(&iData->cs);
EnterCriticalSection(&WINMM_IData->cs);
/* search for the matching one... */
m = &(iData->lpMMIO);
m = &(WINMM_IData->lpMMIO);
while (*m && *m != wm) m = &(*m)->lpNext;
/* ...and destroy */
if (*m) {
@ -493,7 +486,7 @@ static BOOL MMIO_Destroy(LPWINE_MMIO wm)
HeapFree(GetProcessHeap(), 0, wm);
wm = NULL;
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
return wm ? FALSE : TRUE;
}
@ -726,7 +719,7 @@ MMRESULT WINAPI mmioClose(HMMIO hmmio, UINT uFlags)
TRACE("(%04X, %04X);\n", hmmio, uFlags);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
if ((result = MMIO_Flush(wm, 0)) != MMSYSERR_NOERROR)
@ -758,7 +751,7 @@ LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
TRACE("(%04X, %p, %ld);\n", hmmio, pch, cch);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return -1;
/* unbuffered case first */
@ -808,7 +801,7 @@ LONG WINAPI mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch)
TRACE("(%04X, %p, %ld);\n", hmmio, pch, cch);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return -1;
if (wm->info.cchBuffer) {
@ -863,7 +856,7 @@ LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, INT iOrigin)
TRACE("(%04X, %08lX, %d);\n", hmmio, lOffset, iOrigin);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
/* not buffered, direct seek on file */
@ -928,7 +921,7 @@ MMRESULT WINAPI mmioGetInfo(HMMIO hmmio, MMIOINFO* lpmmioinfo, UINT uFlags)
TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
memcpy(lpmmioinfo, &wm->info, sizeof(MMIOINFO));
@ -948,7 +941,7 @@ MMRESULT WINAPI mmioSetInfo(HMMIO hmmio, const MMIOINFO* lpmmioinfo, UINT uFlags
TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
/* check pointers coherence */
@ -976,7 +969,7 @@ MMRESULT WINAPI mmioSetBuffer(HMMIO hmmio, LPSTR pchBuffer, LONG cchBuffer, UINT
TRACE("(hmmio=%04x, pchBuf=%p, cchBuf=%ld, uFlags=%#08x)\n",
hmmio, pchBuffer, cchBuffer, uFlags);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
return MMIO_SetBuffer(wm, pchBuffer, cchBuffer, uFlags);
@ -991,7 +984,7 @@ MMRESULT WINAPI mmioFlush(HMMIO hmmio, UINT uFlags)
TRACE("(%04X, %04X)\n", hmmio, uFlags);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
return MMIO_Flush(wm, uFlags);
@ -1009,7 +1002,7 @@ MMRESULT WINAPI mmioAdvance(HMMIO hmmio, MMIOINFO* lpmmioinfo, UINT uFlags)
/* NOTE: mmioAdvance16 heavily relies on parameters from lpmmioinfo we're using
* here. be sure if you change something here to check mmioAdvance16 as well
*/
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
if (!wm->info.cchBuffer)
@ -1116,7 +1109,7 @@ LRESULT MMIO_SendMessage(HMMIO hmmio, UINT uMessage, LPARAM lParam1,
if (uMessage < MMIOM_USER)
return MMSYSERR_INVALPARAM;
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
return send_message(wm->ioProc, &wm->info, uMessage, lParam1, lParam2, type);

View File

@ -68,7 +68,6 @@ BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
{
HANDLE hndl;
LPWINE_MM_IDATA iData;
TRACE("0x%x 0x%lx\n", hinstDLL, fdwReason);
@ -84,14 +83,12 @@ BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
ERR("Could not load sibling WinMM.dll\n");
return FALSE;
}
iData = MULTIMEDIA_GetIData();
iData->hWinMM16Instance = hinstDLL;
iData->h16Module32 = hndl;
iData->pFnMmioCallback16 = mmioCallback16;
WINMM_IData->hWinMM16Instance = hinstDLL;
WINMM_IData->h16Module32 = hndl;
WINMM_IData->pFnMmioCallback16 = mmioCallback16;
break;
case DLL_PROCESS_DETACH:
iData = MULTIMEDIA_GetIData();
FreeLibrary(iData->h16Module32);
FreeLibrary(WINMM_IData->h16Module32);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
@ -2243,7 +2240,8 @@ MMRESULT16 WINAPI timeGetSystemTime16(LPMMTIME16 lpTime, UINT16 wSize)
if (wSize >= sizeof(*lpTime)) {
lpTime->wType = TIME_MS;
lpTime->u.ms = TIME_MMTimeStart()->mmSysTimeMS;
TIME_MMTimeStart();
lpTime->u.ms = WINMM_IData->mmSysTimeMS;
TRACE("=> %lu\n", lpTime->u.ms);
}
@ -2447,7 +2445,7 @@ static LRESULT MMIO_SetSegmentedBuffer(HMMIO hmmio, SEGPTR ptr)
{
LPWINE_MMIO wm;
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
wm->segBuffer16 = ptr;
return MMSYSERR_NOERROR;
@ -2530,7 +2528,7 @@ MMRESULT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uF
TRACE("(0x%04x,%p,0x%08x)\n", hmmio, lpmmioinfo, uFlags);
if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
if ((wm = MMIO_Get(hmmio)) == NULL)
return MMSYSERR_INVALHANDLE;
ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);

View File

@ -180,14 +180,13 @@ static BOOL PlaySound_IsString(DWORD fdwSound, const void* psz)
static void PlaySound_Free(WINE_PLAYSOUND* wps)
{
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
WINE_PLAYSOUND** p;
EnterCriticalSection(&iData->cs);
for (p = &iData->lpPlaySound; *p && *p != wps; p = &((*p)->lpNext));
EnterCriticalSection(&WINMM_IData->cs);
for (p = &WINMM_IData->lpPlaySound; *p && *p != wps; p = &((*p)->lpNext));
if (*p) *p = (*p)->lpNext;
if (iData->lpPlaySound == NULL) SetEvent(iData->psLastEvent);
LeaveCriticalSection(&iData->cs);
if (WINMM_IData->lpPlaySound == NULL) SetEvent(WINMM_IData->psLastEvent);
LeaveCriticalSection(&WINMM_IData->cs);
if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
HeapFree(GetProcessHeap(), 0, wps);
}
@ -236,7 +235,6 @@ static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
static DWORD WINAPI proc_PlaySound(LPVOID arg)
{
WINE_PLAYSOUND* wps = (WINE_PLAYSOUND*)arg;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
BOOL bRet = FALSE;
HMMIO hmmio = 0;
MMCKINFO ckMainRIFF;
@ -369,7 +367,7 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
mmioSeek(hmmio, mmckInfo.dwDataOffset, SEEK_SET);
while (left)
{
if (WaitForSingleObject(iData->psStopEvent, 0) == WAIT_OBJECT_0)
if (WaitForSingleObject(WINMM_IData->psStopEvent, 0) == WAIT_OBJECT_0)
{
wps->bLoop = FALSE;
break;
@ -410,7 +408,6 @@ errCleanUp:
BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode)
{
WINE_PLAYSOUND* wps = NULL;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
TRACE("pszSound='%p' hmod=%04X fdwSound=%08lX\n",
pszSound, hmod, fdwSound);
@ -418,7 +415,7 @@ BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSound, BO
/* FIXME? I see no difference between SND_NOWAIT and SND_NOSTOP !
* there could be one if several sounds can be played at once...
*/
if ((fdwSound & (SND_NOWAIT | SND_NOSTOP)) && iData->lpPlaySound != NULL)
if ((fdwSound & (SND_NOWAIT | SND_NOSTOP)) && WINMM_IData->lpPlaySound != NULL)
return FALSE;
/* alloc internal structure, if we need to play something */
@ -428,27 +425,27 @@ BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSound, BO
return FALSE;
}
EnterCriticalSection(&iData->cs);
EnterCriticalSection(&WINMM_IData->cs);
/* since several threads can enter PlaySound in parallel, we're not
* sure, at this point, that another thread didn't start a new playsound
*/
while (iData->lpPlaySound != NULL)
while (WINMM_IData->lpPlaySound != NULL)
{
ResetEvent(iData->psLastEvent);
ResetEvent(WINMM_IData->psLastEvent);
/* FIXME: doc says we have to stop all instances of pszSound if it's non
* NULL... as of today, we stop all playing instances */
SetEvent(iData->psStopEvent);
SetEvent(WINMM_IData->psStopEvent);
LeaveCriticalSection(&iData->cs);
WaitForSingleObject(iData->psLastEvent, INFINITE);
EnterCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
WaitForSingleObject(WINMM_IData->psLastEvent, INFINITE);
EnterCriticalSection(&WINMM_IData->cs);
ResetEvent(iData->psStopEvent);
ResetEvent(WINMM_IData->psStopEvent);
}
if (wps) wps->lpNext = iData->lpPlaySound;
iData->lpPlaySound = wps;
LeaveCriticalSection(&iData->cs);
if (wps) wps->lpNext = WINMM_IData->lpPlaySound;
WINMM_IData->lpPlaySound = wps;
LeaveCriticalSection(&WINMM_IData->cs);
if (!pszSound || (fdwSound & SND_PURGE)) return TRUE;
@ -568,4 +565,3 @@ BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev,
TRACE("Done\n");
return TRUE;
}

View File

@ -176,25 +176,22 @@ static DWORD CALLBACK TIME_MMSysTimeThread(LPVOID arg)
/**************************************************************************
* TIME_MMTimeStart
*/
LPWINE_MM_IDATA TIME_MMTimeStart(void)
void TIME_MMTimeStart(void)
{
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
if (IsBadWritePtr(iData, sizeof(WINE_MM_IDATA))) {
if (IsBadWritePtr(WINMM_IData, sizeof(WINE_MM_IDATA))) {
ERR("iData is not correctly set, please report. Expect failure.\n");
return 0;
return;
}
/* one could think it's possible to stop the service thread activity when no more
* mm timers are active, but this would require to keep mmSysTimeMS up-to-date
* without being incremented within the service thread callback.
*/
if (!iData->hMMTimer) {
iData->mmSysTimeMS = GetTickCount();
iData->lpTimerList = NULL;
iData->hMMTimer = CreateThread(NULL, 0, TIME_MMSysTimeThread, iData, 0, NULL);
if (!WINMM_IData->hMMTimer) {
WINMM_IData->mmSysTimeMS = GetTickCount();
WINMM_IData->lpTimerList = NULL;
WINMM_IData->hMMTimer = CreateThread(NULL, 0, TIME_MMSysTimeThread, WINMM_IData, 0, NULL);
}
return iData;
}
/**************************************************************************
@ -202,15 +199,13 @@ LPWINE_MM_IDATA TIME_MMTimeStart(void)
*/
void TIME_MMTimeStop(void)
{
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
if (IsBadWritePtr(iData, sizeof(WINE_MM_IDATA))) {
ERR("iData is not correctly set, please report. Expect failure.\n");
if (IsBadWritePtr(WINMM_IData, sizeof(WINE_MM_IDATA))) {
ERR("WINMM_IData is not correctly set, please report. Expect failure.\n");
return;
}
if (iData->hMMTimer) {
HANDLE hMMTimer = iData->hMMTimer;
iData->hMMTimer = 0;
if (WINMM_IData->hMMTimer) {
HANDLE hMMTimer = WINMM_IData->hMMTimer;
WINMM_IData->hMMTimer = 0;
WaitForSingleObject(hMMTimer, INFINITE);
CloseHandle(hMMTimer);
}
@ -224,8 +219,9 @@ MMRESULT WINAPI timeGetSystemTime(LPMMTIME lpTime, UINT wSize)
TRACE("(%p, %u);\n", lpTime, wSize);
if (wSize >= sizeof(*lpTime)) {
TIME_MMTimeStart();
lpTime->wType = TIME_MS;
lpTime->u.ms = TIME_MMTimeStart()->mmSysTimeMS;
lpTime->u.ms = WINMM_IData->mmSysTimeMS;
TRACE("=> %lu\n", lpTime->u.ms);
}
@ -242,7 +238,6 @@ WORD timeSetEventInternal(UINT wDelay, UINT wResol,
WORD wNewID = 0;
LPWINE_TIMERENTRY lpNewTimer;
LPWINE_TIMERENTRY lpTimer;
LPWINE_MM_IDATA iData;
TRACE("(%u, %u, %p, %08lX, %04X);\n", wDelay, wResol, lpFunc, dwUser, wFlags);
@ -253,7 +248,7 @@ WORD timeSetEventInternal(UINT wDelay, UINT wResol,
if (wDelay < MMSYSTIME_MININTERVAL || wDelay > MMSYSTIME_MAXINTERVAL)
return 0;
iData = TIME_MMTimeStart();
TIME_MMTimeStart();
lpNewTimer->uCurTime = wDelay;
lpNewTimer->wDelay = wDelay;
@ -262,17 +257,17 @@ WORD timeSetEventInternal(UINT wDelay, UINT wResol,
lpNewTimer->dwUser = dwUser;
lpNewTimer->wFlags = wFlags;
EnterCriticalSection(&iData->cs);
EnterCriticalSection(&WINMM_IData->cs);
for (lpTimer = iData->lpTimerList; lpTimer != NULL; lpTimer = lpTimer->lpNext) {
for (lpTimer = WINMM_IData->lpTimerList; lpTimer != NULL; lpTimer = lpTimer->lpNext) {
wNewID = max(wNewID, lpTimer->wTimerID);
}
lpNewTimer->lpNext = iData->lpTimerList;
iData->lpTimerList = lpNewTimer;
lpNewTimer->lpNext = WINMM_IData->lpTimerList;
WINMM_IData->lpTimerList = lpNewTimer;
lpNewTimer->wTimerID = wNewID + 1;
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
TRACE("=> %u\n", wNewID + 1);
@ -298,18 +293,17 @@ MMRESULT WINAPI timeSetEvent(UINT wDelay, UINT wResol, LPTIMECALLBACK lpFunc,
MMRESULT WINAPI timeKillEvent(UINT wID)
{
LPWINE_TIMERENTRY* lpTimer;
LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
MMRESULT ret = MMSYSERR_INVALPARAM;
TRACE("(%u)\n", wID);
EnterCriticalSection(&iData->cs);
EnterCriticalSection(&WINMM_IData->cs);
/* remove WINE_TIMERENTRY from list */
for (lpTimer = &iData->lpTimerList; *lpTimer; lpTimer = &(*lpTimer)->lpNext) {
for (lpTimer = &WINMM_IData->lpTimerList; *lpTimer; lpTimer = &(*lpTimer)->lpNext) {
if (wID == (*lpTimer)->wTimerID) {
break;
}
}
LeaveCriticalSection(&iData->cs);
LeaveCriticalSection(&WINMM_IData->cs);
if (*lpTimer) {
LPWINE_TIMERENTRY lpTemp = *lpTimer;
@ -373,5 +367,6 @@ DWORD WINAPI timeGetTime(void)
DWORD count;
ReleaseThunkLock(&count);
RestoreThunkLock(count);
return TIME_MMTimeStart()->mmSysTimeMS;
TIME_MMTimeStart();
return WINMM_IData->mmSysTimeMS;
}

View File

@ -257,15 +257,17 @@ LPMMIOPROC MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC
DWORD dwFlags, enum mmioProcType type);
LRESULT MMIO_SendMessage(HMMIO hmmio, UINT uMessage, LPARAM lParam1,
LPARAM lParam2, enum mmioProcType type);
LPWINE_MMIO MMIO_Get(LPWINE_MM_IDATA iData, HMMIO h);
LPWINE_MMIO MMIO_Get(HMMIO h);
BOOL MULTIMEDIA_MciInit(void);
LPWINE_MM_IDATA MULTIMEDIA_GetIData(void);
BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode);
LPWINE_MM_IDATA TIME_MMTimeStart(void);
void TIME_MMTimeStart(void);
void TIME_MMTimeStop(void);
/* Global variables */
extern LPWINE_MM_IDATA WINMM_IData;
/* HANDLE16 -> HANDLE conversions */
#define HDRVR_32(h16) ((HDRVR)(ULONG_PTR)(h16))
#define HMIDI_32(h16) ((HMIDI)(ULONG_PTR)(h16))

View File

@ -72,36 +72,23 @@ void MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16)
* G L O B A L S E T T I N G S
* ========================================================================*/
static LPWINE_MM_IDATA S_IData = NULL;
/**************************************************************************
* MULTIMEDIA_GetIData [internal]
*/
LPWINE_MM_IDATA MULTIMEDIA_GetIData(void)
{
if (!S_IData) {
ERR("IData not found for pid=%08lx. Suicide !!!\n", GetCurrentProcessId());
DbgBreakPoint();
ExitProcess(0);
}
return S_IData;
}
LPWINE_MM_IDATA WINMM_IData /* = NULL */;
/**************************************************************************
* MULTIMEDIA_CreateIData [internal]
*/
static BOOL MULTIMEDIA_CreateIData(HINSTANCE hInstDLL)
{
S_IData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MM_IDATA));
WINMM_IData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MM_IDATA));
if (!S_IData)
if (!WINMM_IData)
return FALSE;
S_IData->hWinMM32Instance = hInstDLL;
InitializeCriticalSection(&S_IData->cs);
S_IData->cs.DebugInfo = (void*)__FILE__ ": WinMM";
S_IData->psStopEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
S_IData->psLastEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
TRACE("Created IData (%p)\n", S_IData);
WINMM_IData->hWinMM32Instance = hInstDLL;
InitializeCriticalSection(&WINMM_IData->cs);
WINMM_IData->cs.DebugInfo = (void*)__FILE__ ": WinMM";
WINMM_IData->psStopEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
WINMM_IData->psLastEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
TRACE("Created IData (%p)\n", WINMM_IData);
return TRUE;
}
@ -110,16 +97,16 @@ static BOOL MULTIMEDIA_CreateIData(HINSTANCE hInstDLL)
*/
static void MULTIMEDIA_DeleteIData(void)
{
if (S_IData) {
if (WINMM_IData) {
TIME_MMTimeStop();
/* FIXME: should also free content and resources allocated
* inside S_IData */
CloseHandle(S_IData->psStopEvent);
CloseHandle(S_IData->psLastEvent);
DeleteCriticalSection(&S_IData->cs);
HeapFree(GetProcessHeap(), 0, S_IData);
S_IData = NULL;
* inside WINMM_IData */
CloseHandle(WINMM_IData->psStopEvent);
CloseHandle(WINMM_IData->psLastEvent);
DeleteCriticalSection(&WINMM_IData->cs);
HeapFree(GetProcessHeap(), 0, WINMM_IData);
WINMM_IData = NULL;
}
}
@ -701,7 +688,7 @@ BOOL WINAPI mciGetErrorStringA(DWORD dwError, LPSTR lpstrBuffer, UINT uLength)
if (lpstrBuffer != NULL && uLength > 0 &&
dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
if (LoadStringA(MULTIMEDIA_GetIData()->hWinMM32Instance,
if (LoadStringA(WINMM_IData->hWinMM32Instance,
dwError, lpstrBuffer, uLength) > 0) {
ret = TRUE;
}
@ -986,7 +973,7 @@ static UINT16 MIDI_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
(/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
(uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
if (LoadStringA(MULTIMEDIA_GetIData()->hWinMM32Instance,
if (LoadStringA(WINMM_IData->hWinMM32Instance,
uError, lpText, uSize) > 0) {
ret = MMSYSERR_NOERROR;
}
@ -2286,7 +2273,7 @@ static UINT16 WAVE_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
(/*uError >= MMSYSERR_BASE && */uError <= MMSYSERR_LASTERROR) ||
(uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
if (LoadStringA(MULTIMEDIA_GetIData()->hWinMM32Instance,
if (LoadStringA(WINMM_IData->hWinMM32Instance,
uError, lpText, uSize) > 0) {
ret = MMSYSERR_NOERROR;
}