ReactOS  0.4.14-dev-384-g5b37caa
deviface.c File Reference
#include "sysaudio.h"
#include <debug.h>
Include dependency graph for deviface.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS OpenDevice (IN PUNICODE_STRING DeviceName, IN PHANDLE HandleOut, IN PFILE_OBJECT *FileObjectOut)
 
NTSTATUS InsertAudioDevice (IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING DeviceName)
 
NTSTATUS NTAPI DeviceInterfaceChangeCallback (IN PVOID NotificationStructure, IN PVOID Context)
 
NTSTATUS SysAudioRegisterNotifications (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS SysAudioRegisterDeviceInterfaces (IN PDEVICE_OBJECT DeviceObject)
 

Variables

const GUID GUID_DEVICE_INTERFACE_ARRIVAL = {0xCB3A4004L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}}
 
const GUID GUID_DEVICE_INTERFACE_REMOVAL = {0xCB3A4005L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}}
 
const GUID KS_CATEGORY_AUDIO = {0x6994AD04L, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}}
 
const GUID KS_CATEGORY_TOPOLOGY = {0xDDA54A40, 0x1E4C, 0x11D1, {0xA0, 0x50, 0x40, 0x57, 0x05, 0xC1, 0x00, 0x00}}
 
const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL = {0xBF963D80L, 0xC559, 0x11D0, {0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1}}
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file deviface.c.

Function Documentation

◆ DeviceInterfaceChangeCallback()

NTSTATUS NTAPI DeviceInterfaceChangeCallback ( IN PVOID  NotificationStructure,
IN PVOID  Context 
)

Definition at line 145 of file deviface.c.

