ReactOS 0.4.16-dev-311-g9382aa2
mmdrv.h File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winioctl.h>
#include "mmioctl.h"
#include "mmddk.h"
Include dependency graph for mmdrv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  WaveOverlapInfo
 
union  MediaHeader
 
struct  _ThreadInfo
 
struct  _LoopInfo
 
struct  _SessionInfo
 

Macros

#define WIN32_NO_STATUS
 
#define MAX_DEVICES   256
 
#define MAX_DEVICE_NAME_LENGTH   256
 
#define MAX_BUFFER_SIZE   1048576
 
#define MAX_WAVE_BYTES   1048576
 
#define WHDR_COMPLETE   0x80000000
 
#define IsWaveDevice(devicetype)    ( ( devicetype == WaveOutDevice ) || ( devicetype == WaveInDevice ) )
 
#define IsMidiDevice(devicetype)    ( ( devicetype == MidiOutDevice ) || ( devicetype == MidiInDevice ) )
 
#define IsAuxDevice(devicetype)    ( devicetype == AuxDevice )
 
#define DRVM_TERMINATE   0xFFFFFFFE
 
#define DRVM_INVALID   0xFFFFFFFF
 
#define ASSERT(condition)
 

Typedefs

typedef DWORD ThreadFunction
 
typedef struct _ThreadInfo ThreadInfo
 
typedef struct _LoopInfo LoopInfo
 
typedef struct _SessionInfo SessionInfo
 

Enumerations

enum  DeviceType {
  WaveOutDevice , WaveInDevice , MidiOutDevice , MidiInDevice ,
  AuxDevice
}
 
enum  WaveState { WavePlaying , WaveStopped , WaveReset , WaveRestart }
 

Functions

BOOL NotifyClient (SessionInfo *session_info, DWORD message, DWORD_PTR parameter1, DWORD_PTR parameter2)
 
MMRESULT ErrorToMmResult (UINT error_code)
 
MMRESULT CobbleDeviceName (DeviceType device_type, UINT device_id, PWCHAR out_device_name)
 
MMRESULT OpenKernelDevice (DeviceType device_type, UINT device_id, DWORD access, HANDLE *handle)
 
VOID CloseKernelDevice (HANDLE device_handle)
 
MMRESULT SetDeviceData (HANDLE device_handle, DWORD ioctl, PBYTE input_buffer, DWORD buffer_size)
 
MMRESULT GetDeviceData (HANDLE device_handle, DWORD ioctl, PBYTE output_buffer, DWORD buffer_size)
 
MMRESULT CreateSession (DeviceType device_type, UINT device_id, SessionInfo **session_info)
 
VOID DestroySession (SessionInfo *session)
 
SessionInfoGetSession (DeviceType device_type, UINT device_id)
 
MMRESULT StartSessionThread (SessionInfo *session_info)
 
MMRESULT CallSessionThread (SessionInfo *session_info, ThreadFunction function, PVOID thread_parameter)
 
DWORD HandleBySessionThread (DWORD_PTR private_handle, DWORD_PTR message, DWORD_PTR parameter)
 
DWORD GetDeviceCount (DeviceType device_type)
 
DWORD GetDeviceCapabilities (DeviceType device_type, UINT device_id, DWORD_PTR capabilities, DWORD capabilities_size)
 
DWORD OpenDevice (DeviceType device_type, UINT device_id, PVOID open_descriptor, DWORD flags, DWORD_PTR private_handle)
 
DWORD CloseDevice (DWORD_PTR private_handle)
 
DWORD PauseDevice (DWORD private_handle)
 
DWORD RestartDevice (DWORD private_handle)
 
DWORD ResetDevice (DWORD private_handle)
 
DWORD GetPosition (DWORD private_handle, PMMTIME time, DWORD time_size)
 
DWORD BreakLoop (DWORD private_handle)
 
DWORD QueryWaveFormat (DeviceType device_type, PVOID lpFormat)
 
DWORD WriteWaveBuffer (DWORD_PTR private_handle, PWAVEHDR wave_header, DWORD wave_header_size)
 
