1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * MMSYTEM low level drivers handling functions
6 * Copyright 1999 Eric Pouech
12 #include "user.h" /* should be removed asap; used in MMDRV_(Get|Alloc|Free) */
13 #include "selectors.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(mmsys
)
22 typedef DWORD
CALLBACK (*WINEMM_msgFunc16
)(UINT16
, WORD
, DWORD
, DWORD
, DWORD
);
23 typedef DWORD
CALLBACK (*WINEMM_msgFunc32
)(UINT
, UINT
, DWORD
, DWORD
, DWORD
);
25 /* for each loaded driver and each known type of driver, this structure contains
26 * the information needed to access it
28 typedef struct tagWINE_MM_DRIVER_PART
{
29 int nIDMin
; /* lower bound of global indexes for this type */
30 int nIDMax
; /* hhigher bound of global indexes for this type */
32 WINEMM_msgFunc32 fnMessage32
; /* pointer to fonction */
33 WINEMM_msgFunc16 fnMessage16
;
35 } WINE_MM_DRIVER_PART
;
37 /* each low-level .drv will be associated with an instance of this structure */
38 typedef struct tagWINE_MM_DRIVER
{
39 HDRVR hDrvr
; /* handle of loader driver */
40 LPSTR name
; /* name of the driver */
41 BOOL bIs32
: 1, /* TRUE if 32 bit driver, FALSE for 16 */
42 bIsMapper
: 1; /* TRUE if mapper */
43 WINE_MM_DRIVER_PART parts
[MMDRV_MAX
];/* Information for all known types */
44 } WINE_MM_DRIVER
, *LPWINE_MM_DRIVER
;
47 MMDRV_MAP_NOMEM
, /* ko, memory problem */
48 MMDRV_MAP_MSGERROR
, /* ko, unknown message */
49 MMDRV_MAP_OK
, /* ok, no memory allocated. to be sent to the proc. */
50 MMDRV_MAP_OKMEM
, /* ok, some memory allocated, need to call UnMapMsg. to be sent to the proc. */
51 MMDRV_MAP_PASS
/* not handled (no memory allocated) to be sent to the driver */
54 typedef MMDRV_MapType (*MMDRV_MAPFUNC
)(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
);
56 /* each known type of driver has an instance of this structure */
57 typedef struct tagWINE_LLTYPE
{
58 /* those attributes depend on the specification of the type */
59 LPSTR name
; /* name (for debugging) */
60 BOOL bSupportMapper
; /* if type is allowed to support mapper */
61 MMDRV_MAPFUNC Map16To32A
; /* those are function pointers to handle */
62 MMDRV_MAPFUNC UnMap16To32A
; /* the parameter conversion (16 vs 32 bit) */
63 MMDRV_MAPFUNC Map32ATo16
; /* when hi-func (in mmsystem or winmm) and */
64 MMDRV_MAPFUNC UnMap32ATo16
; /* low-func (in .drv) do not match */
65 LPDRVCALLBACK Callback
; /* handles callback for a specified type */
66 /* those attributes reflect the loaded/current situation for the type */
67 UINT wMaxId
; /* number of loaded devices (sum across all loaded drivers */
68 LPWINE_MLD lpMlds
; /* "static" mlds to access the part though device IDs */
69 int nMapper
; /* index to mapper */
72 static WINE_MM_DRIVER MMDrvs
[3];
74 /* ### start build ### */
75 extern WORD CALLBACK
MMDRV_CallTo16_word_wwlll(FARPROC16
,WORD
,WORD
,LONG
,LONG
,LONG
);
76 /* ### stop build ### */
78 /**************************************************************************
79 * MMDRV_GetDescription16 [internal]
81 static BOOL
MMDRV_GetDescription16(const char* fname
, char* buf
, int buflen
)
89 if ((hFile
= OpenFile(fname
, &ofs
, OF_READ
| OF_SHARE_DENY_WRITE
)) == HFILE_ERROR
) {
90 ERR("Can't open file %s\n", fname
);
94 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
96 if (_lread(hFile
, &w
, 2) != 2) E(("Can't read sig\n"));
97 if (w
!= ('Z' * 256 + 'M')) E(("Bad sig %04x\n", w
));
98 if (_llseek(hFile
, 0x3C, SEEK_SET
) < 0) E(("Can't seek to ext header offset\n"));
99 if (_lread(hFile
, &dw
, 4) != 4) E(("Can't read ext header offset\n"));
100 if (_llseek(hFile
, dw
+ 0x2C, SEEK_SET
) < 0) E(("Can't seek to ext header.nr table %lu\n", dw
+0x2C));
101 if (_lread(hFile
, &dw
, 4) != 4) E(("Can't read nr table offset\n"));
102 if (_llseek(hFile
, dw
, SEEK_SET
) < 0) E(("Can't seek to nr table %lu\n", dw
));
103 if (_lread(hFile
, buf
, 1) != 1) E(("Can't read descr length\n"));
104 buflen
= MIN((BYTE
)buf
[0], buflen
- 1);
105 if (_lread(hFile
, buf
, buflen
) != buflen
) E(("Can't read descr (%d)\n", buflen
));
108 TRACE("Got '%s' [%d]\n", buf
, buflen
);
114 /**************************************************************************
115 * MMDRV_GetDescription32 [internal]
117 static BOOL
MMDRV_GetDescription32(const char* fname
, char* buf
, int buflen
)
127 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
129 if (OpenFile(fname
, &ofs
, OF_EXIST
)==HFILE_ERROR
) E(("Can't find file %s\n", fname
));
131 /* should load version.dll */
132 if (!(dw
= GetFileVersionInfoSizeA(ofs
.szPathName
, &h
))) E(("Can't get FVIS\n"));
133 if (!(ptr
= HeapAlloc(GetProcessHeap(), 0, dw
))) E(("OOM\n"));
134 if (!GetFileVersionInfoA(ofs
.szPathName
, h
, dw
, ptr
)) E(("Can't get FVI\n"));
136 #define A(_x) if (VerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\" #_x, &val, &u)) \
137 TRACE(#_x " => %s\n", (LPSTR)val); else TRACE(#_x " @\n")
153 if (!VerQueryValueA(ptr
, "\\StringFileInfo\\040904B0\\ProductName", &val
, &u
)) E(("Can't get product name\n"));
154 strncpy(buf
, val
, buflen
- 1);
155 buf
[buflen
- 1] = '\0';
160 HeapFree(GetProcessHeap(), 0, ptr
);
164 /**************************************************************************
165 * MMDRV_Callback [internal]
167 static void MMDRV_Callback(LPWINE_MLD mld
, HDRVR hDev
, UINT uMsg
, DWORD dwParam1
, DWORD dwParam2
)
169 TRACE("CB (*%08lx)(%08x %08x %08lx %08lx %08lx\n",
170 mld
->dwCallback
, hDev
, uMsg
, mld
->dwClientInstance
, dwParam1
, dwParam2
);
172 if (!mld
->bFrom32
&& (mld
->dwFlags
& DCB_TYPEMASK
) == DCB_FUNCTION
) {
173 /* 16 bit func, call it */
174 TRACE("Function (16 bit) !\n");
175 MMDRV_CallTo16_word_wwlll((FARPROC16
)mld
->dwCallback
, hDev
, uMsg
,
176 mld
->dwClientInstance
, dwParam1
, dwParam2
);
178 DriverCallback(mld
->dwCallback
, mld
->dwFlags
, hDev
, uMsg
,
179 mld
->dwClientInstance
, dwParam1
, dwParam2
);
183 /* =================================
184 * A U X M A P P E R S
185 * ================================= */
187 /**************************************************************************
188 * MMDRV_Aux_Map16To32A [internal]
190 static MMDRV_MapType
MMDRV_Aux_Map16To32A (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
192 return MMDRV_MAP_MSGERROR
;
195 /**************************************************************************
196 * MMDRV_Aux_UnMap16To32A [internal]
198 static MMDRV_MapType
MMDRV_Aux_UnMap16To32A(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
200 return MMDRV_MAP_MSGERROR
;
203 /**************************************************************************
204 * MMDRV_Aux_Map32ATo16 [internal]
206 static MMDRV_MapType
MMDRV_Aux_Map32ATo16 (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
208 return MMDRV_MAP_MSGERROR
;
211 /**************************************************************************
212 * MMDRV_Aux_UnMap32ATo16 [internal]
214 static MMDRV_MapType
MMDRV_Aux_UnMap32ATo16(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
217 case AUXDM_GETDEVCAPS
:
218 lpCaps
->wMid
= ac16
.wMid
;
219 lpCaps
->wPid
= ac16
.wPid
;
220 lpCaps
->vDriverVersion
= ac16
.vDriverVersion
;
221 strcpy(lpCaps
->szPname
, ac16
.szPname
);
222 lpCaps
->wTechnology
= ac16
.wTechnology
;
223 lpCaps
->dwSupport
= ac16
.dwSupport
;
225 return MMDRV_MAP_MSGERROR
;
228 /**************************************************************************
229 * MMDRV_Aux_Callback [internal]
231 static void CALLBACK
MMDRV_Aux_Callback(HDRVR hDev
, UINT uMsg
, DWORD dwInstance
, DWORD dwParam1
, DWORD dwParam2
)
233 LPWINE_MLD mld
= (LPWINE_MLD
)dwInstance
;
236 MMDRV_Callback(mld
, hDev
, uMsg
, dwParam1
, dwParam2
);
239 /* =================================
240 * M I X E R M A P P E R S
241 * ================================= */
243 /**************************************************************************
244 * xMMDRV_Mixer_Map16To32A [internal]
246 static MMDRV_MapType
MMDRV_Mixer_Map16To32A (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
248 return MMDRV_MAP_MSGERROR
;
251 /**************************************************************************
252 * MMDRV_Mixer_UnMap16To32A [internal]
254 static MMDRV_MapType
MMDRV_Mixer_UnMap16To32A(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
258 UINT ret
= mixerGetDevCapsA(devid
, &micA
, sizeof(micA
));
260 if (ret
== MMSYSERR_NOERROR
) {
261 mixcaps
->wMid
= micA
.wMid
;
262 mixcaps
->wPid
= micA
.wPid
;
263 mixcaps
->vDriverVersion
= micA
.vDriverVersion
;
264 strcpy(mixcaps
->szPname
, micA
.szPname
);
265 mixcaps
->fdwSupport
= micA
.fdwSupport
;
266 mixcaps
->cDestinations
= micA
.cDestinations
;
270 return MMDRV_MAP_MSGERROR
;
273 /**************************************************************************
274 * MMDRV_Mixer_Map32ATo16 [internal]
276 static MMDRV_MapType
MMDRV_Mixer_Map32ATo16 (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
278 return MMDRV_MAP_MSGERROR
;
281 /**************************************************************************
282 * MMDRV_Mixer_UnMap32ATo16 [internal]
284 static MMDRV_MapType
MMDRV_Mixer_UnMap32ATo16(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
286 return MMDRV_MAP_MSGERROR
;
289 /**************************************************************************
290 * MMDRV_Mixer_Callback [internal]
292 static void CALLBACK
MMDRV_Mixer_Callback(HDRVR hDev
, UINT uMsg
, DWORD dwInstance
, DWORD dwParam1
, DWORD dwParam2
)
294 LPWINE_MLD mld
= (LPWINE_MLD
)dwInstance
;
297 MMDRV_Callback(mld
, hDev
, uMsg
, dwParam1
, dwParam2
);
300 /* =================================
301 * M I D I I N M A P P E R S
302 * ================================= */
304 /**************************************************************************
305 * MMDRV_MidiIn_Map16To32A [internal]
307 static MMDRV_MapType
MMDRV_MidiIn_Map16To32A (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
309 return MMDRV_MAP_MSGERROR
;
312 /**************************************************************************
313 * MMDRV_MidiIn_UnMap16To32A [internal]
315 static MMDRV_MapType
MMDRV_MidiIn_UnMap16To32A(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
317 return MMDRV_MAP_MSGERROR
;
320 /**************************************************************************
321 * MMDRV_MidiIn_Map32ATo16 [internal]
323 static MMDRV_MapType
MMDRV_MidiIn_Map32ATo16 (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
325 return MMDRV_MAP_MSGERROR
;
328 /**************************************************************************
329 * MMDRV_MidiIn_UnMap32ATo16 [internal]
331 static MMDRV_MapType
MMDRV_MidiIn_UnMap32ATo16(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
333 return MMDRV_MAP_MSGERROR
;
336 /**************************************************************************
337 * MMDRV_MidiIn_Callback [internal]
339 static void CALLBACK
MMDRV_MidiIn_Callback(HDRVR hDev
, UINT uMsg
, DWORD dwInstance
, DWORD dwParam1
, DWORD dwParam2
)
341 LPWINE_MLD mld
= (LPWINE_MLD
)dwInstance
;
344 MMDRV_Callback(mld
, hDev
, uMsg
, dwParam1
, dwParam2
);
347 /* =================================
348 * M I D I O U T M A P P E R S
349 * ================================= */
351 /**************************************************************************
352 * MMDRV_MidiOut_Map16To32A [internal]
354 static MMDRV_MapType
MMDRV_MidiOut_Map16To32A (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
356 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
359 case MODM_GETNUMDEVS
:
368 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
371 case MODM_GETDEVCAPS
:
373 LPMIDIOUTCAPSA moc32
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPS16
) + sizeof(MIDIOUTCAPSA
));
374 LPMIDIOUTCAPS16 moc16
= PTR_SEG_TO_LIN(*lpParam1
);
377 *(LPMIDIOUTCAPS16
*)moc32
= moc16
;
378 moc32
= (LPMIDIOUTCAPSA
)((LPSTR
)moc32
+ sizeof(LPMIDIOUTCAPS16
));
379 *lpParam1
= (DWORD
)moc32
;
380 *lpParam2
= sizeof(MIDIOUTCAPSA
);
382 ret
= MMDRV_MAP_OKMEM
;
384 ret
= MMDRV_MAP_NOMEM
;
392 case MODM_CACHEPATCHES
:
393 case MODM_CACHEDRUMPATCHES
:
395 FIXME("NIY: no conversion yet for %u\n", wMsg
);
401 /**************************************************************************
402 * MMDRV_MidiOut_UnMap16To32A [internal]
404 static MMDRV_MapType
MMDRV_MidiOut_UnMap16To32A(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
406 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
409 case MODM_GETNUMDEVS
:
418 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
421 case MODM_GETDEVCAPS
:
423 LPMIDIOUTCAPSA moc32
= (LPMIDIOUTCAPSA
)(*lpParam1
);
424 LPMIDIOUTCAPS16 moc16
= *(LPMIDIOUTCAPS16
*)((LPSTR
)moc32
- sizeof(LPMIDIOUTCAPS16
));
426 moc16
->wMid
= moc32
->wMid
;
427 moc16
->wPid
= moc32
->wPid
;
428 moc16
->vDriverVersion
= moc32
->vDriverVersion
;
429 strcpy(moc16
->szPname
, moc32
->szPname
);
430 moc16
->wTechnology
= moc32
->wTechnology
;
431 moc16
->wVoices
= moc32
->wVoices
;
432 moc16
->wNotes
= moc32
->wNotes
;
433 moc16
->wChannelMask
= moc32
->wChannelMask
;
434 moc16
->dwSupport
= moc32
->dwSupport
;
435 HeapFree(GetProcessHeap(), 0, (LPSTR
)moc32
- sizeof(LPMIDIOUTCAPS16
));
443 case MODM_CACHEPATCHES
:
444 case MODM_CACHEDRUMPATCHES
:
446 FIXME("NIY: no conversion yet for %u\n", wMsg
);
452 /**************************************************************************
453 * MMDRV_MidiOut_Map32ATo16 [internal]
455 static MMDRV_MapType
MMDRV_MidiOut_Map32ATo16 (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
457 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
461 case MODM_GETNUMDEVS
:
467 case MODM_GETDEVCAPS
:
469 LPMIDIOUTCAPSA moc32
= (LPMIDIOUTCAPSA
)*lpParam1
;
470 LPSTR ptr
= SEGPTR_ALLOC(sizeof(LPMIDIOUTCAPSA
) + sizeof(MIDIOUTCAPS16
));
473 *(LPMIDIOUTCAPSA
*)ptr
= moc32
;
474 ret
= MMDRV_MAP_OKMEM
;
476 ret
= MMDRV_MAP_NOMEM
;
478 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPMIDIOUTCAPSA
);
479 *lpParam2
= sizeof(MIDIOUTCAPS16
);
487 case MODM_CACHEPATCHES
:
488 case MODM_CACHEDRUMPATCHES
:
490 FIXME("NIY: no conversion yet for %u\n", wMsg
);
496 /**************************************************************************
497 * MMDRV_MidiOut_UnMap32ATo16 [internal]
499 static MMDRV_MapType
MMDRV_MidiOut_UnMap32ATo16(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
501 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
505 case MODM_GETNUMDEVS
:
511 case MODM_GETDEVCAPS
:
513 LPMIDIOUTCAPS16 moc16
= (LPMIDIOUTCAPS16
)PTR_SEG_TO_LIN(*lpParam1
);
514 LPSTR ptr
= (LPSTR
)moc16
- sizeof(LPMIDIOUTCAPSA
);
515 LPMIDIOUTCAPSA moc32
= *(LPMIDIOUTCAPSA
*)ptr
;
517 moc32
->wMid
= moc16
->wMid
;
518 moc32
->wPid
= moc16
->wPid
;
519 moc32
->vDriverVersion
= moc16
->vDriverVersion
;
520 strcpy(moc32
->szPname
, moc16
->szPname
);
521 moc32
->wTechnology
= moc16
->wTechnology
;
522 moc32
->wVoices
= moc16
->wVoices
;
523 moc32
->wNotes
= moc16
->wNotes
;
524 moc32
->wChannelMask
= moc16
->wChannelMask
;
525 moc32
->dwSupport
= moc16
->dwSupport
;
527 if (!SEGPTR_FREE(ptr
))
528 FIXME("bad free line=%d\n", __LINE__
);
537 case MODM_CACHEPATCHES
:
538 case MODM_CACHEDRUMPATCHES
:
540 FIXME("NIY: no conversion yet for %u\n", wMsg
);
546 /**************************************************************************
547 * MMDRV_MidiOut_Callback [internal]
549 static void CALLBACK
MMDRV_MidiOut_Callback(HDRVR hDev
, UINT uMsg
, DWORD dwInstance
, DWORD dwParam1
, DWORD dwParam2
)
551 LPWINE_MLD mld
= (LPWINE_MLD
)dwInstance
;
556 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
559 if (mld
->bFrom32
&& !MMDrvs
[mld
->mmdIndex
].bIs32
) {
560 /* initial map is: 32 => 16 */
561 LPMIDIHDR wh16
= (LPMIDIHDR
)PTR_SEG_TO_LIN(dwParam1
);
562 LPMIDIHDR wh32
= *(LPMIDIHDR
*)((LPSTR
)wh16
- sizeof(LPMIDIHDR
));
564 dwParam1
= (DWORD
)wh32
;
565 wh32
->dwFlags
= wh16
->dwFlags
;
566 } else if (!mld
->bFrom32
&& MMDrvs
[mld
->mmdIndex
].bIs32
) {
567 /* initial map is: 16 => 32 */
568 LPMIDIHDR wh32
= (LPMIDIHDR
)(dwParam1
);
569 LPMIDIHDR segwh16
= *(LPMIDIHDR
*)((LPSTR
)wh32
- sizeof(LPMIDIHDR
));
570 LPMIDIHDR wh16
= PTR_SEG_TO_LIN(segwh16
);
572 dwParam1
= (DWORD
)segwh16
;
573 wh16
->dwFlags
= wh32
->dwFlags
;
575 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
577 /* case MOM_POSITIONCB: */
579 ERR("Unknown msg %u\n", uMsg
);
582 MMDRV_Callback(mld
, hDev
, uMsg
, dwParam1
, dwParam2
);
585 /* =================================
586 * W A V E I N M A P P E R S
587 * ================================= */
589 /**************************************************************************
590 * MMDRV_WaveIn_Map16To32A [internal]
592 static MMDRV_MapType
MMDRV_WaveIn_Map16To32A (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
594 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
597 case WIDM_GETNUMDEVS
:
605 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
607 case WIDM_GETDEVCAPS
:
609 LPWAVEINCAPSA wic32
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEINCAPS16
) + sizeof(WAVEINCAPSA
));
610 LPWAVEINCAPS16 wic16
= PTR_SEG_TO_LIN(*lpParam1
);
613 *(LPWAVEINCAPS16
*)wic32
= wic16
;
614 wic32
= (LPWAVEINCAPSA
)((LPSTR
)wic32
+ sizeof(LPWAVEINCAPS16
));
615 *lpParam1
= (DWORD
)wic32
;
616 *lpParam2
= sizeof(WAVEINCAPSA
);
618 ret
= MMDRV_MAP_OKMEM
;
620 ret
= MMDRV_MAP_NOMEM
;
626 LPMMTIME mmt32
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16
) + sizeof(MMTIME
));
627 LPMMTIME16 mmt16
= PTR_SEG_TO_LIN(*lpParam1
);
630 *(LPMMTIME16
*)mmt32
= mmt16
;
631 mmt32
= (LPMMTIME
)((LPSTR
)mmt32
+ sizeof(LPMMTIME16
));
633 mmt32
->wType
= mmt16
->wType
;
634 *lpParam1
= (DWORD
)mmt32
;
635 *lpParam2
= sizeof(MMTIME
);
637 ret
= MMDRV_MAP_OKMEM
;
639 ret
= MMDRV_MAP_NOMEM
;
645 LPWAVEHDR wh32
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR
) + sizeof(WAVEHDR
));
646 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(*lpParam1
);
649 *(LPWAVEHDR
*)wh32
= (LPWAVEHDR
)*lpParam1
;
650 wh32
= (LPWAVEHDR
)((LPSTR
)wh32
+ sizeof(LPWAVEHDR
));
651 wh32
->lpData
= PTR_SEG_TO_LIN(wh16
->lpData
);
652 wh32
->dwBufferLength
= wh16
->dwBufferLength
;
653 wh32
->dwBytesRecorded
= wh16
->dwBytesRecorded
;
654 wh32
->dwUser
= wh16
->dwUser
;
655 wh32
->dwFlags
= wh16
->dwFlags
;
656 wh32
->dwLoops
= wh16
->dwLoops
;
657 /* FIXME: nothing on wh32->lpNext */
658 /* could link the wh32->lpNext at this level for memory house keeping */
659 wh16
->lpNext
= wh32
; /* for reuse in unprepare and write */
660 *lpParam1
= (DWORD
)wh32
;
661 *lpParam2
= sizeof(WAVEHDR
);
663 ret
= MMDRV_MAP_OKMEM
;
665 ret
= MMDRV_MAP_NOMEM
;
672 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(*lpParam1
);
673 LPWAVEHDR wh32
= (LPWAVEHDR
)wh16
->lpNext
;
675 *lpParam1
= (DWORD
)wh32
;
676 *lpParam2
= sizeof(WAVEHDR
);
677 ret
= MMDRV_MAP_OKMEM
;
681 FIXME("NIY: no conversion yet for %u\n", wMsg
);
687 /**************************************************************************
688 * MMDRV_WaveIn_UnMap16To32A [internal]
690 static MMDRV_MapType
MMDRV_WaveIn_UnMap16To32A(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
692 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
695 case WIDM_GETNUMDEVS
:
703 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
705 case WIDM_GETDEVCAPS
:
707 LPWAVEINCAPSA wic32
= (LPWAVEINCAPSA
)(*lpParam1
);
708 LPWAVEINCAPS16 wic16
= *(LPWAVEINCAPS16
*)((LPSTR
)wic32
- sizeof(LPWAVEINCAPS16
));
710 wic16
->wMid
= wic32
->wMid
;
711 wic16
->wPid
= wic32
->wPid
;
712 wic16
->vDriverVersion
= wic32
->vDriverVersion
;
713 strcpy(wic16
->szPname
, wic32
->szPname
);
714 wic16
->dwFormats
= wic32
->dwFormats
;
715 wic16
->wChannels
= wic32
->wChannels
;
716 HeapFree(GetProcessHeap(), 0, (LPSTR
)wic32
- sizeof(LPWAVEINCAPS16
));
722 LPMMTIME mmt32
= (LPMMTIME
)(*lpParam1
);
723 LPMMTIME16 mmt16
= *(LPMMTIME16
*)((LPSTR
)mmt32
- sizeof(LPMMTIME16
));
725 MMSYSTEM_MMTIME32to16(mmt16
, mmt32
);
726 HeapFree(GetProcessHeap(), 0, (LPSTR
)mmt32
- sizeof(LPMMTIME16
));
734 LPWAVEHDR wh32
= (LPWAVEHDR
)(*lpParam1
);
735 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(*(LPWAVEHDR
*)((LPSTR
)wh32
- sizeof(LPWAVEHDR
)));
737 assert(wh16
->lpNext
== wh32
);
738 wh16
->dwBufferLength
= wh32
->dwBufferLength
;
739 wh16
->dwBytesRecorded
= wh32
->dwBytesRecorded
;
740 wh16
->dwUser
= wh32
->dwUser
;
741 wh16
->dwFlags
= wh32
->dwFlags
;
742 wh16
->dwLoops
= wh32
->dwLoops
;
744 if (wMsg
== WIDM_UNPREPARE
) {
745 HeapFree(GetProcessHeap(), 0, (LPSTR
)wh32
- sizeof(LPWAVEHDR
));
752 FIXME("NIY: no conversion yet for %u\n", wMsg
);
758 /**************************************************************************
759 * MMDRV_WaveIn_Map32ATo16 [internal]
761 static MMDRV_MapType
MMDRV_WaveIn_Map32ATo16 (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
763 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
767 case WIDM_GETNUMDEVS
:
776 LPWAVEOPENDESC wod32
= (LPWAVEOPENDESC
)*lpParam1
;
777 int sz
= sizeof(WAVEFORMATEX
);
779 LPWAVEOPENDESC16 wod16
;
781 /* allocated data are mapped as follows:
782 LPWAVEOPENDESC ptr to orig lParam1
783 DWORD ptr to orig dwUser, which is a pointer to DWORD:driver dwInstance
784 DWORD dwUser passed to driver
785 WAVEOPENDESC16 wod16: openDesc passed to driver
786 WAVEFORMATEX openDesc->lpFormat passed to driver
787 xxx extra bytes to WAVEFORMATEX
789 if (wod32
->lpFormat
->wFormatTag
!= WAVE_FORMAT_PCM
) {
790 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX
)wod32
->lpFormat
)->cbSize
, wod32
->lpFormat
->wFormatTag
);
791 sz
+= ((LPWAVEFORMATEX
)wod32
->lpFormat
)->cbSize
;
794 ptr
= SEGPTR_ALLOC(sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
) + sizeof(WAVEOPENDESC16
) + sz
);
797 *(LPWAVEOPENDESC
*)ptr
= wod32
;
798 *(LPDWORD
)(ptr
+ sizeof(LPWAVEOPENDESC
)) = *lpdwUser
;
799 wod16
= (LPWAVEOPENDESC16
)((LPSTR
)ptr
+ sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
));
801 wod16
->hWave
= wod32
->hWave
;
802 wod16
->lpFormat
= (LPWAVEFORMATEX
)((DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
) + sizeof(WAVEOPENDESC16
));
803 memcpy(wod16
+ 1, wod32
->lpFormat
, sz
);
805 wod16
->dwCallback
= wod32
->dwCallback
;
806 wod16
->dwInstance
= wod32
->dwInstance
;
807 wod16
->uMappedDeviceID
= wod32
->uMappedDeviceID
;
808 wod16
->dnDevNode
= wod32
->dnDevNode
;
810 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
);
811 *lpdwUser
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEOPENDESC
) + sizeof(DWORD
);
813 ret
= MMDRV_MAP_OKMEM
;
815 ret
= MMDRV_MAP_NOMEM
;
821 LPWAVEHDR wh32
= (LPWAVEHDR
)*lpParam1
;
823 LPVOID ptr
= SEGPTR_ALLOC(sizeof(LPWAVEHDR
) + sizeof(WAVEHDR
) + wh32
->dwBufferLength
);
826 *(LPWAVEHDR
*)ptr
= wh32
;
827 wh16
= (LPWAVEHDR
)((LPSTR
)ptr
+ sizeof(LPWAVEHDR
));
828 wh16
->lpData
= (LPSTR
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
) + sizeof(WAVEHDR
);
829 /* data will be copied on WODM_WRITE */
830 wh16
->dwBufferLength
= wh32
->dwBufferLength
;
831 wh16
->dwBytesRecorded
= wh32
->dwBytesRecorded
;
832 wh16
->dwUser
= wh32
->dwUser
;
833 wh16
->dwFlags
= wh32
->dwFlags
;
834 wh16
->dwLoops
= wh32
->dwLoops
;
835 /* FIXME: nothing on wh32->lpNext */
836 /* could link the wh32->lpNext at this level for memory house keeping */
837 wh32
->lpNext
= wh16
; /* for reuse in unprepare and write */
838 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
839 (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
), (DWORD
)wh16
->lpData
,
840 wh32
->dwBufferLength
, (DWORD
)wh32
->lpData
);
841 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
);
842 *lpParam2
= sizeof(WAVEHDR
);
844 ret
= MMDRV_MAP_OKMEM
;
846 ret
= MMDRV_MAP_NOMEM
;
853 LPWAVEHDR wh32
= (LPWAVEHDR
)(*lpParam1
);
854 LPWAVEHDR wh16
= wh32
->lpNext
;
855 LPSTR ptr
= (LPSTR
)wh16
- sizeof(LPWAVEHDR
);
857 assert(*(LPWAVEHDR
*)ptr
== wh32
);
859 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
860 (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
), (DWORD
)wh16
->lpData
,
861 wh32
->dwBufferLength
, (DWORD
)wh32
->lpData
);
863 if (wMsg
== WODM_WRITE
)
864 memcpy((LPSTR
)wh16
+ sizeof(WAVEHDR
), wh32
->lpData
, wh32
->dwBufferLength
);
866 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
);
867 *lpParam2
= sizeof(WAVEHDR
);
868 ret
= MMDRV_MAP_OKMEM
;
871 case WIDM_GETDEVCAPS
:
873 LPWAVEINCAPSA wic32
= (LPWAVEINCAPSA
)*lpParam1
;
874 LPSTR ptr
= SEGPTR_ALLOC(sizeof(LPWAVEINCAPSA
) + sizeof(WAVEINCAPS16
));
877 *(LPWAVEINCAPSA
*)ptr
= wic32
;
878 ret
= MMDRV_MAP_OKMEM
;
880 ret
= MMDRV_MAP_NOMEM
;
882 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEINCAPSA
);
883 *lpParam2
= sizeof(WAVEINCAPS16
);
888 LPMMTIME mmt32
= (LPMMTIME
)*lpParam1
;
889 LPSTR ptr
= SEGPTR_ALLOC(sizeof(LPMMTIME
) + sizeof(MMTIME16
));
890 LPMMTIME16 mmt16
= (LPMMTIME16
)(ptr
+ sizeof(LPMMTIME
));
893 *(LPMMTIME
*)ptr
= mmt32
;
894 mmt16
->wType
= mmt32
->wType
;
895 ret
= MMDRV_MAP_OKMEM
;
897 ret
= MMDRV_MAP_NOMEM
;
899 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPMMTIME
);
900 *lpParam2
= sizeof(MMTIME16
);
904 FIXME("NIY: no conversion yet for %u\n", wMsg
);
910 /**************************************************************************
911 * MMDRV_WaveIn_UnMap32ATo16 [internal]
913 static MMDRV_MapType
MMDRV_WaveIn_UnMap32ATo16(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
915 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
919 case WIDM_GETNUMDEVS
:
928 LPWAVEOPENDESC16 wod16
= (LPWAVEOPENDESC16
)PTR_SEG_TO_LIN(*lpParam1
);
929 LPSTR ptr
= (LPSTR
)wod16
- sizeof(LPWAVEOPENDESC
) - 2*sizeof(DWORD
);
930 LPWAVEOPENDESC wod32
= *(LPWAVEOPENDESC
*)ptr
;
932 wod32
->uMappedDeviceID
= wod16
->uMappedDeviceID
;
933 **(DWORD
**)(ptr
+ sizeof(LPWAVEOPENDESC
)) = *(LPDWORD
)(ptr
+ sizeof(LPWAVEOPENDESC
) + sizeof(DWORD
));
935 if (!SEGPTR_FREE(ptr
))
936 FIXME("bad free line=%d\n", __LINE__
);
946 LPWAVEHDR wh16
= (LPWAVEHDR
)PTR_SEG_TO_LIN(*lpParam1
);
947 LPSTR ptr
= (LPSTR
)wh16
- sizeof(LPWAVEHDR
);
948 LPWAVEHDR wh32
= *(LPWAVEHDR
*)ptr
;
950 assert(wh32
->lpNext
== wh16
);
951 wh32
->dwBytesRecorded
= wh16
->dwBytesRecorded
;
952 wh32
->dwUser
= wh16
->dwUser
;
953 wh32
->dwFlags
= wh16
->dwFlags
;
954 wh32
->dwLoops
= wh16
->dwLoops
;
956 if (wMsg
== WODM_UNPREPARE
) {
957 if (!SEGPTR_FREE(ptr
))
958 FIXME("bad free line=%d\n", __LINE__
);
964 case WIDM_GETDEVCAPS
:
966 LPWAVEINCAPS16 wic16
= (LPWAVEINCAPS16
)PTR_SEG_TO_LIN(*lpParam1
);
967 LPSTR ptr
= (LPSTR
)wic16
- sizeof(LPWAVEINCAPSA
);
968 LPWAVEINCAPSA wic32
= *(LPWAVEINCAPSA
*)ptr
;
970 wic32
->wMid
= wic16
->wMid
;
971 wic32
->wPid
= wic16
->wPid
;
972 wic32
->vDriverVersion
= wic16
->vDriverVersion
;
973 strcpy(wic32
->szPname
, wic16
->szPname
);
974 wic32
->dwFormats
= wic16
->dwFormats
;
975 wic32
->wChannels
= wic16
->wChannels
;
976 if (!SEGPTR_FREE(ptr
))
977 FIXME("bad free line=%d\n", __LINE__
);
983 LPMMTIME16 mmt16
= (LPMMTIME16
)PTR_SEG_TO_LIN(*lpParam1
);
984 LPSTR ptr
= (LPSTR
)mmt16
- sizeof(LPMMTIME
);
985 LPMMTIME mmt32
= *(LPMMTIME
*)ptr
;
987 MMSYSTEM_MMTIME16to32(mmt32
, mmt16
);
989 if (!SEGPTR_FREE(ptr
))
990 FIXME("bad free line=%d\n", __LINE__
);
996 FIXME("NIY: no conversion yet for %u\n", wMsg
);
1002 /**************************************************************************
1003 * MMDRV_WaveIn_Callback [internal]
1005 static void CALLBACK
MMDRV_WaveIn_Callback(HDRVR hDev
, UINT uMsg
, DWORD dwInstance
, DWORD dwParam1
, DWORD dwParam2
)
1007 LPWINE_MLD mld
= (LPWINE_MLD
)dwInstance
;
1012 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1015 if (mld
->bFrom32
&& !MMDrvs
[mld
->mmdIndex
].bIs32
) {
1016 /* initial map is: 32 => 16 */
1017 LPWAVEHDR wh16
= (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
);
1018 LPWAVEHDR wh32
= *(LPWAVEHDR
*)((LPSTR
)wh16
- sizeof(LPWAVEHDR
));
1020 dwParam1
= (DWORD
)wh32
;
1021 wh32
->dwFlags
= wh16
->dwFlags
;
1022 wh32
->dwBytesRecorded
= wh16
->dwBytesRecorded
;
1023 } else if (!mld
->bFrom32
&& MMDrvs
[mld
->mmdIndex
].bIs32
) {
1024 /* initial map is: 16 => 32 */
1025 LPWAVEHDR wh32
= (LPWAVEHDR
)(dwParam1
);
1026 LPWAVEHDR segwh16
= *(LPWAVEHDR
*)((LPSTR
)wh32
- sizeof(LPWAVEHDR
));
1027 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(segwh16
);
1029 dwParam1
= (DWORD
)segwh16
;
1030 wh16
->dwFlags
= wh32
->dwFlags
;
1031 wh16
->dwBytesRecorded
= wh32
->dwBytesRecorded
;
1033 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1036 ERR("Unknown msg %u\n", uMsg
);
1039 MMDRV_Callback(mld
, hDev
, uMsg
, dwParam1
, dwParam2
);
1042 /* =================================
1043 * W A V E O U T M A P P E R S
1044 * ================================= */
1046 /**************************************************************************
1047 * MMDRV_WaveOut_Map16To32A [internal]
1049 static MMDRV_MapType
MMDRV_WaveOut_Map16To32A (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
1051 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
1055 case WODM_BREAKLOOP
:
1057 case WODM_GETNUMDEVS
:
1062 case WODM_SETPLAYBACKRATE
:
1063 case WODM_SETVOLUME
:
1068 case WODM_GETPLAYBACKRATE
:
1069 case WODM_GETVOLUME
:
1071 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
1074 case WODM_GETDEVCAPS
:
1076 LPWAVEOUTCAPSA woc32
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEOUTCAPS16
) + sizeof(WAVEOUTCAPSA
));
1077 LPWAVEOUTCAPS16 woc16
= PTR_SEG_TO_LIN(*lpParam1
);
1080 *(LPWAVEOUTCAPS16
*)woc32
= woc16
;
1081 woc32
= (LPWAVEOUTCAPSA
)((LPSTR
)woc32
+ sizeof(LPWAVEOUTCAPS16
));
1082 *lpParam1
= (DWORD
)woc32
;
1083 *lpParam2
= sizeof(WAVEOUTCAPSA
);
1085 ret
= MMDRV_MAP_OKMEM
;
1087 ret
= MMDRV_MAP_NOMEM
;
1093 LPMMTIME mmt32
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16
) + sizeof(MMTIME
));
1094 LPMMTIME16 mmt16
= PTR_SEG_TO_LIN(*lpParam1
);
1097 *(LPMMTIME16
*)mmt32
= mmt16
;
1098 mmt32
= (LPMMTIME
)((LPSTR
)mmt32
+ sizeof(LPMMTIME16
));
1100 mmt32
->wType
= mmt16
->wType
;
1101 *lpParam1
= (DWORD
)mmt32
;
1102 *lpParam2
= sizeof(MMTIME
);
1104 ret
= MMDRV_MAP_OKMEM
;
1106 ret
= MMDRV_MAP_NOMEM
;
1112 LPWAVEHDR wh32
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR
) + sizeof(WAVEHDR
));
1113 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(*lpParam1
);
1116 *(LPWAVEHDR
*)wh32
= (LPWAVEHDR
)*lpParam1
;
1117 wh32
= (LPWAVEHDR
)((LPSTR
)wh32
+ sizeof(LPWAVEHDR
));
1118 wh32
->lpData
= PTR_SEG_TO_LIN(wh16
->lpData
);
1119 wh32
->dwBufferLength
= wh16
->dwBufferLength
;
1120 wh32
->dwBytesRecorded
= wh16
->dwBytesRecorded
;
1121 wh32
->dwUser
= wh16
->dwUser
;
1122 wh32
->dwFlags
= wh16
->dwFlags
;
1123 wh32
->dwLoops
= wh16
->dwLoops
;
1124 /* FIXME: nothing on wh32->lpNext */
1125 /* could link the wh32->lpNext at this level for memory house keeping */
1126 wh16
->lpNext
= wh32
; /* for reuse in unprepare and write */
1127 *lpParam1
= (DWORD
)wh32
;
1128 *lpParam2
= sizeof(WAVEHDR
);
1130 ret
= MMDRV_MAP_OKMEM
;
1132 ret
= MMDRV_MAP_NOMEM
;
1136 case WODM_UNPREPARE
:
1139 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(*lpParam1
);
1140 LPWAVEHDR wh32
= (LPWAVEHDR
)wh16
->lpNext
;
1142 *lpParam1
= (DWORD
)wh32
;
1143 *lpParam2
= sizeof(WAVEHDR
);
1144 ret
= MMDRV_MAP_OKMEM
;
1148 FIXME("NIY: no conversion yet for %u\n", wMsg
);
1154 /**************************************************************************
1155 * MMDRV_WaveOut_UnMap16To32A [internal]
1157 static MMDRV_MapType
MMDRV_WaveOut_UnMap16To32A(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
1159 MMDRV_MapType ret
= MMDRV_MAP_MSGERROR
;
1163 case WODM_BREAKLOOP
:
1165 case WODM_GETNUMDEVS
:
1170 case WODM_SETPLAYBACKRATE
:
1171 case WODM_SETVOLUME
:
1176 case WODM_GETPLAYBACKRATE
:
1177 case WODM_GETVOLUME
:
1179 FIXME("Shouldn't be used: those 16 bit functions use the 32 bit interface\n");
1182 case WODM_GETDEVCAPS
:
1184 LPWAVEOUTCAPSA woc32
= (LPWAVEOUTCAPSA
)(*lpParam1
);
1185 LPWAVEOUTCAPS16 woc16
= *(LPWAVEOUTCAPS16
*)((LPSTR
)woc32
- sizeof(LPWAVEOUTCAPS16
));
1187 woc16
->wMid
= woc32
->wMid
;
1188 woc16
->wPid
= woc32
->wPid
;
1189 woc16
->vDriverVersion
= woc32
->vDriverVersion
;
1190 strcpy(woc16
->szPname
, woc32
->szPname
);
1191 woc16
->dwFormats
= woc32
->dwFormats
;
1192 woc16
->wChannels
= woc32
->wChannels
;
1193 woc16
->dwSupport
= woc32
->dwSupport
;
1194 HeapFree(GetProcessHeap(), 0, (LPSTR
)woc32
- sizeof(LPWAVEOUTCAPS16
));
1200 LPMMTIME mmt32
= (LPMMTIME
)(*lpParam1
);
1201 LPMMTIME16 mmt16
= *(LPMMTIME16
*)((LPSTR
)mmt32
- sizeof(LPMMTIME16
));
1203 MMSYSTEM_MMTIME32to16(mmt16
, mmt32
);
1204 HeapFree(GetProcessHeap(), 0, (LPSTR
)mmt32
- sizeof(LPMMTIME16
));
1209 case WODM_UNPREPARE
:
1212 LPWAVEHDR wh32
= (LPWAVEHDR
)(*lpParam1
);
1213 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(*(LPWAVEHDR
*)((LPSTR
)wh32
- sizeof(LPWAVEHDR
)));
1215 assert(wh16
->lpNext
== wh32
);
1216 wh16
->dwBufferLength
= wh32
->dwBufferLength
;
1217 wh16
->dwBytesRecorded
= wh32
->dwBytesRecorded
;
1218 wh16
->dwUser
= wh32
->dwUser
;
1219 wh16
->dwFlags
= wh32
->dwFlags
;
1220 wh16
->dwLoops
= wh32
->dwLoops
;
1222 if (wMsg
== WODM_UNPREPARE
) {
1223 HeapFree(GetProcessHeap(), 0, (LPSTR
)wh32
- sizeof(LPWAVEHDR
));
1230 FIXME("NIY: no conversion yet for %u\n", wMsg
);
1236 /**************************************************************************
1237 * MMDRV_WaveOut_Map32ATo16 [internal]
1239 static MMDRV_MapType
MMDRV_WaveOut_Map32ATo16 (UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
1245 case WODM_BREAKLOOP
:
1247 case WODM_GETNUMDEVS
:
1252 case WODM_SETPLAYBACKRATE
:
1253 case WODM_SETVOLUME
:
1257 case WODM_GETDEVCAPS
:
1259 LPWAVEOUTCAPSA woc32
= (LPWAVEOUTCAPSA
)*lpParam1
;
1260 LPSTR ptr
= SEGPTR_ALLOC(sizeof(LPWAVEOUTCAPSA
) + sizeof(WAVEOUTCAPS16
));
1263 *(LPWAVEOUTCAPSA
*)ptr
= woc32
;
1264 ret
= MMDRV_MAP_OKMEM
;
1266 ret
= MMDRV_MAP_NOMEM
;
1268 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEOUTCAPSA
);
1269 *lpParam2
= sizeof(WAVEOUTCAPS16
);
1273 FIXME("NIY: no conversion yet\n");
1274 ret
= MMDRV_MAP_MSGERROR
;
1276 case WODM_GETPLAYBACKRATE
:
1277 FIXME("NIY: no conversion yet\n");
1278 ret
= MMDRV_MAP_MSGERROR
;
1282 LPMMTIME mmt32
= (LPMMTIME
)*lpParam1
;
1283 LPSTR ptr
= SEGPTR_ALLOC(sizeof(LPMMTIME
) + sizeof(MMTIME16
));
1284 LPMMTIME16 mmt16
= (LPMMTIME16
)(ptr
+ sizeof(LPMMTIME
));
1287 *(LPMMTIME
*)ptr
= mmt32
;
1288 mmt16
->wType
= mmt32
->wType
;
1289 ret
= MMDRV_MAP_OKMEM
;
1291 ret
= MMDRV_MAP_NOMEM
;
1293 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPMMTIME
);
1294 *lpParam2
= sizeof(MMTIME16
);
1297 case WODM_GETVOLUME
:
1298 FIXME("NIY: no conversion yet\n");
1299 ret
= MMDRV_MAP_MSGERROR
;
1303 LPWAVEOPENDESC wod32
= (LPWAVEOPENDESC
)*lpParam1
;
1304 int sz
= sizeof(WAVEFORMATEX
);
1306 LPWAVEOPENDESC16 wod16
;
1308 /* allocated data are mapped as follows:
1309 LPWAVEOPENDESC ptr to orig lParam1
1310 DWORD ptr to orig dwUser, which is a pointer to DWORD:driver dwInstance
1311 DWORD dwUser passed to driver
1312 WAVEOPENDESC16 wod16: openDesc passed to driver
1313 WAVEFORMATEX openDesc->lpFormat passed to driver
1314 xxx extra bytes to WAVEFORMATEX
1316 if (wod32
->lpFormat
->wFormatTag
!= WAVE_FORMAT_PCM
) {
1317 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX
)wod32
->lpFormat
)->cbSize
, wod32
->lpFormat
->wFormatTag
);
1318 sz
+= ((LPWAVEFORMATEX
)wod32
->lpFormat
)->cbSize
;
1321 ptr
= SEGPTR_ALLOC(sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
) + sizeof(WAVEOPENDESC16
) + sz
);
1324 *(LPWAVEOPENDESC
*)ptr
= wod32
;
1325 *(LPDWORD
)(ptr
+ sizeof(LPWAVEOPENDESC
)) = *lpdwUser
;
1326 wod16
= (LPWAVEOPENDESC16
)((LPSTR
)ptr
+ sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
));
1328 wod16
->hWave
= wod32
->hWave
;
1329 wod16
->lpFormat
= (LPWAVEFORMATEX
)((DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
) + sizeof(WAVEOPENDESC16
));
1330 memcpy(wod16
+ 1, wod32
->lpFormat
, sz
);
1332 wod16
->dwCallback
= wod32
->dwCallback
;
1333 wod16
->dwInstance
= wod32
->dwInstance
;
1334 wod16
->uMappedDeviceID
= wod32
->uMappedDeviceID
;
1335 wod16
->dnDevNode
= wod32
->dnDevNode
;
1337 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEOPENDESC
) + 2*sizeof(DWORD
);
1338 *lpdwUser
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEOPENDESC
) + sizeof(DWORD
);
1340 ret
= MMDRV_MAP_OKMEM
;
1342 ret
= MMDRV_MAP_NOMEM
;
1348 LPWAVEHDR wh32
= (LPWAVEHDR
)*lpParam1
;
1350 LPVOID ptr
= SEGPTR_ALLOC(sizeof(LPWAVEHDR
) + sizeof(WAVEHDR
) + wh32
->dwBufferLength
);
1353 *(LPWAVEHDR
*)ptr
= wh32
;
1354 wh16
= (LPWAVEHDR
)((LPSTR
)ptr
+ sizeof(LPWAVEHDR
));
1355 wh16
->lpData
= (LPSTR
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
) + sizeof(WAVEHDR
);
1356 /* data will be copied on WODM_WRITE */
1357 wh16
->dwBufferLength
= wh32
->dwBufferLength
;
1358 wh16
->dwBytesRecorded
= wh32
->dwBytesRecorded
;
1359 wh16
->dwUser
= wh32
->dwUser
;
1360 wh16
->dwFlags
= wh32
->dwFlags
;
1361 wh16
->dwLoops
= wh32
->dwLoops
;
1362 /* FIXME: nothing on wh32->lpNext */
1363 /* could link the wh32->lpNext at this level for memory house keeping */
1364 wh32
->lpNext
= wh16
; /* for reuse in unprepare and write */
1365 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1366 (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
), (DWORD
)wh16
->lpData
,
1367 wh32
->dwBufferLength
, (DWORD
)wh32
->lpData
);
1368 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
);
1369 *lpParam2
= sizeof(WAVEHDR
);
1371 ret
= MMDRV_MAP_OKMEM
;
1373 ret
= MMDRV_MAP_NOMEM
;
1377 case WODM_UNPREPARE
:
1380 LPWAVEHDR wh32
= (LPWAVEHDR
)(*lpParam1
);
1381 LPWAVEHDR wh16
= wh32
->lpNext
;
1382 LPSTR ptr
= (LPSTR
)wh16
- sizeof(LPWAVEHDR
);
1384 assert(*(LPWAVEHDR
*)ptr
== wh32
);
1386 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1387 (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
), (DWORD
)wh16
->lpData
,
1388 wh32
->dwBufferLength
, (DWORD
)wh32
->lpData
);
1390 if (wMsg
== WODM_WRITE
)
1391 memcpy((LPSTR
)wh16
+ sizeof(WAVEHDR
), wh32
->lpData
, wh32
->dwBufferLength
);
1393 *lpParam1
= (DWORD
)SEGPTR_GET(ptr
) + sizeof(LPWAVEHDR
);
1394 *lpParam2
= sizeof(WAVEHDR
);
1395 ret
= MMDRV_MAP_OKMEM
;
1399 FIXME("NIY: no conversion yet\n");
1400 ret
= MMDRV_MAP_MSGERROR
;
1406 /**************************************************************************
1407 * MMDRV_WaveOut_UnMap32ATo16 [internal]
1409 static MMDRV_MapType
MMDRV_WaveOut_UnMap32ATo16(UINT wMsg
, LPDWORD lpdwUser
, LPDWORD lpParam1
, LPDWORD lpParam2
)
1415 case WODM_BREAKLOOP
:
1417 case WODM_GETNUMDEVS
:
1422 case WODM_SETPLAYBACKRATE
:
1423 case WODM_SETVOLUME
:
1427 case WODM_GETDEVCAPS
:
1429 LPWAVEOUTCAPS16 woc16
= (LPWAVEOUTCAPS16
)PTR_SEG_TO_LIN(*lpParam1
);
1430 LPSTR ptr
= (LPSTR
)woc16
- sizeof(LPWAVEOUTCAPSA
);
1431 LPWAVEOUTCAPSA woc32
= *(LPWAVEOUTCAPSA
*)ptr
;
1433 woc32
->wMid
= woc16
->wMid
;
1434 woc32
->wPid
= woc16
->wPid
;
1435 woc32
->vDriverVersion
= woc16
->vDriverVersion
;
1436 strcpy(woc32
->szPname
, woc16
->szPname
);
1437 woc32
->dwFormats
= woc16
->dwFormats
;
1438 woc32
->wChannels
= woc16
->wChannels
;
1439 woc32
->dwSupport
= woc16
->dwSupport
;
1440 if (!SEGPTR_FREE(ptr
))
1441 FIXME("bad free line=%d\n", __LINE__
);
1446 FIXME("NIY: no conversion yet\n");
1447 ret
= MMDRV_MAP_MSGERROR
;
1449 case WODM_GETPLAYBACKRATE
:
1450 FIXME("NIY: no conversion yet\n");
1451 ret
= MMDRV_MAP_MSGERROR
;
1455 LPMMTIME16 mmt16
= (LPMMTIME16
)PTR_SEG_TO_LIN(*lpParam1
);
1456 LPSTR ptr
= (LPSTR
)mmt16
- sizeof(LPMMTIME
);
1457 LPMMTIME mmt32
= *(LPMMTIME
*)ptr
;
1459 MMSYSTEM_MMTIME16to32(mmt32
, mmt16
);
1461 if (!SEGPTR_FREE(ptr
))
1462 FIXME("bad free line=%d\n", __LINE__
);
1469 LPWAVEOPENDESC16 wod16
= (LPWAVEOPENDESC16
)PTR_SEG_TO_LIN(*lpParam1
);
1470 LPSTR ptr
= (LPSTR
)wod16
- sizeof(LPWAVEOPENDESC
) - 2*sizeof(DWORD
);
1471 LPWAVEOPENDESC wod32
= *(LPWAVEOPENDESC
*)ptr
;
1473 wod32
->uMappedDeviceID
= wod16
->uMappedDeviceID
;
1474 **(DWORD
**)(ptr
+ sizeof(LPWAVEOPENDESC
)) = *(LPDWORD
)(ptr
+ sizeof(LPWAVEOPENDESC
) + sizeof(DWORD
));
1476 if (!SEGPTR_FREE(ptr
))
1477 FIXME("bad free line=%d\n", __LINE__
);
1483 case WODM_UNPREPARE
:
1486 LPWAVEHDR wh16
= (LPWAVEHDR
)PTR_SEG_TO_LIN(*lpParam1
);
1487 LPSTR ptr
= (LPSTR
)wh16
- sizeof(LPWAVEHDR
);
1488 LPWAVEHDR wh32
= *(LPWAVEHDR
*)ptr
;
1490 assert(wh32
->lpNext
== wh16
);
1491 wh32
->dwBytesRecorded
= wh16
->dwBytesRecorded
;
1492 wh32
->dwUser
= wh16
->dwUser
;
1493 wh32
->dwFlags
= wh16
->dwFlags
;
1494 wh32
->dwLoops
= wh16
->dwLoops
;
1496 if (wMsg
== WODM_UNPREPARE
) {
1497 if (!SEGPTR_FREE(ptr
))
1498 FIXME("bad free line=%d\n", __LINE__
);
1504 case WODM_GETVOLUME
:
1505 FIXME("NIY: no conversion yet\n");
1506 ret
= MMDRV_MAP_MSGERROR
;
1509 FIXME("NIY: no conversion yet\n");
1510 ret
= MMDRV_MAP_MSGERROR
;
1516 /**************************************************************************
1517 * MMDRV_WaveOut_Callback [internal]
1519 static void CALLBACK
MMDRV_WaveOut_Callback(HDRVR hDev
, UINT uMsg
, DWORD dwInstance
, DWORD dwParam1
, DWORD dwParam2
)
1521 LPWINE_MLD mld
= (LPWINE_MLD
)dwInstance
;
1526 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1529 if (mld
->bFrom32
&& !MMDrvs
[mld
->mmdIndex
].bIs32
) {
1530 /* initial map is: 32 => 16 */
1531 LPWAVEHDR wh16
= (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
);
1532 LPWAVEHDR wh32
= *(LPWAVEHDR
*)((LPSTR
)wh16
- sizeof(LPWAVEHDR
));
1534 dwParam1
= (DWORD
)wh32
;
1535 wh32
->dwFlags
= wh16
->dwFlags
;
1536 } else if (!mld
->bFrom32
&& MMDrvs
[mld
->mmdIndex
].bIs32
) {
1537 /* initial map is: 16 => 32 */
1538 LPWAVEHDR wh32
= (LPWAVEHDR
)(dwParam1
);
1539 LPWAVEHDR segwh16
= *(LPWAVEHDR
*)((LPSTR
)wh32
- sizeof(LPWAVEHDR
));
1540 LPWAVEHDR wh16
= PTR_SEG_TO_LIN(segwh16
);
1542 dwParam1
= (DWORD
)segwh16
;
1543 wh16
->dwFlags
= wh32
->dwFlags
;
1545 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1548 ERR("Unknown msg %u\n", uMsg
);
1551 MMDRV_Callback(mld
, hDev
, uMsg
, dwParam1
, dwParam2
);
1554 #define A(_x,_y) {#_y, _x, \
1555 MMDRV_##_y##_Map16To32A, MMDRV_##_y##_UnMap16To32A, \
1556 MMDRV_##_y##_Map32ATo16, MMDRV_##_y##_UnMap32ATo16, \
1557 MMDRV_##_y##_Callback, 0, NULL, -1}
1559 /* Note: the indices of this array must match the definitions
1560 * of the MMDRV_???? manifest constants
1562 static WINE_LLTYPE llTypes
[MMDRV_MAX
] = {
1572 /**************************************************************************
1573 * MMDRV_GetNum [internal]
1575 UINT
MMDRV_GetNum(UINT type
)
1577 assert(type
< MMDRV_MAX
);
1578 return llTypes
[type
].wMaxId
;
1581 /**************************************************************************
1582 * WINE_Message [internal]
1584 DWORD
MMDRV_Message(LPWINE_MLD mld
, WORD wMsg
, DWORD dwParam1
,
1585 DWORD dwParam2
, BOOL bFrom32
)
1587 LPWINE_MM_DRIVER lpDrv
;
1589 WINE_MM_DRIVER_PART
* part
;
1590 WINE_LLTYPE
* llType
= &llTypes
[mld
->type
];
1594 TRACE("(%s %u %u 0x%08lx 0x%08lx 0x%08lx %c)!\n",
1595 llTypes
[mld
->type
].name
, mld
->uDeviceID
, wMsg
,
1596 mld
->dwDriverInstance
, dwParam1
, dwParam2
, bFrom32
?'Y':'N');
1598 if (mld
->uDeviceID
== (UINT16
)-1) {
1599 if (!llType
->bSupportMapper
) {
1600 WARN("uDev=-1 requested on non-mappable ll type %s\n",
1601 llTypes
[mld
->type
].name
);
1602 return MMSYSERR_BADDEVICEID
;
1606 if (mld
->uDeviceID
>= llType
->wMaxId
) {
1607 WARN("uDev(%u) requested >= max (%d)\n", mld
->uDeviceID
, llType
->wMaxId
);
1608 return MMSYSERR_BADDEVICEID
;
1610 devID
= mld
->uDeviceID
;
1613 lpDrv
= &MMDrvs
[mld
->mmdIndex
];
1614 part
= &lpDrv
->parts
[mld
->type
];
1617 /* some sanity checks */
1618 if (!(part
->nIDMin
<= devID
))
1619 ERR("!(part->nIDMin(%d) <= devID(%d))\n", part
->nIDMin
, devID
);
1620 if (!(devID
< part
->nIDMax
))
1621 ERR("!(devID(%d) < part->nIDMax(%d))\n", devID
, part
->nIDMax
);
1625 assert(part
->u
.fnMessage32
);
1628 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1629 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
1630 ret
= part
->u
.fnMessage32(mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
1631 TRACE("=> %lu\n", ret
);
1633 map
= llType
->Map16To32A(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
1635 case MMDRV_MAP_NOMEM
:
1636 ret
= MMSYSERR_NOMEM
;
1638 case MMDRV_MAP_MSGERROR
:
1639 FIXME("NIY: no conversion yet 16->32 (%u)\n", wMsg
);
1640 ret
= MMSYSERR_ERROR
;
1643 case MMDRV_MAP_OKMEM
:
1644 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1645 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
1646 ret
= part
->u
.fnMessage32(mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
,
1647 dwParam1
, dwParam2
);
1648 TRACE("=> %lu\n", ret
);
1649 if (map
== MMDRV_MAP_OKMEM
)
1650 llType
->UnMap16To32A(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
1653 case MMDRV_MAP_PASS
:
1654 FIXME("NIY: pass used ?\n");
1655 ret
= MMSYSERR_NOTSUPPORTED
;
1660 assert(part
->u
.fnMessage16
);
1663 map
= llType
->Map32ATo16(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
1665 case MMDRV_MAP_NOMEM
:
1666 ret
= MMSYSERR_NOMEM
;
1668 case MMDRV_MAP_MSGERROR
:
1669 FIXME("NIY: no conversion yet 32->16 (%u)\n", wMsg
);
1670 ret
= MMSYSERR_ERROR
;
1673 case MMDRV_MAP_OKMEM
:
1674 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1675 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
1676 ret
= MMDRV_CallTo16_word_wwlll((FARPROC16
)part
->u
.fnMessage16
, mld
->uDeviceID
,
1677 wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
1678 TRACE("=> %lu\n", ret
);
1679 if (map
== MMDRV_MAP_OKMEM
)
1680 llType
->UnMap32ATo16(wMsg
, &mld
->dwDriverInstance
, &dwParam1
, &dwParam2
);
1683 case MMDRV_MAP_PASS
:
1684 FIXME("NIY: pass used ?\n");
1685 ret
= MMSYSERR_NOTSUPPORTED
;
1689 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1690 mld
->uDeviceID
, wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
1691 ret
= MMDRV_CallTo16_word_wwlll((FARPROC16
)part
->u
.fnMessage16
, mld
->uDeviceID
,
1692 wMsg
, mld
->dwDriverInstance
, dwParam1
, dwParam2
);
1693 TRACE("=> %lu\n", ret
);
1699 /**************************************************************************
1700 * MMDRV_Alloc [internal]
1702 LPWINE_MLD
MMDRV_Alloc(UINT size
, UINT type
, LPHANDLE hndl
, DWORD
* dwFlags
,
1703 DWORD
* dwCallback
, DWORD
* dwInstance
, BOOL bFrom32
)
1707 if ((*hndl
= USER_HEAP_ALLOC(size
)) == 0)
1710 mld
= (LPWINE_MLD
) USER_HEAP_LIN_ADDR(*hndl
);
1711 if (!mld
) return NULL
;
1713 if ((UINT
)*hndl
< MMDRV_GetNum(type
) || HIWORD(*hndl
) != 0) {
1714 /* FIXME: those conditions must be fulfilled so that:
1715 * - we can distinguish between device IDs and handles
1716 * - we can use handles as 16 or 32 bit entities
1718 ERR("Shouldn't happen. Bad allocation scheme\n");
1721 mld
->bFrom32
= bFrom32
;
1722 mld
->dwFlags
= HIWORD(*dwFlags
);
1723 mld
->dwCallback
= *dwCallback
;
1724 mld
->dwClientInstance
= *dwInstance
;
1726 *dwFlags
= LOWORD(*dwFlags
) | CALLBACK_FUNCTION
;
1727 *dwCallback
= (DWORD
)llTypes
[type
].Callback
;
1728 *dwInstance
= (DWORD
)mld
; /* FIXME: wouldn't some 16 bit drivers only use the loword ? */
1733 /**************************************************************************
1734 * MMDRV_Free [internal]
1736 void MMDRV_Free(HANDLE hndl
, LPWINE_MLD mld
)
1738 USER_HEAP_FREE(hndl
);
1741 /**************************************************************************
1742 * MMDRV_Open [internal]
1744 DWORD
MMDRV_Open(LPWINE_MLD mld
, UINT wMsg
, DWORD dwParam1
, DWORD dwFlags
)
1746 DWORD dwRet
= MMSYSERR_BADDEVICEID
;
1748 WINE_LLTYPE
* llType
= &llTypes
[mld
->type
];
1750 mld
->dwDriverInstance
= (DWORD
)&dwInstance
;
1752 if (mld
->uDeviceID
== (UINT
)-1) {
1753 TRACE("MAPPER mode requested !\n");
1754 /* check if mapper is supported by type */
1755 if (llType
->bSupportMapper
) {
1756 if (llType
->nMapper
== -1) {
1757 /* no driver for mapper has been loaded, try a dumb implementation */
1758 TRACE("No mapper loaded, doing it by hand\n");
1759 for (mld
->uDeviceID
= 0; mld
->uDeviceID
< llType
->wMaxId
; mld
->uDeviceID
++) {
1760 if ((dwRet
= MMDRV_Open(mld
, wMsg
, dwParam1
, dwFlags
)) == MMSYSERR_NOERROR
) {
1761 /* to share this function epilog */
1762 dwInstance
= mld
->dwDriverInstance
;
1767 mld
->uDeviceID
= (UINT16
)0/*-1*/;
1768 mld
->mmdIndex
= llType
->lpMlds
[-1].mmdIndex
;
1769 TRACE("Setting mmdIndex to %u\n", mld
->mmdIndex
);
1770 dwRet
= MMDRV_Message(mld
, wMsg
, dwParam1
, dwFlags
, TRUE
);
1774 if (mld
->uDeviceID
< llType
->wMaxId
) {
1775 mld
->mmdIndex
= llType
->lpMlds
[mld
->uDeviceID
].mmdIndex
;
1776 TRACE("Setting mmdIndex to %u\n", mld
->mmdIndex
);
1777 dwRet
= MMDRV_Message(mld
, wMsg
, dwParam1
, dwFlags
, TRUE
);
1780 if (dwRet
== MMSYSERR_NOERROR
)
1781 mld
->dwDriverInstance
= dwInstance
;
1785 /**************************************************************************
1786 * MMDRV_Close [internal]
1788 DWORD
MMDRV_Close(LPWINE_MLD mld
, UINT wMsg
)
1790 return MMDRV_Message(mld
, wMsg
, 0L, 0L, TRUE
);
1793 /**************************************************************************
1794 * MMDRV_GetVByID [internal]
1796 LPWINE_MLD
MMDRV_GetByID(UINT uDevID
, UINT type
)
1798 return (uDevID
< llTypes
[type
].wMaxId
) ?
1799 &llTypes
[type
].lpMlds
[uDevID
] : NULL
;
1802 /**************************************************************************
1803 * MMDRV_Get [internal]
1805 LPWINE_MLD
MMDRV_Get(HANDLE hndl
, UINT type
, BOOL bCanBeID
)
1807 LPWINE_MLD mld
= NULL
;
1809 assert(type
< MMDRV_MAX
);
1811 if ((UINT
)hndl
>= llTypes
[type
].wMaxId
) {
1812 mld
= (LPWINE_MLD
)USER_HEAP_LIN_ADDR(hndl
);
1814 if (mld
&& mld
->type
!= type
) mld
= NULL
;
1815 } else if (bCanBeID
) {
1816 mld
= MMDRV_GetByID((UINT
)hndl
, type
);
1821 /**************************************************************************
1822 * MMDRV_GetRelated [internal]
1824 LPWINE_MLD
MMDRV_GetRelated(HANDLE hndl
, UINT srcType
,
1825 BOOL bSrcCanBeID
, UINT dstType
)
1829 if ((mld
= MMDRV_Get(hndl
, srcType
, bSrcCanBeID
)) != NULL
) {
1830 WINE_MM_DRIVER_PART
* part
= &MMDrvs
[mld
->mmdIndex
].parts
[dstType
];
1831 if (part
->nIDMin
< part
->nIDMax
)
1832 return MMDRV_GetByID(part
->nIDMin
, dstType
);
1837 /**************************************************************************
1838 * MMDRV_PhysicalFeatures [internal]
1840 UINT
MMDRV_PhysicalFeatures(LPWINE_MLD mld
, UINT uMsg
, DWORD dwParam1
,
1843 WINE_MM_DRIVER
* lpDrv
= &MMDrvs
[mld
->mmdIndex
];
1845 TRACE("(%p, %04x, %08lx, %08lx)\n", mld
, uMsg
, dwParam1
, dwParam2
);
1847 /* all those function calls are undocumented */
1850 strncpy((LPSTR
)dwParam1
, lpDrv
->name
, LOWORD(dwParam2
));
1853 *(LPDWORD
)dwParam1
= 0L; /* should be DevNode */
1855 case 0x803: /* dont know */
1856 WARN("NIY 0x803\n");
1859 WARN("NIY call VxD\n");
1860 /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
1861 * dwParam1 is buffer and dwParam2 is sizeof buffer
1862 * I don't know where the result is stored though
1866 return (lpDrv
->bIsMapper
) ? 2 : 0;
1868 WARN("Unknown call %04x\n", uMsg
);
1869 return MMSYSERR_INVALPARAM
;
1874 /**************************************************************************
1875 * MMDRV_InitPerType [internal]
1877 static BOOL
MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv
, UINT num
,
1878 UINT type
, UINT wMsg
)
1880 WINE_MM_DRIVER_PART
* part
= &lpDrv
->parts
[type
];
1885 part
->nIDMin
= part
->nIDMax
= 0;
1887 /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
1888 /* the DRVM_ENABLE is only required when the PnP node is non zero */
1890 if (lpDrv
->bIs32
&& part
->u
.fnMessage32
) {
1891 ret
= part
->u
.fnMessage32(0, DRVM_INIT
, 0L, 0L, 0L);
1892 TRACE("DRVM_INIT => %08lx\n", ret
);
1894 ret
= part
->u
.fnMessage32(0, DRVM_ENABLE
, 0L, 0L, 0L);
1895 TRACE("DRVM_ENABLE => %08lx\n", ret
);
1897 count
= part
->u
.fnMessage32(0, wMsg
, 0L, 0L, 0L);
1900 if (!lpDrv
->bIs32
&& part
->u
.fnMessage16
) {
1901 ret
= MMDRV_CallTo16_word_wwlll((FARPROC16
)part
->u
.fnMessage16
,
1902 0, DRVM_INIT
, 0L, 0L, 0L);
1903 TRACE("DRVM_INIT => %08lx\n", ret
);
1905 ret
= MMDRV_CallTo16_word_wwlll((FARPROC16
)part
->u
.fnMessage16
,
1906 0, DRVM_ENABLE
, 0L, 0L, 0L);
1907 TRACE("DRVM_ENABLE => %08lx\n", ret
);
1909 count
= MMDRV_CallTo16_word_wwlll((FARPROC16
)part
->u
.fnMessage16
,
1910 0, wMsg
, 0L, 0L, 0L);
1913 TRACE("Got %u dev for (%s:%s)\n", count
, lpDrv
->name
, llTypes
[type
].name
);
1917 /* got some drivers */
1918 if (lpDrv
->bIsMapper
) {
1919 if (llTypes
[type
].nMapper
!= -1)
1920 ERR("Two mappers for type %s (%d, %s)\n",
1921 llTypes
[type
].name
, llTypes
[type
].nMapper
, lpDrv
->name
);
1923 ERR("Strange: mapper with %d > 1 devices\n", count
);
1924 llTypes
[type
].nMapper
= num
;
1926 part
->nIDMin
= llTypes
[type
].wMaxId
;
1927 llTypes
[type
].wMaxId
+= count
;
1928 part
->nIDMax
= llTypes
[type
].wMaxId
;
1930 TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
1931 part
->nIDMin
, part
->nIDMax
, llTypes
[type
].wMaxId
,
1932 lpDrv
->name
, llTypes
[type
].name
);
1933 /* realloc translation table */
1934 llTypes
[type
].lpMlds
= (LPWINE_MLD
)
1935 HeapReAlloc(SystemHeap
, 0, (llTypes
[type
].lpMlds
) ? llTypes
[type
].lpMlds
- 1 : NULL
,
1936 sizeof(WINE_MLD
) * (llTypes
[type
].wMaxId
+ 1)) + 1;
1937 /* re-build the translation table */
1938 if (llTypes
[type
].nMapper
!= -1) {
1939 TRACE("%s:Trans[%d] -> %s\n", llTypes
[type
].name
, -1, MMDrvs
[llTypes
[type
].nMapper
].name
);
1940 llTypes
[type
].lpMlds
[-1].uDeviceID
= -1;
1941 llTypes
[type
].lpMlds
[-1].type
= type
;
1942 llTypes
[type
].lpMlds
[-1].mmdIndex
= llTypes
[type
].nMapper
;
1943 llTypes
[type
].lpMlds
[-1].dwDriverInstance
= 0;
1945 for (i
= k
= 0; i
<= num
; i
++) {
1946 while (MMDrvs
[i
].parts
[type
].nIDMin
<= k
&& k
< MMDrvs
[i
].parts
[type
].nIDMax
) {
1947 TRACE("%s:Trans[%d] -> %s\n", llTypes
[type
].name
, k
, MMDrvs
[i
].name
);
1948 llTypes
[type
].lpMlds
[k
].uDeviceID
= k
;
1949 llTypes
[type
].lpMlds
[k
].type
= type
;
1950 llTypes
[type
].lpMlds
[k
].mmdIndex
= i
;
1951 llTypes
[type
].lpMlds
[k
].dwDriverInstance
= 0;
1958 /**************************************************************************
1959 * MMDRV_Install [internal]
1961 static BOOL
MMDRV_Install(LPCSTR name
, int num
, BOOL bIsMapper
)
1966 LPWINE_MM_DRIVER lpDrv
= &MMDrvs
[num
];
1968 TRACE("('%s');\n", name
);
1970 memset(lpDrv
, 0, sizeof(*lpDrv
));
1972 /* First load driver */
1973 if ((lpDrv
->hDrvr
= OpenDriverA(name
, 0, 0)) == 0) {
1974 WARN("Couldn't open driver '%s'\n", name
);
1978 /* Then look for xxxMessage functions */
1979 #define AA(_w,_x,_y,_z) \
1980 func = (WINEMM_msgFunc##_y) _z (hModule, #_x); \
1982 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
1983 TRACE("Got %d bit func '%s'\n", _y, #_x); }
1985 if ((DRIVER_GetType(lpDrv
->hDrvr
) & WINE_DI_TYPE_MASK
) == WINE_DI_TYPE_32
) {
1986 WINEMM_msgFunc32 func
;
1988 lpDrv
->bIs32
= TRUE
;
1989 if ((hModule
= GetDriverModuleHandle(lpDrv
->hDrvr
))) {
1990 #define A(_x,_y) AA(_x,_y,32,GetProcAddress)
1991 A(MMDRV_AUX
, auxMessage
);
1992 A(MMDRV_MIXER
, mixMessage
);
1993 A(MMDRV_MIDIIN
, midMessage
);
1994 A(MMDRV_MIDIOUT
, modMessage
);
1995 A(MMDRV_WAVEIN
, widMessage
);
1996 A(MMDRV_WAVEOUT
, wodMessage
);
2000 WINEMM_msgFunc16 func
;
2003 * DESCRIPTION 'wave,aux,mixer:Creative Labs Sound Blaster 16 Driver'
2004 * The beginning of the module description indicates the driver supports
2005 * waveform, auxiliary, and mixer devices. Use one of the following
2006 * device-type names, followed by a colon (:) to indicate the type of
2007 * device your driver supports. If the driver supports more than one
2008 * type of device, separate each device-type name with a comma (,).
2010 * wave for waveform audio devices
2011 * wavemapper for wave mappers
2012 * midi for MIDI audio devices
2013 * midimapper for midi mappers
2014 * aux for auxiliary audio devices
2015 * mixer for mixer devices
2018 lpDrv
->bIs32
= FALSE
;
2019 if ((hModule
= GetDriverModuleHandle16(lpDrv
->hDrvr
))) {
2020 #define A(_x,_y) AA(_x,_y,16,WIN32_GetProcAddress16)
2021 A(MMDRV_AUX
, auxMessage
);
2022 A(MMDRV_MIXER
, mixMessage
);
2023 A(MMDRV_MIDIIN
, midMessage
);
2024 A(MMDRV_MIDIOUT
, modMessage
);
2025 A(MMDRV_WAVEIN
, widMessage
);
2026 A(MMDRV_WAVEOUT
, wodMessage
);
2032 if (TRACE_ON(mmsys
)) {
2033 if ((lpDrv
->bIs32
) ? MMDRV_GetDescription32(name
, buffer
, sizeof(buffer
)) :
2034 MMDRV_GetDescription16(name
, buffer
, sizeof(buffer
)))
2035 TRACE("%s => %s\n", name
, buffer
);
2037 TRACE("%s => No description\n", name
);
2041 CloseDriver(lpDrv
->hDrvr
, 0, 0);
2042 WARN("No message functions found\n");
2046 /* FIXME: being a mapper or not should be known by another way */
2047 /* it's known for NE drvs (the description is of the form '*mapper: *'
2048 * I don't have any clue for PE drvs
2049 * on Win 9x, the value is gotten from the key mappable under
2050 * HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\MediaResources\
2052 lpDrv
->bIsMapper
= bIsMapper
;
2053 lpDrv
->name
= HEAP_strdupA(GetProcessHeap(), 0, name
);
2055 /* Finish init and get the count of the devices */
2056 MMDRV_InitPerType(lpDrv
, num
, MMDRV_AUX
, AUXDM_GETNUMDEVS
);
2057 MMDRV_InitPerType(lpDrv
, num
, MMDRV_MIXER
, MXDM_GETNUMDEVS
);
2058 MMDRV_InitPerType(lpDrv
, num
, MMDRV_MIDIIN
, MIDM_GETNUMDEVS
);
2059 MMDRV_InitPerType(lpDrv
, num
, MMDRV_MIDIOUT
, MODM_GETNUMDEVS
);
2060 MMDRV_InitPerType(lpDrv
, num
, MMDRV_WAVEIN
, WIDM_GETNUMDEVS
);
2061 MMDRV_InitPerType(lpDrv
, num
, MMDRV_WAVEOUT
, WODM_GETNUMDEVS
);
2062 /* FIXME: if all those func calls return FALSE, then the driver must be unloaded */
2066 /**************************************************************************
2067 * MMDRV_Init [internal]
2069 BOOL
MMDRV_Init(void)
2073 /* FIXME: this should be moved to init files;
2074 * - either .winerc/wine.conf
2075 * - or made of registry keys
2076 * this is a temporary hack, shall be removed anytime now
2078 /* first load hardware drivers */
2079 if (MMDRV_Install("wineoss.drv", num
, FALSE
)) num
++;
2081 /* finish with mappers */
2082 if (MMDRV_Install("msacm.drv", num
, TRUE
)) num
++;
2083 if (MMDRV_Install("midimap.drv", num
, TRUE
)) num
++;
2086 /* be sure that size of MMDrvs matches the max number of loadable drivers !!
2087 * if not just increase size of MMDrvs */
2088 assert(num
<= sizeof(MMDrvs
)/sizeof(MMDrvs
[0]));