2007-07-08 17:31:55 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Kernel Streaming
|
|
|
|
* FILE: drivers/wdm/audio/sysaudio/main.c
|
|
|
|
* PURPOSE: System Audio graph builder
|
|
|
|
* PROGRAMMER: Andrew Greenwood
|
2009-02-20 17:52:47 +00:00
|
|
|
* Johannes Anderwald
|
2007-07-08 17:31:55 +00:00
|
|
|
* HISTORY:
|
|
|
|
* 8 Jul 07 Started basic implementation
|
|
|
|
*/
|
|
|
|
|
2009-01-26 10:08:17 +00:00
|
|
|
#include "sysaudio.h"
|
|
|
|
|
2013-12-19 22:45:32 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2009-02-14 16:10:38 +00:00
|
|
|
const GUID KSCATEGORY_SYSAUDIO = {0xA7C7A5B1L, 0x5AF3, 0x11D1, {0x9C, 0xED, 0x00, 0xA0, 0x24, 0xBF, 0x04, 0x07}};
|
2009-02-10 16:28:24 +00:00
|
|
|
const GUID KSCATEGORY_AUDIO_DEVICE = {0xFBF6F530L, 0x07B9, 0x11D2, {0xA7, 0x1E, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
|
|
|
|
const GUID KSCATEGORY_PREFERRED_WAVEOUT_DEVICE = {0xD6C5066EL, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
|
|
|
|
const GUID KSCATEGORY_PREFERRED_WAVEIN_DEVICE = {0xD6C50671L, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
|
|
|
|
const GUID KSCATEGORY_PREFERRED_MIDIOUT_DEVICE = {0xD6C50674L, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}};
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2010-06-19 07:26:20 +00:00
|
|
|
PVOID
|
|
|
|
AllocateItem(
|
|
|
|
IN POOL_TYPE PoolType,
|
|
|
|
IN SIZE_T NumberOfBytes)
|
|
|
|
{
|
|
|
|
PVOID Item = ExAllocatePool(PoolType, NumberOfBytes);
|
|
|
|
if (!Item)
|
|
|
|
return Item;
|
|
|
|
|
|
|
|
RtlZeroMemory(Item, NumberOfBytes);
|
|
|
|
return Item;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FreeItem(
|
|
|
|
IN PVOID Item)
|
|
|
|
{
|
|
|
|
ExFreePool(Item);
|
|
|
|
}
|
2009-01-26 10:08:17 +00:00
|
|
|
|
2009-01-27 20:02:50 +00:00
|
|
|
|
2009-01-26 10:08:17 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
SysAudio_Unload(IN PDRIVER_OBJECT DriverObject)
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("SysAudio_Unload called\n");
|
2009-01-26 10:08:17 +00:00
|
|
|
}
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-05-27 20:33:00 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SysAudio_Shutdown(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PKSAUDIO_DEVICE_ENTRY DeviceEntry;
|
|
|
|
PSYSAUDIODEVEXT DeviceExtension;
|
2009-07-10 15:14:56 +00:00
|
|
|
PLIST_ENTRY Entry;
|
2009-05-27 20:33:00 +00:00
|
|
|
|
2009-11-13 15:08:00 +00:00
|
|
|
DPRINT("SysAudio_Shutdown called\n");
|
2009-05-27 20:33:00 +00:00
|
|
|
|
|
|
|
DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
while(!IsListEmpty(&DeviceExtension->KsAudioDeviceList))
|
|
|
|
{
|
|
|
|
Entry = RemoveHeadList(&DeviceExtension->KsAudioDeviceList);
|
|
|
|
DeviceEntry = (PKSAUDIO_DEVICE_ENTRY)CONTAINING_RECORD(Entry, KSAUDIO_DEVICE_ENTRY, Entry);
|
|
|
|
|
2009-11-13 15:08:00 +00:00
|
|
|
DPRINT("Freeing item %wZ\n", &DeviceEntry->DeviceName);
|
2009-06-07 18:22:24 +00:00
|
|
|
|
2009-08-02 18:20:39 +00:00
|
|
|
/* dereference audio device file object */
|
|
|
|
ObDereferenceObject(DeviceEntry->FileObject);
|
|
|
|
|
|
|
|
/* close audio device handle */
|
|
|
|
ZwClose(DeviceEntry->Handle);
|
2010-05-15 19:05:58 +00:00
|
|
|
|
2009-08-02 18:20:39 +00:00
|
|
|
/* free device string */
|
|
|
|
RtlFreeUnicodeString(&DeviceEntry->DeviceName);
|
2010-05-15 19:05:58 +00:00
|
|
|
|
2009-08-02 18:20:39 +00:00
|
|
|
/* free audio device entry */
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(DeviceEntry);
|
2009-05-27 20:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-08 17:31:55 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2009-01-26 10:08:17 +00:00
|
|
|
SysAudio_Pnp(
|
2007-07-08 17:31:55 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2009-01-26 10:08:17 +00:00
|
|
|
PIO_STACK_LOCATION IrpStack;
|
|
|
|
UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\DosDevices\\sysaudio");
|
|
|
|
SYSAUDIODEVEXT *DeviceExtension;
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Get current irp stack */
|
2009-01-26 10:08:17 +00:00
|
|
|
IrpStack = IoGetCurrentIrpStackLocation(Irp);
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Fetch the device extension */
|
2009-01-26 10:08:17 +00:00
|
|
|
DeviceExtension = (SYSAUDIODEVEXT*)DeviceObject->DeviceExtension;
|
2009-03-25 19:14:04 +00:00
|
|
|
ASSERT(DeviceExtension);
|
2009-01-26 10:08:17 +00:00
|
|
|
|
|
|
|
if (IrpStack->MinorFunction == IRP_MN_REMOVE_DEVICE)
|
|
|
|
{
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Unregister the echo cancel hook */
|
2009-01-26 10:08:17 +00:00
|
|
|
if (DeviceExtension->EchoCancelNotificationEntry)
|
|
|
|
IoUnregisterPlugPlayNotification(DeviceExtension->EchoCancelNotificationEntry);
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Unregister the ks audio hook */
|
2009-01-26 10:08:17 +00:00
|
|
|
if (DeviceExtension->KsAudioNotificationEntry)
|
|
|
|
IoUnregisterPlugPlayNotification(DeviceExtension->KsAudioNotificationEntry);
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Destroy our symbolic link */
|
2009-01-26 10:08:17 +00:00
|
|
|
IoDeleteSymbolicLink(&SymlinkName);
|
|
|
|
}
|
2009-02-10 16:28:24 +00:00
|
|
|
else if (IrpStack->MinorFunction == IRP_MN_QUERY_PNP_DEVICE_STATE)
|
|
|
|
{
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Sysaudio can not be disabled */
|
2009-02-10 16:28:24 +00:00
|
|
|
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
|
|
|
|
}
|
2009-01-26 10:08:17 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Perform default pnp actions */
|
2009-01-26 10:08:17 +00:00
|
|
|
return KsDefaultDispatchPnp(DeviceObject, Irp);
|
2007-07-08 17:31:55 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 10:08:17 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2009-02-14 16:10:38 +00:00
|
|
|
SysAudio_InstallDevice(
|
|
|
|
IN PDRIVER_OBJECT DriverObject)
|
2007-07-08 17:31:55 +00:00
|
|
|
{
|
2009-01-26 10:08:17 +00:00
|
|
|
NTSTATUS Status;
|
2007-07-08 17:31:55 +00:00
|
|
|
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\sysaudio");
|
|
|
|
UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\DosDevices\\sysaudio");
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2009-01-26 10:08:17 +00:00
|
|
|
SYSAUDIODEVEXT *DeviceExtension;
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("SysAudio_InstallDevice called\n");
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Create the device */
|
2009-01-26 10:08:17 +00:00
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
sizeof(SYSAUDIODEVEXT),
|
2007-07-08 17:31:55 +00:00
|
|
|
&DeviceName,
|
2009-01-26 10:08:17 +00:00
|
|
|
FILE_DEVICE_KS,
|
|
|
|
0,
|
2007-07-08 17:31:55 +00:00
|
|
|
FALSE,
|
|
|
|
&DeviceObject);
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Check for success */
|
2009-01-26 10:08:17 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2007-07-08 17:31:55 +00:00
|
|
|
{
|
|
|
|
DPRINT("Failed to create \\Device\\sysaudio !\n");
|
2009-01-26 10:08:17 +00:00
|
|
|
return Status;
|
2007-07-08 17:31:55 +00:00
|
|
|
}
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Register device interfaces */
|
2009-02-20 17:52:47 +00:00
|
|
|
Status = SysAudioRegisterDeviceInterfaces(DeviceObject);
|
2009-01-26 10:08:17 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2007-07-08 17:31:55 +00:00
|
|
|
{
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Failed to register
|
|
|
|
* Create a hack interface
|
2009-02-20 17:52:47 +00:00
|
|
|
*/
|
|
|
|
Status = IoCreateSymbolicLink(&SymlinkName, &DeviceName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IoDeleteDevice(DeviceObject);
|
2009-11-13 15:08:00 +00:00
|
|
|
DPRINT1("Failed to create sysaudio symlink!\n");
|
2009-02-20 17:52:47 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2007-07-08 17:31:55 +00:00
|
|
|
}
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Acquire device extension */
|
2009-01-26 10:08:17 +00:00
|
|
|
DeviceExtension = (SYSAUDIODEVEXT*)DeviceObject->DeviceExtension;
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Initialize device extension */
|
2009-01-26 10:08:17 +00:00
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(SYSAUDIODEVEXT));
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Initialize the mutex */
|
2009-04-22 10:57:28 +00:00
|
|
|
KeInitializeSpinLock(&DeviceExtension->Lock);
|
2009-03-25 19:14:04 +00:00
|
|
|
|
|
|
|
/* Initialize the ks audio device list */
|
2009-02-10 16:28:24 +00:00
|
|
|
InitializeListHead(&DeviceExtension->KsAudioDeviceList);
|
2009-01-26 10:08:17 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Allocate kernel streaming device header */
|
2009-02-20 17:52:47 +00:00
|
|
|
Status = SysAudioAllocateDeviceHeader(DeviceExtension);
|
2009-02-14 16:10:38 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-26 10:08:17 +00:00
|
|
|
{
|
2009-02-14 16:10:38 +00:00
|
|
|
DPRINT1("KsAllocateDeviceHeader failed with %x\n", Status);
|
|
|
|
goto cleanup;
|
2009-04-03 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 16:05:54 +00:00
|
|
|
/* Register device notification hooks */
|
|
|
|
Status = SysAudioRegisterNotifications(DriverObject,
|
|
|
|
DeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to register device notifications\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-04-03 17:06:16 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Load kmixer */
|
2009-03-11 09:30:33 +00:00
|
|
|
Status = SysAudioOpenKMixer(DeviceExtension);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("SysAudioOpenKMixer failed with %x\n", Status);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-02-14 16:10:38 +00:00
|
|
|
/* set io flags */
|
|
|
|
DeviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE;
|
|
|
|
/* clear initializing flag */
|
|
|
|
DeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;
|
|
|
|
|
2009-05-27 20:33:00 +00:00
|
|
|
/* register shutdown notfication */
|
|
|
|
IoRegisterShutdownNotification(DeviceObject);
|
|
|
|
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Done */
|
2009-02-11 09:54:47 +00:00
|
|
|
return STATUS_SUCCESS;
|
2009-02-14 16:10:38 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
|
|
|
if (DeviceExtension->KsAudioNotificationEntry)
|
|
|
|
IoUnregisterPlugPlayNotification(DeviceExtension->KsAudioNotificationEntry);
|
|
|
|
|
|
|
|
if (DeviceExtension->EchoCancelNotificationEntry)
|
|
|
|
IoUnregisterPlugPlayNotification(DeviceExtension->EchoCancelNotificationEntry);
|
|
|
|
|
|
|
|
IoDeleteSymbolicLink(&SymlinkName);
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
return Status;
|
2007-07-08 17:31:55 +00:00
|
|
|
}
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2007-07-08 17:31:55 +00:00
|
|
|
DriverEntry(
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("System audio graph builder (sysaudio) started\n");
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Let ks handle these */
|
2009-01-26 10:08:17 +00:00
|
|
|
KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CREATE);
|
|
|
|
KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CLOSE);
|
|
|
|
KsSetMajorFunctionHandler(DriverObject, IRP_MJ_WRITE);
|
|
|
|
KsSetMajorFunctionHandler(DriverObject, IRP_MJ_DEVICE_CONTROL);
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Let ks handle these */
|
2009-01-26 10:08:17 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_POWER] = KsDefaultDispatchPower;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = KsDefaultForwardIrp;
|
2009-03-25 19:14:04 +00:00
|
|
|
|
|
|
|
/* Use provided ks unload function */
|
|
|
|
DriverObject->DriverUnload = KsNullDriverUnload;
|
|
|
|
|
|
|
|
/* Sysaudio needs to do work on pnp, so handle it */
|
2009-01-26 10:08:17 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_PNP] = SysAudio_Pnp;
|
2009-05-27 20:33:00 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = SysAudio_Shutdown;
|
2007-07-08 17:31:55 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Call our initialization function */
|
2009-02-14 16:10:38 +00:00
|
|
|
return SysAudio_InstallDevice(DriverObject);
|
2007-07-08 17:31:55 +00:00
|
|
|
}
|