DWORD WaveThread (LPVOID parameter)
 
VOID PerformWaveIO (SessionInfo *session_info)
 

Variables

CRITICAL_SECTION critical_section
 

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   condition)
Value:
if ( ! (condition) ) \
DPRINT("ASSERT FAILED: %s\n", #condition);
GLenum condition
Definition: glext.h:9255

Definition at line 176 of file mmdrv.h.

◆ DRVM_INVALID

#define DRVM_INVALID   0xFFFFFFFF

Definition at line 87 of file mmdrv.h.

◆ DRVM_TERMINATE

#define DRVM_TERMINATE   0xFFFFFFFE

Definition at line 86 of file mmdrv.h.

◆ IsAuxDevice

#define IsAuxDevice (   devicetype)     ( devicetype == AuxDevice )

Definition at line 56 of file mmdrv.h.

◆ IsMidiDevice

#define IsMidiDevice (   devicetype)     ( ( devicetype == MidiOutDevice ) || ( devicetype == MidiInDevice ) )

Definition at line 53 of file mmdrv.h.

◆ IsWaveDevice

#define IsWaveDevice (   devicetype)     ( ( devicetype == WaveOutDevice ) || ( devicetype == WaveInDevice ) )

Definition at line 50 of file mmdrv.h.

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   1048576

Definition at line 30 of file mmdrv.h.

◆ MAX_DEVICE_NAME_LENGTH

#define MAX_DEVICE_NAME_LENGTH   256

Definition at line 29 of file mmdrv.h.

◆ MAX_DEVICES

#define MAX_DEVICES   256

Definition at line 28 of file mmdrv.h.

◆ MAX_WAVE_BYTES

#define MAX_WAVE_BYTES   1048576

Definition at line 31 of file mmdrv.h.

◆ WHDR_COMPLETE

#define WHDR_COMPLETE   0x80000000

Definition at line 34 of file mmdrv.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 19 of file mmdrv.h.

Typedef Documentation

◆ LoopInfo

◆ SessionInfo

◆ ThreadFunction

Definition at line 85 of file mmdrv.h.

◆ ThreadInfo

Enumeration Type Documentation

◆ DeviceType

Initial value:
{
DeviceType
Definition: mmdrv.h:42
#define WdfFunctions
Definition: wdf.h:66
_In_ PWDFDEVICE_INIT DeviceInit
Definition: wdfcontrol.h:113
PWDF_DRIVER_GLOBALS WdfDriverGlobals
@ WdfDeviceInitSetDeviceTypeTableIndex
Definition: wdffuncenum.h:91
Enumerator
WaveOutDevice 
WaveInDevice 
MidiOutDevice 
MidiInDevice 
AuxDevice 

Definition at line 41 of file mmdrv.h.

42{
@ MidiOutDevice
Definition: mmdrv.h:45
@ MidiInDevice
Definition: mmdrv.h:46
@ WaveInDevice
Definition: mmdrv.h:44
@ AuxDevice
Definition: mmdrv.h:47
@ WaveOutDevice
Definition: mmdrv.h:43

◆ WaveState

Enumerator
WavePlaying 
WaveStopped 
WaveReset 
WaveRestart 

Definition at line 89 of file mmdrv.h.

90{
95} WaveState;
WaveState
Definition: mmdrv.h:90
@ WaveReset
Definition: mmdrv.h:93
@ WavePlaying
Definition: mmdrv.h:91
@ WaveRestart
Definition: mmdrv.h:94
@ WaveStopped
Definition: mmdrv.h:92

Function Documentation

◆ BreakLoop()

DWORD BreakLoop ( DWORD  private_handle)

◆ CallSessionThread()

MMRESULT CallSessionThread ( SessionInfo session_info,
ThreadFunction  function,
PVOID  thread_parameter 
)

Definition at line 219 of file session.c.

223{
224 ASSERT(session_info);
225
226 session_info->thread.function = function;
227 session_info->thread.parameter = thread_parameter;
228
229 DPRINT("Calling session thread\n");
230 SetEvent(session_info->thread.go_event);
231
232 DPRINT("Waiting for thread response\n");
234
235 return session_info->thread.result;
236}
#define INFINITE
Definition: serial.h:102
#define ASSERT(a)
Definition: mode.c:44
#define DPRINT
Definition: sndvol32.h:73
ThreadInfo thread
Definition: mmdrv.h:172
MMRESULT result
Definition: mmdrv.h:120
HANDLE ready_event
Definition: mmdrv.h:113
PVOID parameter
Definition: mmdrv.h:118
DWORD function
Definition: mmdrv.h:117
HANDLE go_event
Definition: mmdrv.h:114
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733

Referenced by CloseDevice(), HandleBySessionThread(), and WriteWaveBuffer().

◆ CloseDevice()

DWORD CloseDevice ( DWORD_PTR  private_handle)

Definition at line 239 of file common.c.

241{
243 SessionInfo* session_info = (SessionInfo*) private_handle;
244 /* TODO: Maybe this is best off inside the playback thread? */
245
246 ASSERT(session_info);
247
248 result = CallSessionThread(session_info, WODM_CLOSE, 0);
249
250 if ( result == MMSYSERR_NOERROR )
251 {
252 /* TODO: Wait for it to be safe to terminate */
253
255
256 DestroySession(session_info);
257 }
258
259 return result;
260}
void CloseKernelDevice(HANDLE device_handle)
Definition: kernel.c:132
#define WODM_CLOSE
Definition: mmddk.h:111
GLuint64EXT * result
Definition: glext.h:11304
MMRESULT CallSessionThread(SessionInfo *session_info, ThreadFunction function, PVOID thread_parameter)
Definition: session.c:219
VOID DestroySession(SessionInfo *session)
Definition: session.c:113
UINT MMRESULT
Definition: mmsystem.h:962
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
HANDLE kernel_device_handle
Definition: mmdrv.h:136

◆ CloseKernelDevice()

VOID CloseKernelDevice ( HANDLE  device_handle)

Definition at line 132 of file kernel.c.

133{
134 CloseHandle(device_handle);
135}
#define CloseHandle
Definition: compat.h:739

Referenced by CloseDevice(), and GetDeviceCapabilities().

◆ CobbleDeviceName()

MMRESULT CobbleDeviceName ( DeviceType  device_type,
UINT  device_id,
PWCHAR  out_device_name 
)

Definition at line 28 of file kernel.c.

32{
33 WCHAR base_device_name[MAX_DEVICE_NAME_LENGTH];
34
35 /* Work out the base name from the device type */
36
37 switch ( device_type )
38 {
39 case WaveOutDevice :
40 wsprintf(base_device_name, L"%ls", WAVE_OUT_DEVICE_NAME);
41 break;
42
43 case WaveInDevice :
44 wsprintf(base_device_name, L"%ls", WAVE_IN_DEVICE_NAME);
45 break;
46
47 case MidiOutDevice :
48 wsprintf(base_device_name, L"%ls", MIDI_OUT_DEVICE_NAME);
49 break;
50
51 case MidiInDevice :
52 wsprintf(base_device_name, L"%ls", MIDI_IN_DEVICE_NAME);
53 break;
54
55 case AuxDevice :
56 wsprintf(base_device_name, L"%ls", AUX_DEVICE_NAME);
57 break;
58
59 default :
61 };
62
63 /* Now append the device number, removing the leading \Device */
64
65 wsprintf(out_device_name,
66 L"\\\\.%ls%d",
67 base_device_name + strlen("\\Device"),
68 device_id);
69
70 return MMSYSERR_NOERROR;
71}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
device_type
#define WAVE_OUT_DEVICE_NAME
Definition: mmdef.h:31
#define MIDI_IN_DEVICE_NAME
Definition: mmdef.h:34
#define MIDI_OUT_DEVICE_NAME
Definition: mmdef.h:36
#define WAVE_IN_DEVICE_NAME
Definition: mmdef.h:29
#define AUX_DEVICE_NAME
Definition: mmdef.h:39
#define MAX_DEVICE_NAME_LENGTH
Definition: mmdrv.h:29
#define MMSYSERR_BADDEVICEID
Definition: mmsystem.h:98
#define L(x)
Definition: ntvdm.h:50
#define wsprintf
Definition: winuser.h:5877
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by OpenKernelDevice().

◆ CreateSession()

MMRESULT CreateSession ( DeviceType  device_type,
UINT  device_id,
SessionInfo **  session_info 
)

Definition at line 63 of file session.c.

67{
69
70 ASSERT(session_info);
71
73
74 /* Ensure we're not creating a duplicate session */
75
76 if ( GetSession(device_type, device_id) )
77 {
78 DPRINT("Already allocated session\n");
80 return MMSYSERR_ALLOCATED;
81 }
82
83 *session_info = HeapAlloc(heap, HEAP_ZERO_MEMORY, sizeof(SessionInfo));
84
85 if ( ! *session_info )
86 {
87 DPRINT("Failed to allocate mem for session info\n");
89 return MMSYSERR_NOMEM;
90 }
91
92 (*session_info)->device_type = device_type;
93 (*session_info)->device_id = device_id;
94
95 /* Add to the list */
96
97 (*session_info)->next = session_list;
98 session_list = *session_info;
99
101
102 return MMSYSERR_NOERROR;
103}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
SessionInfo * GetSession(DeviceType device_type, UINT device_id)
Definition: session.c:30
SessionInfo * session_list
Definition: session.c:19
CRITICAL_SECTION session_lock
Definition: session.c:20
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define MMSYSERR_ALLOCATED
Definition: mmsystem.h:100
static HANDLE heap
Definition: heap.c:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by CsrSbCreateSession(), OpenDevice(), and SmpLoadSubSystem().

◆ DestroySession()

VOID DestroySession ( SessionInfo session)

Definition at line 113 of file session.c.

114{
116 SessionInfo* session_node;
117 SessionInfo* session_prev;
118
119 /* TODO: More cleanup stuff */
120
121 /* Remove from the list */
122
124
125 session_node = session_list;
126 session_prev = NULL;
127
128 while ( session_node )
129 {
130 if ( session_node == session )
131 {
132 /* Bridge the gap for when we go */
133 session_prev->next = session->next;
134 break;
135 }
136
137 /* Save the previous node, fetch the next */
138 session_prev = session_node;
139 session_node = session_node->next;
140 }
141
143
144 HeapFree(heap, 0, session);
145}
#define NULL
Definition: types.h:112
#define HeapFree(x, y, z)
Definition: compat.h:735
struct _SessionInfo * next
Definition: mmdrv.h:131

Referenced by CloseDevice(), and OpenDevice().

◆ ErrorToMmResult()

MMRESULT ErrorToMmResult ( UINT  error_code)

Definition at line 22 of file common.c.

23{
24 switch ( error_code )
25 {
26 case NO_ERROR :
27 case ERROR_IO_PENDING :
28 return MMSYSERR_NOERROR;
29
30 case ERROR_BUSY :
31 return MMSYSERR_ALLOCATED;
32
36
38 return MMSYSERR_NOMEM;
39
42
45 };
46
47 /* If all else fails, it's just a plain old error */
48
49 return MMSYSERR_ERROR;
50}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_BUSY
Definition: dderror.h:12
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
#define MMSYSERR_INVALPARAM
Definition: mmsystem.h:107
#define MMSYSERR_ERROR
Definition: mmsystem.h:97
static int error_code[8]
Definition: odbccp32.c:61

Referenced by GetDeviceCapabilities(), GetDeviceData(), and OpenKernelDevice().

◆ GetDeviceCapabilities()

DWORD GetDeviceCapabilities ( DeviceType  device_type,
UINT  device_id,
DWORD_PTR  capabilities,
DWORD  capabilities_size 
)

Definition at line 84 of file common.c.

89{
93 DWORD bytes_returned;
94 BOOL device_io_result;
95
96 ASSERT(capabilities);
97
98 /* Choose the right IOCTL for the job */
99
102 else if ( IsMidiDevice(device_type) )
104 else if ( IsAuxDevice(device_type) )
105 return MMSYSERR_NOTSUPPORTED; /* TODO */
106 else
108
110 device_id,
112 &handle);
113
114 if ( result != MMSYSERR_NOERROR )
115 {
116 DPRINT("Failed to open kernel device\n");
117 return result;
118 }
119
120 device_io_result = DeviceIoControl(handle,
121 ioctl,
122 NULL,
123 0,
124 (LPVOID) capabilities,
125 capabilities_size,
126 &bytes_returned,
127 NULL);
128
129 /* Translate result */
130
131 if ( device_io_result )
133 else
135
136 /* Clean up and return */
137
139
140 return result;
141}
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define GENERIC_READ
Definition: compat.h:135
MMRESULT ErrorToMmResult(UINT error_code)
Definition: common.c:22
MMRESULT OpenKernelDevice(DeviceType device_type, UINT device_id, DWORD access, HANDLE *handle)
Definition: kernel.c:84
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IOCTL_WAVE_GET_CAPABILITIES
Definition: mmdef.h:52
#define IOCTL_MIDI_GET_CAPABILITIES
Definition: mmdef.h:69
#define IsMidiDevice(devicetype)
Definition: mmdrv.h:53
#define IsWaveDevice(devicetype)
Definition: mmdrv.h:50
#define IsAuxDevice(devicetype)
Definition: mmdrv.h:56
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ioctl
Definition: wintirpc.h:60

◆ GetDeviceCount()

DWORD GetDeviceCount ( DeviceType  device_type)

Definition at line 58 of file common.c.

59{
60 UINT index = 0;
62
63 /* Cycle through devices until an error occurs */
64
66 {
68 index ++;
69 }
70
71 DPRINT("Found %d devices of type %d\n", index, device_type);
72
73 return index;
74}
#define index(s, c)
Definition: various.h:29
GLuint index
Definition: glext.h:6031
unsigned int UINT
Definition: ndis.h:50

Referenced by auxMessage(), midMessage(), modMessage(), and wodMessage().

◆ GetDeviceData()

MMRESULT GetDeviceData ( HANDLE  device_handle,
DWORD  ioctl,
PBYTE  output_buffer,
DWORD  buffer_size 
)

Definition at line 152 of file kernel.c.

157{
158 OVERLAPPED overlap;
159 DWORD bytes_returned;
161 DWORD transfer;
162
163 DPRINT("GetDeviceData\n");
164
165 memset(&overlap, 0, sizeof(overlap));
166
167 overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
168
169 if ( ! overlap.hEvent )
170 return MMSYSERR_NOMEM;
171
172 success = DeviceIoControl(device_handle,
173 ioctl,
174 NULL,
175 0,
178 &bytes_returned,
179 &overlap);
180
181 if ( ! success )
182 {
184 {
185 if ( ! GetOverlappedResult(device_handle, &overlap, &transfer, TRUE) )
186 {
187 CloseHandle(overlap.hEvent);
189 }
190 }
191 else
192 {
193 CloseHandle(overlap.hEvent);
195 }
196 }
197
198 while ( TRUE )
199 {
200 SetEvent(overlap.hEvent);
201
203 {
204 break;
205 }
206 }
207
208 CloseHandle(overlap.hEvent);
209
210 return MMSYSERR_NOERROR;
211}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:221
#define memset(x, y, z)
Definition: compat.h:39
HANDLE hEvent
Definition: winbase.h:845
static void buffer_size(GLcontext *ctx, GLuint *width, GLuint *height)
Definition: swimpl.c:888
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
#define success(from, fromstr, to, tostr)
#define WAIT_IO_COMPLETION
Definition: winbase.h:437
#define CreateEvent
Definition: winbase.h:3773

◆ GetPosition()

DWORD GetPosition ( DWORD  private_handle,
PMMTIME  time,
DWORD  time_size 
)

Referenced by DECLARE_INTERFACE_(), and wodMessage().

◆ GetSession()

SessionInfo * GetSession ( DeviceType  device_type,
UINT  device_id 
)

Definition at line 30 of file session.c.

33{
34 SessionInfo* session_info;
35
37 session_info = session_list;
38
39 while ( session_info )
40 {
41 if ( ( session_info->device_type == device_type ) &&
42 ( session_info->device_id == device_id ) )
43 {
45 return session_info;
46 }
47
48 session_info = session_info->next;
49 }
50
52 return NULL;
53}
DeviceType device_type
Definition: mmdrv.h:133
UINT device_id
Definition: mmdrv.h:134

Referenced by CreateSession().

◆ HandleBySessionThread()

DWORD HandleBySessionThread ( DWORD_PTR  private_handle,
DWORD_PTR  message,
DWORD_PTR  parameter 
)

Definition at line 240 of file session.c.

244{
245 return CallSessionThread((SessionInfo*) private_handle,
246 message,
247 (PVOID) parameter);
248}
MMRESULT CallSessionThread(SessionInfo *session_info, ThreadFunction function, PVOID thread_parameter)
Definition: session.c:219
Definition: tftpd.h:60

Referenced by wodMessage().

◆ NotifyClient()

BOOL NotifyClient ( SessionInfo session_info,
DWORD  message,
DWORD_PTR  parameter1,
DWORD_PTR  parameter2 
)

Definition at line 25 of file mme.c.

30{
31 return DriverCallback(session_info->callback,
32 HIWORD(session_info->flags),
33 session_info->mme_handle,
34 message,
35 session_info->app_user_data,
36 parameter1,
37 parameter2);
38}
BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2)
DWORD flags
Definition: mmdrv.h:153
DWORD_PTR app_user_data
Definition: mmdrv.h:150
DWORD_PTR callback
Definition: mmdrv.h:151
HDRVR mme_handle
Definition: mmdrv.h:141
#define HIWORD(l)
Definition: typedefs.h:247

Referenced by OpenDevice(), and ReturnCompletedBuffers().

◆ OpenDevice()

DWORD OpenDevice ( DeviceType  device_type,
UINT  device_id,
PVOID  open_descriptor,
DWORD  flags,
DWORD_PTR  private_handle 
)

Definition at line 153 of file common.c.

159{
160 SessionInfo* session_info;
163
164 /* This will automatically check for duplicate sessions */
165 result = CreateSession(device_type, device_id, &session_info);
166
167 if ( result != MMSYSERR_NOERROR )
168 {
169 DPRINT("Couldn't allocate session info\n");
170 return result;
171 }
172
174 device_id,
176 &session_info->kernel_device_handle);
177
178 if ( result != MMSYSERR_NOERROR )
179 {
180 DPRINT("Failed to open kernel device\n");
181 DestroySession(session_info);
182 return result;
183 }
184
185 /* Set common session data */
186
187 session_info->flags = flags;
188
189 /* Set wave/MIDI specific data */
190
192 {
193 LPWAVEOPENDESC wave_open_desc = (LPWAVEOPENDESC) open_descriptor;
194 session_info->callback = wave_open_desc->dwCallback;
195 session_info->mme_wave_handle = wave_open_desc->hWave;
196 session_info->app_user_data = wave_open_desc->dwInstance;
197 }
198 else
199 {
200 DPRINT("Only wave devices are supported at present!\n");
201 DestroySession(session_info);
203 }
204
205 /* Start the processing thread */
206
207 result = StartSessionThread(session_info);
208
209 if ( result != MMSYSERR_NOERROR )
210 {
211 DestroySession(session_info);
212 return result;
213 }
214
215 /* Store the session info */
216
217 *((SessionInfo**)private_handle) = session_info;
218
219 /* Send the right message */
220
224 (device_type == MidiInDevice) ? MIM_OPEN : 0xFFFFFFFF;
225
226 NotifyClient(session_info, message, 0, 0);
227
228 return MMSYSERR_NOERROR;
229}
struct WAVEOPENDESC * LPWAVEOPENDESC
GLbitfield flags
Definition: glext.h:7161
MMRESULT CreateSession(DeviceType device_type, UINT device_id, SessionInfo **session_info)
Definition: session.c:63
MMRESULT StartSessionThread(SessionInfo *session_info)
Definition: session.c:154
BOOL NotifyClient(SessionInfo *session_info, DWORD message, DWORD_PTR parameter1, DWORD_PTR parameter2)
Definition: mme.c:25
#define MIM_OPEN
Definition: mmsystem.h:241
#define WOM_OPEN
Definition: mmsystem.h:181
#define MOM_OPEN
Definition: mmsystem.h:247
#define WIM_OPEN
Definition: mmsystem.h:184
HWAVE hWave
Definition: mmddk.h:398
DWORD dwInstance
Definition: mmddk.h:401
DWORD dwCallback
Definition: mmddk.h:400
HWAVE mme_wave_handle
Definition: mmdrv.h:142

