2009-02-21 20:18:44 +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-21 20:18:44 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Pin_fnDeviceIoControl(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
PDISPATCH_CONTEXT Context;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG BytesReturned;
|
2009-10-31 18:00:05 +00:00
|
|
|
PFILE_OBJECT FileObject = NULL;
|
2009-02-21 20:18:44 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
2009-10-12 21:06:21 +00:00
|
|
|
DPRINT("Pin_fnDeviceIoControl called DeviceObject %p Irp %p\n", DeviceObject, Irp);
|
2009-02-21 20:18:44 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Get current stack location */
|
2009-02-21 20:18:44 +00:00
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
2009-09-12 14:35:27 +00:00
|
|
|
/* The dispatch context is stored in the FsContext member */
|
|
|
|
Context = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
|
2009-03-25 19:14:04 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
2009-02-22 18:58:51 +00:00
|
|
|
ASSERT(Context);
|
2009-06-10 18:28:15 +00:00
|
|
|
|
|
|
|
/* acquire real pin file object */
|
|
|
|
Status = ObReferenceObjectByHandle(Context->Handle, GENERIC_WRITE, IoFileObjectType, KernelMode, (PVOID*)&FileObject, NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
/* Complete the irp */
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
2009-02-22 18:58:51 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Re-dispatch the request to the real target pin */
|
2009-06-10 18:28:15 +00:00
|
|
|
Status = KsSynchronousIoControlDevice(FileObject, KernelMode, IoStack->Parameters.DeviceIoControl.IoControlCode,
|
2009-02-21 20:18:44 +00:00
|
|
|
IoStack->Parameters.DeviceIoControl.Type3InputBuffer,
|
|
|
|
IoStack->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
Irp->UserBuffer,
|
|
|
|
IoStack->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&BytesReturned);
|
2009-06-10 18:28:15 +00:00
|
|
|
/* release file object */
|
|
|
|
ObDereferenceObject(FileObject);
|
2009-02-21 20:18:44 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Save status and information */
|
2009-02-21 20:18:44 +00:00
|
|
|
Irp->IoStatus.Information = BytesReturned;
|
|
|
|
Irp->IoStatus.Status = Status;
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Complete the irp */
|
2009-02-21 20:18:44 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Done */
|
2009-02-21 20:18:44 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
|
2009-02-21 20:18:44 +00:00
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Pin_fnWrite(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
PDISPATCH_CONTEXT Context;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
2009-06-10 18:28:15 +00:00
|
|
|
PFILE_OBJECT FileObject;
|
2009-02-21 20:18:44 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* Get current stack location */
|
2009-02-21 20:18:44 +00:00
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
2009-09-12 14:35:27 +00:00
|
|
|
/* The dispatch context is stored in the FsContext member */
|
|
|
|
Context = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
|
2009-03-25 19:14:04 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
2009-02-22 18:58:51 +00:00
|
|
|
ASSERT(Context);
|
2009-03-25 19:14:04 +00:00
|
|
|
|
2009-06-10 18:28:15 +00:00
|
|
|
if (Context->hMixerPin)
|
2009-03-25 19:14:04 +00:00
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
// call kmixer to convert stream
|
|
|
|
UNIMPLEMENTED
|
|
|
|
}
|
2009-02-22 18:58:51 +00:00
|
|
|
|
2009-06-10 18:28:15 +00:00
|
|
|
/* acquire real pin file object */
|
|
|
|
Status = ObReferenceObjectByHandle(Context->Handle, GENERIC_WRITE, IoFileObjectType, KernelMode, (PVOID*)&FileObject, NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2009-09-13 22:26:59 +00:00
|
|
|
DPRINT1("failed\n");
|
2009-06-10 18:28:15 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
/* Complete the irp */
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
2009-03-25 19:14:04 +00:00
|
|
|
|
2009-09-13 22:26:59 +00:00
|
|
|
/* skip current irp location */
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
2009-06-10 18:28:15 +00:00
|
|
|
|
2009-09-13 22:26:59 +00:00
|
|
|
/* get next stack location */
|
|
|
|
IoStack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
/* store file object of next device object */
|
|
|
|
IoStack->FileObject = FileObject;
|
|
|
|
IoStack->MajorFunction = IRP_MJ_DEVICE_CONTROL;
|
2009-10-26 00:15:22 +00:00
|
|
|
//ASSERT(Irp->AssociatedIrp.SystemBuffer);
|
2009-03-25 19:14:04 +00:00
|
|
|
|
2009-09-13 22:26:59 +00:00
|
|
|
/* now call the driver */
|
2009-10-07 10:41:34 +00:00
|
|
|
Status = IoCallDriver(IoGetRelatedDeviceObject(FileObject), Irp);
|
|
|
|
|
|
|
|
/* dereference file object */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
2009-02-21 20:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Pin_fnClose(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
2009-06-10 18:28:15 +00:00
|
|
|
PDISPATCH_CONTEXT Context;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
2009-10-31 18:00:05 +00:00
|
|
|
//DPRINT("Pin_fnClose called DeviceObject %p Irp %p\n", DeviceObject, Irp);
|
2009-02-21 20:18:44 +00:00
|
|
|
|
2009-06-10 18:28:15 +00:00
|
|
|
/* Get current stack location */
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
2009-09-12 14:35:27 +00:00
|
|
|
/* The dispatch context is stored in the FsContext member */
|
|
|
|
Context = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
|
2009-06-10 18:28:15 +00:00
|
|
|
|
|
|
|
if (Context->Handle)
|
|
|
|
{
|
|
|
|
ZwClose(Context->Handle);
|
|
|
|
}
|
2009-10-31 18:00:05 +00:00
|
|
|
|
|
|
|
if (Context->hMixerPin)
|
|
|
|
{
|
|
|
|
ZwClose(Context->hMixerPin);
|
|
|
|
}
|
2009-06-10 18:28:15 +00:00
|
|
|
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(Context);
|
2009-06-10 18:28:15 +00:00
|
|
|
|
2009-02-23 23:24:58 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2009-02-21 20:18:44 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static KSDISPATCH_TABLE PinTable =
|
|
|
|
{
|
|
|
|
Pin_fnDeviceIoControl,
|
2009-09-13 22:26:59 +00:00
|
|
|
KsDispatchInvalidDeviceRequest,
|
2009-02-21 20:18:44 +00:00
|
|
|
Pin_fnWrite,
|
2009-09-13 22:26:59 +00:00
|
|
|
KsDispatchInvalidDeviceRequest,
|
2009-02-21 20:18:44 +00:00
|
|
|
Pin_fnClose,
|
2009-09-13 22:26:59 +00:00
|
|
|
KsDispatchInvalidDeviceRequest,
|
|
|
|
KsDispatchInvalidDeviceRequest,
|
|
|
|
KsDispatchFastIoDeviceControlFailure,
|
|
|
|
KsDispatchFastReadFailure,
|
2009-10-07 10:41:34 +00:00
|
|
|
KsDispatchFastWriteFailure,
|
2009-02-21 20:18:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NTSTATUS
|
2009-08-10 07:14:04 +00:00
|
|
|
SetMixerInputOutputFormat(
|
|
|
|
IN PFILE_OBJECT FileObject,
|
|
|
|
IN PKSDATAFORMAT InputFormat,
|
|
|
|
IN PKSDATAFORMAT OutputFormat)
|
|
|
|
{
|
|
|
|
KSP_PIN PinRequest;
|
|
|
|
ULONG BytesReturned;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* re-using pin */
|
|
|
|
PinRequest.Property.Set = KSPROPSETID_Connection;
|
|
|
|
PinRequest.Property.Flags = KSPROPERTY_TYPE_SET;
|
|
|
|
PinRequest.Property.Id = KSPROPERTY_CONNECTION_DATAFORMAT;
|
|
|
|
|
|
|
|
/* set the input format */
|
|
|
|
PinRequest.PinId = 0;
|
|
|
|
DPRINT("InputFormat %p Size %u WaveFormatSize %u DataFormat %u WaveEx %u\n", InputFormat, InputFormat->FormatSize, sizeof(KSDATAFORMAT_WAVEFORMATEX), sizeof(KSDATAFORMAT), sizeof(WAVEFORMATEX));
|
|
|
|
Status = KsSynchronousIoControlDevice(FileObject, KernelMode, IOCTL_KS_PROPERTY,
|
|
|
|
(PVOID)&PinRequest,
|
|
|
|
sizeof(KSP_PIN),
|
|
|
|
(PVOID)InputFormat,
|
|
|
|
InputFormat->FormatSize,
|
|
|
|
&BytesReturned);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
/* set the the output format */
|
|
|
|
PinRequest.PinId = 1;
|
|
|
|
DPRINT("OutputFormat %p Size %u WaveFormatSize %u DataFormat %u WaveEx %u\n", OutputFormat, OutputFormat->FormatSize, sizeof(KSDATAFORMAT_WAVEFORMATEX), sizeof(KSDATAFORMAT), sizeof(WAVEFORMATEX));
|
|
|
|
Status = KsSynchronousIoControlDevice(FileObject, KernelMode, IOCTL_KS_PROPERTY,
|
|
|
|
(PVOID)&PinRequest,
|
|
|
|
sizeof(KSP_PIN),
|
|
|
|
(PVOID)OutputFormat,
|
|
|
|
OutputFormat->FormatSize,
|
|
|
|
&BytesReturned);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CreateMixerPinAndSetFormat(
|
|
|
|
IN HANDLE KMixerHandle,
|
|
|
|
IN KSPIN_CONNECT *PinConnect,
|
|
|
|
IN PKSDATAFORMAT InputFormat,
|
|
|
|
IN PKSDATAFORMAT OutputFormat,
|
|
|
|
OUT PHANDLE MixerPinHandle)
|
2009-02-21 20:18:44 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2009-08-10 07:14:04 +00:00
|
|
|
HANDLE PinHandle;
|
2009-10-31 18:00:05 +00:00
|
|
|
PFILE_OBJECT FileObject = NULL;
|
2009-08-10 07:14:04 +00:00
|
|
|
|
|
|
|
Status = KsCreatePin(KMixerHandle, PinConnect, GENERIC_READ | GENERIC_WRITE, &PinHandle);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create Mixer Pin with %x\n", Status);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = ObReferenceObjectByHandle(PinHandle,
|
|
|
|
GENERIC_READ | GENERIC_WRITE,
|
|
|
|
IoFileObjectType, KernelMode, (PVOID*)&FileObject, NULL);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to get file object with %x\n", Status);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = SetMixerInputOutputFormat(FileObject, InputFormat, OutputFormat);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
ZwClose(PinHandle);
|
2009-10-31 18:00:05 +00:00
|
|
|
return Status;
|
2009-08-10 07:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
|
|
|
|
*MixerPinHandle = PinHandle;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
InstantiatePins(
|
|
|
|
IN PKSAUDIO_DEVICE_ENTRY DeviceEntry,
|
|
|
|
IN PKSPIN_CONNECT Connect,
|
|
|
|
IN PDISPATCH_CONTEXT DispatchContext,
|
|
|
|
IN PSYSAUDIODEVEXT DeviceExtension)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE RealPinHandle;
|
|
|
|
PKSDATAFORMAT_WAVEFORMATEX InputFormat;
|
|
|
|
PKSDATAFORMAT_WAVEFORMATEX OutputFormat = NULL;
|
|
|
|
PKSPIN_CONNECT MixerPinConnect = NULL;
|
|
|
|
KSPIN_CINSTANCES PinInstances;
|
|
|
|
|
|
|
|
DPRINT("InstantiatePins entered\n");
|
|
|
|
|
|
|
|
/* query instance count */
|
|
|
|
Status = GetPinInstanceCount(DeviceEntry, &PinInstances, Connect);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed to query instance count */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* can be the pin be instantiated */
|
|
|
|
if (PinInstances.PossibleCount == 0)
|
|
|
|
{
|
|
|
|
/* caller wanted to open an instance-less pin */
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* has the maximum instance count been exceeded */
|
|
|
|
if (PinInstances.CurrentCount == PinInstances.PossibleCount)
|
|
|
|
{
|
|
|
|
/* FIXME pin already exists
|
|
|
|
* and kmixer infrastructure is not implemented
|
|
|
|
*/
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch input format */
|
|
|
|
InputFormat = (PKSDATAFORMAT_WAVEFORMATEX)(Connect + 1);
|
|
|
|
|
|
|
|
/* Let's try to create the audio irp pin */
|
|
|
|
Status = KsCreatePin(DeviceEntry->Handle, Connect, GENERIC_READ | GENERIC_WRITE, &RealPinHandle);
|
|
|
|
|
2009-10-31 18:00:05 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* FIXME disable kmixer
|
|
|
|
*/
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
#if 0
|
2009-08-10 07:14:04 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* the audio irp pin didnt accept the input format
|
|
|
|
* let's compute a compatible format
|
|
|
|
*/
|
2010-06-19 07:26:20 +00:00
|
|
|
MixerPinConnect = AllocateItem(NonPagedPool, sizeof(KSPIN_CONNECT) + sizeof(KSDATAFORMAT_WAVEFORMATEX));
|
2009-08-10 07:14:04 +00:00
|
|
|
if (!MixerPinConnect)
|
|
|
|
{
|
|
|
|
/* not enough memory */
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero pin connect */
|
|
|
|
RtlZeroMemory(MixerPinConnect, sizeof(KSPIN_CONNECT) + sizeof(KSDATAFORMAT_WAVEFORMATEX));
|
|
|
|
|
|
|
|
/* Copy initial connect details */
|
|
|
|
RtlMoveMemory(MixerPinConnect, Connect, sizeof(KSPIN_CONNECT));
|
|
|
|
|
|
|
|
|
|
|
|
OutputFormat = (PKSDATAFORMAT_WAVEFORMATEX)(MixerPinConnect + 1);
|
|
|
|
|
|
|
|
Status = ComputeCompatibleFormat(DeviceEntry, Connect->PinId, InputFormat, OutputFormat);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("ComputeCompatibleFormat failed with %x\n", Status);
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(MixerPinConnect);
|
2009-08-10 07:14:04 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retry with Mixer format */
|
|
|
|
Status = KsCreatePin(DeviceEntry->Handle, MixerPinConnect, GENERIC_READ | GENERIC_WRITE, &RealPinHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* This should not fail */
|
|
|
|
DPRINT1("KsCreatePin failed with %x\n", Status);
|
|
|
|
DPRINT1(" InputFormat: SampleRate %u Bits %u Channels %u\n", InputFormat->WaveFormatEx.nSamplesPerSec, InputFormat->WaveFormatEx.wBitsPerSample, InputFormat->WaveFormatEx.nChannels);
|
|
|
|
DPRINT1("OutputFormat: SampleRate %u Bits %u Channels %u\n", OutputFormat->WaveFormatEx.nSamplesPerSec, OutputFormat->WaveFormatEx.wBitsPerSample, OutputFormat->WaveFormatEx.nChannels);
|
|
|
|
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(MixerPinConnect);
|
2009-08-10 07:14:04 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
2009-10-31 18:00:05 +00:00
|
|
|
#endif
|
2009-08-10 07:14:04 +00:00
|
|
|
|
2010-05-15 19:05:58 +00:00
|
|
|
//DeviceEntry->Pins[Connect->PinId].References = 0;
|
2009-08-10 07:14:04 +00:00
|
|
|
|
|
|
|
/* initialize dispatch context */
|
|
|
|
DispatchContext->Handle = RealPinHandle;
|
|
|
|
DispatchContext->PinId = Connect->PinId;
|
|
|
|
DispatchContext->AudioEntry = DeviceEntry;
|
|
|
|
|
|
|
|
|
2009-11-13 15:08:00 +00:00
|
|
|
DPRINT("RealPinHandle %p\n", RealPinHandle);
|
2009-10-31 18:00:05 +00:00
|
|
|
|
2009-08-10 07:14:04 +00:00
|
|
|
/* Do we need to transform the audio stream */
|
|
|
|
if (OutputFormat != NULL)
|
|
|
|
{
|
|
|
|
/* Now create the mixer pin */
|
|
|
|
Status = CreateMixerPinAndSetFormat(DeviceExtension->KMixerHandle,
|
|
|
|
MixerPinConnect,
|
|
|
|
(PKSDATAFORMAT)InputFormat,
|
|
|
|
(PKSDATAFORMAT)OutputFormat,
|
|
|
|
&DispatchContext->hMixerPin);
|
|
|
|
|
|
|
|
/* check for success */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create Mixer Pin with %x\n", Status);
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(MixerPinConnect);
|
2009-08-10 07:14:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* done */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2010-05-15 19:05:58 +00:00
|
|
|
NTSTATUS
|
|
|
|
GetConnectRequest(
|
|
|
|
IN PIRP Irp,
|
|
|
|
OUT PKSPIN_CONNECT * Result)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
ULONG ObjectLength, ParametersLength;
|
|
|
|
PVOID Buffer;
|
|
|
|
|
|
|
|
/* get current irp stack */
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
/* get object class length */
|
2010-11-02 09:37:30 +00:00
|
|
|
ObjectLength = (wcslen(KSSTRING_Pin) + 1) * sizeof(WCHAR);
|
2010-05-15 19:05:58 +00:00
|
|
|
|
|
|
|
/* check for minium length requirement */
|
|
|
|
if (ObjectLength + sizeof(KSPIN_CONNECT) > IoStack->FileObject->FileName.MaximumLength)
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
|
|
|
|
/* extract parameters length */
|
|
|
|
ParametersLength = IoStack->FileObject->FileName.MaximumLength - ObjectLength;
|
|
|
|
|
|
|
|
/* allocate buffer */
|
2010-06-19 07:26:20 +00:00
|
|
|
Buffer = AllocateItem(NonPagedPool, ParametersLength);
|
2010-05-15 19:05:58 +00:00
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
/* copy parameters */
|
|
|
|
RtlMoveMemory(Buffer, &IoStack->FileObject->FileName.Buffer[ObjectLength / sizeof(WCHAR)], ParametersLength);
|
|
|
|
|
|
|
|
/* store result */
|
|
|
|
*Result = (PKSPIN_CONNECT)Buffer;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-10 07:14:04 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DispatchCreateSysAudioPin(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PKSAUDIO_DEVICE_ENTRY DeviceEntry;
|
2010-05-15 19:05:58 +00:00
|
|
|
PKSPIN_CONNECT Connect;
|
2009-08-10 07:14:04 +00:00
|
|
|
PDISPATCH_CONTEXT DispatchContext;
|
|
|
|
|
|
|
|
DPRINT("DispatchCreateSysAudioPin entered\n");
|
|
|
|
|
|
|
|
/* get current stack location */
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
ASSERT(IoStack->FileObject);
|
|
|
|
ASSERT(IoStack->FileObject->RelatedFileObject);
|
2009-09-12 14:35:27 +00:00
|
|
|
ASSERT(IoStack->FileObject->RelatedFileObject->FsContext);
|
2009-08-10 07:14:04 +00:00
|
|
|
|
|
|
|
/* get current attached virtual device */
|
2009-09-12 14:35:27 +00:00
|
|
|
DeviceEntry = (PKSAUDIO_DEVICE_ENTRY)IoStack->FileObject->RelatedFileObject->FsContext;
|
2009-08-10 07:14:04 +00:00
|
|
|
|
|
|
|
/* check for success */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed */
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2010-05-15 19:05:58 +00:00
|
|
|
/* get connect details */
|
|
|
|
Status = GetConnectRequest(Irp, &Connect);
|
|
|
|
|
|
|
|
/* check for success */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed to obtain connect details */
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-10 07:14:04 +00:00
|
|
|
/* allocate dispatch context */
|
2010-06-19 07:26:20 +00:00
|
|
|
DispatchContext = AllocateItem(NonPagedPool, sizeof(DISPATCH_CONTEXT));
|
2009-08-10 07:14:04 +00:00
|
|
|
if (!DispatchContext)
|
|
|
|
{
|
|
|
|
/* failed */
|
|
|
|
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* zero dispatch context */
|
|
|
|
RtlZeroMemory(DispatchContext, sizeof(DISPATCH_CONTEXT));
|
2009-02-21 20:18:44 +00:00
|
|
|
|
|
|
|
/* allocate object header */
|
2009-09-12 14:35:27 +00:00
|
|
|
Status = KsAllocateObjectHeader(&DispatchContext->ObjectHeader, 0, NULL, Irp, &PinTable);
|
2009-08-10 07:14:04 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed */
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(DispatchContext);
|
2009-08-10 07:14:04 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now instantiate the pins */
|
|
|
|
Status = InstantiatePins(DeviceEntry, Connect, DispatchContext, (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* failed */
|
2009-09-12 14:35:27 +00:00
|
|
|
KsFreeObjectHeader(DispatchContext->ObjectHeader);
|
2010-06-19 07:26:20 +00:00
|
|
|
FreeItem(DispatchContext);
|
2009-08-10 07:14:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* store dispatch context */
|
2009-09-12 14:35:27 +00:00
|
|
|
IoStack->FileObject->FsContext = (PVOID)DispatchContext;
|
2009-08-10 07:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME create items for clocks / allocators */
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2009-02-21 20:18:44 +00:00
|
|
|
return Status;
|
|
|
|
}
|