3d3c9f462a1d001dd8a0fff69e1d7bdf819a71db
[reactos.git] / drivers / wdm / audio / filters / kmixer / filter.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/filters/kmixer/filter.c
5 * PURPOSE: Filter File Context Header header
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9 #include "kmixer.h"
10
11 NTSTATUS
12 NTAPI
13 Dispatch_fnDeviceIoControl(
14 PDEVICE_OBJECT DeviceObject,
15 PIRP Irp)
16 {
17 PIO_STACK_LOCATION IoStack;
18
19 IoStack = IoGetCurrentIrpStackLocation(Irp);
20
21 UNIMPLEMENTED
22
23 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
24 Irp->IoStatus.Information = 0;
25 IoCompleteRequest(Irp, IO_NO_INCREMENT);
26 return STATUS_UNSUCCESSFUL;
27 }
28
29 NTSTATUS
30 NTAPI
31 Dispatch_fnClose(
32 PDEVICE_OBJECT DeviceObject,
33 PIRP Irp)
34 {
35 UNIMPLEMENTED
36
37 Irp->IoStatus.Status = STATUS_SUCCESS;
38 Irp->IoStatus.Information = 0;
39 IoCompleteRequest(Irp, IO_NO_INCREMENT);
40 return STATUS_SUCCESS;
41 }
42
43 static KSDISPATCH_TABLE DispatchTable =
44 {
45 Dispatch_fnDeviceIoControl,
46 KsDispatchInvalidDeviceRequest,
47 KsDispatchInvalidDeviceRequest,
48 KsDispatchInvalidDeviceRequest,
49 Dispatch_fnClose,
50 KsDispatchInvalidDeviceRequest,
51 KsDispatchInvalidDeviceRequest,
52 KsDispatchFastIoDeviceControlFailure,
53 KsDispatchFastWriteFailure,
54 KsDispatchFastWriteFailure,
55 };
56
57 NTSTATUS
58 NTAPI
59 DispatchCreateKMixPin(
60 IN PDEVICE_OBJECT DeviceObject,
61 IN PIRP Irp)
62 {
63 NTSTATUS Status;
64
65 DPRINT("DispatchCreateKMix entered\n");
66
67 /* create the pin */
68 Status = CreatePin(Irp);
69
70 /* save result */
71 Irp->IoStatus.Status = Status;
72 /* complete the request */
73 IoCompleteRequest(Irp, IO_NO_INCREMENT);
74 /* done */
75 return Status;
76 }
77
78 NTSTATUS
79 NTAPI
80 DispatchCreateKMixAllocator(
81 IN PDEVICE_OBJECT DeviceObject,
82 IN PIRP Irp)
83 {
84 NTSTATUS Status;
85
86 /* create the allocator */
87 Status = KsCreateDefaultAllocator(Irp);
88
89 /* save result */
90 Irp->IoStatus.Status = Status;
91 /* complete the request */
92 IoCompleteRequest(Irp, IO_NO_INCREMENT);
93 /* done */
94 return Status;
95 }
96
97 NTSTATUS
98 NTAPI
99 DispatchCreateKMix(
100 IN PDEVICE_OBJECT DeviceObject,
101 IN PIRP Irp)
102 {
103 NTSTATUS Status;
104 KSOBJECT_HEADER ObjectHeader;
105 PKSOBJECT_CREATE_ITEM CreateItem;
106 PKMIXER_DEVICE_EXT DeviceExtension;
107
108 DPRINT("DispatchCreateKMix entered\n");
109
110 /* check if the request was from usermode */
111 if (Irp->RequestorMode == UserMode)
112 {
113 /* deny access from usermode */
114 Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
115 Irp->IoStatus.Information = 0;
116 IoCompleteRequest(Irp, IO_NO_INCREMENT);
117 return STATUS_INVALID_DEVICE_REQUEST;
118 }
119
120 /* get device extension */
121 DeviceExtension = (PKMIXER_DEVICE_EXT)DeviceObject->DeviceExtension;
122
123 #if 0
124 /* reference the software bus object */
125 Status = KsReferenceSoftwareBusObject(DeviceExtension->KsDeviceHeader);
126
127 if (!NT_SUCCESS(Status))
128 {
129 /* failed to reference bus object */
130 Irp->IoStatus.Status = Status;
131 Irp->IoStatus.Information = 0;
132 IoCompleteRequest(Irp, IO_NO_INCREMENT);
133 return Status;
134 }
135 #endif
136
137 /* allocate create item */
138 CreateItem = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM) * 2);
139 if (!CreateItem)
140 {
141 /* not enough memory */
142 Irp->IoStatus.Information = 0;
143 Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
144 IoCompleteRequest(Irp, IO_NO_INCREMENT);
145 return STATUS_INSUFFICIENT_RESOURCES;
146 }
147
148 /* zero create struct */
149 RtlZeroMemory(CreateItem, sizeof(KSOBJECT_CREATE_ITEM) * 2);
150
151 /* initialize pin create item */
152 CreateItem[0].Create = DispatchCreateKMixPin;
153 RtlInitUnicodeString(&CreateItem[0].ObjectClass, KSSTRING_Pin);
154 CreateItem[1].Create = DispatchCreateKMixAllocator;
155 RtlInitUnicodeString(&CreateItem[1].ObjectClass, KSSTRING_Allocator);
156
157 /* allocate object header */
158 Status = KsAllocateObjectHeader(&ObjectHeader, 2, CreateItem, Irp, &DispatchTable);
159
160 if (!NT_SUCCESS(Status))
161 {
162 /* failed to allocate object header */
163 ExFreePool(CreateItem);
164 KsDereferenceSoftwareBusObject(DeviceExtension->KsDeviceHeader);
165 }
166
167 DPRINT("KsAllocateObjectHeader result %x\n", Status);
168 /* complete the irp */
169 Irp->IoStatus.Information = 0;
170 Irp->IoStatus.Status = Status;
171 IoCompleteRequest(Irp, IO_NO_INCREMENT);
172 return Status;
173 }
174
175 NTSTATUS
176 NTAPI
177 KMixAllocateDeviceHeader(
178 IN PKMIXER_DEVICE_EXT DeviceExtension)
179 {
180 NTSTATUS Status;
181 PKSOBJECT_CREATE_ITEM CreateItem;
182
183 /* allocate create item */
184 CreateItem = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM) * 2);
185 if (!CreateItem)
186 return STATUS_INSUFFICIENT_RESOURCES;
187
188 /* initialize create item struct */
189 RtlZeroMemory(CreateItem, sizeof(KSOBJECT_CREATE_ITEM) * 2);
190 CreateItem[0].Create = DispatchCreateKMix;
191 RtlInitUnicodeString(&CreateItem[0].ObjectClass, L"GLOBAL");
192 CreateItem[1].Create = DispatchCreateKMix;
193 RtlInitUnicodeString(&CreateItem[1].ObjectClass, KSSTRING_Filter);
194
195 Status = KsAllocateDeviceHeader(&DeviceExtension->KsDeviceHeader,
196 2,
197 CreateItem);
198 return Status;
199 }
200