◆ OpenKernelDevice()

MMRESULT OpenKernelDevice ( DeviceType  device_type,
UINT  device_id,
DWORD  access,
HANDLE handle 
)

Definition at line 84 of file kernel.c.

89{
92 DWORD open_flags = 0;
93
95
96 /* Glue the base device name and the ID together */
97
99
100 DPRINT("Opening kernel device %ls\n", device_name);
101
102 if ( result != MMSYSERR_NOERROR )
103 return result;
104
105 /* We want overlapped I/O when writing */
106
107 if ( access != GENERIC_READ )
108 open_flags = FILE_FLAG_OVERLAPPED;
109
110 /* Now try opening... */
111
113 access,
115 NULL,
117 open_flags,
118 NULL);
119
122
123 return MMSYSERR_NOERROR;
124}
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
MMRESULT CobbleDeviceName(DeviceType device_type, UINT device_id, PWCHAR out_device_name)
Definition: kernel.c:28
static const WCHAR device_name[]
Definition: btrfs.c:60
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define CreateFile
Definition: winbase.h:3774

Referenced by GetDeviceCapabilities(), GetDeviceCount(), and OpenDevice().

◆ PauseDevice()

DWORD PauseDevice ( DWORD  private_handle)

◆ PerformWaveIO()

VOID PerformWaveIO ( SessionInfo session_info)

