2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/sysaudio/main.c
5 * PURPOSE: System Audio graph builder
6 * PROGRAMMER: Andrew Greenwood
9 * 8 Jul 07 Started basic implementation
16 //#include <dxsdk/mediaobj.h>
21 const GUID KS_CATEGORY_AUDIO
= {0x6994AD04, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
24 SysAudio_Unload(IN PDRIVER_OBJECT DriverObject
)
26 DPRINT1("SysAudio_Unload called\n");
32 IN PDEVICE_OBJECT DeviceObject
,
35 PIO_STACK_LOCATION IrpStack
;
36 UNICODE_STRING SymlinkName
= RTL_CONSTANT_STRING(L
"\\DosDevices\\sysaudio");
37 SYSAUDIODEVEXT
*DeviceExtension
;
39 DPRINT1("SysAudio_Pnp called\n");
42 IrpStack
= IoGetCurrentIrpStackLocation(Irp
);
44 DeviceExtension
= (SYSAUDIODEVEXT
*)DeviceObject
->DeviceExtension
;
46 if (IrpStack
->MinorFunction
== IRP_MN_REMOVE_DEVICE
)
48 if (DeviceExtension
->EchoCancelNotificationEntry
)
49 IoUnregisterPlugPlayNotification(DeviceExtension
->EchoCancelNotificationEntry
);
51 if (DeviceExtension
->KsAudioNotificationEntry
)
52 IoUnregisterPlugPlayNotification(DeviceExtension
->KsAudioNotificationEntry
);
54 IoDeleteSymbolicLink(&SymlinkName
);
57 return KsDefaultDispatchPnp(DeviceObject
, Irp
);
62 DeviceInterfaceChangeCallback(
63 IN PVOID NotificationStructure
,
66 DEVICE_INTERFACE_CHANGE_NOTIFICATION
* Event
= (DEVICE_INTERFACE_CHANGE_NOTIFICATION
*)NotificationStructure
;
68 DPRINT1("DeviceInterfaceChangeCallback called %p\n", Event
);
69 return STATUS_SUCCESS
;
75 IN PDEVICE_OBJECT DeviceObject
,
78 DPRINT1("DispatchCreate\n");
80 return STATUS_SUCCESS
;
83 const GUID KSCATEGORY_AUDIO_DEVICE
= {0xFBF6F530L
, 0x07B9, 0x11D2, {0xA7, 0x1E, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
84 const GUID KSCATEGORY_PREFERRED_WAVEOUT_DEVICE
= {0xD6C5066EL
, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
85 const GUID KSCATEGORY_PREFERRED_WAVEIN_DEVICE
= {0xD6C50671L
, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
86 const GUID KSCATEGORY_PREFERRED_MIDIOUT_DEVICE
= {0xD6C50674L
, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
93 IN PDRIVER_OBJECT DriverObject
,
94 IN PDEVICE_OBJECT PhysicalDeviceObject
)
97 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Device\\sysaudio");
98 UNICODE_STRING SymlinkName
= RTL_CONSTANT_STRING(L
"\\DosDevices\\sysaudio");
99 PDEVICE_OBJECT DeviceObject
;
100 PDEVICE_OBJECT NextDeviceObject
;
101 KSOBJECT_CREATE_ITEM CreateItem
;
102 SYSAUDIODEVEXT
*DeviceExtension
;
103 UNICODE_STRING SymbolicLink
;
105 DPRINT1("SysAudio_AddDevice called\n");
107 /* create the device */
108 Status
= IoCreateDevice(DriverObject
,
109 sizeof(SYSAUDIODEVEXT
),
116 /* check for success */
117 if (!NT_SUCCESS(Status
))
119 DPRINT("Failed to create \\Device\\sysaudio !\n");
123 /* create the symbolic link */
124 Status
= IoCreateSymbolicLink(&SymlinkName
, &DeviceName
);
125 if (!NT_SUCCESS(Status
))
127 IoDeleteDevice(DeviceObject
);
128 DPRINT("Failed to create \\DosDevices\\sysaudio symlink!\n");
133 DeviceExtension
= (SYSAUDIODEVEXT
*)DeviceObject
->DeviceExtension
;
134 /* initialize device extension */
135 RtlZeroMemory(DeviceExtension
, sizeof(SYSAUDIODEVEXT
));
137 KeInitializeMutex(&DeviceExtension
->Mutex
, 0);
139 DeviceExtension
->PhysicalDeviceObject
= PhysicalDeviceObject
;
141 /* initialize create item struct */
142 RtlZeroMemory(&CreateItem
, sizeof(KSOBJECT_CREATE_ITEM
));
143 CreateItem
.Create
= DispatchCreate
;
145 Status
= KsAllocateDeviceHeader(&DeviceExtension
->KsDeviceHeader
,
149 if (NT_SUCCESS(Status
))
151 NextDeviceObject
= IoAttachDeviceToDeviceStack(DeviceObject
, PhysicalDeviceObject
);
152 if (NextDeviceObject
)
155 /// KsSetDevicePnpAndBaseObject(DeviceExtension->KsDeviceHeader, NextDeviceObject, DeviceObject);
158 DeviceExtension
->NextDeviceObject
= NextDeviceObject
;
160 Status
= IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
161 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
162 (PVOID
)&KS_CATEGORY_AUDIO
,
164 DeviceInterfaceChangeCallback
,
165 (PVOID
)DeviceExtension
,
166 (PVOID
*)&DeviceExtension
->KsAudioNotificationEntry
);
167 if (!NT_SUCCESS(Status
))
169 DPRINT1("IoRegisterPlugPlayNotification failed with %x\n", Status
);
173 Status
= IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
174 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
175 &DMOCATEGORY_ACOUSTIC_ECHO_CANCEL
,
177 DeviceInterfaceChangeCallback
,
178 (PVOID
)DeviceExtension
,
179 &DeviceExtension
->EchoCancelNotificationEntry
);
180 if (!NT_SUCCESS(Status
))
182 DPRINT1("IoRegisterPlugPlayNotification failed with %x\n", Status
);
187 Status
= IoRegisterDeviceInterface(PhysicalDeviceObject
, &KSCATEGORY_PREFERRED_MIDIOUT_DEVICE
, NULL
, &SymbolicLink
);
188 if (!NT_SUCCESS(Status
))
190 DPRINT1("Failed to register KSCATEGORY_PREFERRED_MIDIOUT_DEVICE interface\n");
193 RtlFreeUnicodeString(&SymbolicLink
);
195 Status
= IoRegisterDeviceInterface(PhysicalDeviceObject
, &KSCATEGORY_PREFERRED_WAVEIN_DEVICE
, NULL
, &SymbolicLink
);
196 if (!NT_SUCCESS(Status
))
198 DPRINT1("Failed to register KSCATEGORY_PREFERRED_WAVEIN_DEVICE interface\n");
201 RtlFreeUnicodeString(&SymbolicLink
);
203 Status
= IoRegisterDeviceInterface(PhysicalDeviceObject
, &KSCATEGORY_PREFERRED_WAVEOUT_DEVICE
, NULL
, &SymbolicLink
);
204 if (!NT_SUCCESS(Status
))
206 DPRINT1("Failed to register KSCATEGORY_PREFERRED_WAVEOUT_DEVICE interface\n");
209 RtlFreeUnicodeString(&SymbolicLink
);
212 DeviceObject
->Flags
|= DO_DIRECT_IO
| DO_POWER_PAGABLE
;
213 /* clear initializing flag */
214 DeviceObject
->Flags
&= ~ DO_DEVICE_INITIALIZING
;
220 DPRINT("Device SysAudio_AddDevice result %x\n", Status
);
227 IN PDRIVER_OBJECT DriverObject
,
228 IN PUNICODE_STRING RegistryPath
)
230 DPRINT1("System audio graph builder (sysaudio) started\n");
232 DPRINT1("Setting KS function handlers\n");
233 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_CREATE
);
234 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_CLOSE
);
235 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_WRITE
);
236 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_DEVICE_CONTROL
);
238 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = KsDefaultDispatchPower
;
239 DriverObject
->MajorFunction
[IRP_MJ_SYSTEM_CONTROL
] = KsDefaultForwardIrp
;
240 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = SysAudio_Pnp
;
241 DriverObject
->DriverUnload
= SysAudio_Unload
;
242 DriverObject
->DriverExtension
->AddDevice
= SysAudio_AddDevice
;
244 return STATUS_SUCCESS
;