2 * PROJECT: ReactOS Sound System "MME Buddy" NT4 Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/drivers/sound/mment4/control.c
6 * PURPOSE: Device control for NT4 audio devices
8 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
22 Convenience routine for getting the path of a device and opening it.
25 OpenNt4KernelSoundDevice(
26 IN PSOUND_DEVICE SoundDevice
,
33 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
34 VALIDATE_MMSYS_PARAMETER( Handle
);
36 Result
= GetSoundDeviceIdentifier(SoundDevice
, (PVOID
*) &Path
);
37 if ( ! MMSUCCESS(Result
) )
39 SND_ERR(L
"Unable to get sound device path");
40 return TranslateInternalMmResult(Result
);
45 return OpenKernelSoundDeviceByName(Path
, ReadOnly
, Handle
);
49 Device open/close. These are basically wrappers for the MME-Buddy
50 open and close routines, which provide a Windows device handle.
51 These may seem simple but as you can return pretty much anything
52 as the handle, we could just as easily return a structure etc.
56 IN PSOUND_DEVICE SoundDevice
,
59 SND_TRACE(L
"Opening NT4 style sound device\n");
61 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
62 VALIDATE_MMSYS_PARAMETER( Handle
);
64 return OpenNt4KernelSoundDevice(SoundDevice
, FALSE
, Handle
);
69 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
72 SND_TRACE(L
"Closing NT4 style sound device\n");
74 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance
) );
75 return CloseKernelSoundDevice((HANDLE
) Handle
);
79 Provides an implementation for the "get capabilities" request,
80 using the standard IOCTLs used by NT4 sound drivers.
83 GetNt4SoundDeviceCapabilities(
84 IN PSOUND_DEVICE SoundDevice
,
85 OUT PVOID Capabilities
,
86 IN DWORD CapabilitiesSize
)
89 MMDEVICE_TYPE DeviceType
;
93 /* If these are bad there's an internal error with MME-Buddy! */
94 SND_ASSERT( SoundDevice
);
95 SND_ASSERT( Capabilities
);
96 SND_ASSERT( CapabilitiesSize
> 0 );
98 SND_TRACE(L
"NT4 get-capabilities routine called\n");
100 /* Get the device type */
101 Result
= GetSoundDeviceType(SoundDevice
, &DeviceType
);
102 SND_ASSERT( Result
== MMSYSERR_NOERROR
);
104 if ( ! MMSUCCESS(Result
) );
105 return TranslateInternalMmResult(Result
);
107 /* Choose the appropriate IOCTL */
108 if ( IS_WAVE_DEVICE_TYPE(DeviceType
) )
110 IoCtl
= IOCTL_WAVE_GET_CAPABILITIES
;
112 else if ( IS_MIDI_DEVICE_TYPE(DeviceType
) )
114 IoCtl
= IOCTL_MIDI_GET_CAPABILITIES
;
118 /* FIXME - need to support AUX and mixer devices */
122 /* Get the capabilities information from the driver */
123 Result
= OpenNt4KernelSoundDevice(SoundDevice
, TRUE
, &DeviceHandle
);
125 if ( ! MMSUCCESS(Result
) )
127 SND_ERR(L
"Failed to open device");
128 return TranslateInternalMmResult(Result
);
131 Result
= SyncOverlappedDeviceIoControl(DeviceHandle
,
139 CloseKernelSoundDevice(DeviceHandle
);
141 if ( ! MMSUCCESS(Result
) )
143 SND_ERR(L
"Retrieval of capabilities information failed\n");
144 Result
= TranslateInternalMmResult(Result
);
151 Querying/setting the format of a wave device. Querying format support
152 requires us to first open the device, whereas setting format is done
153 on an already opened device.
156 QueryNt4WaveDeviceFormatSupport(
157 IN PSOUND_DEVICE SoundDevice
,
158 IN LPWAVEFORMATEX Format
,
164 SND_TRACE(L
"NT4 wave format support querying routine called\n");
166 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
167 VALIDATE_MMSYS_PARAMETER( Format
);
168 VALIDATE_MMSYS_PARAMETER( FormatSize
>= sizeof(WAVEFORMATEX
) );
170 /* Get the device path */
171 Result
= OpenNt4KernelSoundDevice(SoundDevice
,
175 if ( ! MMSUCCESS(Result
) )
177 SND_ERR(L
"Unable to open kernel sound device\n");
178 return TranslateInternalMmResult(Result
);
181 Result
= SyncOverlappedDeviceIoControl(Handle
,
182 IOCTL_WAVE_QUERY_FORMAT
,
189 if ( ! MMSUCCESS(Result
) )
191 SND_ERR(L
"Sync overlapped I/O failed - MMSYS_ERROR %d\n", Result
);
192 Result
= TranslateInternalMmResult(Result
);
195 CloseKernelSoundDevice(Handle
);
197 return MMSYSERR_NOERROR
;
201 SetNt4WaveDeviceFormat(
202 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
204 IN LPWAVEFORMATEX Format
,
210 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance
) );
211 VALIDATE_MMSYS_PARAMETER( Format
);
212 VALIDATE_MMSYS_PARAMETER( FormatSize
>= sizeof(WAVEFORMATEX
) );
214 Result
= GetSoundDeviceInstanceHandle(SoundDeviceInstance
, &Handle
);
216 if ( ! MMSUCCESS(Result
) )
217 return TranslateInternalMmResult(Result
);
219 SND_TRACE(L
"Setting wave device format on handle %x\n", Handle
);
221 Result
= SyncOverlappedDeviceIoControl(Handle
,
222 IOCTL_WAVE_SET_FORMAT
,
229 if ( ! MMSUCCESS(Result
) )
230 return TranslateInternalMmResult(Result
);
232 return MMSYSERR_NOERROR
;
238 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
239 IN PWAVEHDR WaveHeader
)
241 VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance
);
242 VALIDATE_MMSYS_PARAMETER( WaveHeader
);
244 SND_TRACE(L
"Submitting wave header %p (in sound thread)\n", WaveHeader
);
246 /* TODO: This should only submit the header to the device, nothing more! */