Definition at line 39 of file wave_io.c.

41{
42
43}

Referenced by WaveThread().

◆ QueryWaveFormat()

DWORD QueryWaveFormat ( DeviceType  device_type,
PVOID  lpFormat 
)

Definition at line 335 of file wave.c.

338{
339 /* TODO */
340 return WAVERR_BADFORMAT;
341}
#define WAVERR_BADFORMAT
Definition: mmsystem.h:176

Referenced by wodMessage().

◆ ResetDevice()

DWORD ResetDevice ( DWORD  private_handle)

Referenced by USBSTOR_TimerRoutine().

◆ RestartDevice()

DWORD RestartDevice ( DWORD  private_handle)

◆ SetDeviceData()

MMRESULT SetDeviceData ( HANDLE  device_handle,
DWORD  ioctl,
PBYTE  input_buffer,
DWORD  buffer_size 
)

Definition at line 139 of file kernel.c.

144{
145 DPRINT("SetDeviceData\n");
146 /* TODO */
147 return 0;
148}

Referenced by ProcessSessionThreadRequest().

◆ StartSessionThread()

MMRESULT StartSessionThread ( SessionInfo session_info)

Definition at line 154 of file session.c.

155{
156 LPTASKCALLBACK task;
158
159 ASSERT(session_info);
160
161 /* This is our "ready" event, sent when the thread is idle */
162
163 session_info->thread.ready_event = CreateEvent(NULL, FALSE, FALSE, NULL);
164
165 if ( ! session_info->thread.ready_event )
166 {
167 DPRINT("Couldn't create thread_ready event\n");
168 return MMSYSERR_NOMEM;
169 }
170
171 /* This is our "go" event, sent when we want the thread to do something */
172
173 session_info->thread.go_event = CreateEvent(NULL, FALSE, FALSE, NULL);
174
175 if ( ! session_info->thread.go_event )
176 {
177 DPRINT("Couldn't create thread_go event\n");
178 CloseHandle(session_info->thread.ready_event);
179 return MMSYSERR_NOMEM;
180 }
181
182 /* TODO - other kinds of devices need attention, too */
183 task = ( session_info->device_type == WaveOutDevice )
185
186 ASSERT(task);
187
188 /* Effectively, this is a beefed-up CreateThread */
189
190 result = mmTaskCreate(task,
191 &session_info->thread.handle,
192 (DWORD_PTR)session_info);
193
194 if ( result != MMSYSERR_NOERROR )
195 {
196 DPRINT("Task creation failed\n");
197 CloseHandle(session_info->thread.ready_event);
198 CloseHandle(session_info->thread.go_event);
199 return result;
200 }
201
202 /* Wait for the thread to be ready before completing */
203
205
206 return MMSYSERR_NOERROR;
207}
TASKCALLBACK FAR * LPTASKCALLBACK
Definition: mmddk.h:33
UINT APIENTRY mmTaskCreate(LPTASKCALLBACK lpfn, HANDLE FAR *lph, DWORD dwInst)
DWORD WaveThread(LPVOID parameter)
Definition: wave.c:266
HANDLE handle
Definition: mmdrv.h:112
uint32_t DWORD_PTR
Definition: typedefs.h:65

