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
13 Pin_fnDeviceIoControl(
14 PDEVICE_OBJECT DeviceObject
,
17 PDISPATCH_CONTEXT Context
;
20 PFILE_OBJECT FileObject
;
21 PIO_STACK_LOCATION IoStack
;
23 DPRINT("Pin_fnDeviceIoControl called DeviceObject %p Irp %p\n", DeviceObject
);
25 /* Get current stack location */
26 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
28 /* The dispatch context is stored in the FsContext2 member */
29 Context
= (PDISPATCH_CONTEXT
)IoStack
->FileObject
->FsContext2
;
34 /* acquire real pin file object */
35 Status
= ObReferenceObjectByHandle(Context
->Handle
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
36 if (!NT_SUCCESS(Status
))
38 Irp
->IoStatus
.Information
= 0;
39 Irp
->IoStatus
.Status
= Status
;
40 /* Complete the irp */
41 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
45 /* Re-dispatch the request to the real target pin */
46 Status
= KsSynchronousIoControlDevice(FileObject
, KernelMode
, IoStack
->Parameters
.DeviceIoControl
.IoControlCode
,
47 IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
,
48 IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
,
50 IoStack
->Parameters
.DeviceIoControl
.OutputBufferLength
,
52 /* release file object */
53 ObDereferenceObject(FileObject
);
55 /* Save status and information */
56 Irp
->IoStatus
.Information
= BytesReturned
;
57 Irp
->IoStatus
.Status
= Status
;
58 /* Complete the irp */
59 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
67 PDEVICE_OBJECT DeviceObject
,
70 PDISPATCH_CONTEXT Context
;
71 PIO_STACK_LOCATION IoStack
;
73 PFILE_OBJECT FileObject
;
76 /* Get current stack location */
77 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
79 /* The dispatch context is stored in the FsContext2 member */
80 Context
= (PDISPATCH_CONTEXT
)IoStack
->FileObject
->FsContext2
;
85 /* acquire real pin file object */
86 Status
= ObReferenceObjectByHandle(Context
->Handle
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
87 if (!NT_SUCCESS(Status
))
89 Irp
->IoStatus
.Information
= 0;
90 Irp
->IoStatus
.Status
= Status
;
91 /* Complete the irp */
92 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
96 /* Re-dispatch the request to the real target pin */
97 Status
= KsSynchronousIoControlDevice(FileObject
, KernelMode
, IOCTL_KS_READ_STREAM
,
98 MmGetMdlVirtualAddress(Irp
->MdlAddress
),
99 IoStack
->Parameters
.Read
.Length
,
104 /* release file object */
105 ObDereferenceObject(FileObject
);
107 if (Context
->hMixerPin
)
110 // call kmixer to convert stream
114 /* Save status and information */
115 Irp
->IoStatus
.Status
= Status
;
116 Irp
->IoStatus
.Information
= 0;
117 /* Complete the irp */
118 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
126 PDEVICE_OBJECT DeviceObject
,
129 PDISPATCH_CONTEXT Context
;
130 PIO_STACK_LOCATION IoStack
;
132 PFILE_OBJECT FileObject
;
135 /* Get current stack location */
136 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
138 /* The dispatch context is stored in the FsContext2 member */
139 Context
= (PDISPATCH_CONTEXT
)IoStack
->FileObject
->FsContext2
;
144 if (Context
->hMixerPin
)
147 // call kmixer to convert stream
151 /* acquire real pin file object */
152 Status
= ObReferenceObjectByHandle(Context
->Handle
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
153 if (!NT_SUCCESS(Status
))
155 Irp
->IoStatus
.Information
= 0;
156 Irp
->IoStatus
.Status
= Status
;
157 /* Complete the irp */
158 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
162 /* Re-dispatch the request to the real target pin */
163 Status
= KsSynchronousIoControlDevice(FileObject
, KernelMode
, IOCTL_KS_WRITE_STREAM
,
164 MmGetMdlVirtualAddress(Irp
->MdlAddress
),
165 IoStack
->Parameters
.Read
.Length
,
170 /* release file object */
171 ObDereferenceObject(FileObject
);
173 /* Save status and information */
174 Irp
->IoStatus
.Status
= Status
;
175 Irp
->IoStatus
.Information
= 0;
176 /* Complete the irp */
177 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
185 PDEVICE_OBJECT DeviceObject
,
188 PDISPATCH_CONTEXT Context
;
189 PIO_STACK_LOCATION IoStack
;
190 PDEVICE_OBJECT PinDeviceObject
;
192 PFILE_OBJECT FileObject
;
193 IO_STATUS_BLOCK IoStatus
;
195 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
197 /* Get current stack location */
198 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
200 /* The dispatch context is stored in the FsContext2 member */
201 Context
= (PDISPATCH_CONTEXT
)IoStack
->FileObject
->FsContext2
;
207 /* acquire real pin file object */
208 Status
= ObReferenceObjectByHandle(Context
->Handle
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
209 if (!NT_SUCCESS(Status
))
211 Irp
->IoStatus
.Information
= 0;
212 Irp
->IoStatus
.Status
= Status
;
213 /* Complete the irp */
214 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
218 /* Get Pin's device object */
219 PinDeviceObject
= IoGetRelatedDeviceObject(FileObject
);
221 /* release file object */
222 ObDereferenceObject(FileObject
);
224 /* Initialize notification event */
225 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
227 /* build target irp */
228 PinIrp
= IoBuildSynchronousFsdRequest(IRP_MJ_FLUSH_BUFFERS
, PinDeviceObject
, NULL
, 0, NULL
, &Event
, &IoStatus
);
232 /* Get the next stack location */
233 IoStack
= IoGetNextIrpStackLocation(PinIrp
);
234 /* The file object must be present in the irp as it contains the KSOBJECT_HEADER */
235 IoStack
->FileObject
= FileObject
;
237 /* call the driver */
238 Status
= IoCallDriver(PinDeviceObject
, PinIrp
);
239 /* Has request already completed ? */
240 if (Status
== STATUS_PENDING
)
242 /* Wait untill the request has completed */
243 KeWaitForSingleObject(&Event
, UserRequest
, KernelMode
, FALSE
, NULL
);
245 Status
= IoStatus
.Status
;
250 Irp
->IoStatus
.Status
= Status
;
251 Irp
->IoStatus
.Information
= 0;
252 /* Complete the irp */
253 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
261 PDEVICE_OBJECT DeviceObject
,
264 PDISPATCH_CONTEXT Context
;
265 PIO_STACK_LOCATION IoStack
;
267 DPRINT("Pin_fnClose called DeviceObject %p Irp %p\n", DeviceObject
);
269 /* Get current stack location */
270 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
272 /* The dispatch context is stored in the FsContext2 member */
273 Context
= (PDISPATCH_CONTEXT
)IoStack
->FileObject
->FsContext2
;
277 ZwClose(Context
->Handle
);
279 ZwClose(Context
->hMixerPin
);
283 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
284 Irp
->IoStatus
.Information
= 0;
285 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
286 return STATUS_SUCCESS
;
292 PDEVICE_OBJECT DeviceObject
,
295 DPRINT("Pin_fnQuerySecurity called DeviceObject %p Irp %p\n", DeviceObject
);
297 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
298 Irp
->IoStatus
.Information
= 0;
299 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
300 return STATUS_UNSUCCESSFUL
;
306 PDEVICE_OBJECT DeviceObject
,
310 DPRINT("Pin_fnSetSecurity called DeviceObject %p Irp %p\n", DeviceObject
);
312 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
313 Irp
->IoStatus
.Information
= 0;
314 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
315 return STATUS_UNSUCCESSFUL
;
320 Pin_fnFastDeviceIoControl(
321 PFILE_OBJECT FileObject
,
324 ULONG InputBufferLength
,
326 ULONG OutputBufferLength
,
328 PIO_STATUS_BLOCK IoStatus
,
329 PDEVICE_OBJECT DeviceObject
)
331 DPRINT("Pin_fnFastDeviceIoControl called DeviceObject %p Irp %p\n", DeviceObject
);
341 PFILE_OBJECT FileObject
,
342 PLARGE_INTEGER FileOffset
,
347 PIO_STATUS_BLOCK IoStatus
,
348 PDEVICE_OBJECT DeviceObject
)
350 DPRINT("Pin_fnFastRead called DeviceObject %p Irp %p\n", DeviceObject
);
359 PFILE_OBJECT FileObject
,
360 PLARGE_INTEGER FileOffset
,
365 PIO_STATUS_BLOCK IoStatus
,
366 PDEVICE_OBJECT DeviceObject
)
368 PDISPATCH_CONTEXT Context
;
369 PFILE_OBJECT RealFileObject
;
372 DPRINT("Pin_fnFastWrite called DeviceObject %p Irp %p\n", DeviceObject
);
374 Context
= (PDISPATCH_CONTEXT
)FileObject
->FsContext2
;
376 if (Context
->hMixerPin
)
378 Status
= ObReferenceObjectByHandle(Context
->hMixerPin
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&RealFileObject
, NULL
);
379 if (NT_SUCCESS(Status
))
381 Status
= KsStreamIo(RealFileObject
, NULL
, NULL
, NULL
, NULL
, 0, IoStatus
, Buffer
, Length
, KSSTREAM_WRITE
, KernelMode
);
382 ObDereferenceObject(RealFileObject
);
385 if (!NT_SUCCESS(Status
))
387 DPRINT1("Mixing stream failed with %lx\n", Status
);
392 Status
= ObReferenceObjectByHandle(Context
->Handle
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&RealFileObject
, NULL
);
393 if (!NT_SUCCESS(Status
))
396 Status
= KsStreamIo(RealFileObject
, NULL
, NULL
, NULL
, NULL
, 0, IoStatus
, Buffer
, Length
, KSSTREAM_WRITE
, KernelMode
);
398 ObDereferenceObject(RealFileObject
);
400 if (Status
== STATUS_SUCCESS
)
406 static KSDISPATCH_TABLE PinTable
=
408 Pin_fnDeviceIoControl
,
415 Pin_fnFastDeviceIoControl
,
425 KSOBJECT_HEADER ObjectHeader
;
427 /* allocate object header */
428 Status
= KsAllocateObjectHeader(&ObjectHeader
, 0, NULL
, Irp
, &PinTable
);