[MMDRV]
[reactos.git] / reactos / dll / win32 / mmdrv / mmdrv.h
1 /*
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS Multimedia
5 * FILE: dll/win32/mmdrv/mmdrv.h
6 * PURPOSE: Multimedia User Mode Driver (header)
7 * PROGRAMMER: Andrew Greenwood
8 * Aleksey Bragin
9 * UPDATE HISTORY:
10 * Jan 30, 2004: Imported into ReactOS tree
11 * Jan 10, 2007: Rewritten and tidied up
12 */
13
14 #ifndef MMDRV_H
15 #define MMDRV_H
16
17 #include <stdarg.h>
18
19 #define WIN32_NO_STATUS
20
21 #include <windef.h>
22 #include <winbase.h>
23 #include <winioctl.h>
24
25 #include "mmioctl.h"
26 #include "mmddk.h"
27
28 /* Need to check these */
29 #define MAX_DEVICES 256
30 #define MAX_DEVICE_NAME_LENGTH 256
31 #define MAX_BUFFER_SIZE 1048576
32 #define MAX_WAVE_BYTES 1048576
33
34 /* Custom flag set when overlapped I/O is done */
35 #define WHDR_COMPLETE 0x80000000
36
37
38 /*
39 The kinds of devices which MMSYSTEM/WINMM may request from us.
40 */
41
42 typedef enum
43 {
44 WaveOutDevice,
45 WaveInDevice,
46 MidiOutDevice,
47 MidiInDevice,
48 AuxDevice
49 } DeviceType;
50
51 #define IsWaveDevice(devicetype) \
52 ( ( devicetype == WaveOutDevice ) || ( devicetype == WaveInDevice ) )
53
54 #define IsMidiDevice(devicetype) \
55 ( ( devicetype == MidiOutDevice ) || ( devicetype == MidiInDevice ) )
56
57 #define IsAuxDevice(devicetype) \
58 ( devicetype == AuxDevice )
59
60
61 /*
62 We use these structures to store information regarding open devices. Since
63 the main structure gets destroyed when a device is closed, I call this a
64 "session".
65 */
66
67 typedef struct
68 {
69 OVERLAPPED overlap;
70 LPWAVEHDR header;
71 } WaveOverlapInfo;
72
73 /*
74 typedef enum
75 {
76 WaveAddBuffer,
77 WaveClose,
78 WaveReset,
79 WaveRestart,
80 SessionThreadTerminate,
81 InvalidFunction
82 } ThreadFunction;
83 */
84
85 /* Our own values, used with the session threads */
86 typedef DWORD ThreadFunction;
87 #define DRVM_TERMINATE 0xFFFFFFFE
88 #define DRVM_INVALID 0xFFFFFFFF
89
90 typedef enum
91 {
92 WavePlaying,
93 WaveStopped,
94 WaveReset,
95 WaveRestart
96 } WaveState;
97
98 typedef union
99 {
100 PWAVEHDR wave_header;
101 PMIDIHDR midi_header;
102 } MediaHeader;
103
104 /*
105 typedef union
106 {
107 MediaHeader header;
108 } ThreadParameter;
109 */
110
111 typedef struct _ThreadInfo
112 {
113 HANDLE handle;
114 HANDLE ready_event;
115 HANDLE go_event;
116
117 /*ThreadFunction function;*/
118 DWORD function;
119 PVOID parameter;
120
121 MMRESULT result;
122 } ThreadInfo;
123
124 typedef struct _LoopInfo
125 {
126 PWAVEHDR head;
127 DWORD iterations;
128 } LoopInfo;
129
130 typedef struct _SessionInfo
131 {
132 struct _SessionInfo* next;
133
134 DeviceType device_type;
135 UINT device_id;
136
137 HANDLE kernel_device_handle;
138
139 /* These are all the same */
140 union
141 {
142 HDRVR mme_handle;
143 HWAVE mme_wave_handle;
144 HMIDI mme_midi_handle;
145 };
146
147 /* If playback is paused or not */
148 BOOL is_paused;
149
150 /* Stuff passed to us from winmm */
151 DWORD_PTR app_user_data;
152 DWORD_PTR callback;
153
154 DWORD flags;
155
156 /* Can only be one or the other */
157 union
158 {
159 PWAVEHDR wave_queue;
160 PMIDIHDR midi_queue;
161 };
162
163 /* Current playback point */
164 //PWAVEHDR next_buffer;
165
166 /* Where in the current buffer we are */
167 DWORD buffer_position;
168
169 // DWORD remaining_bytes;
170
171 LoopInfo loop;
172
173 ThreadInfo thread;
174 } SessionInfo;
175
176 #undef ASSERT
177 #define ASSERT(condition) \
178 if ( ! (condition) ) \
179 DPRINT("ASSERT FAILED: %s\n", #condition);
180
181 /*
182 MME interface
183 */
184
185 BOOL
186 NotifyClient(
187 SessionInfo* session_info,
188 DWORD message,
189 DWORD_PTR parameter1,
190 DWORD_PTR parameter2);
191
192
193 /*
194 Helpers
195 */
196
197 MMRESULT
198 ErrorToMmResult(UINT error_code);
199
200
201 /* Kernel interface */
202
203 MMRESULT
204 CobbleDeviceName(
205 DeviceType device_type,
206 UINT device_id,
207 PWCHAR out_device_name);
208
209 MMRESULT
210 OpenKernelDevice(
211 DeviceType device_type,
212 UINT device_id,
213 DWORD access,
214 HANDLE* handle);
215
216 VOID
217 CloseKernelDevice(HANDLE device_handle);
218
219 MMRESULT
220 SetDeviceData(
221 HANDLE device_handle,
222 DWORD ioctl,
223 PBYTE input_buffer,
224 DWORD buffer_size);
225
226 MMRESULT
227 GetDeviceData(
228 HANDLE device_handle,
229 DWORD ioctl,
230 PBYTE output_buffer,
231 DWORD buffer_size);
232
233
234 /* Session management */
235
236 MMRESULT
237 CreateSession(
238 DeviceType device_type,
239 UINT device_id,
240 SessionInfo** session_info);
241
242 VOID
243 DestroySession(SessionInfo* session);
244
245 SessionInfo*
246 GetSession(
247 DeviceType device_type,
248 UINT device_id);
249
250 MMRESULT
251 StartSessionThread(SessionInfo* session_info);
252
253 MMRESULT
254 CallSessionThread(
255 SessionInfo* session_info,
256 ThreadFunction function,
257 PVOID thread_parameter);
258
259 DWORD
260 HandleBySessionThread(
261 DWORD_PTR private_handle,
262 DWORD_PTR message,
263 DWORD_PTR parameter);
264
265
266 /* General */
267
268 DWORD
269 GetDeviceCount(DeviceType device_type);
270
271 DWORD
272 GetDeviceCapabilities(
273 DeviceType device_type,
274 UINT device_id,
275 DWORD_PTR capabilities,
276 DWORD capabilities_size);
277
278 DWORD
279 OpenDevice(
280 DeviceType device_type,
281 UINT device_id,
282 PVOID open_descriptor,
283 DWORD flags,
284 DWORD_PTR private_handle);
285
286 DWORD
287 CloseDevice(
288 DWORD_PTR private_handle);
289
290 DWORD
291 PauseDevice(
292 DWORD private_handle);
293
294 DWORD
295 RestartDevice(
296 DWORD private_handle);
297
298 DWORD
299 ResetDevice(
300 DWORD private_handle);
301
302 DWORD
303 GetPosition(
304 DWORD private_handle,
305 PMMTIME time,
306 DWORD time_size);
307
308 DWORD
309 BreakLoop(DWORD private_handle);
310
311 DWORD
312 QueryWaveFormat(
313 DeviceType device_type,
314 PVOID lpFormat);
315
316 DWORD
317 WriteWaveBuffer(
318 DWORD_PTR private_handle,
319 PWAVEHDR wave_header,
320 DWORD wave_header_size);
321
322
323
324
325
326 /* wave thread */
327
328 DWORD
329 WaveThread(LPVOID parameter);
330
331
332 /* Wave I/O */
333
334 VOID
335 PerformWaveIO(SessionInfo* session_info);
336
337
338 extern CRITICAL_SECTION critical_section;
339
340 #endif