2009-02-20 17:52:47 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Kernel Streaming
|
|
|
|
* FILE: drivers/wdm/audio/sysaudio/deviface.c
|
|
|
|
* PURPOSE: System Audio graph builder
|
|
|
|
* PROGRAMMER: Johannes Anderwald
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysaudio.h"
|
|
|
|
|
2013-12-19 22:45:32 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2009-02-20 17:52:47 +00:00
|
|
|
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}};
|
2009-06-07 18:22:24 +00:00
|
|
|
const GUID KS_CATEGORY_TOPOLOGY = {0xDDA54A40, 0x1E4C, 0x11D1, {0xA0, 0x50, 0x40, 0x57, 0x05, 0xC1, 0x00, 0x00}};
|
2009-02-20 17:52:47 +00:00
|
|
|
const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL = {0xBF963D80L, 0xC559, 0x11D0, {0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1}};
|
|
|
|
|
2009-03-11 09:30:33 +00:00
|
|
|
NTSTATUS
|
|
|
|
OpenDevice(
|
|
|
|
IN PUNICODE_STRING DeviceName,
|
|
|
|
IN PHANDLE HandleOut,
|
|
|
|
IN PFILE_OBJECT * FileObjectOut)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE NodeHandle;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, DeviceName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
|
|
|
|
Status = ZwCreateFile(&NodeHandle,
|
2013-07-19 15:19:03 +00:00
|
|
|
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
|
2009-03-11 09:30:33 +00:00
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
FILE_OPEN,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT,
|
|
|
|
NULL,
|
|
|
|
0);
|
2009-02-27 11:22:16 +00:00
|
|
|
|
|
|
|
|
2009-03-11 09:30:33 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2009-07-10 15:14:56 +00:00
|
|
|
DPRINT("ZwCreateFile failed with %x %S\n", Status, DeviceName->Buffer);
|
2009-03-11 09:30:33 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = ObReferenceObjectByHandle(NodeHandle, GENERIC_READ | GENERIC_WRITE, IoFileObjectType, KernelMode, (PVOID*)&FileObject, NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ZwClose(NodeHandle);
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("ObReferenceObjectByHandle failed with %x\n", Status);
|
2009-03-11 09:30:33 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
*HandleOut = NodeHandle;
|
|
|
|
*FileObjectOut = FileObject;
|
|
|
|
return Status;
|
|
|
|
}
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2009-07-10 15:14:56 +00:00
|
|
|
NTSTATUS
|
|
|
|
InsertAudioDevice(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
2009-08-21 10:06:29 +00:00
|
|
|
IN PUNICODE_STRING DeviceName)
|
2009-07-10 15:14:56 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PSYSAUDIODEVEXT DeviceExtension;
|
|
|
|
PKSAUDIO_DEVICE_ENTRY DeviceEntry = NULL;
|
|
|
|
|
|
|
|
/* a new device has arrived */
|
2010-06-19 07:26:20 +00:00
|
|
|
DeviceEntry = AllocateItem(NonPagedPool, sizeof(KSAUDIO_DEVICE_ENTRY));
|
2009-07-10 15:14:56 +00:00
|
|
|
if (!DeviceEntry)
|
|
|
|
{
|
|
|
|
/* no memory */
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize audio device entry */
|
|
|
|
RtlZeroMemory(DeviceEntry, sizeof(KSAUDIO_DEVICE_ENTRY));
|
|
|
|
|
|
|
|
/* set device name */
|
|
|
|
DeviceEntry->DeviceName.Length = 0;
|
|
|
|
DeviceEntry->DeviceName.MaximumLength = DeviceName->MaximumLength + 10 * sizeof(WCHAR);
|
|
|
|
|
2010-06-19 07:26:20 +00:00
|
|
|
DeviceEntry->DeviceName.Buffer = AllocateItem(NonPagedPool, DeviceEntry->DeviceName.MaximumLength);
|
2009-07-10 15:14:56 +00:00
|
|
|
|
|
|
|
if (!DeviceEntry->DeviceName.Buffer)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-30 22:07:40 +00:00
|
|
|
/* open device */
|
|
|
|
Status = OpenDevice(DeviceName, &DeviceEntry->Handle, &DeviceEntry->FileObject);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* copy device name */
|
|
|
|
RtlAppendUnicodeStringToString(&DeviceEntry->DeviceName, DeviceName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* the device name needs to be prefixed */
|
|
|
|
RtlAppendUnicodeToString(&DeviceEntry->DeviceName, L"\\??\\");
|
|
|
|
RtlAppendUnicodeStringToString(&DeviceEntry->DeviceName, DeviceName);
|
2009-07-10 15:14:56 +00:00
|
|
|
|
2013-05-30 22:07:40 +00:00
|
|
|
/* open device */
|
|
|
|
Status = OpenDevice(&DeviceEntry->DeviceName, &DeviceEntry->Handle, &DeviceEntry->FileObject);
|
|
|
|
}
|
2009-07-10 15:14:56 +00:00
|
|
|
|
2013-05-30 22:07:40 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-10 15:14:56 +00:00
|
|
|
|
|
|
|
/* fetch device extension */
|
|
|
|
DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
|
|
|
|
/* insert new audio device */
|
|
|
|
ExInterlockedInsertTailList(&DeviceExtension->KsAudioDeviceList, &DeviceEntry->Entry, &DeviceExtension->Lock);
|
|
|
|
InterlockedIncrement((PLONG)&DeviceExtension->NumberOfKsAudioDevices);
|
|
|
|
|
|
|
|
DPRINT("Successfully opened audio device %u Device %S\n", DeviceExtension->NumberOfKsAudioDevices, DeviceEntry->DeviceName.Buffer);
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (DeviceEntry)
|
|
|
|
{
|
|
|
|
if (DeviceEntry->DeviceName.Buffer)
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(DeviceEntry->DeviceName.Buffer);
|
2009-07-10 15:14:56 +00:00
|
|
|
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(DeviceEntry);
|
2009-07-10 15:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-20 17:52:47 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DeviceInterfaceChangeCallback(
|
|
|
|
IN PVOID NotificationStructure,
|
|
|
|
IN PVOID Context)
|
|
|
|
{
|
|
|
|
DEVICE_INTERFACE_CHANGE_NOTIFICATION * Event;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2009-02-27 11:22:16 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject = (PDEVICE_OBJECT)Context;
|
|
|
|
|
2009-02-20 17:52:47 +00:00
|
|
|
Event = (DEVICE_INTERFACE_CHANGE_NOTIFICATION*)NotificationStructure;
|
|
|
|
|
|
|
|
if (IsEqualGUIDAligned(&Event->Event,
|
|
|
|
&GUID_DEVICE_INTERFACE_ARRIVAL))
|
|
|
|
{
|
2009-08-21 10:06:29 +00:00
|
|
|
Status = InsertAudioDevice(DeviceObject, Event->SymbolicLinkName);
|
2009-02-20 17:52:47 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Remove interface to audio device!\n");
|
2009-03-25 19:14:04 +00:00
|
|
|
UNIMPLEMENTED
|
2009-02-20 17:52:47 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2009-04-22 10:57:28 +00:00
|
|
|
|
|
|
|
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
SysAudioRegisterNotifications(
|
2009-02-27 11:22:16 +00:00
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
2009-02-20 17:52:47 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2009-02-27 11:22:16 +00:00
|
|
|
PSYSAUDIODEVEXT DeviceExtension;
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2009-02-27 11:22:16 +00:00
|
|
|
DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
|
2009-02-20 17:52:47 +00:00
|
|
|
|
|
|
|
Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
|
|
|
|
PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
|
|
|
|
(PVOID)&KS_CATEGORY_AUDIO,
|
|
|
|
DriverObject,
|
|
|
|
DeviceInterfaceChangeCallback,
|
2009-02-27 11:22:16 +00:00
|
|
|
(PVOID)DeviceObject,
|
2009-02-20 17:52:47 +00:00
|
|
|
(PVOID*)&DeviceExtension->KsAudioNotificationEntry);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("IoRegisterPlugPlayNotification failed with %x\n", Status);
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
|
|
|
|
PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
|
|
|
|
(PVOID)&DMOCATEGORY_ACOUSTIC_ECHO_CANCEL,
|
|
|
|
DriverObject,
|
|
|
|
DeviceInterfaceChangeCallback,
|
2009-02-27 11:22:16 +00:00
|
|
|
(PVOID)DeviceObject,
|
2009-02-20 17:52:47 +00:00
|
|
|
(PVOID*)&DeviceExtension->EchoCancelNotificationEntry);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* ignore failure for now */
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("IoRegisterPlugPlayNotification failed for DMOCATEGORY_ACOUSTIC_ECHO_CANCEL\n", Status);
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
SysAudioRegisterDeviceInterfaces(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING SymbolicLink;
|
|
|
|
|
|
|
|
Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_PREFERRED_MIDIOUT_DEVICE, NULL, &SymbolicLink);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IoSetDeviceInterfaceState(&SymbolicLink, TRUE);
|
|
|
|
RtlFreeUnicodeString(&SymbolicLink);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Failed to register KSCATEGORY_PREFERRED_MIDIOUT_DEVICE interface Status %x\n", Status);
|
2009-02-20 17:52:47 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_PREFERRED_WAVEIN_DEVICE, NULL, &SymbolicLink);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IoSetDeviceInterfaceState(&SymbolicLink, TRUE);
|
|
|
|
RtlFreeUnicodeString(&SymbolicLink);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEIN_DEVICE interface Status %x\n", Status);
|
2009-02-20 17:52:47 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_PREFERRED_WAVEOUT_DEVICE, NULL, &SymbolicLink);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IoSetDeviceInterfaceState(&SymbolicLink, TRUE);
|
|
|
|
RtlFreeUnicodeString(&SymbolicLink);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEOUT_DEVICE interface Status %x\n", Status);
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_SYSAUDIO, NULL, &SymbolicLink);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IoSetDeviceInterfaceState(&SymbolicLink, TRUE);
|
|
|
|
RtlFreeUnicodeString(&SymbolicLink);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Failed to register KSCATEGORY_SYSAUDIO interface Status %x\n", Status);
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|