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)
19 Convenience routine for getting the path of a device and opening it.
22 OpenNt4KernelSoundDevice(
23 IN PSOUND_DEVICE SoundDevice
,
30 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
31 VALIDATE_MMSYS_PARAMETER( Handle
);
33 Result
= GetSoundDeviceIdentifier(SoundDevice
, (PVOID
*) &Path
);
34 if ( ! MMSUCCESS(Result
) )
36 SND_ERR(L
"Unable to get sound device path");
37 return TranslateInternalMmResult(Result
);
42 return OpenKernelSoundDeviceByName(Path
, ReadOnly
, Handle
);
46 Device open/close. These are basically wrappers for the MME-Buddy
47 open and close routines, which provide a Windows device handle.
48 These may seem simple but as you can return pretty much anything
49 as the handle, we could just as easily return a structure etc.
53 IN PSOUND_DEVICE SoundDevice
,
56 SND_TRACE(L
"Opening NT4 style sound device\n");
58 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
59 VALIDATE_MMSYS_PARAMETER( Handle
);
61 return OpenNt4KernelSoundDevice(SoundDevice
, FALSE
, Handle
);
66 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
69 SND_TRACE(L
"Closing NT4 style sound device\n");
71 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance
) );
72 return CloseKernelSoundDevice((HANDLE
) Handle
);
76 Provides an implementation for the "get capabilities" request,
77 using the standard IOCTLs used by NT4 sound drivers.
80 GetNt4SoundDeviceCapabilities(
81 IN PSOUND_DEVICE SoundDevice
,
82 OUT PVOID Capabilities
,
83 IN DWORD CapabilitiesSize
)
86 MMDEVICE_TYPE DeviceType
;
90 /* If these are bad there's an internal error with MME-Buddy! */
91 SND_ASSERT( SoundDevice
);
92 SND_ASSERT( Capabilities
);
93 SND_ASSERT( CapabilitiesSize
> 0 );
95 SND_TRACE(L
"NT4 get-capabilities routine called\n");
97 /* Get the device type */
98 Result
= GetSoundDeviceType(SoundDevice
, &DeviceType
);
99 SND_ASSERT( Result
== MMSYSERR_NOERROR
);
101 if ( ! MMSUCCESS(Result
) );
102 return TranslateInternalMmResult(Result
);
104 /* Choose the appropriate IOCTL */
105 if ( IS_WAVE_DEVICE_TYPE(DeviceType
) )
107 IoCtl
= IOCTL_WAVE_GET_CAPABILITIES
;
109 else if ( IS_MIDI_DEVICE_TYPE(DeviceType
) )
111 IoCtl
= IOCTL_MIDI_GET_CAPABILITIES
;
115 /* FIXME - need to support AUX and mixer devices */
119 /* Get the capabilities information from the driver */
120 Result
= OpenNt4KernelSoundDevice(SoundDevice
, TRUE
, &DeviceHandle
);
122 if ( ! MMSUCCESS(Result
) )
124 SND_ERR(L
"Failed to open device");
125 return TranslateInternalMmResult(Result
);
128 Result
= SyncOverlappedDeviceIoControl(DeviceHandle
,
136 CloseKernelSoundDevice(DeviceHandle
);
138 if ( ! MMSUCCESS(Result
) )
140 SND_ERR(L
"Retrieval of capabilities information failed\n");
141 Result
= TranslateInternalMmResult(Result
);
148 Querying/setting the format of a wave device. Querying format support
149 requires us to first open the device, whereas setting format is done
150 on an already opened device.
153 QueryNt4WaveDeviceFormatSupport(
154 IN PSOUND_DEVICE SoundDevice
,
155 IN LPWAVEFORMATEX Format
,
161 SND_TRACE(L
"NT4 wave format support querying routine called\n");
163 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
164 VALIDATE_MMSYS_PARAMETER( Format
);
165 VALIDATE_MMSYS_PARAMETER( FormatSize
>= sizeof(WAVEFORMATEX
) );
167 /* Get the device path */
168 Result
= OpenNt4KernelSoundDevice(SoundDevice
,
172 if ( ! MMSUCCESS(Result
) )
174 SND_ERR(L
"Unable to open kernel sound device\n");
175 return TranslateInternalMmResult(Result
);
178 Result
= SyncOverlappedDeviceIoControl(Handle
,
179 IOCTL_WAVE_QUERY_FORMAT
,
186 if ( ! MMSUCCESS(Result
) )
188 SND_ERR(L
"Sync overlapped I/O failed - MMSYS_ERROR %d\n", Result
);
189 Result
= TranslateInternalMmResult(Result
);
192 CloseKernelSoundDevice(Handle
);
194 return MMSYSERR_NOERROR
;
198 SetNt4WaveDeviceFormat(
199 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
200 IN LPWAVEFORMATEX Format
,
206 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance
) );
207 VALIDATE_MMSYS_PARAMETER( Format
);
208 VALIDATE_MMSYS_PARAMETER( FormatSize
>= sizeof(WAVEFORMATEX
) );
210 Result
= GetSoundDeviceInstanceHandle(SoundDeviceInstance
, &Handle
);
212 if ( ! MMSUCCESS(Result
) )
213 return TranslateInternalMmResult(Result
);
215 SND_TRACE(L
"Setting wave device format on handle %x\n", Handle
);
217 Result
= SyncOverlappedDeviceIoControl(Handle
,
218 IOCTL_WAVE_SET_FORMAT
,
225 if ( ! MMSUCCESS(Result
) )
226 return TranslateInternalMmResult(Result
);
228 return MMSYSERR_NOERROR
;