Sync to trunk head (r40091)
[reactos.git] / reactos / drivers / wdm / audio / sysaudio / pin.c
1 /*
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
7 */
8
9 #include <ntifs.h>
10 #include <ntddk.h>
11 #include <portcls.h>
12 #include <ks.h>
13 #include <ksmedia.h>
14 #include <math.h>
15 #define YDEBUG
16 #include <debug.h>
17 #include "sysaudio.h"
18
19 NTSTATUS
20 NTAPI
21 Pin_fnDeviceIoControl(
22 PDEVICE_OBJECT DeviceObject,
23 PIRP Irp)
24 {
25 PDISPATCH_CONTEXT Context;
26 NTSTATUS Status;
27 ULONG BytesReturned;
28 PIO_STACK_LOCATION IoStack;
29
30 DPRINT1("Pin_fnDeviceIoControl called DeviceObject %p Irp %p\n", DeviceObject);
31
32 IoStack = IoGetCurrentIrpStackLocation(Irp);
33
34 Context = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext2;
35 ASSERT(Context);
36
37 Status = KsSynchronousIoControlDevice(Context->FileObject, KernelMode, IoStack->Parameters.DeviceIoControl.IoControlCode,
38 IoStack->Parameters.DeviceIoControl.Type3InputBuffer,
39 IoStack->Parameters.DeviceIoControl.InputBufferLength,
40 Irp->UserBuffer,
41 IoStack->Parameters.DeviceIoControl.OutputBufferLength,
42 &BytesReturned);
43
44 DPRINT1("Status %x\n", Status);
45
46 Irp->IoStatus.Information = BytesReturned;
47 Irp->IoStatus.Status = Status;
48 IoCompleteRequest(Irp, IO_NO_INCREMENT);
49 return Status;
50 }
51
52 NTSTATUS
53 NTAPI
54 Pin_fnRead(
55 PDEVICE_OBJECT DeviceObject,
56 PIRP Irp)
57 {
58 DPRINT1("Pin_fnRead called DeviceObject %p Irp %p\n", DeviceObject);
59
60 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
61 Irp->IoStatus.Information = 0;
62 IoCompleteRequest(Irp, IO_NO_INCREMENT);
63 return STATUS_UNSUCCESSFUL;
64 }
65
66 NTSTATUS
67 NTAPI
68 PinWriteCompletionRoutine(
69 IN PDEVICE_OBJECT DeviceObject,
70 IN PIRP Irp,
71 IN PVOID Context)
72 {
73 PIRP CIrp = (PIRP)Context;
74
75 CIrp->IoStatus.Status = STATUS_SUCCESS;
76 CIrp->IoStatus.Information = 0;
77 IoCompleteRequest(CIrp, IO_NO_INCREMENT);
78 return STATUS_SUCCESS;
79 }
80
81 NTSTATUS
82 NTAPI
83 Pin_fnWrite(
84 PDEVICE_OBJECT DeviceObject,
85 PIRP Irp)
86 {
87 PDISPATCH_CONTEXT Context;
88 PIO_STACK_LOCATION IoStack;
89 ULONG BytesReturned;
90 NTSTATUS Status;
91
92 DPRINT1("Pin_fnWrite called DeviceObject %p Irp %p\n", DeviceObject);
93
94 IoStack = IoGetCurrentIrpStackLocation(Irp);
95
96 Context = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext2;
97 ASSERT(Context);
98
99 Status = KsSynchronousIoControlDevice(Context->FileObject, KernelMode, IOCTL_KS_WRITE_STREAM,
100 MmGetMdlVirtualAddress(Irp->MdlAddress),
101 IoStack->Parameters.Write.Length,
102 NULL,
103 0,
104 &BytesReturned);
105
106 Irp->IoStatus.Information = BytesReturned;
107 Irp->IoStatus.Status = Status;
108 IoCompleteRequest(Irp, IO_NO_INCREMENT);
109 return Status;
110 }
111
112 NTSTATUS
113 NTAPI
114 Pin_fnFlush(
115 PDEVICE_OBJECT DeviceObject,
116 PIRP Irp)
117 {
118 DPRINT1("Pin_fnFlush called DeviceObject %p Irp %p\n", DeviceObject);
119
120 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
121 Irp->IoStatus.Information = 0;
122 IoCompleteRequest(Irp, IO_NO_INCREMENT);
123 return STATUS_UNSUCCESSFUL;
124 }
125
126 NTSTATUS
127 NTAPI
128 Pin_fnClose(
129 PDEVICE_OBJECT DeviceObject,
130 PIRP Irp)
131 {
132 DPRINT1("Pin_fnClose called DeviceObject %p Irp %p\n", DeviceObject);
133
134 Irp->IoStatus.Status = STATUS_SUCCESS;
135 Irp->IoStatus.Information = 0;
136 IoCompleteRequest(Irp, IO_NO_INCREMENT);
137 return STATUS_SUCCESS;
138 }
139
140 NTSTATUS
141 NTAPI
142 Pin_fnQuerySecurity(
143 PDEVICE_OBJECT DeviceObject,
144 PIRP Irp)
145 {
146 DPRINT1("Pin_fnQuerySecurity called DeviceObject %p Irp %p\n", DeviceObject);
147
148 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
149 Irp->IoStatus.Information = 0;
150 IoCompleteRequest(Irp, IO_NO_INCREMENT);
151 return STATUS_UNSUCCESSFUL;
152 }
153
154 NTSTATUS
155 NTAPI
156 Pin_fnSetSecurity(
157 PDEVICE_OBJECT DeviceObject,
158 PIRP Irp)
159 {
160
161 DPRINT1("Pin_fnSetSecurity called DeviceObject %p Irp %p\n", DeviceObject);
162
163 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
164 Irp->IoStatus.Information = 0;
165 IoCompleteRequest(Irp, IO_NO_INCREMENT);
166 return STATUS_UNSUCCESSFUL;
167 }
168
169 BOOLEAN
170 NTAPI
171 Pin_fnFastDeviceIoControl(
172 PFILE_OBJECT FileObject,
173 BOOLEAN Wait,
174 PVOID InputBuffer,
175 ULONG InputBufferLength,
176 PVOID OutputBuffer,
177 ULONG OutputBufferLength,
178 ULONG IoControlCode,
179 PIO_STATUS_BLOCK IoStatus,
180 PDEVICE_OBJECT DeviceObject)
181 {
182 DPRINT1("Pin_fnFastDeviceIoControl called DeviceObject %p Irp %p\n", DeviceObject);
183
184
185 return FALSE;
186 }
187
188
189 BOOLEAN
190 NTAPI
191 Pin_fnFastRead(
192 PFILE_OBJECT FileObject,
193 PLARGE_INTEGER FileOffset,
194 ULONG Length,
195 BOOLEAN Wait,
196 ULONG LockKey,
197 PVOID Buffer,
198 PIO_STATUS_BLOCK IoStatus,
199 PDEVICE_OBJECT DeviceObject)
200 {
201 DPRINT1("Pin_fnFastRead called DeviceObject %p Irp %p\n", DeviceObject);
202
203 return FALSE;
204
205 }
206
207 BOOLEAN
208 NTAPI
209 Pin_fnFastWrite(
210 PFILE_OBJECT FileObject,
211 PLARGE_INTEGER FileOffset,
212 ULONG Length,
213 BOOLEAN Wait,
214 ULONG LockKey,
215 PVOID Buffer,
216 PIO_STATUS_BLOCK IoStatus,
217 PDEVICE_OBJECT DeviceObject)
218 {
219 PDISPATCH_CONTEXT Context;
220 NTSTATUS Status;
221
222 //DPRINT1("Pin_fnFastWrite called DeviceObject %p Irp %p\n", DeviceObject);
223
224 Context = (PDISPATCH_CONTEXT)FileObject->FsContext2;
225
226 #if 1
227 if (Context->hMixerPin && Context->MixerFileObject)
228 {
229 Status = KsStreamIo(Context->MixerFileObject, NULL, NULL, NULL, NULL, 0, IoStatus, Buffer, Length, KSSTREAM_WRITE, KernelMode);
230 if (!NT_SUCCESS(Status))
231 {
232 DPRINT1("Mixing stream failed with %lx\n", Status);
233 return FALSE;
234 }
235 }
236 #endif
237 Status = KsStreamIo(Context->FileObject, NULL, NULL, NULL, NULL, 0, IoStatus, Buffer, Length, KSSTREAM_WRITE, KernelMode);
238 if (Status == STATUS_SUCCESS)
239 return TRUE;
240 else
241 return FALSE;
242 }
243
244 static KSDISPATCH_TABLE PinTable =
245 {
246 Pin_fnDeviceIoControl,
247 Pin_fnRead,
248 Pin_fnWrite,
249 Pin_fnFlush,
250 Pin_fnClose,
251 Pin_fnQuerySecurity,
252 Pin_fnSetSecurity,
253 Pin_fnFastDeviceIoControl,
254 Pin_fnFastRead,
255 Pin_fnFastWrite,
256 };
257
258 NTSTATUS
259 CreateDispatcher(
260 IN PIRP Irp)
261 {
262 NTSTATUS Status;
263 KSOBJECT_HEADER ObjectHeader;
264
265 /* allocate object header */
266 Status = KsAllocateObjectHeader(&ObjectHeader, 0, NULL, Irp, &PinTable);
267 return Status;
268 }