ReactOS  0.4.15-dev-1171-gab82533
devicelist.c File Reference
#include "precomp.h"
Include dependency graph for devicelist.c:

Go to the source code of this file.

Functions

MMRESULT AllocateSoundDevice (IN MMDEVICE_TYPE DeviceType, OUT PSOUND_DEVICE *SoundDevice)
 
VOID FreeSoundDevice (IN PSOUND_DEVICE SoundDevice)
 
ULONG GetSoundDeviceCount (IN MMDEVICE_TYPE DeviceType)
 
BOOLEAN IsValidSoundDevice (IN PSOUND_DEVICE SoundDevice)
 
MMRESULT ListSoundDevice (IN MMDEVICE_TYPE DeviceType, IN PVOID Identifier OPTIONAL, OUT PSOUND_DEVICE *SoundDevice OPTIONAL)
 
MMRESULT UnlistSoundDevice (IN MMDEVICE_TYPE DeviceType, IN PSOUND_DEVICE SoundDevice)
 
MMRESULT UnlistSoundDevices (IN MMDEVICE_TYPE DeviceType)
 
VOID UnlistAllSoundDevices ()
 
MMRESULT GetSoundDevice (IN MMDEVICE_TYPE DeviceType, IN DWORD DeviceIndex, OUT PSOUND_DEVICE *SoundDevice)
 
MMRESULT GetSoundDeviceIdentifier (IN PSOUND_DEVICE SoundDevice, OUT PVOID *Identifier)
 
MMRESULT GetSoundDeviceType (IN PSOUND_DEVICE SoundDevice, OUT PMMDEVICE_TYPE DeviceType)
 

Variables

ULONG SoundDeviceCounts [SOUND_DEVICE_TYPES]
 
PSOUND_DEVICE SoundDeviceListHeads [SOUND_DEVICE_TYPES]
 
PSOUND_DEVICE SoundDeviceListTails [SOUND_DEVICE_TYPES]
 

Function Documentation

◆ AllocateSoundDevice()

MMRESULT AllocateSoundDevice ( IN MMDEVICE_TYPE  DeviceType,
OUT PSOUND_DEVICE SoundDevice 
)

Definition at line 21 of file devicelist.c.

24 {
25  PSOUND_DEVICE NewDevice;
26 
28  SND_ASSERT( SoundDevice );
29 
30  SND_TRACE(L"Allocating a SOUND_DEVICE structure\n");
31 
32  NewDevice = AllocateStruct(SOUND_DEVICE);
33 
34  if ( ! NewDevice )
35  return MMSYSERR_NOMEM;
36 
37  NewDevice->Type = DeviceType;
38 
39  /* Return the new structure to the caller and report success */
40  *SoundDevice = NewDevice;
41 
42  return MMSYSERR_NOERROR;
43 }
DeviceType
Definition: mmdrv.h:41
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define IsValidSoundDeviceType
Definition: mmebuddy.h:69
#define SND_ASSERT(condition)
MMDEVICE_TYPE Type
Definition: mmebuddy.h:261
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define AllocateStruct(thing)
Definition: mmebuddy.h:27
static const WCHAR L[]
Definition: oid.c:1250
#define SND_TRACE(...)

Referenced by ListSoundDevice().

◆ FreeSoundDevice()

VOID FreeSoundDevice ( IN PSOUND_DEVICE  SoundDevice)

Definition at line 49 of file devicelist.c.

51 {
52  SND_ASSERT( SoundDevice );
53 
54  SND_TRACE(L"Freeing a SOUND_DEVICE structure");
55 
56  /* For safety the whole struct gets zeroed */
57  ZeroMemory(SoundDevice, sizeof(SOUND_DEVICE));
58  FreeMemory(SoundDevice);
59 }
static VOID FreeMemory(PCREATE_DATA Data)
Definition: create.c:134
#define ZeroMemory
Definition: winbase.h:1648
#define SND_ASSERT(condition)
static const WCHAR L[]
Definition: oid.c:1250
#define SND_TRACE(...)

Referenced by UnlistSoundDevice().

◆ GetSoundDevice()

MMRESULT GetSoundDevice ( IN MMDEVICE_TYPE  DeviceType,
IN DWORD  DeviceIndex,
OUT PSOUND_DEVICE SoundDevice 
)

Definition at line 289 of file devicelist.c.

