2 * PROJECT: ReactOS Sound System "MME Buddy" Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/drivers/sound/mmebuddy/mmewrap.c
6 * PURPOSE: Interface between MME functions and MME Buddy's own.
8 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
18 Call the client application when something interesting happens (MME API
19 defines "interesting things" as device open, close, and buffer
24 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
28 SND_ASSERT( SoundDeviceInstance
);
30 SND_TRACE(L
"MME client callback - message %d, parameter %d\n",
34 if ( SoundDeviceInstance
->WinMM
.ClientCallback
)
36 DriverCallback(SoundDeviceInstance
->WinMM
.ClientCallback
,
37 HIWORD(SoundDeviceInstance
->WinMM
.Flags
),
38 SoundDeviceInstance
->WinMM
.Handle
,
40 SoundDeviceInstance
->WinMM
.ClientCallbackInstanceData
,
47 This is a helper function to alleviate some of the repetition involved with
48 implementing the various MME message functions.
51 MmeGetSoundDeviceCapabilities(
52 IN MMDEVICE_TYPE DeviceType
,
54 IN PVOID Capabilities
,
55 IN DWORD CapabilitiesSize
)
57 PSOUND_DEVICE SoundDevice
;
60 SND_TRACE(L
"MME *_GETCAPS for device %d of type %d\n", DeviceId
, DeviceType
);
62 /* FIXME: Validate device type and ID */
63 VALIDATE_MMSYS_PARAMETER( Capabilities
);
64 VALIDATE_MMSYS_PARAMETER( CapabilitiesSize
> 0 );
66 /* Our parameter checks are done elsewhere */
67 Result
= GetSoundDevice(DeviceType
, DeviceId
, &SoundDevice
);
69 if ( ! MMSUCCESS(Result
) )
72 return GetSoundDeviceCapabilities(SoundDevice
,
79 IN MMDEVICE_TYPE DeviceType
,
81 IN LPWAVEOPENDESC OpenParameters
,
83 OUT DWORD
* PrivateHandle
)
87 PSOUND_DEVICE SoundDevice
;
88 PSOUND_DEVICE_INSTANCE SoundDeviceInstance
;
89 LPWAVEFORMATEX Format
;
91 SND_TRACE(L
"Opening wave device (WIDM_OPEN / WODM_OPEN)");
93 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType
) ); /* FIXME? wave in too? */
94 VALIDATE_MMSYS_PARAMETER( OpenParameters
);
96 Format
= OpenParameters
->lpFormat
;
98 Result
= GetSoundDevice(DeviceType
, DeviceId
, &SoundDevice
);
99 if ( ! MMSUCCESS(Result
) )
100 return TranslateInternalMmResult(Result
);
102 /* Does this device support the format? */
103 Result
= QueryWaveDeviceFormatSupport(SoundDevice
, Format
, sizeof(WAVEFORMATEX
));
104 if ( ! MMSUCCESS(Result
) )
106 SND_ERR(L
"Format not supported\n");
107 return TranslateInternalMmResult(Result
);
110 /* If the caller just wanted to know if a format is supported, end here */
111 if ( Flags
& WAVE_FORMAT_QUERY
)
112 return MMSYSERR_NOERROR
;
114 /* Check that winmm gave us a private handle to fill */
115 VALIDATE_MMSYS_PARAMETER( PrivateHandle
);
117 /* Create a sound device instance and open the sound device */
118 Result
= CreateSoundDeviceInstance(SoundDevice
, &SoundDeviceInstance
);
119 if ( ! MMSUCCESS(Result
) )
120 return TranslateInternalMmResult(Result
);
122 Result
= SetWaveDeviceFormat(SoundDeviceInstance
, Format
, sizeof(WAVEFORMATEX
));
123 if ( ! MMSUCCESS(Result
) )
125 /* TODO: Destroy sound instance */
126 return TranslateInternalMmResult(Result
);
129 /* Store the device instance pointer in the private handle - is DWORD safe here? */
130 *PrivateHandle
= (DWORD
) SoundDeviceInstance
;
132 /* Store the additional information we were given - FIXME: Need flags! */
133 SetSoundDeviceInstanceMmeData(SoundDeviceInstance
,
134 (HDRVR
)OpenParameters
->hWave
,
135 OpenParameters
->dwCallback
,
136 OpenParameters
->dwInstance
,
139 /* Let the application know the device is open */
140 ReleaseEntrypointMutex(DeviceType
);
141 NotifyMmeClient(SoundDeviceInstance
,
142 DeviceType
== WAVE_OUT_DEVICE_TYPE
? WOM_OPEN
: WIM_OPEN
,
145 AcquireEntrypointMutex(DeviceType
);
147 SND_TRACE(L
"Wave device now open\n");
149 return MMSYSERR_NOERROR
;
154 IN DWORD PrivateHandle
)
157 PSOUND_DEVICE_INSTANCE SoundDeviceInstance
;
158 PSOUND_DEVICE SoundDevice
;
159 MMDEVICE_TYPE DeviceType
;
161 SND_TRACE(L
"Closing wave device (WIDM_CLOSE / WODM_CLOSE)\n");
163 VALIDATE_MMSYS_PARAMETER( PrivateHandle
);
164 SoundDeviceInstance
= (PSOUND_DEVICE_INSTANCE
) PrivateHandle
;
166 Result
= GetSoundDeviceFromInstance(SoundDeviceInstance
, &SoundDevice
);
167 if ( ! MMSUCCESS(Result
) )
168 return TranslateInternalMmResult(Result
);
170 Result
= GetSoundDeviceType(SoundDevice
, &DeviceType
);
171 if ( ! MMSUCCESS(Result
) )
172 return TranslateInternalMmResult(Result
);
174 ReleaseEntrypointMutex(DeviceType
);
175 NotifyMmeClient(SoundDeviceInstance
,
176 DeviceType
== WAVE_OUT_DEVICE_TYPE
? WOM_CLOSE
: WIM_CLOSE
,
178 AcquireEntrypointMutex(DeviceType
);
180 Result
= DestroySoundDeviceInstance(SoundDeviceInstance
);