ReactOS 0.4.16-dev-329-g9223134
filter.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/legacy/stream/filter.c
5 * PURPOSE: filter instance handling
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9
10#include "stream.h"
11
12
17 IN PIRP Irp)
18{
20
21 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
22 Irp->IoStatus.Information = 0;
25}
26
27
32 PIRP Irp)
33{
34 DPRINT1("FilterDispatch Called\n");
35
36 Irp->IoStatus.Status = STATUS_SUCCESS;
37 Irp->IoStatus.Information = 0;
39 return STATUS_SUCCESS;
40}
41
42
47 PIRP Irp)
48{
50 PSTREAM_DEVICE_EXTENSION DeviceExtension;
51 HW_STREAM_REQUEST_BLOCK_EXT RequestBlock;
52
53 /* Get device extension */
55
57 {
58 /* driver supports only one instance */
59 if (DeviceExtension->InstanceCount)
60 {
61 /* there is already one instance open */
63 }
64 }
65 else
66 {
67 /* driver supports more than one filter instance */
68 RtlZeroMemory(&RequestBlock, sizeof(HW_STREAM_REQUEST_BLOCK_EXT));
69
70 /* set up request block */
72 RequestBlock.Block.HwDeviceExtension = DeviceExtension->DeviceExtension;
73 RequestBlock.Block.Irp = Irp;
75
76 /*FIXME SYNCHRONIZATION */
77
78 /* Send the request */
79 DeviceExtension->DriverExtension->Data.HwReceivePacket((PHW_STREAM_REQUEST_BLOCK)&RequestBlock);
80 if (RequestBlock.Block.Status == STATUS_PENDING)
81 {
82 /* Wait for the request */
83 KeWaitForSingleObject(&RequestBlock.Event, Executive, KernelMode, FALSE, NULL);
84 }
85 }
86
87 /* Increment total instance count */
88 InterlockedDecrement(&DeviceExtension->InstanceCount);
89
90 Irp->IoStatus.Status = Status;
91 Irp->IoStatus.Information = 0;
93 return Status;
94}
95
96static KSDISPATCH_TABLE DispatchTable =
97{
103 NULL,
104 NULL,
105 NULL,
106 NULL,
107 NULL
108};
109
110VOID
112 IN PSTREAM_DEVICE_EXTENSION DeviceExtension)
113{
114 ULONG Index;
115 PHW_STREAM_INFORMATION StreamInformation;
118
119 /* Sanity check */
120 ASSERT(DeviceExtension->StreamDescriptor);
121 ASSERT(DeviceExtension->StreamDescriptorSize);
122
123 /* Loop all stream descriptors and register device interfaces */
124 StreamInformation = (PHW_STREAM_INFORMATION)&DeviceExtension->StreamDescriptor->StreamInfo;
125
126 for(Index = 0; DeviceExtension->StreamDescriptor->StreamHeader.NumberOfStreams; Index++)
127 {
128 if (StreamInformation->Category)
129 {
130 /* Register device interface */
131 Status = IoRegisterDeviceInterface(DeviceExtension->PhysicalDeviceObject,
132 StreamInformation->Category,
133 NULL, /* see CORE-4218 and r42457 */
134 &SymbolicLink);
135
136 if (NT_SUCCESS(Status))
137 {
138 /* Activate device interface */
140 /* Release Symbolic Link */
142 }
143 }
144 StreamInformation = (PHW_STREAM_INFORMATION) (ULONG_PTR)StreamInformation + DeviceExtension->StreamDescriptor->StreamHeader.SizeOfHwStreamInformation;
145 }
146
147}
148
152 IN PIRP Irp)
153{
155 PSTREAM_DEVICE_EXTENSION DeviceExtension;
156 KSOBJECT_HEADER ObjectHeader;
157 PKSOBJECT_CREATE_ITEM CreateItem;
158 PIO_STACK_LOCATION IoStack;
159 HW_STREAM_REQUEST_BLOCK_EXT RequestBlock;
160 PVOID HwInstanceExtension = NULL;
161
162 /* Get device extension */
164
166 {
167 /* driver supports only one instance */
168 if (DeviceExtension->InstanceCount)
169 {
170 /* there is already one instance open */
171 return STATUS_UNSUCCESSFUL;
172 }
173 }
174 else
175 {
176 /* driver supports more than one filter instance */
177 RtlZeroMemory(&RequestBlock, sizeof(HW_STREAM_REQUEST_BLOCK_EXT));
178
179 /* allocate instance extension */
180 HwInstanceExtension = ExAllocatePool(NonPagedPool, DeviceExtension->DriverExtension->Data.FilterInstanceExtensionSize);
181 if (!HwInstanceExtension)
182 {
183 /* Not enough memory */
185 }
186
187 /* Zero instance extension */
188 RtlZeroMemory(HwInstanceExtension, DeviceExtension->DriverExtension->Data.FilterInstanceExtensionSize);
189
190 /* set up request block */
192 RequestBlock.Block.HwDeviceExtension = DeviceExtension->DeviceExtension;
193 RequestBlock.Block.Irp = Irp;
194 RequestBlock.Block.HwInstanceExtension = HwInstanceExtension;
196
197 /*FIXME SYNCHRONIZATION */
198
199 /* Send the request */
200 DeviceExtension->DriverExtension->Data.HwReceivePacket((PHW_STREAM_REQUEST_BLOCK)&RequestBlock);
201 if (RequestBlock.Block.Status == STATUS_PENDING)
202 {
203 /* Wait for the request */
204 KeWaitForSingleObject(&RequestBlock.Event, Executive, KernelMode, FALSE, NULL);
205 }
206 /* Check for success */
207 if (!NT_SUCCESS(RequestBlock.Block.Status))
208 {
209 /* Resource is not available */
210 ExFreePool(HwInstanceExtension);
211 return RequestBlock.Block.Status;
212 }
213 }
214
215 /* Allocate create item */
216 CreateItem = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM));
217 if (!CreateItem)
218 {
219 /* not enough memory */
221 }
222
223 /* Zero create item */
224 RtlZeroMemory(CreateItem, sizeof(KSOBJECT_CREATE_ITEM));
225 /* Initialize createitem */
228
229 /* Get current irp stack location */
231 /* Create Ks streaming object header */
233 if (!NT_SUCCESS(Status))
234 {
235 /* Failed to create header */
237 if (HwInstanceExtension)
238 {
239 /* free instance buffer */
240 ExFreePool(HwInstanceExtension);
241 }
242 return Status;
243 }
244
245 /* Store instance buffer in file object context */
246 IoStack->FileObject->FsContext2 = HwInstanceExtension;
247
248 /* Increment total instance count */
249 InterlockedIncrement(&DeviceExtension->InstanceCount);
250
251 /* Register device stream interfaces */
252 RegisterDeviceInterfaces(DeviceExtension);
253
254 /* Return result */
255 return Status;
256
257}
258
260NTAPI
263 IN PIRP Irp)
264{
266 DPRINT1("StreamClassCreateFilter Called\n");
267
268 /* Init filter */
270
271 Irp->IoStatus.Status = Status;
272 Irp->IoStatus.Information = 0;
274 return Status;
275}
276
277
278
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static const WCHAR SymbolicLink[]
Definition: interface.c:31
KSDDKAPI NTSTATUS NTAPI KsAllocateObjectHeader(OUT KSOBJECT_HEADER *Header, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL, IN PIRP Irp, IN KSDISPATCH_TABLE *Table)
Definition: api.c:610
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1189
NTSTATUS NTAPI StreamClassCreatePin(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:15
VOID RegisterDeviceInterfaces(IN PSTREAM_DEVICE_EXTENSION DeviceExtension)
Definition: filter.c:111
NTSTATUS InitializeFilterWithKs(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:150
NTSTATUS NTAPI FilterDispatch_fnClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filter.c:45
NTSTATUS NTAPI FilterDispatch_fnDeviceIoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filter.c:30
NTSTATUS NTAPI StreamClassCreateFilter(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:261
struct STREAM_DEVICE_EXTENSION * PSTREAM_DEVICE_EXTENSION
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
static CABITEM * CreateItem(LPCWSTR Path, UINT Attrib, UINT Size, UINT DateTime)
Definition: folder.cpp:69
Status
Definition: gdiplustypes.h:25
#define KSSTRING_Pin
Definition: ks.h:48
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define KernelMode
Definition: asm.h:34
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
@ SynchronizationEvent
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define IoCompleteRequest
Definition: irp.c:1240
Console I/O streams.
#define STATUS_SUCCESS
Definition: shellext.h:65
@ SRB_OPEN_DEVICE_INSTANCE
Definition: strmini.h:194
@ SRB_CLOSE_DEVICE_INSTANCE
Definition: strmini.h:195
struct _HW_STREAM_INFORMATION * PHW_STREAM_INFORMATION
HW_STREAM_REQUEST_BLOCK Block
Definition: stream.h:54
HW_INITIALIZATION_DATA Data
Definition: stream.h:14
PSTREAM_CLASS_DRIVER_EXTENSION DriverExtension
Definition: stream.h:45
PHW_RECEIVE_DEVICE_SRB HwReceivePacket
Definition: strmini.h:356
ULONG FilterInstanceExtensionSize
Definition: strmini.h:362
SRB_COMMAND Command
Definition: strmini.h:224
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:248
#define IO_NO_INCREMENT
Definition: iotypes.h:598
@ Executive
Definition: ketypes.h:415