293 {
295  DWORD CurrentIndex = 0;
296  PSOUND_DEVICE CurrentDevice;
297 
299 
300  if ( DeviceIndex >= SoundDeviceCounts[TypeIndex] )
301  {
302  SND_ERR(L"Invalid device ID %d for type %d\n", DeviceIndex, DeviceType);
303  return MMSYSERR_BADDEVICEID;
304  }
305 
306  CurrentDevice = SoundDeviceListHeads[TypeIndex];
307 
308  /* Following the earlier checks, the index should be valid here. */
309  for ( CurrentIndex = 0; CurrentIndex != DeviceIndex; ++ CurrentIndex )
310  {
311  SND_ASSERT( CurrentDevice );
312  CurrentDevice = CurrentDevice->Next;
313  }
314 
315  SND_TRACE(L"Returning sound device %x\n", CurrentDevice);
316 
317  *SoundDevice = CurrentDevice;
318 
319  return MMSYSERR_NOERROR;
320 }
DeviceType
Definition: mmdrv.h:41
PSOUND_DEVICE SoundDeviceListHeads[SOUND_DEVICE_TYPES]
Definition: devicelist.c:14
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
#define IsValidSoundDeviceType
Definition: mmebuddy.h:69
#define SND_ASSERT(condition)
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define SND_ERR(...)
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _SOUND_DEVICE * Next
Definition: mmebuddy.h:258
static const WCHAR L[]
Definition: oid.c:1250
#define MMSYSERR_BADDEVICEID
Definition: mmsystem.h:98
ULONG SoundDeviceCounts[SOUND_DEVICE_TYPES]
Definition: devicelist.c:13
#define SOUND_DEVICE_TYPE_TO_INDEX(x)
Definition: mmebuddy.h:58
#define SND_TRACE(...)

Referenced by MmeGetDeviceInterfaceString(), MmeGetLineInfo(), MmeGetSoundDeviceCapabilities(), and MmeOpenDevice().

◆ GetSoundDeviceCount()

ULONG GetSoundDeviceCount ( IN MMDEVICE_TYPE  DeviceType)

Definition at line 67 of file devicelist.c.

69 {
71 
73  {
74  return 0;
75  }
76 
77  SND_TRACE(L"Returning a count of %d devices\n", SoundDeviceCounts[Index]);
78  return SoundDeviceCounts[Index];
79 }
DeviceType
Definition: mmdrv.h:41
#define IsValidSoundDeviceType
Definition: mmebuddy.h:69
static const UCHAR Index[8]
Definition: usbohci.c:18
static const WCHAR L[]
Definition: oid.c:1250
ULONG SoundDeviceCounts[SOUND_DEVICE_TYPES]
Definition: devicelist.c:13
unsigned int ULONG
Definition: retypes.h:1
#define SOUND_DEVICE_TYPE_TO_INDEX(x)
Definition: mmebuddy.h:58
#define SND_TRACE(...)

Referenced by auxMessage(), midMessage(), modMessage(), mxdMessage(), widMessage(), and wodMessage().

◆ GetSoundDeviceIdentifier()

MMRESULT GetSoundDeviceIdentifier ( IN PSOUND_DEVICE  SoundDevice,
OUT PVOID Identifier 
)

Definition at line 328 of file devicelist.c.

331 {
332  VALIDATE_MMSYS_PARAMETER( SoundDevice );
333  VALIDATE_MMSYS_PARAMETER( Identifier );
334 
335  /* The caller should not modify this! */
336  *Identifier = SoundDevice->Identifier;
337 
338  return MMSYSERR_NOERROR;
339 }
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96

Referenced by OpenNt4KernelSoundDevice(), and WdmAudSetWaveDeviceFormatByLegacy().

◆ GetSoundDeviceType()

◆ IsValidSoundDevice()

BOOLEAN IsValidSoundDevice ( IN PSOUND_DEVICE  SoundDevice)

Definition at line 87 of file devicelist.c.

89 {
90  UCHAR TypeIndex;
91  PSOUND_DEVICE CurrentDevice;
92 
93  if ( ! SoundDevice )
94  return FALSE;
95 
96  /* Go through all the device lists */
97  for ( TypeIndex = 0; TypeIndex < SOUND_DEVICE_TYPES; ++ TypeIndex )
98  {
99  CurrentDevice = SoundDeviceListHeads[TypeIndex];
100 
101  while ( CurrentDevice )
102  {
103  if ( CurrentDevice == SoundDevice )
104  {
105  /* Found the device */
106  return TRUE;
107  }
108 
109  CurrentDevice = CurrentDevice->Next;
110  }
111  }
112 
113  /* If we get here, nothing was found */
114  return FALSE;
115 }
#define TRUE
Definition: types.h:120
PSOUND_DEVICE SoundDeviceListHeads[SOUND_DEVICE_TYPES]
Definition: devicelist.c:14
#define FALSE
Definition: types.h:117
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _SOUND_DEVICE * Next
Definition: mmebuddy.h:258