148 {
152 
154 
155  if (IsEqualGUIDAligned(&Event->Event,
157  {
158  Status = InsertAudioDevice(DeviceObject, Event->SymbolicLinkName);
159  return Status;
160  }
161  else
162  {
163  DPRINT("Remove interface to audio device!\n");
165  return STATUS_SUCCESS;
166  }
167 
168 
169 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
const GUID GUID_DEVICE_INTERFACE_ARRIVAL
Definition: deviface.c:14
NTSTATUS InsertAudioDevice(IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING DeviceName)
Definition: deviface.c:67
struct _DEVICE_OBJECT * PDEVICE_OBJECT
LONG NTSTATUS
Definition: precomp.h:26
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define UNIMPLEMENTED
Definition: debug.h:114
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ InsertAudioDevice()

NTSTATUS InsertAudioDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PUNICODE_STRING  DeviceName 
)

Definition at line 67 of file deviface.c.

70 {
72  PSYSAUDIODEVEXT DeviceExtension;
73  PKSAUDIO_DEVICE_ENTRY DeviceEntry = NULL;
74 
75  /* a new device has arrived */
76  DeviceEntry = AllocateItem(NonPagedPool, sizeof(KSAUDIO_DEVICE_ENTRY));
77  if (!DeviceEntry)
78  {
79  /* no memory */
81  }
82 
83  /* initialize audio device entry */
84  RtlZeroMemory(DeviceEntry, sizeof(KSAUDIO_DEVICE_ENTRY));
85 
86  /* set device name */
87  DeviceEntry->DeviceName.Length = 0;
88  DeviceEntry->DeviceName.MaximumLength = DeviceName->MaximumLength + 10 * sizeof(WCHAR);
89 
90  DeviceEntry->DeviceName.Buffer = AllocateItem(NonPagedPool, DeviceEntry->DeviceName.MaximumLength);
91 
92  if (!DeviceEntry->DeviceName.Buffer)
93  {
95  goto cleanup;
96  }
97 
98  /* open device */
99  Status = OpenDevice(DeviceName, &DeviceEntry->Handle, &DeviceEntry->FileObject);
100  if (NT_SUCCESS(Status))
101  {
102  /* copy device name */
104  }
105  else
106  {
107  /* the device name needs to be prefixed */
108  RtlAppendUnicodeToString(&DeviceEntry->DeviceName, L"\\??\\");
110 
111  /* open device */
112  Status = OpenDevice(&DeviceEntry->DeviceName, &DeviceEntry->Handle, &DeviceEntry->FileObject);
113  }
114 
115  if (!NT_SUCCESS(Status))
116  {
117  goto cleanup;
118  }
119 
120  /* fetch device extension */
121  DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
122  /* insert new audio device */
123  ExInterlockedInsertTailList(&DeviceExtension->KsAudioDeviceList, &DeviceEntry->Entry, &DeviceExtension->Lock);
125 
126  DPRINT("Successfully opened audio device %u Device %S\n", DeviceExtension->NumberOfKsAudioDevices, DeviceEntry->DeviceName.Buffer);
127  return Status;
128 
129 cleanup:
130  if (DeviceEntry)
131  {
132  if (DeviceEntry->DeviceName.Buffer)
133  FreeItem(DeviceEntry->DeviceName.Buffer);
134 
135  FreeItem(DeviceEntry);
136  }
137 
138  return Status;
139 
140 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LIST_ENTRY Entry
Definition: sysaudio.h:14
USHORT MaximumLength
Definition: env_spec_w32.h:370
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY KsAudioDeviceList
Definition: sysaudio.h:30
KSPIN_LOCK Lock
Definition: sysaudio.h:33
ULONG NumberOfKsAudioDevices
Definition: sysaudio.h:28
WCHAR DeviceName[]
Definition: adapter.cpp:21
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFILE_OBJECT FileObject
Definition: sysaudio.h:18
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
Definition: sysaudio.h:12
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS OpenDevice(IN PUNICODE_STRING DeviceName, IN PHANDLE HandleOut, IN PFILE_OBJECT *FileObjectOut)
Definition: deviface.c:21
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define InterlockedIncrement
Definition: armddk.h:53
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
struct SYSAUDIODEVEXT * PSYSAUDIODEVEXT
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
char * cleanup(char *str)
Definition: wpickclick.c:99
return STATUS_SUCCESS
Definition: btrfs.c:2938
signed int * PLONG
Definition: retypes.h:5
UNICODE_STRING DeviceName
Definition: sysaudio.h:15
HANDLE Handle
Definition: sysaudio.h:17

Referenced by DeviceInterfaceChangeCallback().

◆ OpenDevice()

NTSTATUS OpenDevice ( IN PUNICODE_STRING  DeviceName,
IN PHANDLE  HandleOut,
IN PFILE_OBJECT FileObjectOut 
)

Definition at line 21 of file deviface.c.

25 {
31 
33 
34  Status = ZwCreateFile(&NodeHandle,
38  NULL,
39  0,
40  0,
41  FILE_OPEN,
43  NULL,
44  0);
45 
46 
47  if (!NT_SUCCESS(Status))
48  {
49  DPRINT("ZwCreateFile failed with %x %S\n", Status, DeviceName->Buffer);
50  return Status;
51  }
52 
54  if (!NT_SUCCESS(Status))
55  {
57  DPRINT("ObReferenceObjectByHandle failed with %x\n", Status);
58  return Status;
59  }
60 
61  *HandleOut = NodeHandle;
62  *FileObjectOut = FileObject;
63  return Status;
64 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4546
WCHAR DeviceName[]
Definition: adapter.cpp:21
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define GENERIC_READ
Definition: compat.h:124
#define SYNCHRONIZE
Definition: nt_native.h:61
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by InsertAudioDevice().

◆ SysAudioRegisterDeviceInterfaces()

NTSTATUS SysAudioRegisterDeviceInterfaces ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 214 of file deviface.c.

216 {
219 
221  if (NT_SUCCESS(Status))
222  {
225  }
226  else
227  {
228  DPRINT("Failed to register KSCATEGORY_PREFERRED_MIDIOUT_DEVICE interface Status %x\n", Status);
229  return Status;
230  }
231 
233  if (NT_SUCCESS(Status))
234  {
237  }
238  else
239  {
240  DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEIN_DEVICE interface Status %x\n", Status);
241  return Status;
242  }
243 
245  if (NT_SUCCESS(Status))
246  {
249  }
250  else
251  {
252  DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEOUT_DEVICE interface Status %x\n", Status);
253  }
254 
256  if (NT_SUCCESS(Status))
257  {
260  }
261  else
262  {
263  DPRINT("Failed to register KSCATEGORY_SYSAUDIO interface Status %x\n", Status);
264  }
265 
266  return Status;
267 }
const GUID KSCATEGORY_PREFERRED_WAVEIN_DEVICE
Definition: main.c:20
#define TRUE
Definition: types.h:120
const GUID KSCATEGORY_PREFERRED_MIDIOUT_DEVICE
Definition: main.c:21
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define KSCATEGORY_SYSAUDIO
Definition: ksmedia.h:217
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
const GUID KSCATEGORY_PREFERRED_WAVEOUT_DEVICE
Definition: main.c:19
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
static const WCHAR SymbolicLink[]
Definition: interface.c:31

Referenced by SysAudio_AddDevice().

◆ SysAudioRegisterNotifications()

NTSTATUS SysAudioRegisterNotifications ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  DeviceObject 
)

Definition at line 172 of file deviface.c.

175 {
177  PSYSAUDIODEVEXT DeviceExtension;
178 
179  DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
180 
184  DriverObject,
187  (PVOID*)&DeviceExtension->KsAudioNotificationEntry);
188 
189  if (!NT_SUCCESS(Status))
190  {
191  DPRINT("IoRegisterPlugPlayNotification failed with %x\n", Status);
192  }
193 
197  DriverObject,
200  (PVOID*)&DeviceExtension->EchoCancelNotificationEntry);
201 
202  if (!NT_SUCCESS(Status))
203  {
204  /* ignore failure for now */
205  DPRINT("IoRegisterPlugPlayNotification failed for DMOCATEGORY_ACOUSTIC_ECHO_CANCEL\n", Status);
206  }
207 
208  return STATUS_SUCCESS;
209 }
const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL
Definition: deviface.c:18
LONG NTSTATUS
Definition: precomp.h:26
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
NTSTATUS NTAPI DeviceInterfaceChangeCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: deviface.c:48
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID EchoCancelNotificationEntry
Definition: sysaudio.h:32
PVOID KsAudioNotificationEntry
Definition: sysaudio.h:31
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct SYSAUDIODEVEXT * PSYSAUDIODEVEXT
const GUID KS_CATEGORY_AUDIO
Definition: deviface.c:16
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by SysAudio_AddDevice().

Variable Documentation

◆ DMOCATEGORY_ACOUSTIC_ECHO_CANCEL

const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL = {0xBF963D80L, 0xC559, 0x11D0, {0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1}}

Definition at line 18 of file deviface.c.

Referenced by SysAudioRegisterNotifications().

◆ GUID_DEVICE_INTERFACE_ARRIVAL

const GUID GUID_DEVICE_INTERFACE_ARRIVAL = {0xCB3A4004L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}}

◆ GUID_DEVICE_INTERFACE_REMOVAL

const GUID GUID_DEVICE_INTERFACE_REMOVAL = {0xCB3A4005L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}}

◆ KS_CATEGORY_AUDIO

const GUID KS_CATEGORY_AUDIO = {0x6994AD04L, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}}

Definition at line 16 of file deviface.c.

Referenced by SysAudioRegisterNotifications().

◆ KS_CATEGORY_TOPOLOGY

const GUID KS_CATEGORY_TOPOLOGY = {0xDDA54A40, 0x1E4C, 0x11D1, {0xA0, 0x50, 0x40, 0x57, 0x05, 0xC1, 0x00, 0x00}}

Definition at line 17 of file deviface.c.