ReactOS 0.4.16-dev-320-g3bd9ddc
port_dmus.cpp
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/backpln/portcls/port_dmus.cpp
5 * PURPOSE: DirectMusic Port driver
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9#include "private.hpp"
10
11#define NDEBUG
12#include <debug.h>
13
14class CPortDMus : public CUnknownImpl<IPortDMus, ISubdevice>
15{
16public:
18
21 CPortDMus(IUnknown *OuterUnknown){}
22 virtual ~CPortDMus(){}
23
24protected:
25
27 IMiniportDMus * m_pMiniport;
28 IMiniportMidi * m_pMiniportMidi;
34
37
38 friend VOID GetDMusMiniport(IN IPortDMus * iface, IN PMINIPORTDMUS * Miniport, IN PMINIPORTMIDI * MidiMiniport);
39
40};
41
43{
44 {
46 0x6994AD04, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
47 },
48 {
50 0x65E8773E, 0x8F56, 0x11D0, {0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
51 },
52 {
54 0x65E8773D, 0x8F56, 0x11D0, {0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
55 }
56};
57
60
61KSPROPERTY_SET PortDMusPropertySet[] =
62{
63 {
65 sizeof(PortFilterDMusTopologySet) / sizeof(KSPROPERTY_ITEM),
66 (const KSPROPERTY_ITEM*)&PortFilterDMusTopologySet,
67 0,
68 NULL
69 },
70 {
72 sizeof(PortFilterDMusPinSet) / sizeof(KSPROPERTY_ITEM),
73 (const KSPROPERTY_ITEM*)&PortFilterDMusPinSet,
74 0,
75 NULL
76 }
77};
78
79//---------------------------------------------------------------
80// IUnknown interface functions
81//
82
86 IN REFIID refiid,
88{
90
91 if (IsEqualGUIDAligned(refiid, IID_IPortDMus) ||
92 IsEqualGUIDAligned(refiid, IID_IPortMidi) ||
93 IsEqualGUIDAligned(refiid, IID_IPort) ||
95 {
96 *Output = PVOID(PUNKNOWN((IPortDMus*)this));
97 PUNKNOWN(*Output)->AddRef();
98 return STATUS_SUCCESS;
99 }
100 else if (IsEqualGUIDAligned(refiid, IID_ISubdevice))
101 {
102 *Output = PVOID(PSUBDEVICE(this));
103 PUNKNOWN(*Output)->AddRef();
104 return STATUS_SUCCESS;
105 }
106 else if (IsEqualGUIDAligned(refiid, IID_IDrmPort) ||
107 IsEqualGUIDAligned(refiid, IID_IDrmPort2))
108 {
109 return NewIDrmPort((PDRMPORT2*)Output);
110 }
111 else if (IsEqualGUIDAligned(refiid, IID_IPortClsVersion))
112 {
114 }
115 else if (IsEqualGUIDAligned(refiid, IID_IUnregisterSubdevice))
116 {
118 }
119 else if (IsEqualGUIDAligned(refiid, IID_IUnregisterPhysicalConnection))
120 {
122 }
123
125 {
126 DPRINT("IPortMidi_fnQueryInterface no interface!!! iface %S\n", GuidString.Buffer);
128 }
129 return STATUS_UNSUCCESSFUL;
130}
131
132//---------------------------------------------------------------
133// IPort interface functions
134//
135
137NTAPI
138CPortDMus::GetDeviceProperty(
139 IN DEVICE_REGISTRY_PROPERTY DeviceRegistryProperty,
143{
145
146 if (!m_bInitialized)
147 {
148 DPRINT("IPortDMus_fnNewRegistryKey called w/o initialized\n");
149 return STATUS_UNSUCCESSFUL;
150 }
151
153}
154
156NTAPI
157CPortDMus::Init(
159 IN PIRP Irp,
160 IN PUNKNOWN UnknownMiniport,
161 IN PUNKNOWN UnknownAdapter OPTIONAL,
163{
164 IMiniportDMus * Miniport = NULL;
165 IMiniportMidi * MidiMiniport = NULL;
167 PSERVICEGROUP ServiceGroup = NULL;
169 PPOWERNOTIFY PowerNotify;
170
172
173 if (m_bInitialized)
174 {
175 DPRINT("IPortDMus_Init called again\n");
176 return STATUS_SUCCESS;
177 }
178
179 Status = UnknownMiniport->QueryInterface(IID_IMiniportDMus, (PVOID*)&Miniport);
180 if (!NT_SUCCESS(Status))
181 {
182 // check for legacy interface
183 Status = UnknownMiniport->QueryInterface(IID_IMiniportMidi, (PVOID*)&MidiMiniport);
184 if (!NT_SUCCESS(Status))
185 {
186 DPRINT("IPortDMus_Init called with invalid IMiniport adapter\n");
188 }
189 }
190
191 // Initialize port object
192 m_pMiniport = Miniport;
193 m_pMiniportMidi = MidiMiniport;
196
197 if (Miniport)
198 {
199 // initialize IMiniportDMus
200 Status = Miniport->Init(UnknownAdapter, ResourceList, this, &ServiceGroup);
201 if (!NT_SUCCESS(Status))
202 {
203 DPRINT("IMiniportDMus_Init failed with %x\n", Status);
205 return Status;
206 }
207
208 // get the miniport device descriptor
209 Status = Miniport->GetDescription(&m_pDescriptor);
210 if (!NT_SUCCESS(Status))
211 {
212 DPRINT("failed to get description\n");
213 Miniport->Release();
215 return Status;
216 }
217
218 // increment reference on miniport adapter
219 Miniport->AddRef();
220
221 }
222 else
223 {
224 // initialize IMiniportMidi
225 Status = MidiMiniport->Init(UnknownAdapter, ResourceList, (IPortMidi*)this, &ServiceGroup);
226 if (!NT_SUCCESS(Status))
227 {
228 DPRINT("IMiniportMidi_Init failed with %x\n", Status);
230 return Status;
231 }
232
233 // get the miniport device descriptor
234 Status = MidiMiniport->GetDescription(&m_pDescriptor);
235 if (!NT_SUCCESS(Status))
236 {
237 DPRINT("failed to get description\n");
238 MidiMiniport->Release();
240 return Status;
241 }
242
243 // increment reference on miniport adapter
244 MidiMiniport->AddRef();
245 }
246
247 // create the subdevice descriptor
249 3,
251 0,
252 NULL,
253 2,
255 0,
256 0,
257 0,
258 NULL,
259 0,
260 NULL,
262
263 if (!NT_SUCCESS(Status))
264 {
265 DPRINT("Failed to create descriptor\n");
266
267 if (Miniport)
268 Miniport->Release();
269 else
270 MidiMiniport->Release();
271
273 return Status;
274 }
275
276 if (m_ServiceGroup == NULL && ServiceGroup)
277 {
278 // register service group
279 m_ServiceGroup = ServiceGroup;
280 }
281
282 // check if it supports IPinCount interface
283 Status = UnknownMiniport->QueryInterface(IID_IPinCount, (PVOID*)&PinCount);
284 if (NT_SUCCESS(Status))
285 {
286 // store IPinCount interface
288 }
289
290 // does the Miniport adapter support IPowerNotify interface*/
291 Status = UnknownMiniport->QueryInterface(IID_IPowerNotify, (PVOID*)&PowerNotify);
292 if (NT_SUCCESS(Status))
293 {
294 // store reference
295 m_pPowerNotify = PowerNotify;
296 }
297
298 return STATUS_SUCCESS;
299}
300
302NTAPI
303CPortDMus::NewRegistryKey(
304 OUT PREGISTRYKEY *OutRegistryKey,
305 IN PUNKNOWN OuterUnknown OPTIONAL,
306 IN ULONG RegistryKeyType,
311{
313
314 if (!m_bInitialized)
315 {
316 DPRINT("IPortDMus_fnNewRegistryKey called w/o initialized\n");
317 return STATUS_UNSUCCESSFUL;
318 }
319
320 return PcNewRegistryKey(OutRegistryKey,
321 OuterUnknown,
322 RegistryKeyType,
325 (ISubdevice*)this,
329}
330
331VOID
332NTAPI
333CPortDMus::Notify(
334 IN PSERVICEGROUP ServiceGroup OPTIONAL)
335{
336 if (ServiceGroup)
337 {
338 ServiceGroup->RequestService ();
339 return;
340 }
341
343
344 // notify miniport service group
345 m_ServiceGroup->RequestService();
346
347 // notify stream miniport service group
348 if (m_Filter)
349 {
350 m_Filter->NotifyPins();
351 }
352}
353
354VOID
355NTAPI
356CPortDMus::RegisterServiceGroup(
357 IN PSERVICEGROUP ServiceGroup)
358{
360
361 m_ServiceGroup = ServiceGroup;
362
363 ServiceGroup->AddMember(PSERVICESINK(this));
364}
365//---------------------------------------------------------------
366// ISubdevice interface
367//
368
370NTAPI
371CPortDMus::NewIrpTarget(
372 OUT struct IIrpTarget **OutTarget,
373 IN PCWSTR Name,
377 IN PIRP Irp,
378 IN KSOBJECT_CREATE *CreateObject)
379{
382
383 DPRINT("ISubDevice_NewIrpTarget this %p\n", this);
384
385 if (m_Filter)
386 {
387 *OutTarget = (IIrpTarget*)m_Filter;
388 return STATUS_SUCCESS;
389 }
390
392 if (!NT_SUCCESS(Status))
393 {
394 return Status;
395 }
396
397 Status = Filter->Init(PPORTDMUS(this));
398 if (!NT_SUCCESS(Status))
399 {
400 Filter->Release();
401 return Status;
402 }
403
404 *OutTarget = (IIrpTarget*)Filter;
405 return Status;
406}
407
409NTAPI
410CPortDMus::ReleaseChildren()
411{
413 return STATUS_UNSUCCESSFUL;
414}
415
417NTAPI
418CPortDMus::GetDescriptor(
420{
421 DPRINT("ISubDevice_GetDescriptor this %p\n", this);
423 return STATUS_SUCCESS;
424}
425
427NTAPI
428CPortDMus::DataRangeIntersection(
429 IN ULONG PinId,
430 IN PKSDATARANGE DataRange,
431 IN PKSDATARANGE MatchingDataRange,
433 OUT PVOID ResultantFormat OPTIONAL,
434 OUT PULONG ResultantFormatLength)
435{
436 DPRINT("ISubDevice_DataRangeIntersection this %p\n", this);
437
438 if (m_pMiniport)
439 {
440 return m_pMiniport->DataRangeIntersection (PinId, DataRange, MatchingDataRange, OutputBufferLength, ResultantFormat, ResultantFormatLength);
441 }
442
443 return STATUS_UNSUCCESSFUL;
444}
445
447NTAPI
448CPortDMus::PowerChangeNotify(
450{
451 if (m_pPowerNotify)
452 {
453 m_pPowerNotify->PowerChangeNotify(PowerState);
454 }
455
456 return STATUS_SUCCESS;
457}
458
460NTAPI
461CPortDMus::PinCount(
462 IN ULONG PinId,
463 IN OUT PULONG FilterNecessary,
464 IN OUT PULONG FilterCurrent,
465 IN OUT PULONG FilterPossible,
466 IN OUT PULONG GlobalCurrent,
467 IN OUT PULONG GlobalPossible)
468{
469 if (m_pPinCount)
470 {
471 m_pPinCount->PinCount(PinId, FilterNecessary, FilterCurrent, FilterPossible, GlobalCurrent, GlobalPossible);
472 return STATUS_SUCCESS;
473 }
474
475 // FIXME
476 // scan filter descriptor
477
478 return STATUS_UNSUCCESSFUL;
479}
480
483 OUT PPORT* OutPort)
484{
487 if (!Port)
489
490 Status = Port->QueryInterface(IID_IPort, (PVOID*)OutPort);
491
492 if (!NT_SUCCESS(Status))
493 {
494 delete Port;
495 }
496
497 DPRINT("NewPortDMus %p Status %u\n", Port, Status);
498 return Status;
499
500}
501
502VOID
504 IN IPortDMus * iface,
505 IN PMINIPORTDMUS * Miniport,
506 IN PMINIPORTMIDI * MidiMiniport)
507{
508 CPortDMus * This = (CPortDMus*)iface;
509
510 *Miniport = This->m_pMiniport;
511 *MidiMiniport = This->m_pMiniportMidi;
512}
IPortFilterDMus * PPORTFILTERDMUS
Definition: interfaces.hpp:839
ISubdevice * PSUBDEVICE
Definition: interfaces.hpp:307
LONG NTSTATUS
Definition: precomp.h:26
#define STDMETHODIMP
Definition: basetyps.h:43
const GUID IID_IUnknown
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
PPORTFILTERDMUS m_Filter
Definition: port_dmus.cpp:33
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor
Definition: port_dmus.cpp:36
BOOL m_bInitialized
Definition: port_dmus.cpp:26
DEVICE_OBJECT * m_pDeviceObject
Definition: port_dmus.cpp:29
IMiniportMidi * m_pMiniportMidi
Definition: port_dmus.cpp:28
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: port_dmus.cpp:85
virtual ~CPortDMus()
Definition: port_dmus.cpp:22
PSERVICEGROUP m_ServiceGroup
Definition: port_dmus.cpp:30
IMiniportDMus * m_pMiniport
Definition: port_dmus.cpp:27
PPCFILTER_DESCRIPTOR m_pDescriptor
Definition: port_dmus.cpp:35
CPortDMus(IUnknown *OuterUnknown)
Definition: port_dmus.cpp:21
PPOWERNOTIFY m_pPowerNotify
Definition: port_dmus.cpp:32
friend VOID GetDMusMiniport(IN IPortDMus *iface, IN PMINIPORTDMUS *Miniport, IN PMINIPORTMIDI *MidiMiniport)
Definition: port_dmus.cpp:503
PPINCOUNT m_pPinCount
Definition: port_dmus.cpp:31
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
NTSTATUS NTAPI NewIUnregisterPhysicalConnection(OUT PUNREGISTERPHYSICALCONNECTION *OutConnection)
Definition: connection.cpp:124
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ PIRP Irp
Definition: csq.h:116
#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
IPortDMus * PPORTDMUS
Definition: dmusicks.h:168
IMiniportDMus * PMINIPORTDMUS
Definition: dmusicks.h:211
#define DEFINE_KSPROPERTY_PINPROPOSEDATAFORMAT(PinSet, PropGeneral, PropInstances, PropIntersection)
Definition: precomp.h:20
NTSTATUS NTAPI PcNewRegistryKey(OUT PREGISTRYKEY *OutRegistryKey, IN PUNKNOWN OuterUnknown OPTIONAL, IN ULONG RegistryKeyType, IN ACCESS_MASK DesiredAccess, IN PVOID DeviceObject OPTIONAL, IN PVOID SubDevice OPTIONAL, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN ULONG CreateOptions OPTIONAL, OUT PULONG Disposition OPTIONAL)
Definition: registry.cpp:264
NTSTATUS NewIDrmPort(OUT PDRMPORT2 *OutPort)
Definition: drm_port.cpp:122
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define NonPagedPool
Definition: env_spec_w32.h:307
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS NewPortFilterDMus(OUT PPORTFILTERDMUS *OutFilter)
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1801
Status
Definition: gdiplustypes.h:25
CPPORT Port[4]
Definition: headless.c:35
@ Unknown
Definition: i8042prt.h:114
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
ULONG AddRef()
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
nsrefcnt AddRef()
nsrefcnt Release()
#define KSPROPSETID_Pin
Definition: ks.h:617
#define DEFINE_KSPROPERTY_TOPOLOGYSET(TopologySet, Handler)
Definition: ks.h:2663
#define KSPROPSETID_Topology
Definition: ks.h:842
static PWSTR GuidString
Definition: apphelp.c:93
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
NTSTATUS NewPortDMus(OUT PPORT *OutPort)
Definition: port_dmus.cpp:482
KSPROPERTY_SET PortDMusPropertySet[]
Definition: port_dmus.cpp:61
static GUID InterfaceGuids[3]
Definition: port_dmus.cpp:42
VOID GetDMusMiniport(IN IPortDMus *iface, IN PMINIPORTDMUS *Miniport, IN PMINIPORTMIDI *MidiMiniport)
Definition: port_dmus.cpp:503
IRegistryKey * PREGISTRYKEY
Definition: portcls.h:1009
IPinCount * PPINCOUNT
Definition: portcls.h:2091
IServiceSink * PSERVICESINK
Definition: portcls.h:569
IResourceList * PRESOURCELIST
Definition: portcls.h:442
IUnregisterSubdevice * PUNREGISTERSUBDEVICE
Definition: portcls.h:635
IPortClsVersion * PPORTCLSVERSION
Definition: portcls.h:2263
IUnregisterPhysicalConnection * PUNREGISTERPHYSICALCONNECTION
Definition: portcls.h:677
IDrmPort2 * PDRMPORT2
Definition: portcls.h:2228
IServiceGroup * PSERVICEGROUP
Definition: portcls.h:614
IMiniportMidi * PMINIPORTMIDI
Definition: portcls.h:1378
IPowerNotify * PPOWERNOTIFY
Definition: portcls.h:2059
IPort * PPORT
Definition: portcls.h:1105
NTSTATUS NTAPI PinPropertyHandler(IN PIRP Irp, IN PKSIDENTIFIER Request, IN OUT PVOID Data)
NTSTATUS NTAPI NewIUnregisterSubdevice(OUT PUNREGISTERSUBDEVICE *OutDevice)
Definition: unregister.cpp:119
NTSTATUS NTAPI PcCreateSubdeviceDescriptor(OUT SUBDEVICE_DESCRIPTOR **OutSubdeviceDescriptor, IN ULONG InterfaceCount, IN GUID *InterfaceGuids, IN ULONG IdentifierCount, IN KSIDENTIFIER *Identifier, IN ULONG FilterPropertiesCount, IN KSPROPERTY_SET *FilterProperties, IN ULONG Unknown1, IN ULONG Unknown2, IN ULONG PinPropertiesCount, IN KSPROPERTY_SET *PinProperties, IN ULONG EventSetCount, IN KSEVENT_SET *EventSet, IN PPCFILTER_DESCRIPTOR FilterDescription)
Definition: undoc.cpp:717
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
NTSTATUS NewPortClsVersion(OUT PPORTCLSVERSION *OutVersion)
Definition: version.cpp:66
NTSTATUS NTAPI TopologyPropertyHandler(IN PIRP Irp, IN PKSIDENTIFIER Request, IN OUT PVOID Data)
#define TAG_PORTCLASS
Definition: private.hpp:24
#define PC_ASSERT(exp)
Definition: private.hpp:26
#define REFIID
Definition: guiddef.h:118
@ Output
Definition: arc.h:85
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
_In_ const GUID _In_ ULONG PinCount
Definition: strmini.h:505
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
INT POOL_TYPE
Definition: typedefs.h:78
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID PropertyBuffer
Definition: wdfdevice.h:4437
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
DEVICE_REGISTRY_PROPERTY
Definition: iotypes.h:1194