Referenced by OpenDevice().

◆ WaveThread()

DWORD WaveThread ( LPVOID  parameter)

Definition at line 266 of file wave.c.

267{
269 SessionInfo* session_info = (SessionInfo*) parameter;
271
272 /* All your CPU time are belong to us */
274
275 DPRINT("Wave processing thread setting ready state\n");
276
277 SetEvent(session_info->thread.ready_event);
278
279 while ( ! terminate )
280 {
281 /* Wait for GO event, or IO completion notification */
282 while ( WaitForSingleObjectEx(session_info->thread.go_event,
283 INFINITE,
285 {
286 /* A buffer has been finished with - pass back to the client */
287 ReturnCompletedBuffers(session_info);
288 }
289
290 DPRINT("Wave processing thread woken up\n");
291
292 /* Set the terminate flag if that's what the caller wants */
293 terminate = (session_info->thread.function == DRVM_TERMINATE);
294
295 /* Process the request */
296 DPRINT("Processing thread request\n");
297 result = ProcessSessionThreadRequest(session_info);
298
299 /* Store the result code */
300 session_info->thread.result = result;
301
302 /* Submit new buffers and continue existing ones */
303 DPRINT("Performing wave I/O\n");
304 PerformWaveIO(session_info);
305
306 /* Now we're ready for more action */
307 DPRINT("Wave processing thread sleeping\n");
308 SetEvent(session_info->thread.ready_event);
309 }
310
311 return 0;
312}
BOOL WINAPI SetThreadPriority(IN HANDLE hThread, IN int nPriority)
Definition: thread.c:700
DWORD ProcessSessionThreadRequest(SessionInfo *session_info)
Definition: wave.c:136
VOID ReturnCompletedBuffers(SessionInfo *session_info)
Definition: wave.c:94
void MSVCRT() terminate()
Definition: cpp.c:716
VOID PerformWaveIO(SessionInfo *session_info)
Definition: wave_io.c:39
#define DRVM_TERMINATE
Definition: mmdrv.h:86
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1148
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:307

Referenced by StartSessionThread().

◆ WriteWaveBuffer()

DWORD WriteWaveBuffer ( DWORD_PTR  private_handle,
PWAVEHDR  wave_header,
DWORD  wave_header_size 
)

Definition at line 372 of file wave.c.

376{
377 SessionInfo* session_info = (SessionInfo*) private_handle;
378 ASSERT(session_info);
379
380 /* Let the processing thread know that it has work to do */
381 return CallSessionThread(session_info, WODM_WRITE, wave_header);
382}
#define WODM_WRITE
Definition: mmddk.h:114

Referenced by wodMessage().

Variable Documentation

◆ critical_section

CRITICAL_SECTION critical_section
extern