Referenced by CreateSoundDeviceInstance(), GetSoundDeviceCapabilities(), GetSoundDeviceFunctionTable(), ListSoundDeviceInstance(), OpenNt4KernelSoundDevice(), OpenNt4SoundDevice(), QueryNt4WaveDeviceFormatSupport(), QueryWaveDeviceFormatSupport(), SetSoundDeviceFunctionTable(), and UnlistSoundDevice().

◆ ListSoundDevice()

MMRESULT ListSoundDevice ( IN MMDEVICE_TYPE  DeviceType,
IN PVOID Identifier  OPTIONAL,
OUT PSOUND_DEVICE *SoundDevice  OPTIONAL 
)

Definition at line 131 of file devicelist.c.

135 {
137  PSOUND_DEVICE NewDevice;
139 
141 
142  Result = AllocateSoundDevice(DeviceType, &NewDevice);
143 
144  if ( ! MMSUCCESS(Result) )
145  {
146  SND_ERR(L"Failed to allocate SOUND_DEVICE structure\n");
147  return Result;
148  }
149 
150  if ( ! SoundDeviceListHeads[TypeIndex] )
151  {
152  SND_TRACE(L"Putting first entry into device list %d\n", DeviceType);
153  SoundDeviceListHeads[TypeIndex] = NewDevice;
154  SoundDeviceListTails[TypeIndex] = NewDevice;
155  }
156  else
157  {
158  SND_TRACE(L"Putting another entry into device list %d\n", DeviceType);
159  SoundDeviceListTails[TypeIndex]->Next = NewDevice;
160  SoundDeviceListTails[TypeIndex] = NewDevice;
161  }
162 
163  /* Add to the count */
164  ++ SoundDeviceCounts[TypeIndex];
165 
166  /* Set up the default function table */
167  SetSoundDeviceFunctionTable(NewDevice, NULL);
168 
169  /* Set up other members of the structure */
170  NewDevice->Identifier = Identifier;
171  NewDevice->HeadInstance = NULL;
172  NewDevice->TailInstance = NULL;
173 
174  /* Fill in the caller's PSOUND_DEVICE */
175  if ( SoundDevice )
176  {
177  *SoundDevice = NewDevice;
178  }
179 
180  return MMSYSERR_NOERROR;
181 }
struct _SOUND_DEVICE_INSTANCE * TailInstance
Definition: mmebuddy.h:260
MMRESULT SetSoundDeviceFunctionTable(IN PSOUND_DEVICE SoundDevice, IN PMMFUNCTION_TABLE FunctionTable)
Definition: functiontable.c:21
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
DeviceType
Definition: mmdrv.h:41
PSOUND_DEVICE SoundDeviceListHeads[SOUND_DEVICE_TYPES]
Definition: devicelist.c:14
UINT MMRESULT
Definition: mmsystem.h:962
PVOID Identifier
Definition: mmebuddy.h:262
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
#define IsValidSoundDeviceType
Definition: mmebuddy.h:69
smooth NULL
Definition: ftsmooth.c:416
_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
struct _SOUND_DEVICE_INSTANCE * HeadInstance
Definition: mmebuddy.h:259
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define SND_ERR(...)
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _SOUND_DEVICE * Next
Definition: mmebuddy.h:258
static const WCHAR L[]
Definition: oid.c:1250
PSOUND_DEVICE SoundDeviceListTails[SOUND_DEVICE_TYPES]
Definition: devicelist.c:15
ULONG SoundDeviceCounts[SOUND_DEVICE_TYPES]
Definition: devicelist.c:13
#define SOUND_DEVICE_TYPE_TO_INDEX(x)
Definition: mmebuddy.h:58
MMRESULT AllocateSoundDevice(IN MMDEVICE_TYPE DeviceType, OUT PSOUND_DEVICE *SoundDevice)
Definition: devicelist.c:21
#define SND_TRACE(...)

Referenced by FoundDevice(), and PopulateWdmDeviceList().

◆ UnlistAllSoundDevices()

VOID UnlistAllSoundDevices ( )

Definition at line 270 of file devicelist.c.

271 {
273 
274  SND_TRACE(L"Unlisting all sound devices\n");
275 
277  {
281  }
282 }
Type
Definition: Type.h:6
UINT MMRESULT
Definition: mmsystem.h:962
UCHAR MMDEVICE_TYPE
Definition: mmebuddy.h:88
#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 MMSYSERR_NOERROR
Definition: mmsystem.h:96
static const WCHAR L[]
Definition: oid.c:1250
MMRESULT UnlistSoundDevices(IN MMDEVICE_TYPE DeviceType)
Definition: devicelist.c:245
#define SND_TRACE(...)

