ReactOS  0.4.14-dev-297-g23e575c
deviface.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel Streaming
4  * FILE: drivers/wdm/audio/sysaudio/deviface.c
5  * PURPOSE: System Audio graph builder
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 #include "sysaudio.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 const GUID GUID_DEVICE_INTERFACE_ARRIVAL = {0xCB3A4004L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}};
15 const GUID GUID_DEVICE_INTERFACE_REMOVAL = {0xCB3A4005L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}};
16 const GUID KS_CATEGORY_AUDIO = {0x6994AD04L, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
17 const GUID KS_CATEGORY_TOPOLOGY = {0xDDA54A40, 0x1E4C, 0x11D1, {0xA0, 0x50, 0x40, 0x57, 0x05, 0xC1, 0x00, 0x00}};
18 const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL = {0xBF963D80L, 0xC559, 0x11D0, {0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1}};
19 
23  IN PHANDLE HandleOut,
24  IN PFILE_OBJECT * FileObjectOut)
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 }
65 
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 }
141 
142 
143 NTSTATUS
144 NTAPI
147  IN PVOID Context)
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 }
170 
171 NTSTATUS
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 }
210 
211 
212 
213 NTSTATUS
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
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL
Definition: deviface.c:18
#define TRUE
Definition: types.h:120
const GUID GUID_DEVICE_INTERFACE_ARRIVAL
Definition: deviface.c:14
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LIST_ENTRY Entry
Definition: sysaudio.h:14
NTSTATUS InsertAudioDevice(IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING DeviceName)
Definition: deviface.c:67
const GUID KS_CATEGORY_TOPOLOGY
Definition: deviface.c:17
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSTATUS SysAudioRegisterDeviceInterfaces(IN PDEVICE_OBJECT DeviceObject)
Definition: deviface.c:214
struct _DEVICE_OBJECT * PDEVICE_OBJECT
const GUID KSCATEGORY_PREFERRED_MIDIOUT_DEVICE
Definition: main.c:21
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
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
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
ULONG NumberOfKsAudioDevices
Definition: sysaudio.h:28
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4546
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
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
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define GENERIC_WRITE
Definition: nt_native.h:90
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS NTAPI DeviceInterfaceChangeCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: deviface.c:48
#define KSCATEGORY_SYSAUDIO
Definition: ksmedia.h:217
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
PVOID EchoCancelNotificationEntry
Definition: sysaudio.h:32
PVOID KsAudioNotificationEntry
Definition: sysaudio.h:31
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
* PFILE_OBJECT
Definition: iotypes.h:1955
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSTATUS OpenDevice(IN PUNICODE_STRING DeviceName, IN PHANDLE HandleOut, IN PFILE_OBJECT *FileObjectOut)
Definition: deviface.c:21
const GUID KSCATEGORY_PREFERRED_WAVEOUT_DEVICE
Definition: main.c:19
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
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
#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
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
#define InterlockedIncrement
Definition: armddk.h:53
const GUID GUID_DEVICE_INTERFACE_REMOVAL
Definition: deviface.c:15
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
NTSTATUS SysAudioRegisterNotifications(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject)
Definition: deviface.c:172
struct SYSAUDIODEVEXT * PSYSAUDIODEVEXT
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
char * cleanup(char *str)
Definition: wpickclick.c:99
const GUID KS_CATEGORY_AUDIO
Definition: deviface.c:16
return STATUS_SUCCESS
Definition: btrfs.c:2966
signed int * PLONG
Definition: retypes.h:5
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
UNICODE_STRING DeviceName
Definition: sysaudio.h:15
HANDLE Handle
Definition: sysaudio.h:17
static const WCHAR SymbolicLink[]
Definition: interface.c:31