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)
15 #include <reactos/sndtypes.h>
20 Convenience routine for getting the path of a device and opening it.
23 OpenNt4KernelSoundDevice(
24 IN PSOUND_DEVICE SoundDevice
,
31 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
32 VALIDATE_MMSYS_PARAMETER( Handle
);
34 Result
= GetSoundDeviceIdentifier(SoundDevice
, (PVOID
*) &Path
);
35 if ( ! MMSUCCESS(Result
) )
37 SND_ERR(L
"Unable to get sound device path");
38 return TranslateInternalMmResult(Result
);
43 return OpenKernelSoundDeviceByName(Path
, ReadOnly
, Handle
);
47 Device open/close. These are basically wrappers for the MME-Buddy
48 open and close routines, which provide a Windows device handle.
49 These may seem simple but as you can return pretty much anything
50 as the handle, we could just as easily return a structure etc.
54 IN PSOUND_DEVICE SoundDevice
,
57 SND_TRACE(L
"Opening NT4 style sound device\n");
59 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
60 VALIDATE_MMSYS_PARAMETER( Handle
);
62 return OpenNt4KernelSoundDevice(SoundDevice
, FALSE
, Handle
);
67 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
70 SND_TRACE(L
"Closing NT4 style sound device\n");
72 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance
) );
73 return CloseKernelSoundDevice((HANDLE
) Handle
);
77 Provides an implementation for the "get capabilities" request,
78 using the standard IOCTLs used by NT4 sound drivers.
81 GetNt4SoundDeviceCapabilities(
82 IN PSOUND_DEVICE SoundDevice
,
83 OUT PVOID Capabilities
,
84 IN DWORD CapabilitiesSize
)
87 MMDEVICE_TYPE DeviceType
;
91 /* If these are bad there's an internal error with MME-Buddy! */
92 SND_ASSERT( SoundDevice
);
93 SND_ASSERT( Capabilities
);
94 SND_ASSERT( CapabilitiesSize
> 0 );
96 SND_TRACE(L
"NT4 get-capabilities routine called\n");
98 /* Get the device type */
99 Result
= GetSoundDeviceType(SoundDevice
, &DeviceType
);
100 SND_ASSERT( Result
== MMSYSERR_NOERROR
);
102 if ( ! MMSUCCESS(Result
) );
103 return TranslateInternalMmResult(Result
);
105 /* Choose the appropriate IOCTL */
106 if ( IS_WAVE_DEVICE_TYPE(DeviceType
) )
108 IoCtl
= IOCTL_WAVE_GET_CAPABILITIES
;
110 else if ( IS_MIDI_DEVICE_TYPE(DeviceType
) )
112 IoCtl
= IOCTL_MIDI_GET_CAPABILITIES
;
116 /* FIXME - need to support AUX and mixer devices */
120 /* Get the capabilities information from the driver */
121 Result
= OpenNt4KernelSoundDevice(SoundDevice
, TRUE
, &DeviceHandle
);
123 if ( ! MMSUCCESS(Result
) )
125 SND_ERR(L
"Failed to open device");
126 return TranslateInternalMmResult(Result
);
129 Result
= SyncOverlappedDeviceIoControl(DeviceHandle
,
137 CloseKernelSoundDevice(DeviceHandle
);
139 if ( ! MMSUCCESS(Result
) )
141 SND_ERR(L
"Retrieval of capabilities information failed\n");
142 Result
= TranslateInternalMmResult(Result
);
149 Querying/setting the format of a wave device. Querying format support
150 requires us to first open the device, whereas setting format is done
151 on an already opened device.
154 QueryNt4WaveDeviceFormatSupport(
155 IN PSOUND_DEVICE SoundDevice
,
156 IN LPWAVEFORMATEX Format
,
162 SND_TRACE(L
"NT4 wave format support querying routine called\n");
164 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice
) );
165 VALIDATE_MMSYS_PARAMETER( Format
);
166 VALIDATE_MMSYS_PARAMETER( FormatSize
>= sizeof(WAVEFORMATEX
) );
168 /* Get the device path */
169 Result
= OpenNt4KernelSoundDevice(SoundDevice
,
173 if ( ! MMSUCCESS(Result
) )
175 SND_ERR(L
"Unable to open kernel sound device\n");
176 return TranslateInternalMmResult(Result
);
179 Result
= SyncOverlappedDeviceIoControl(Handle
,
180 IOCTL_WAVE_QUERY_FORMAT
,
187 if ( ! MMSUCCESS(Result
) )
189 SND_ERR(L
"Sync overlapped I/O failed - MMSYS_ERROR %d\n", Result
);
190 Result
= TranslateInternalMmResult(Result
);
193 CloseKernelSoundDevice(Handle
);
195 return MMSYSERR_NOERROR
;
199 SetNt4WaveDeviceFormat(
200 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance
,
201 IN LPWAVEFORMATEX Format
,
207 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance
) );
208 VALIDATE_MMSYS_PARAMETER( Format
);
209 VALIDATE_MMSYS_PARAMETER( FormatSize
>= sizeof(WAVEFORMATEX
) );
211 Result
= GetSoundDeviceInstanceHandle(SoundDeviceInstance
, &Handle
);
213 if ( ! MMSUCCESS(Result
) )
214 return TranslateInternalMmResult(Result
);
216 SND_TRACE(L
"Setting wave device format on handle %x\n", Handle
);
218 Result
= SyncOverlappedDeviceIoControl(Handle
,
219 IOCTL_WAVE_SET_FORMAT
,
226 if ( ! MMSUCCESS(Result
) )
227 return TranslateInternalMmResult(Result
);
229 return MMSYSERR_NOERROR
;