ReactOS  0.4.13-dev-1148-g9b75b67
control.c
Go to the documentation of this file.
1 /*
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
5  *
6  * PURPOSE: Device control for NT4 audio devices
7  *
8  * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
9 */
10 
11 #include "precomp.h"
12 
13 #include <winioctl.h>
14 #include <ntddsnd.h>
15 
16 #include <mmebuddy_debug.h>
17 
18 /*
19  Convenience routine for getting the path of a device and opening it.
20 */
23  IN PSOUND_DEVICE SoundDevice,
26 {
27  PWSTR Path;
29 
32 
33  Result = GetSoundDeviceIdentifier(SoundDevice, (PVOID*) &Path);
34  if ( ! MMSUCCESS(Result) )
35  {
36  SND_ERR(L"Unable to get sound device path");
38  }
39 
40  SND_ASSERT( Path );
41 
43 }
44 
45 /*
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.
50 */
53  IN PSOUND_DEVICE SoundDevice,
54  OUT PVOID* Handle)
55 {
56  SND_TRACE(L"Opening NT4 style sound device\n");
57 
60 
61  return OpenNt4KernelSoundDevice(SoundDevice, FALSE, Handle);
62 }
63 
66  IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
67  IN PVOID Handle)
68 {
69  SND_TRACE(L"Closing NT4 style sound device\n");
70 
73 }
74 
75 /*
76  Provides an implementation for the "get capabilities" request,
77  using the standard IOCTLs used by NT4 sound drivers.
78 */
81  IN PSOUND_DEVICE SoundDevice,
83  IN DWORD CapabilitiesSize)
84 {
87  DWORD IoCtl;
89 
90  /* If these are bad there's an internal error with MME-Buddy! */
91  SND_ASSERT( SoundDevice );
93  SND_ASSERT( CapabilitiesSize > 0 );
94 
95  SND_TRACE(L"NT4 get-capabilities routine called\n");
96 
97  /* Get the device type */
98  Result = GetSoundDeviceType(SoundDevice, &DeviceType);
100 
101  if ( ! MMSUCCESS(Result) )
103 
104  /* Choose the appropriate IOCTL */
106  {
108  }
109  else if ( IS_MIDI_DEVICE_TYPE(DeviceType) )
110  {
112  }
113  else
114  {
115  /* FIXME - need to support AUX and mixer devices */
116  SND_ASSERT( FALSE );
117  IoCtl = 0;
118  }
119 
120  /* Get the capabilities information from the driver */
122 
123  if ( ! MMSUCCESS(Result) )
124  {
125  SND_ERR(L"Failed to open device");
127  }
128 
130  IoCtl,
131  Capabilities,
132  CapabilitiesSize,
133  NULL,
134  0,
135  NULL);
136 
138 
139  if ( ! MMSUCCESS(Result) )
140  {
141  SND_ERR(L"Retrieval of capabilities information failed\n");
143  }
144 
145  return Result;
146 }
147 
148 /*
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.
152 */
153 MMRESULT
155  IN PSOUND_DEVICE SoundDevice,
157  IN DWORD FormatSize)
158 {
160  HANDLE Handle;
161 
162  SND_TRACE(L"NT4 wave format support querying routine called\n");
163 
166  VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) );
167 
168  /* Get the device path */
169  Result = OpenNt4KernelSoundDevice(SoundDevice,
170  FALSE,
171  &Handle);
172 
173  if ( ! MMSUCCESS(Result) )
174  {
175  SND_ERR(L"Unable to open kernel sound device\n");
177  }
178 
181  (LPVOID) Format,
182  FormatSize,
183  NULL,
184  0,
185  NULL);
186 
187  if ( ! MMSUCCESS(Result) )
188  {
189  SND_ERR(L"Sync overlapped I/O failed - MMSYS_ERROR %d\n", Result);
191  }
192 
194 
195  return MMSYSERR_NOERROR;
196 }
197 
198 MMRESULT
200  IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
201  IN DWORD DeviceId,
203  IN DWORD FormatSize)
204 {
206  HANDLE Handle;
207 
210  VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) );
211 
212  Result = GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
213 
214  if ( ! MMSUCCESS(Result) )
216 
217  SND_TRACE(L"Setting wave device format on handle %x\n", Handle);
218 
221  (LPVOID) Format,
222  FormatSize,
223  NULL,
224  0,
225  NULL);
226 
227  if ( ! MMSUCCESS(Result) )
229 
230  return MMSYSERR_NOERROR;
231 }
232 
233 #if 0
234 MMRESULT
235 SubmitNt4WaveHeader(
236  IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
237  IN PWAVEHDR WaveHeader)
238 {
239  VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance );
240  VALIDATE_MMSYS_PARAMETER( WaveHeader );
241 
242  SND_TRACE(L"Submitting wave header %p (in sound thread)\n", WaveHeader);
243 
244  /* TODO: This should only submit the header to the device, nothing more! */
245 }
246 #endif
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
MMRESULT GetSoundDeviceIdentifier(IN PSOUND_DEVICE SoundDevice, OUT PVOID *Identifier)
Definition: devicelist.c:328
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
uint16_t * PWSTR
Definition: typedefs.h:54
DeviceType
Definition: mmdrv.h:41
Definition: arc.h:80
MMRESULT TranslateInternalMmResult(IN MMRESULT Result)
Definition: utility.c:132
UINT MMRESULT
Definition: mmsystem.h:962
#define IS_MIDI_DEVICE_TYPE(x)
Definition: sndtypes.h:49
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
UCHAR MMDEVICE_TYPE
Definition: mmebuddy.h:88
MMRESULT OpenNt4KernelSoundDevice(IN PSOUND_DEVICE SoundDevice, IN BOOLEAN ReadOnly, OUT PHANDLE Handle)
Definition: control.c:22
MMRESULT QueryNt4WaveDeviceFormatSupport(IN PSOUND_DEVICE SoundDevice, IN LPWAVEFORMATEX Format, IN DWORD FormatSize)
Definition: control.c:154
MMRESULT OpenKernelSoundDeviceByName(IN PWSTR DevicePath, IN BOOLEAN ReadOnly, OUT PHANDLE Handle)
Definition: kernel.c:23
#define IOCTL_MIDI_GET_CAPABILITIES
Definition: mmdef.h:69
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
MMRESULT CloseNt4SoundDevice(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Handle)
Definition: control.c:65
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SND_ASSERT(condition)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define IS_WAVE_DEVICE_TYPE(x)
Definition: sndtypes.h:46
BOOLEAN IsValidSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
_In_ HANDLE Handle
Definition: extypes.h:390
#define IOCTL_WAVE_QUERY_FORMAT
Definition: mmdef.h:50
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define IOCTL_WAVE_SET_FORMAT
Definition: mmdef.h:51
#define SND_ERR(...)
unsigned long DWORD
Definition: ntddk_ex.h:95
MMRESULT GetNt4SoundDeviceCapabilities(IN PSOUND_DEVICE SoundDevice, OUT PVOID Capabilities, IN DWORD CapabilitiesSize)
Definition: control.c:80
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
PRTL_UNICODE_STRING_BUFFER Path
BOOLEAN IsValidSoundDevice(IN PSOUND_DEVICE SoundDevice)
Definition: devicelist.c:87
MMRESULT GetSoundDeviceType(IN PSOUND_DEVICE SoundDevice, OUT PMMDEVICE_TYPE DeviceType)
Definition: devicelist.c:346
MMRESULT CloseKernelSoundDevice(IN HANDLE Handle)
Definition: kernel.c:58
#define OUT
Definition: typedefs.h:39
#define IOCTL_WAVE_GET_CAPABILITIES
Definition: mmdef.h:52
MMRESULT OpenNt4SoundDevice(IN PSOUND_DEVICE SoundDevice, OUT PVOID *Handle)
Definition: control.c:52
MMRESULT GetSoundDeviceInstanceHandle(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PVOID *Handle)
MMRESULT SetNt4WaveDeviceFormat(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN DWORD DeviceId, IN LPWAVEFORMATEX Format, IN DWORD FormatSize)
Definition: control.c:199
#define SND_TRACE(...)