ReactOS 0.4.15-dev-7906-g1b85a5f
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
14const GUID GUID_DEVICE_INTERFACE_ARRIVAL = {0xCB3A4004L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}};
15const GUID GUID_DEVICE_INTERFACE_REMOVAL = {0xCB3A4005L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}};
16const GUID KS_CATEGORY_AUDIO = {0x6994AD04L, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
17const GUID KS_CATEGORY_TOPOLOGY = {0xDDA54A40, 0x1E4C, 0x11D1, {0xA0, 0x50, 0x40, 0x57, 0x05, 0xC1, 0x00, 0x00}};
18const 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,
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
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
129cleanup:
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
144NTAPI
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
175{
177 PSYSAUDIODEVEXT DeviceExtension;
178
179 DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
180
187 (PVOID*)&DeviceExtension->KsAudioNotificationEntry);
188
189 if (!NT_SUCCESS(Status))
190 {
191 DPRINT("IoRegisterPlugPlayNotification failed with %x\n", Status);
192 }
193
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
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}
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTSTATUS
Definition: precomp.h:26
#define UNIMPLEMENTED
Definition: debug.h:115
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GENERIC_READ
Definition: compat.h:135
static void cleanup(void)
Definition: main.c:1335
static const WCHAR SymbolicLink[]
Definition: interface.c:31
NTSTATUS NTAPI DeviceInterfaceChangeCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: deviface.c:48
NTSTATUS SysAudioRegisterNotifications(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject)
Definition: deviface.c:172
const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL
Definition: deviface.c:18
const GUID GUID_DEVICE_INTERFACE_ARRIVAL
Definition: deviface.c:14
const GUID GUID_DEVICE_INTERFACE_REMOVAL
Definition: deviface.c:15
const GUID KS_CATEGORY_TOPOLOGY
Definition: deviface.c:17
NTSTATUS SysAudioRegisterDeviceInterfaces(IN PDEVICE_OBJECT DeviceObject)
Definition: deviface.c:214
NTSTATUS OpenDevice(IN PUNICODE_STRING DeviceName, IN PHANDLE HandleOut, IN PFILE_OBJECT *FileObjectOut)
Definition: deviface.c:21
const GUID KS_CATEGORY_AUDIO
Definition: deviface.c:16
NTSTATUS InsertAudioDevice(IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING DeviceName)
Definition: deviface.c:67
struct _DEVICE_OBJECT * PDEVICE_OBJECT
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define NonPagedPool
Definition: env_spec_w32.h:307
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4548
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
#define KSCATEGORY_PREFERRED_MIDIOUT_DEVICE
Definition: ksmedia.h:164
#define KSCATEGORY_PREFERRED_WAVEOUT_DEVICE
Definition: ksmedia.h:154
#define KSCATEGORY_SYSAUDIO
Definition: ksmedia.h:217
#define KSCATEGORY_PREFERRED_WAVEIN_DEVICE
Definition: ksmedia.h:159
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define GENERIC_WRITE
Definition: nt_native.h:90
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define L(x)
Definition: ntvdm.h:50
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:494
NTSTATUS NTAPI IoRegisterPlugPlayNotification(_In_ IO_NOTIFICATION_EVENT_CATEGORY EventCategory, _In_ ULONG EventCategoryFlags, _In_opt_ PVOID EventCategoryData, _In_ PDRIVER_OBJECT DriverObject, _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, _Inout_opt_ PVOID Context, _Out_ PVOID *NotificationEntry)
Definition: pnpnotify.c:345
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
Definition: sysaudio.h:13
PFILE_OBJECT FileObject
Definition: sysaudio.h:18
HANDLE Handle
Definition: sysaudio.h:17
UNICODE_STRING DeviceName
Definition: sysaudio.h:15
LIST_ENTRY Entry
Definition: sysaudio.h:14
PVOID EchoCancelNotificationEntry
Definition: sysaudio.h:32
PVOID KsAudioNotificationEntry
Definition: sysaudio.h:31
LIST_ENTRY KsAudioDeviceList
Definition: sysaudio.h:30
KSPIN_LOCK Lock
Definition: sysaudio.h:33
ULONG NumberOfKsAudioDevices
Definition: sysaudio.h:28
USHORT MaximumLength
Definition: env_spec_w32.h:370
struct SYSAUDIODEVEXT * PSYSAUDIODEVEXT
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
int32_t * PLONG
Definition: typedefs.h:58
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
@ EventCategoryDeviceInterfaceChange
Definition: iotypes.h:1226
* PFILE_OBJECT
Definition: iotypes.h:1998
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1239
__wchar_t WCHAR
Definition: xmlstorage.h:180