22ff8ed10321925d781e10252525b1f29db91fde
[reactos.git] / reactos / lib / winmm / winemm.h
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*****************************************************************************
4 * Copyright 1998, Luiz Otavio L. Zorzella
5 * 1999, Eric Pouech
6 *
7 * Purpose: multimedia declarations (internal to WINMM & MMSYSTEM DLLs)
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *****************************************************************************
23 */
24
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "mmddk.h"
30
31 #define WINE_DEFAULT_WINMM_DRIVER "oss"
32 #define WINE_DEFAULT_WINMM_MAPPER "msacm.drv"
33 #define WINE_DEFAULT_WINMM_MIDI "midimap.drv"
34
35 typedef DWORD (WINAPI *MessageProc16)(UINT16 wDevID, UINT16 wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
36 typedef DWORD (WINAPI *MessageProc32)(UINT wDevID, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
37
38 typedef enum {
39 WINMM_MAP_NOMEM, /* ko, memory problem */
40 WINMM_MAP_MSGERROR, /* ko, unknown message */
41 WINMM_MAP_OK, /* ok, no memory allocated. to be sent to the proc. */
42 WINMM_MAP_OKMEM, /* ok, some memory allocated, need to call UnMapMsg. to be sent to the proc. */
43 } WINMM_MapType;
44
45 /* Who said goofy boy ? */
46 #define WINE_DI_MAGIC 0x900F1B01
47
48 typedef struct tagWINE_DRIVER
49 {
50 DWORD dwMagic;
51 /* as usual LPWINE_DRIVER == hDriver32 */
52 DWORD dwFlags;
53 union {
54 struct {
55 HMODULE hModule;
56 DRIVERPROC lpDrvProc;
57 DWORD dwDriverID;
58 } d32;
59 struct {
60 UINT16 hDriver16;
61 } d16;
62 } d;
63 struct tagWINE_DRIVER* lpPrevItem;
64 struct tagWINE_DRIVER* lpNextItem;
65 } WINE_DRIVER, *LPWINE_DRIVER;
66
67 typedef DWORD (CALLBACK *WINEMM_msgFunc16)(UINT16, WORD, DWORD, DWORD, DWORD);
68 typedef DWORD (CALLBACK *WINEMM_msgFunc32)(UINT , UINT, DWORD, DWORD, DWORD);
69
70 /* for each loaded driver and each known type of driver, this structure contains
71 * the information needed to access it
72 */
73 typedef struct tagWINE_MM_DRIVER_PART {
74 int nIDMin; /* lower bound of global indexes for this type */
75 int nIDMax; /* hhigher bound of global indexes for this type */
76 union {
77 WINEMM_msgFunc32 fnMessage32; /* pointer to function */
78 WINEMM_msgFunc16 fnMessage16;
79 } u;
80 } WINE_MM_DRIVER_PART;
81
82 #define MMDRV_AUX 0
83 #define MMDRV_MIXER 1
84 #define MMDRV_MIDIIN 2
85 #define MMDRV_MIDIOUT 3
86 #define MMDRV_WAVEIN 4
87 #define MMDRV_WAVEOUT 5
88 #define MMDRV_MAX 6
89
90 /* each low-level .drv will be associated with an instance of this structure */
91 typedef struct tagWINE_MM_DRIVER {
92 HDRVR hDriver;
93 LPSTR drvname; /* name of the driver */
94 unsigned bIs32 : 1, /* TRUE if 32 bit driver, FALSE for 16 */
95 bIsMapper : 1; /* TRUE if mapper */
96 WINE_MM_DRIVER_PART parts[MMDRV_MAX];/* Information for all known types */
97 } WINE_MM_DRIVER, *LPWINE_MM_DRIVER;
98
99 typedef struct tagWINE_MLD {
100 /* EPP struct tagWINE_MLD* lpNext; */ /* not used so far */
101 UINT uDeviceID;
102 UINT type;
103 UINT mmdIndex; /* index to low-level driver in MMDrvs table */
104 DWORD dwDriverInstance; /* this value is driver related, as opposed to
105 * opendesc.dwInstance which is client (callback) related */
106 WORD bFrom32;
107 WORD dwFlags;
108 DWORD dwCallback;
109 DWORD dwClientInstance;
110 } WINE_MLD, *LPWINE_MLD;
111
112 typedef struct {
113 WINE_MLD mld;
114 } WINE_WAVE, *LPWINE_WAVE;
115
116 typedef struct {
117 WINE_MLD mld;
118 MIDIOPENDESC mod; /* FIXME: should be removed */
119 } WINE_MIDI, *LPWINE_MIDI;
120
121 typedef struct {
122 WINE_MLD mld;
123 } WINE_MIXER, *LPWINE_MIXER;
124
125 #define WINE_MMTHREAD_CREATED 0x4153494C /* "BSIL" */
126 #define WINE_MMTHREAD_DELETED 0xDEADDEAD
127
128 typedef struct {
129 DWORD dwSignature; /* 00 "BSIL" when ok, 0xDEADDEAD when being deleted */
130 DWORD dwCounter; /* 04 > 1 when in mmThread functions */
131 HANDLE hThread; /* 08 hThread */
132 DWORD dwThreadID; /* 0C */
133 DWORD fpThread; /* 10 address of thread proc (segptr or lin depending on dwFlags) */
134 DWORD dwThreadPmt; /* 14 parameter to be passed upon thread creation to fpThread */
135 DWORD dwSignalCount; /* 18 counter used for signaling */
136 HANDLE hEvent; /* 1C event */
137 HANDLE hVxD; /* 20 return from OpenVxDHandle */
138 DWORD dwStatus; /* 24 0x00, 0x10, 0x20, 0x30 */
139 DWORD dwFlags; /* 28 dwFlags upon creation */
140 UINT16 hTask; /* 2C handle to created task */
141 } WINE_MMTHREAD;
142
143 typedef struct tagWINE_MCIDRIVER {
144 UINT wDeviceID;
145 UINT wType;
146 LPWSTR lpstrElementName;
147 LPWSTR lpstrDeviceType;
148 LPWSTR lpstrAlias;
149 HDRVR hDriver;
150 DWORD dwPrivate;
151 YIELDPROC lpfnYieldProc;
152 DWORD dwYieldData;
153 BOOL bIs32;
154 DWORD CreatorThread;
155 UINT uTypeCmdTable;
156 UINT uSpecificCmdTable;
157 struct tagWINE_MCIDRIVER*lpNext;
158 } WINE_MCIDRIVER, *LPWINE_MCIDRIVER;
159
160 #define WINE_TIMER_IS32 0x80
161
162 typedef struct tagWINE_TIMERENTRY {
163 UINT wDelay;
164 UINT wResol;
165 LPTIMECALLBACK lpFunc; /* can be lots of things */
166 DWORD dwUser;
167 UINT16 wFlags;
168 UINT16 wTimerID;
169 DWORD dwTriggerTime;
170 struct tagWINE_TIMERENTRY* lpNext;
171 } WINE_TIMERENTRY, *LPWINE_TIMERENTRY;
172
173 enum mmioProcType {MMIO_PROC_16,MMIO_PROC_32A,MMIO_PROC_32W};
174
175 struct IOProcList
176 {
177 struct IOProcList*pNext; /* Next item in linked list */
178 FOURCC fourCC; /* four-character code identifying IOProc */
179 LPMMIOPROC pIOProc; /* pointer to IProc */
180 enum mmioProcType type; /* 16, 32A or 32W */
181 int count; /* number of objects linked to it */
182 };
183
184 typedef struct tagWINE_MMIO {
185 MMIOINFO info;
186 struct tagWINE_MMIO* lpNext;
187 struct IOProcList* ioProc;
188 unsigned bTmpIOProc : 1,
189 bBufferLoaded : 1;
190 DWORD segBuffer16;
191 DWORD dwFileSize;
192 } WINE_MMIO, *LPWINE_MMIO;
193
194 typedef struct tagWINE_PLAYSOUND {
195 unsigned bLoop : 1,
196 bAlloc : 1;
197 LPCWSTR pszSound;
198 HMODULE hMod;
199 DWORD fdwSound;
200 HANDLE hThread;
201 struct tagWINE_PLAYSOUND* lpNext;
202 } WINE_PLAYSOUND, *LPWINE_PLAYSOUND;
203
204 typedef struct tagWINE_MM_IDATA {
205 /* winmm part */
206 HANDLE hWinMM32Instance;
207 HANDLE hWinMM16Instance;
208 CRITICAL_SECTION cs;
209 /* mci part */
210 LPWINE_MCIDRIVER lpMciDrvs;
211 /* low level drivers (unused yet) */
212 /* LPWINE_WAVE lpWave; */
213 /* LPWINE_MIDI lpMidi; */
214 /* LPWINE_MIXER lpMixer; */
215 /* mmio part */
216 LPWINE_MMIO lpMMIO;
217 /* playsound and sndPlaySound */
218 WINE_PLAYSOUND* lpPlaySound;
219 HANDLE psLastEvent;
220 HANDLE psStopEvent;
221 } WINE_MM_IDATA, *LPWINE_MM_IDATA;
222
223 /* function prototypes */
224
225 typedef LONG (*MCIPROC)(DWORD, HDRVR, DWORD, DWORD, DWORD);
226 typedef WINMM_MapType (*MMDRV_MAPFUNC)(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2);
227 typedef WINMM_MapType (*MMDRV_UNMAPFUNC)(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT ret);
228
229 HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2);
230 LPWINE_DRIVER DRIVER_FindFromHDrvr(HDRVR hDrvr);
231 BOOL DRIVER_GetLibName(LPCWSTR keyName, LPCWSTR sectName, LPWSTR buf, int sz);
232 LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2);
233 void DRIVER_UnloadAll(void);
234
235 BOOL MMDRV_Init(void);
236 void MMDRV_Exit(void);
237 UINT MMDRV_GetNum(UINT);
238 LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
239 DWORD* dwCallback, DWORD* dwInstance, BOOL bFrom32);
240 void MMDRV_Free(HANDLE hndl, LPWINE_MLD mld);
241 DWORD MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwParam2);
242 DWORD MMDRV_Close(LPWINE_MLD mld, UINT wMsg);
243 LPWINE_MLD MMDRV_Get(HANDLE hndl, UINT type, BOOL bCanBeID);
244 LPWINE_MLD MMDRV_GetRelated(HANDLE hndl, UINT srcType, BOOL bSrcCanBeID, UINT dstTyped);
245 DWORD MMDRV_Message(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2, BOOL bFrom32);
246 UINT MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1, DWORD dwParam2);
247 BOOL MMDRV_Is32(unsigned int);
248 void MMDRV_InstallMap(unsigned int, MMDRV_MAPFUNC, MMDRV_UNMAPFUNC,
249 MMDRV_MAPFUNC, MMDRV_UNMAPFUNC, LPDRVCALLBACK);
250
251 WINE_MCIDRIVER* MCI_GetDriver(UINT16 uDevID);
252 UINT MCI_GetDriverFromString(LPCWSTR str);
253 DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr);
254 const char* MCI_MessageToString(UINT wMsg);
255 UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
256 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2);
257 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
258 DWORD MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2);
259 DWORD MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2);
260 UINT MCI_SetCommandTable(void *table, UINT uDevType);
261 BOOL MCI_DeleteCommandTable(UINT uTbl, BOOL delete);
262 LPWSTR MCI_strdupAtoW(LPCSTR str);
263 LPSTR MCI_strdupWtoA(LPCWSTR str);
264
265 BOOL WINMM_CheckForMMSystem(void);
266 const char* WINMM_ErrorToString(MMRESULT error);
267
268 UINT MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
269 DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32);
270 UINT MIDI_OutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback,
271 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32);
272 UINT MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD_PTR dwCallback,
273 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32);
274 MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
275 DWORD cMidi, DWORD_PTR dwCallback,
276 DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32);
277 UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
278 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
279 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32);
280
281 HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo,
282 DWORD dwOpenFlags, enum mmioProcType type);
283 LPMMIOPROC MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
284 DWORD dwFlags, enum mmioProcType type);
285 LRESULT MMIO_SendMessage(HMMIO hmmio, UINT uMessage, LPARAM lParam1,
286 LPARAM lParam2, enum mmioProcType type);
287 LPWINE_MMIO MMIO_Get(HMMIO h);
288
289 WORD TIME_SetEventInternal(UINT wDelay, UINT wResol, LPTIMECALLBACK lpFunc,
290 DWORD dwUser, UINT wFlags);
291 void TIME_MMTimeStart(void);
292 void TIME_MMTimeStop(void);
293
294 /* Global variables */
295 extern WINE_MM_IDATA WINMM_IData;
296
297 /* pointers to 16 bit functions (if sibling MMSYSTEM.DLL is loaded
298 * NULL otherwise
299 */
300 extern WINE_MMTHREAD* (*pFnGetMMThread16)(UINT16);
301 extern LPWINE_DRIVER (*pFnOpenDriver16)(LPCWSTR,LPCWSTR,LPARAM);
302 extern LRESULT (*pFnCloseDriver16)(UINT16,LPARAM,LPARAM);
303 extern LRESULT (*pFnSendMessage16)(UINT16,UINT,LPARAM,LPARAM);
304 extern WINMM_MapType (*pFnMciMapMsg16To32W)(WORD,WORD,DWORD,DWORD*);
305 extern WINMM_MapType (*pFnMciUnMapMsg16To32W)(WORD,WORD,DWORD,DWORD);
306 extern WINMM_MapType (*pFnMciMapMsg32WTo16)(WORD,WORD,DWORD,DWORD*);
307 extern WINMM_MapType (*pFnMciUnMapMsg32WTo16)(WORD,WORD,DWORD,DWORD);
308 extern LRESULT (*pFnCallMMDrvFunc16)(DWORD /* in fact FARPROC16 */,WORD,WORD,LONG,LONG,LONG);
309 extern unsigned (*pFnLoadMMDrvFunc16)(LPCSTR,LPWINE_DRIVER, LPWINE_MM_DRIVER);
310 extern LRESULT (*pFnMmioCallback16)(DWORD,LPMMIOINFO,UINT,LPARAM,LPARAM);
311 extern void (WINAPI *pFnReleaseThunkLock)(DWORD*);
312 extern void (WINAPI *pFnRestoreThunkLock)(DWORD);
313 /* GetDriverFlags() returned bits is not documented (nor the call itself)
314 * Here are Wine only definitions of the bits
315 */
316 #define WINE_GDF_EXIST 0x80000000
317 #define WINE_GDF_16BIT 0x10000000