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