ReactOS 0.4.15-dev-5666-gc548b97
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#ifndef YDEBUG
12#define NDEBUG
13#endif
14
15#include <debug.h>
16
17class CPortDMus : public CUnknownImpl<IPortDMus, ISubdevice>
18{
19public:
21
24 CPortDMus(IUnknown *OuterUnknown){}
25 virtual ~CPortDMus(){}
26
27protected:
28
30 IMiniportDMus * m_pMiniport;
31 IMiniportMidi * m_pMiniportMidi;
37
40
41 friend VOID GetDMusMiniport(IN IPortDMus * iface, IN PMINIPORTDMUS * Miniport, IN PMINIPORTMIDI * MidiMiniport);
42
43};
44
46{
47 {
49 0x6994AD04, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
50 },
51 {
53 0x65E8773E, 0x8F56, 0x11D0, {0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
54 },
55 {
57 0x65E8773D, 0x8F56, 0x11D0, {0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
58 }
59};
60
63
64KSPROPERTY_SET PortDMusPropertySet[] =
65{
66 {
68 sizeof(PortFilterDMusTopologySet) / sizeof(KSPROPERTY_ITEM),
69 (const KSPROPERTY_ITEM*)&PortFilterDMusTopologySet,
70 0,
71 NULL
72 },
73 {
75 sizeof(PortFilterDMusPinSet) / sizeof(KSPROPERTY_ITEM),
76 (const KSPROPERTY_ITEM*)&PortFilterDMusPinSet,
77 0,
78 NULL
79 }
80};
81
82
83//---------------------------------------------------------------
84// IUnknown interface functions
85//
86
90 IN REFIID refiid,
92{
94
95 if (IsEqualGUIDAligned(refiid, IID_IPortDMus) ||
96 IsEqualGUIDAligned(refiid, IID_IPortMidi) ||
97 IsEqualGUIDAligned(refiid, IID_IPort) ||
99 {
100 *Output = PVOID(PUNKNOWN((IPortDMus*)this));
101 PUNKNOWN(*Output)->AddRef();
102 return STATUS_SUCCESS;
103 }
104 else if (IsEqualGUIDAligned(refiid, IID_ISubdevice))
105 {
106 *Output = PVOID(PSUBDEVICE(this));
107 PUNKNOWN(*Output)->AddRef();
108 return STATUS_SUCCESS;
109 }
110 else if (IsEqualGUIDAligned(refiid, IID_IDrmPort) ||
111 IsEqualGUIDAligned(refiid, IID_IDrmPort2))
112 {
113 return NewIDrmPort((PDRMPORT2*)Output);
114 }
115 else if (IsEqualGUIDAligned(refiid, IID_IPortClsVersion))
116 {
118 }
119 else if (IsEqualGUIDAligned(refiid, IID_IUnregisterSubdevice))
120 {
122 }
123 else if (IsEqualGUIDAligned(refiid, IID_IUnregisterPhysicalConnection))
124 {
126 }
127
129 {
130 DPRINT("IPortMidi_fnQueryInterface no interface!!! iface %S\n", GuidString.Buffer);
132 }
133 return STATUS_UNSUCCESSFUL;
134}
135
136//---------------------------------------------------------------
137// IPort interface functions
138//
139
141NTAPI
142CPortDMus::GetDeviceProperty(
143 IN DEVICE_REGISTRY_PROPERTY DeviceRegistryProperty,
147{
149
150 if (!m_bInitialized)
151 {
152 DPRINT("IPortDMus_fnNewRegistryKey called w/o initialized\n");
153 return STATUS_UNSUCCESSFUL;
154 }
155
157}
158
160NTAPI
161CPortDMus::Init(
163 IN PIRP Irp,
164 IN PUNKNOWN UnknownMiniport,
165 IN PUNKNOWN UnknownAdapter OPTIONAL,
167{
168 IMiniportDMus * Miniport = NULL;
169 IMiniportMidi * MidiMiniport = NULL;
171 PSERVICEGROUP ServiceGroup = NULL;
173 PPOWERNOTIFY PowerNotify;
174
176
177 if (m_bInitialized)
178 {
179 DPRINT("IPortDMus_Init called again\n");
180 return STATUS_SUCCESS;
181 }
182
183 Status = UnknownMiniport->QueryInterface(IID_IMiniportDMus, (PVOID*)&Miniport);
184 if (!NT_SUCCESS(Status))
185 {
186 // check for legacy interface
187 Status = UnknownMiniport->QueryInterface(IID_IMiniportMidi, (PVOID*)&MidiMiniport);
188 if (!NT_SUCCESS(Status))
189 {
190 DPRINT("IPortDMus_Init called with invalid IMiniport adapter\n");
192 }
193 }
194
195 // Initialize port object
196 m_pMiniport = Miniport;
197 m_pMiniportMidi = MidiMiniport;
200
201 if (Miniport)
202 {
203 // initialize IMiniportDMus
204 Status = Miniport->Init(UnknownAdapter, ResourceList, this, &ServiceGroup);
205 if (!NT_SUCCESS(Status))
206 {
207 DPRINT("IMiniportDMus_Init failed with %x\n", Status);
209 return Status;
210 }
211
212 // get the miniport device descriptor
213 Status = Miniport->GetDescription(&m_pDescriptor);
214 if (!NT_SUCCESS(Status))
215 {
216 DPRINT("failed to get description\n");
217 Miniport->Release();
219 return Status;
220 }
221
222 // increment reference on miniport adapter
223 Miniport->AddRef();
224
225 }
226 else
227 {
228 // initialize IMiniportMidi
229 Status = MidiMiniport->Init(UnknownAdapter, ResourceList, (IPortMidi*)this, &ServiceGroup);
230 if (!NT_SUCCESS(Status))
231 {
232 DPRINT("IMiniportMidi_Init failed with %x\n", Status);
234 return Status;
235 }
236
237 // get the miniport device descriptor
238 Status = MidiMiniport->GetDescription(&m_pDescriptor);
239 if (!NT_SUCCESS(Status))
240 {
241 DPRINT("failed to get description\n");
242 MidiMiniport->Release();
244 return Status;
245 }
246
247 // increment reference on miniport adapter
248 MidiMiniport->AddRef();
249 }
250
251 // create the subdevice descriptor
253 3,
255 0,
256 NULL,
257 2,
259 0,
260 0,
261 0,
262 NULL,
263 0,
264 NULL,
266
267 if (!NT_SUCCESS(Status))
268 {
269 DPRINT("Failed to create descriptor\n");
270
271 if (Miniport)
272 Miniport->Release();
273 else
274 MidiMiniport->Release();
275
277 return Status;
278 }
279
280 if (m_ServiceGroup == NULL && ServiceGroup)
281 {
282 // register service group
283 m_ServiceGroup = ServiceGroup;
284 }
285
286 // check if it supports IPinCount interface
287 Status = UnknownMiniport->QueryInterface(IID_IPinCount, (PVOID*)&PinCount);
288 if (NT_SUCCESS(Status))
289 {
290 // store IPinCount interface
292 }
293
294 // does the Miniport adapter support IPowerNotify interface*/
295 Status = UnknownMiniport->QueryInterface(IID_IPowerNotify, (PVOID*)&PowerNotify);
296 if (NT_SUCCESS(Status))
297 {
298 // store reference
299 m_pPowerNotify = PowerNotify;
300 }
301
302 return STATUS_SUCCESS;
303}
304
305
307NTAPI
308CPortDMus::NewRegistryKey(
309 OUT PREGISTRYKEY *OutRegistryKey,
310 IN PUNKNOWN OuterUnknown OPTIONAL,
311 IN ULONG RegistryKeyType,
316{
318
319 if (!m_bInitialized)
320 {
321 DPRINT("IPortDMus_fnNewRegistryKey called w/o initialized\n");
322 return STATUS_UNSUCCESSFUL;
323 }
324
325 return PcNewRegistryKey(OutRegistryKey,
326 OuterUnknown,
327 RegistryKeyType,
330 (ISubdevice*)this,
334}
335
336VOID
337NTAPI
338CPortDMus::Notify(
339 IN PSERVICEGROUP ServiceGroup OPTIONAL)
340{
341 if (ServiceGroup)
342 {
343 ServiceGroup->RequestService ();
344 return;
345 }
346
348
349 // notify miniport service group
350 m_ServiceGroup->RequestService();
351
352 // notify stream miniport service group
353 if (m_Filter)
354 {
355 m_Filter->NotifyPins();
356 }
357}
358
359VOID
360NTAPI
361CPortDMus::RegisterServiceGroup(
362 IN PSERVICEGROUP ServiceGroup)
363{
365
366 m_ServiceGroup = ServiceGroup;
367
368 ServiceGroup->AddMember(PSERVICESINK(this));
369}
370//---------------------------------------------------------------
371// ISubdevice interface
372//
373
375NTAPI
376CPortDMus::NewIrpTarget(
377 OUT struct IIrpTarget **OutTarget,
378 IN PCWSTR Name,
382 IN PIRP Irp,
383 IN KSOBJECT_CREATE *CreateObject)
384{
387
388 DPRINT("ISubDevice_NewIrpTarget this %p\n", this);
389
390 if (m_Filter)
391 {
392 *OutTarget = (IIrpTarget*)m_Filter;
393 return STATUS_SUCCESS;
394 }
395
396
398 if (!NT_SUCCESS(Status))
399 {
400 return Status;
401 }
402
403 Status = Filter->Init(PPORTDMUS(this));
404 if (!NT_SUCCESS(Status))
405 {
406 Filter->Release();
407 return Status;
408 }
409
410 *OutTarget = (IIrpTarget*)Filter;
411 return Status;
412}
413
415NTAPI
416CPortDMus::ReleaseChildren()
417{
419 return STATUS_UNSUCCESSFUL;
420}
421
423NTAPI
424CPortDMus::GetDescriptor(
426{
427 DPRINT("ISubDevice_GetDescriptor this %p\n", this);
429 return STATUS_SUCCESS;
430}
431
433NTAPI
434CPortDMus::DataRangeIntersection(
435 IN ULONG PinId,
436 IN PKSDATARANGE DataRange,
437 IN PKSDATARANGE MatchingDataRange,
439 OUT PVOID ResultantFormat OPTIONAL,
440 OUT PULONG ResultantFormatLength)
441{
442 DPRINT("ISubDevice_DataRangeIntersection this %p\n", this);
443
444 if (m_pMiniport)
445 {
446 return m_pMiniport->DataRangeIntersection (PinId, DataRange, MatchingDataRange, OutputBufferLength, ResultantFormat, ResultantFormatLength);
447 }
448
449 return STATUS_UNSUCCESSFUL;
450}
451
453NTAPI
454CPortDMus::PowerChangeNotify(
456{
457 if (m_pPowerNotify)
458 {
459 m_pPowerNotify->PowerChangeNotify(PowerState);
460 }
461
462 return STATUS_SUCCESS;
463}
464
465
467NTAPI
468CPortDMus::PinCount(
469 IN ULONG PinId,
470 IN OUT PULONG FilterNecessary,
471 IN OUT PULONG FilterCurrent,
472 IN OUT PULONG FilterPossible,
473 IN OUT PULONG GlobalCurrent,
474 IN OUT PULONG GlobalPossible)
475{
476 if (m_pPinCount)
477 {
478 m_pPinCount->PinCount(PinId, FilterNecessary, FilterCurrent, FilterPossible, GlobalCurrent, GlobalPossible);
479 return STATUS_SUCCESS;
480 }
481
482 // FIXME
483 // scan filter descriptor
484
485 return STATUS_UNSUCCESSFUL;
486}
487
488
489
492 OUT PPORT* OutPort)
493{
496 if (!Port)
498
499 Status = Port->QueryInterface(IID_IPort, (PVOID*)OutPort);
500
501 if (!NT_SUCCESS(Status))
502 {
503 delete Port;
504 }
505
506 DPRINT("NewPortDMus %p Status %u\n", Port, Status);
507 return Status;
508
509}
510
511
512
513VOID
515 IN IPortDMus * iface,
516 IN PMINIPORTDMUS * Miniport,
517 IN PMINIPORTMIDI * MidiMiniport)
518{
519 CPortDMus * This = (CPortDMus*)iface;
520
521 *Miniport = This->m_pMiniport;
522 *MidiMiniport = This->m_pMiniportMidi;
523}
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: debug.h:115
PPORTFILTERDMUS m_Filter
Definition: port_dmus.cpp:36
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor
Definition: port_dmus.cpp:39
BOOL m_bInitialized
Definition: port_dmus.cpp:29
DEVICE_OBJECT * m_pDeviceObject
Definition: port_dmus.cpp:32
IMiniportMidi * m_pMiniportMidi
Definition: port_dmus.cpp:31
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: port_dmus.cpp:89
virtual ~CPortDMus()
Definition: port_dmus.cpp:25
PSERVICEGROUP m_ServiceGroup
Definition: port_dmus.cpp:33
IMiniportDMus * m_pMiniport
Definition: port_dmus.cpp:30
PPCFILTER_DESCRIPTOR m_pDescriptor
Definition: port_dmus.cpp:38
CPortDMus(IUnknown *OuterUnknown)
Definition: port_dmus.cpp:24
PPOWERNOTIFY m_pPowerNotify
Definition: port_dmus.cpp:35
friend VOID GetDMusMiniport(IN IPortDMus *iface, IN PMINIPORTDMUS *Miniport, IN PMINIPORTMIDI *MidiMiniport)
Definition: port_dmus.cpp:514
PPINCOUNT m_pPinCount
Definition: port_dmus.cpp:34
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
NTSTATUS NTAPI NewIUnregisterPhysicalConnection(OUT PUNREGISTERPHYSICALCONNECTION *OutConnection)
Definition: connection.cpp:128
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:32
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:268
NTSTATUS NewIDrmPort(OUT PDRMPORT2 *OutPort)
Definition: drm_port.cpp:125
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
unsigned int * PULONG
Definition: retypes.h:1
void * PVOID
Definition: retypes.h:9
unsigned int ULONG
Definition: retypes.h:1
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:1952
NTSTATUS NewPortDMus(OUT PPORT *OutPort)
Definition: port_dmus.cpp:491
KSPROPERTY_SET PortDMusPropertySet[]
Definition: port_dmus.cpp:64
static GUID InterfaceGuids[3]
Definition: port_dmus.cpp:45
VOID GetDMusMiniport(IN IPortDMus *iface, IN PMINIPORTDMUS *Miniport, IN PMINIPORTMIDI *MidiMiniport)
Definition: port_dmus.cpp:514
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:122
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:730
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
NTSTATUS NewPortClsVersion(OUT PPORTCLSVERSION *OutVersion)
Definition: version.cpp:71
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:71
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
_In_ const GUID _In_ ULONG PinCount
Definition: strmini.h:505
const uint16_t * PCWSTR
Definition: typedefs.h:57
INT POOL_TYPE
Definition: typedefs.h:78
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#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