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)
19 Call the client application when something interesting happens (MME API
20 defines "interesting things" as device open, close, and buffer
25 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
29 SND_ASSERT( SoundDeviceInstance
);
31 SND_TRACE(L
"MME client callback - message %d, parameter %d\n",
35 if ( SoundDeviceInstance
->WinMM
.ClientCallback
)
37 DriverCallback(SoundDeviceInstance
->WinMM
.ClientCallback
,
38 HIWORD(SoundDeviceInstance
->WinMM
.Flags
),
39 SoundDeviceInstance
->WinMM
.Handle
,
41 SoundDeviceInstance
->WinMM
.ClientCallbackInstanceData
,
48 This is a helper function to alleviate some of the repetition involved with
49 implementing the various MME message functions.
52 MmeGetSoundDeviceCapabilities(
53 IN MMDEVICE_TYPE DeviceType
,
55 IN PVOID Capabilities
,
56 IN DWORD CapabilitiesSize
)
58 PSOUND_DEVICE SoundDevice
;
61 SND_TRACE(L
"MME *_GETCAPS for device %d of type %d\n", DeviceId
, DeviceType
);
63 /* FIXME: Validate device type and ID */
64 VALIDATE_MMSYS_PARAMETER( Capabilities
);
65 VALIDATE_MMSYS_PARAMETER( CapabilitiesSize
> 0 );
67 /* Our parameter checks are done elsewhere */
68 Result
= GetSoundDevice(DeviceType
, DeviceId
, &SoundDevice
);
70 if ( ! MMSUCCESS(Result
) )
73 return GetSoundDeviceCapabilities(SoundDevice
,
80 IN MMDEVICE_TYPE DeviceType
,
82 IN LPWAVEOPENDESC OpenParameters
,
84 OUT DWORD
* PrivateHandle
)
88 PSOUND_DEVICE SoundDevice
;
89 PSOUND_DEVICE_INSTANCE SoundDeviceInstance
;
90 LPWAVEFORMATEX Format
;
92 SND_TRACE(L
"Opening wave device (WIDM_OPEN / WODM_OPEN)");
94 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType
) ); /* FIXME? wave in too? */
95 VALIDATE_MMSYS_PARAMETER( OpenParameters
);
97 Format
= OpenParameters
->lpFormat
;
99 Result
= GetSoundDevice(DeviceType
, DeviceId
, &SoundDevice
);
100 if ( ! MMSUCCESS(Result
) )
101 return TranslateInternalMmResult(Result
);
103 /* Does this device support the format? */
104 Result
= QueryWaveDeviceFormatSupport(SoundDevice
, Format
, sizeof(WAVEFORMATEX
));
105 if ( ! MMSUCCESS(Result
) )
107 SND_ERR(L
"Format not supported\n");
108 return TranslateInternalMmResult(Result
);
111 /* If the caller just wanted to know if a format is supported, end here */
112 if ( Flags
& WAVE_FORMAT_QUERY
)
113 return MMSYSERR_NOERROR
;
115 /* Check that winmm gave us a private handle to fill */
116 VALIDATE_MMSYS_PARAMETER( PrivateHandle
);
118 /* Create a sound device instance and open the sound device */
119 Result
= CreateSoundDeviceInstance(SoundDevice
, &SoundDeviceInstance
);
120 if ( ! MMSUCCESS(Result
) )
121 return TranslateInternalMmResult(Result
);
123 Result
= SetWaveDeviceFormat(SoundDeviceInstance
, Format
, sizeof(WAVEFORMATEX
));
124 if ( ! MMSUCCESS(Result
) )
126 /* TODO: Destroy sound instance */
127 return TranslateInternalMmResult(Result
);
130 /* Store the device instance pointer in the private handle - is DWORD safe here? */
131 *PrivateHandle
= (DWORD
) SoundDeviceInstance
;
133 /* Store the additional information we were given - FIXME: Need flags! */
134 SetSoundDeviceInstanceMmeData(SoundDeviceInstance
,
135 (HDRVR
)OpenParameters
->hWave
,
136 OpenParameters
->dwCallback
,
137 OpenParameters
->dwInstance
,
140 /* Let the application know the device is open */
141 ReleaseEntrypointMutex(DeviceType
);
142 NotifyMmeClient(SoundDeviceInstance
,
143 DeviceType
== WAVE_OUT_DEVICE_TYPE
? WOM_OPEN
: WIM_OPEN
,
146 AcquireEntrypointMutex(DeviceType
);
148 SND_TRACE(L
"Wave device now open\n");
150 return MMSYSERR_NOERROR
;
155 IN DWORD PrivateHandle
)
158 PSOUND_DEVICE_INSTANCE SoundDeviceInstance
;
159 PSOUND_DEVICE SoundDevice
;
160 MMDEVICE_TYPE DeviceType
;
162 SND_TRACE(L
"Closing wave device (WIDM_CLOSE / WODM_CLOSE)\n");
164 VALIDATE_MMSYS_PARAMETER( PrivateHandle
);
165 SoundDeviceInstance
= (PSOUND_DEVICE_INSTANCE
) PrivateHandle
;
167 Result
= GetSoundDeviceFromInstance(SoundDeviceInstance
, &SoundDevice
);
168 if ( ! MMSUCCESS(Result
) )
169 return TranslateInternalMmResult(Result
);
171 Result
= GetSoundDeviceType(SoundDevice
, &DeviceType
);
172 if ( ! MMSUCCESS(Result
) )
173 return TranslateInternalMmResult(Result
);
175 ReleaseEntrypointMutex(DeviceType
);
176 NotifyMmeClient(SoundDeviceInstance
,
177 DeviceType
== WAVE_OUT_DEVICE_TYPE
? WOM_CLOSE
: WIM_CLOSE
,
179 AcquireEntrypointMutex(DeviceType
);
181 Result
= DestroySoundDeviceInstance(SoundDeviceInstance
);