◆ UnlistSoundDevice()

MMRESULT UnlistSoundDevice ( IN MMDEVICE_TYPE  DeviceType,
IN PSOUND_DEVICE  SoundDevice 
)

Definition at line 188 of file devicelist.c.

191 {
192  PSOUND_DEVICE CurrentDevice, PreviousDevice;
193 
195 
198 
199  PreviousDevice = NULL;
200  CurrentDevice = SoundDeviceListHeads[TypeIndex];
201 
202  while ( CurrentDevice )
203  {
204  if ( CurrentDevice == SoundDevice )
205  {
206  if ( ! PreviousDevice )
207  {
208  /* This is the head node */
209  SND_TRACE(L"Removing head node from device list %d\n", DeviceType);
210  SoundDeviceListHeads[TypeIndex] =
211  SoundDeviceListHeads[TypeIndex]->Next;
212  }
213  else
214  {
215  SND_TRACE(L"Removing node from device list %d\n", DeviceType);
216  /* There are nodes before this one - cut our device out */
217  PreviousDevice->Next = CurrentDevice->Next;
218  }
219 
220  if ( ! CurrentDevice->Next )
221  {
222  /* This is the tail node */
223  SND_TRACE(L"Removing tail node from device list %d\n", DeviceType);
224  SoundDeviceListTails[TypeIndex] = PreviousDevice;
225  }
226  }
227 
228  PreviousDevice = CurrentDevice;
229  CurrentDevice = CurrentDevice->Next;
230  }
231 
232  /* Subtract from the count */
233  -- SoundDeviceCounts[TypeIndex];
234 
235  /* Finally, free up the deleted entry */
236  FreeSoundDevice(SoundDevice);
237 
238  return MMSYSERR_NOERROR;
239 }
DeviceType
Definition: mmdrv.h:41
PSOUND_DEVICE SoundDeviceListHeads[SOUND_DEVICE_TYPES]
Definition: devicelist.c:14
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
VOID FreeSoundDevice(IN PSOUND_DEVICE SoundDevice)
Definition: devicelist.c:49
#define IsValidSoundDeviceType
Definition: mmebuddy.h:69
smooth NULL
Definition: ftsmooth.c:416
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
BOOLEAN IsValidSoundDevice(IN PSOUND_DEVICE SoundDevice)
Definition: devicelist.c:87
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _SOUND_DEVICE * Next
Definition: mmebuddy.h:258
static const WCHAR L[]
Definition: oid.c:1250
PSOUND_DEVICE SoundDeviceListTails[SOUND_DEVICE_TYPES]
Definition: devicelist.c:15
ULONG SoundDeviceCounts[SOUND_DEVICE_TYPES]
Definition: devicelist.c:13
#define SOUND_DEVICE_TYPE_TO_INDEX(x)
Definition: mmebuddy.h:58
#define SND_TRACE(...)

Referenced by UnlistSoundDevices().

◆ UnlistSoundDevices()

MMRESULT UnlistSoundDevices ( IN MMDEVICE_TYPE  DeviceType)

Definition at line 245 of file devicelist.c.

247 {
248  UCHAR TypeIndex;
250 
251  SND_TRACE(L"Unlisting all sound devices of type %d\n", DeviceType);
252 
254 
255  /* Munch away at the head of the list until it's drained */
256  while ( SoundDeviceCounts[TypeIndex] > 0 )
257  {
261  }
262 
263  return MMSYSERR_NOERROR;
264 }
DeviceType
Definition: mmdrv.h:41
MMRESULT UnlistSoundDevice(IN MMDEVICE_TYPE DeviceType, IN PSOUND_DEVICE SoundDevice)
Definition: devicelist.c:188
PSOUND_DEVICE SoundDeviceListHeads[SOUND_DEVICE_TYPES]
Definition: devicelist.c:14
UINT MMRESULT
Definition: mmsystem.h:962
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
#define IsValidSoundDeviceType
Definition: mmebuddy.h:69
#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 MMSYSERR_NOERROR
Definition: mmsystem.h:96
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
ULONG SoundDeviceCounts[SOUND_DEVICE_TYPES]
Definition: devicelist.c:13
#define SOUND_DEVICE_TYPE_TO_INDEX(x)
Definition: mmebuddy.h:58
#define SND_TRACE(...)

Referenced by UnlistAllSoundDevices().

Variable Documentation

◆ SoundDeviceCounts

◆ SoundDeviceListHeads

◆ SoundDeviceListTails

PSOUND_DEVICE SoundDeviceListTails[SOUND_DEVICE_TYPES]

Definition at line 15 of file devicelist.c.

Referenced by ListSoundDevice(), and UnlistSoundDevice().