winsta: fix spec file
[reactos.git] / reactos / drivers / wdm / audio / backpln / portcls / undoc.cpp
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/backpln/portcls/api.cpp
5 * PURPOSE: Port api functions
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9 #include "private.hpp"
10
11 NTSTATUS
12 NTAPI
13 KsoDispatchCreateWithGenericFactory(
14 LONG Unknown,
15 PIRP Irp)
16 {
17 UNIMPLEMENTED;
18 return STATUS_NOT_IMPLEMENTED;
19 }
20
21 IIrpTarget *
22 NTAPI
23 KsoGetIrpTargetFromFileObject(
24 PFILE_OBJECT FileObject)
25 {
26 PC_ASSERT(FileObject);
27
28 // IrpTarget is stored in FsContext
29 return (IIrpTarget*)FileObject->FsContext;
30 }
31
32 IIrpTarget *
33 NTAPI
34 KsoGetIrpTargetFromIrp(
35 PIRP Irp)
36 {
37 PKSOBJECT_CREATE_ITEM CreateItem;
38
39 // access the create item
40 CreateItem = KSCREATE_ITEM_IRP_STORAGE(Irp);
41
42 // IIrpTarget is stored in Context member
43 return (IIrpTarget*)CreateItem->Context;
44 }
45
46 VOID
47 NTAPI
48 PcAcquireFormatResources(
49 LONG Unknown,
50 LONG Unknown2,
51 LONG Unknown3,
52 LONG Unknown4)
53 {
54 UNIMPLEMENTED;
55 }
56
57 NTSTATUS
58 PcAddToEventTable(
59 PVOID Ptr,
60 LONG Unknown2,
61 ULONG Length,
62 LONG Unknown3,
63 LONG Unknown4,
64 LONG Unknown5,
65 LONG Unknown6,
66 LONG Unknown7)
67 {
68 UNIMPLEMENTED;
69 return STATUS_NOT_IMPLEMENTED;
70 }
71
72 NTSTATUS
73 PcAddToPropertyTable(
74 PVOID Ptr,
75 LONG Unknown,
76 LONG Unknown2,
77 LONG Unknown3,
78 CHAR Unknown4)
79 {
80 UNIMPLEMENTED;
81 return STATUS_NOT_IMPLEMENTED;
82 }
83
84 NTSTATUS
85 PcCaptureFormat(
86 LONG Unknown,
87 LONG Unknown2,
88 LONG Unknown3,
89 LONG Unknown4)
90 {
91 UNIMPLEMENTED;
92 return STATUS_NOT_IMPLEMENTED;
93 }
94
95 NTSTATUS
96 AddToPropertyTable(
97 IN OUT SUBDEVICE_DESCRIPTOR * Descriptor,
98 IN KSPROPERTY_SET * FilterProperty)
99 {
100 if (Descriptor->FilterPropertySet.FreeKsPropertySetOffset >= Descriptor->FilterPropertySet.MaxKsPropertySetCount)
101 {
102 DPRINT1("FIXME\n");
103 return STATUS_UNSUCCESSFUL;
104 }
105
106 RtlMoveMemory(&Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset],
107 FilterProperty,
108 sizeof(KSPROPERTY_SET));
109
110 if (FilterProperty->PropertiesCount)
111 {
112 Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].PropertyItem = (const KSPROPERTY_ITEM*)AllocateItem(NonPagedPool,
113 sizeof(KSPROPERTY_ITEM) * FilterProperty->PropertiesCount,
114 TAG_PORTCLASS);
115
116 if (!Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].PropertyItem)
117 {
118 Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].PropertiesCount = 0;
119 return STATUS_INSUFFICIENT_RESOURCES;
120 }
121 RtlMoveMemory((PVOID)Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].PropertyItem,
122 FilterProperty->PropertyItem,
123 sizeof(KSPROPERTY_ITEM) * FilterProperty->PropertiesCount);
124
125 }
126 Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].Set = (const GUID *)AllocateItem(NonPagedPool, sizeof(GUID), TAG_PORTCLASS);
127 if (!Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].Set)
128 return STATUS_INSUFFICIENT_RESOURCES;
129
130 RtlCopyMemory((PVOID)Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].Set, FilterProperty->Set, sizeof(GUID));
131
132 // ignore fast io table for now
133 Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].FastIoCount = 0;
134 Descriptor->FilterPropertySet.Properties[Descriptor->FilterPropertySet.FreeKsPropertySetOffset].FastIoTable = NULL;
135
136 Descriptor->FilterPropertySet.FreeKsPropertySetOffset++;
137
138 return STATUS_SUCCESS;
139 }
140
141 NTSTATUS
142 NTAPI
143 PcCreateSubdeviceDescriptor(
144 OUT SUBDEVICE_DESCRIPTOR ** OutSubdeviceDescriptor,
145 IN ULONG InterfaceCount,
146 IN GUID * InterfaceGuids,
147 IN ULONG IdentifierCount,
148 IN KSIDENTIFIER *Identifier,
149 IN ULONG FilterPropertiesCount,
150 IN KSPROPERTY_SET * FilterProperties,
151 IN ULONG Unknown1,
152 IN ULONG Unknown2,
153 IN ULONG PinPropertiesCount,
154 IN KSPROPERTY_SET * PinProperties,
155 IN ULONG EventSetCount,
156 IN KSEVENT_SET * EventSet,
157 IN PPCFILTER_DESCRIPTOR FilterDescription)
158 {
159 SUBDEVICE_DESCRIPTOR * Descriptor;
160 ULONG Index, SubIndex;
161 PKSDATARANGE DataRange;
162 NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
163
164 Descriptor = (PSUBDEVICE_DESCRIPTOR)AllocateItem(NonPagedPool, sizeof(SUBDEVICE_DESCRIPTOR), TAG_PORTCLASS);
165 if (!Descriptor)
166 return STATUS_INSUFFICIENT_RESOURCES;
167
168 Descriptor->Interfaces = (GUID*)AllocateItem(NonPagedPool, sizeof(GUID) * InterfaceCount, TAG_PORTCLASS);
169 if (!Descriptor->Interfaces)
170 goto cleanup;
171
172 // copy interface guids
173 RtlCopyMemory(Descriptor->Interfaces, InterfaceGuids, sizeof(GUID) * InterfaceCount);
174 Descriptor->InterfaceCount = InterfaceCount;
175
176 if (FilterPropertiesCount)
177 {
178 /// FIXME
179 /// handle driver properties
180 Descriptor->FilterPropertySet.Properties = (PKSPROPERTY_SET)AllocateItem(NonPagedPool, sizeof(KSPROPERTY_SET) * FilterPropertiesCount, TAG_PORTCLASS);
181 if (! Descriptor->FilterPropertySet.Properties)
182 goto cleanup;
183
184 Descriptor->FilterPropertySet.MaxKsPropertySetCount = FilterPropertiesCount;
185 for(Index = 0; Index < FilterPropertiesCount; Index++)
186 {
187 Status = AddToPropertyTable(Descriptor, &FilterProperties[Index]);
188 if (!NT_SUCCESS(Status))
189 goto cleanup;
190 }
191 }
192
193 Descriptor->Topology = (PKSTOPOLOGY)AllocateItem(NonPagedPool, sizeof(KSTOPOLOGY), TAG_PORTCLASS);
194 if (!Descriptor->Topology)
195 goto cleanup;
196
197 if (FilterDescription->ConnectionCount)
198 {
199 Descriptor->Topology->TopologyConnections = (PKSTOPOLOGY_CONNECTION)AllocateItem(NonPagedPool, sizeof(KSTOPOLOGY_CONNECTION) * FilterDescription->ConnectionCount, TAG_PORTCLASS);
200 if (!Descriptor->Topology->TopologyConnections)
201 goto cleanup;
202
203 RtlMoveMemory((PVOID)Descriptor->Topology->TopologyConnections, FilterDescription->Connections, FilterDescription->ConnectionCount * sizeof(PCCONNECTION_DESCRIPTOR));
204 Descriptor->Topology->TopologyConnectionsCount = FilterDescription->ConnectionCount;
205 }
206
207 if (FilterDescription->NodeCount)
208 {
209 Descriptor->Topology->TopologyNodes = (const GUID *)AllocateItem(NonPagedPool, sizeof(GUID) * FilterDescription->NodeCount, TAG_PORTCLASS);
210 if (!Descriptor->Topology->TopologyNodes)
211 goto cleanup;
212
213 Descriptor->Topology->TopologyNodesNames = (const GUID *)AllocateItem(NonPagedPool, sizeof(GUID) * FilterDescription->NodeCount, TAG_PORTCLASS);
214 if (!Descriptor->Topology->TopologyNodesNames)
215 goto cleanup;
216
217 for(Index = 0; Index < FilterDescription->NodeCount; Index++)
218 {
219 if (FilterDescription->Nodes[Index].Type)
220 {
221 RtlMoveMemory((PVOID)&Descriptor->Topology->TopologyNodes[Index], FilterDescription->Nodes[Index].Type, sizeof(GUID));
222 }
223 if (FilterDescription->Nodes[Index].Name)
224 {
225 RtlMoveMemory((PVOID)&Descriptor->Topology->TopologyNodesNames[Index], FilterDescription->Nodes[Index].Name, sizeof(GUID));
226 }
227 }
228 Descriptor->Topology->TopologyNodesCount = FilterDescription->NodeCount;
229 }
230
231 if (FilterDescription->PinCount)
232 {
233 Descriptor->Factory.KsPinDescriptor = (PKSPIN_DESCRIPTOR)AllocateItem(NonPagedPool, FilterDescription->PinSize * FilterDescription->PinCount, TAG_PORTCLASS);
234 if (!Descriptor->Factory.KsPinDescriptor)
235 goto cleanup;
236
237 Descriptor->Factory.Instances = (PPIN_INSTANCE_INFO)AllocateItem(NonPagedPool, FilterDescription->PinCount * sizeof(PIN_INSTANCE_INFO), TAG_PORTCLASS);
238 if (!Descriptor->Factory.Instances)
239 goto cleanup;
240
241 Descriptor->Factory.PinDescriptorCount = FilterDescription->PinCount;
242 Descriptor->Factory.PinDescriptorSize = FilterDescription->PinSize;
243
244 // copy pin factories
245 for(Index = 0; Index < FilterDescription->PinCount; Index++)
246 {
247 RtlMoveMemory(&Descriptor->Factory.KsPinDescriptor[Index], &FilterDescription->Pins[Index].KsPinDescriptor, FilterDescription->PinSize);
248
249 if (FilterDescription->Pins[Index].KsPinDescriptor.DataRangesCount)
250 {
251 Descriptor->Factory.KsPinDescriptor[Index].DataRanges = (const PKSDATARANGE*)AllocateItem(NonPagedPool, FilterDescription->Pins[Index].KsPinDescriptor.DataRangesCount * sizeof(PKSDATARANGE), TAG_PORTCLASS);
252 if(!Descriptor->Factory.KsPinDescriptor[Index].DataRanges)
253 goto cleanup;
254
255 for (SubIndex = 0; SubIndex < FilterDescription->Pins[Index].KsPinDescriptor.DataRangesCount; SubIndex++)
256 {
257 DataRange = (PKSDATARANGE)AllocateItem(NonPagedPool, FilterDescription->Pins[Index].KsPinDescriptor.DataRanges[SubIndex]->FormatSize, TAG_PORTCLASS);
258 if (!DataRange)
259 goto cleanup;
260
261 RtlMoveMemory(DataRange,
262 FilterDescription->Pins[Index].KsPinDescriptor.DataRanges[SubIndex],
263 FilterDescription->Pins[Index].KsPinDescriptor.DataRanges[SubIndex]->FormatSize);
264
265 ((PKSDATAFORMAT*)Descriptor->Factory.KsPinDescriptor[Index].DataRanges)[SubIndex] = DataRange;
266
267 }
268
269 Descriptor->Factory.KsPinDescriptor[Index].DataRangesCount = FilterDescription->Pins[Index].KsPinDescriptor.DataRangesCount;
270 }
271
272 Descriptor->Factory.Instances[Index].CurrentPinInstanceCount = 0;
273 Descriptor->Factory.Instances[Index].MaxFilterInstanceCount = FilterDescription->Pins[Index].MaxFilterInstanceCount;
274 Descriptor->Factory.Instances[Index].MaxGlobalInstanceCount = FilterDescription->Pins[Index].MaxGlobalInstanceCount;
275 Descriptor->Factory.Instances[Index].MinFilterInstanceCount = FilterDescription->Pins[Index].MinFilterInstanceCount;
276 }
277 }
278 Descriptor->DeviceDescriptor = FilterDescription;
279 *OutSubdeviceDescriptor = Descriptor;
280 return STATUS_SUCCESS;
281
282 cleanup:
283 if (Descriptor)
284 {
285 if (Descriptor->Interfaces)
286 FreeItem(Descriptor->Interfaces, TAG_PORTCLASS);
287
288 if (Descriptor->Factory.KsPinDescriptor)
289 FreeItem(Descriptor->Factory.KsPinDescriptor, TAG_PORTCLASS);
290
291 FreeItem(Descriptor, TAG_PORTCLASS);
292 }
293 return Status;
294 }
295
296 NTSTATUS
297 NTAPI
298 PcValidateConnectRequest(
299 IN PIRP Irp,
300 IN KSPIN_FACTORY * Factory,
301 OUT PKSPIN_CONNECT * Connect)
302 {
303 return KsValidateConnectRequest(Irp, Factory->PinDescriptorCount, Factory->KsPinDescriptor, Connect);
304 }
305