ReactOS  0.4.14-dev-41-g31d7680
filter_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/filter_dmus.cpp
5  * PURPOSE: portcls wave pci filter
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 
17 class CPortFilterDMus : public IPortFilterDMus
18 {
19 public:
21 
23  {
25  return m_Ref;
26  }
28  {
30 
31  if (!m_Ref)
32  {
33  delete this;
34  return 0;
35  }
36  return m_Ref;
37  }
39  CPortFilterDMus(IUnknown *OuterUnknown){}
40  virtual ~CPortFilterDMus(){}
41 
42 protected:
43  IPortDMus* m_Port;
44  IPortPinDMus ** m_Pins;
47 };
48 
50 NTAPI
52  IN REFIID refiid,
53  OUT PVOID* Output)
54 {
55 
56  if (IsEqualGUIDAligned(refiid, IID_IIrpTarget) ||
58  {
59  *Output = PVOID(PUNKNOWN(this));
60  PUNKNOWN(*Output)->AddRef();
61  return STATUS_SUCCESS;
62  }
63  else if (IsEqualGUIDAligned(refiid, IID_IPort))
64  {
66  PUNKNOWN(*Output)->AddRef();
67  return STATUS_SUCCESS;
68  }
69 
70  return STATUS_UNSUCCESSFUL;
71 }
72 
74 NTAPI
75 CPortFilterDMus::NewIrpTarget(
76  OUT struct IIrpTarget **OutTarget,
77  IN PCWSTR Name,
81  IN PIRP Irp,
82  IN KSOBJECT_CREATE *CreateObject)
83 {
85  IPortPinDMus * Pin;
86  PKSPIN_CONNECT ConnectDetails;
87 
91 
92  DPRINT("CPortFilterDMus::NewIrpTarget entered\n");
93 
94  // let's verify the connection request
96  if (!NT_SUCCESS(Status))
97  {
98  return STATUS_UNSUCCESSFUL;
99  }
100 
101  if (m_Pins[ConnectDetails->PinId] && m_Descriptor->Factory.Instances[ConnectDetails->PinId].CurrentPinInstanceCount)
102  {
103  // release existing instance
104  PC_ASSERT(0);
105  }
106 
107  // now create the pin
109  if (!NT_SUCCESS(Status))
110  {
111  return Status;
112  }
113 
114  // initialize the pin
115  Status = Pin->Init(m_Port, this, ConnectDetails, &m_Descriptor->Factory.KsPinDescriptor[ConnectDetails->PinId], DeviceObject);
116  if (!NT_SUCCESS(Status))
117  {
118  Pin->Release();
119  return Status;
120  }
121 
122  // store pin
123  m_Pins[ConnectDetails->PinId] = Pin;
124 
125  // store result
126  *OutTarget = (IIrpTarget*)Pin;
127 
128  // increment current instance count
130 
131  return Status;
132 }
133 
134 NTSTATUS
135 NTAPI
138  IN PIRP Irp)
139 {
140  PIO_STACK_LOCATION IoStack;
142 
144 
145  if (IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_PROPERTY)
146  {
147  DPRINT("Unhandled function %lx Length %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode, IoStack->Parameters.DeviceIoControl.InputBufferLength);
148 
149  Irp->IoStatus.Status = STATUS_SUCCESS;
150 
152  return STATUS_SUCCESS;
153  }
154 
156  if (Status != STATUS_PENDING)
157  {
158  Irp->IoStatus.Status = Status;
159  DPRINT("Result %x Length %u\n", Status, Irp->IoStatus.Information);
161  }
162  return Status;
163 }
164 
165 NTSTATUS
166 NTAPI
169  IN PIRP Irp)
170 {
172 }
173 
174 NTSTATUS
175 NTAPI
178  IN PIRP Irp)
179 {
181 }
182 
183 NTSTATUS
184 NTAPI
187  IN PIRP Irp)
188 {
190 }
191 
192 NTSTATUS
193 NTAPI
196  IN PIRP Irp)
197 {
198  Irp->IoStatus.Status = STATUS_SUCCESS;
199  Irp->IoStatus.Information = 0;
201 
202  return STATUS_UNSUCCESSFUL;
203 }
204 
205 NTSTATUS
206 NTAPI
207 CPortFilterDMus::QuerySecurity(
209  IN PIRP Irp)
210 {
212 }
213 
214 NTSTATUS
215 NTAPI
216 CPortFilterDMus::SetSecurity(
218  IN PIRP Irp)
219 {
221 }
222 
223 BOOLEAN
224 NTAPI
225 CPortFilterDMus::FastDeviceIoControl(
227  IN BOOLEAN Wait,
233  OUT PIO_STATUS_BLOCK StatusBlock,
235 {
236  return FALSE;
237 }
238 
239 BOOLEAN
240 NTAPI
241 CPortFilterDMus::FastRead(
244  IN ULONG Length,
245  IN BOOLEAN Wait,
246  IN ULONG LockKey,
247  IN PVOID Buffer,
248  OUT PIO_STATUS_BLOCK StatusBlock,
250 {
252  return FALSE;
253 }
254 
255 BOOLEAN
256 NTAPI
257 CPortFilterDMus::FastWrite(
260  IN ULONG Length,
261  IN BOOLEAN Wait,
262  IN ULONG LockKey,
263  IN PVOID Buffer,
264  OUT PIO_STATUS_BLOCK StatusBlock,
266 {
268  return FALSE;
269 }
270 
271 NTSTATUS
272 NTAPI
274  IN IPortDMus* Port)
275 {
276  ISubdevice * ISubDevice;
278 
279  m_Port = Port;
280 
281  // get our private interface
282  Status = m_Port->QueryInterface(IID_ISubdevice, (PVOID*)&ISubDevice);
283  if (!NT_SUCCESS(Status))
284  return STATUS_UNSUCCESSFUL;
285 
286  // get the subdevice descriptor
287  Status = ISubDevice->GetDescriptor(&m_Descriptor);
288 
289  // release subdevice interface
290  ISubDevice->Release();
291 
292  if (!NT_SUCCESS(Status))
293  return STATUS_UNSUCCESSFUL;
294 
295  // allocate pin array
296  m_Pins = (IPortPinDMus**)AllocateItem(NonPagedPool, m_Descriptor->Factory.PinDescriptorCount * sizeof(IPortPinDMus*), TAG_PORTCLASS);
297 
298  if (!m_Pins)
299  return STATUS_UNSUCCESSFUL;
300 
301  // increment reference count
302  Port->AddRef();
303 
304  return STATUS_SUCCESS;
305 }
306 
307 
308 NTSTATUS
309 NTAPI
310 CPortFilterDMus::FreePin(
311  IN struct IPortPinDMus* Pin)
312 {
313  ULONG Index;
314 
316  {
317  if (m_Pins[Index] == Pin)
318  {
319  m_Pins[Index]->Release();
320  m_Pins[Index] = NULL;
321  return STATUS_SUCCESS;
322  }
323  }
324  return STATUS_UNSUCCESSFUL;
325 }
326 
327 VOID
328 NTAPI
329 CPortFilterDMus::NotifyPins()
330 {
331  ULONG Index;
332 
333  DPRINT("Notifying %u pins\n", m_Descriptor->Factory.PinDescriptorCount);
334 
336  {
337  m_Pins[Index]->Notify();
338  }
339 }
340 
341 
342 NTSTATUS
344  OUT PPORTFILTERDMUS * OutFilter)
345 {
347 
349  if (!This)
351 
352  This->AddRef();
353 
354  // return result
355  *OutFilter = (CPortFilterDMus*)This;
356 
357  return STATUS_SUCCESS;
358 }
359 
360 
CPortFilterDMus(IUnknown *OuterUnknown)
Definition: filter_dmus.cpp:39
CPPORT Port[4]
Definition: headless.c:34
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
_In_ BOOLEAN Read
Definition: strmini.h:479
NTSTATUS NTAPI PcHandlePropertyWithTable(IN PIRP Irp, IN ULONG PropertySetCount, IN PKSPROPERTY_SET PropertySet, IN PSUBDEVICE_DESCRIPTOR Descriptor)
Definition: undoc.cpp:81
#define REFIID
Definition: guiddef.h:118
IPortFilterDMus * PPORTFILTERDMUS
Definition: interfaces.hpp:838
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PC_ASSERT(exp)
Definition: usbehci.h:17
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
_In_ BOOLEAN Release
Definition: classpnp.h:929
_In_ PIRP Irp
Definition: csq.h:116
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
#define TAG_PORTCLASS
Definition: private.hpp:24
IPortDMus * m_Port
Definition: filter_dmus.cpp:43
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NewPortFilterDMus(OUT PPORTFILTERDMUS *OutFilter)
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
SUBDEVICE_DESCRIPTOR * m_Descriptor
Definition: filter_dmus.cpp:45
BOOL Init(PUSERCONNECT UserCon)
Definition: dllmain.c:385
static BOOL Write(PBYTE Address, PBYTE Data, SIZE_T Size)
Definition: vmhorizon.c:15
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
ULONG PinId
Definition: ks.h:2603
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
ULONG CurrentPinInstanceCount
Definition: interfaces.hpp:191
long LONG
Definition: pedump.c:60
#define STDMETHODIMP
Definition: basetyps.h:43
KSPIN_FACTORY Factory
Definition: interfaces.hpp:208
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2650
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1156
IN PDCB IN VBO IN ULONG IN BOOLEAN Pin
Definition: fatprocs.h:415
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
IPortPinDMus ** m_Pins
Definition: filter_dmus.cpp:44
INT POOL_TYPE
Definition: typedefs.h:76
const GUID IID_IUnknown
static const UCHAR Index[8]
Definition: usbohci.c:18
nsrefcnt Release()
virtual ~CPortFilterDMus()
Definition: filter_dmus.cpp:40
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1955
ULONG AddRef()
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: filter_dmus.cpp:51
#define InterlockedDecrement
Definition: armddk.h:52
Definition: arc.h:85
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
STDMETHODIMP_(ULONG) AddRef()
Definition: filter_dmus.cpp:22
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define InterlockedIncrement
Definition: armddk.h:53
NTSTATUS NTAPI PcValidateConnectRequest(IN PIRP Irp, IN KSPIN_FACTORY *Descriptor, OUT PKSPIN_CONNECT *Connect)
Definition: undoc.cpp:998
Definition: sacdrv.h:267
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
STDMETHODIMP_(ULONG) Release()
Definition: filter_dmus.cpp:27
ULONG PinDescriptorCount
Definition: interfaces.hpp:198
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
PIN_INSTANCE_INFO * Instances
Definition: interfaces.hpp:201
#define OUT
Definition: typedefs.h:39
NTSTATUS NewPortPinDMus(OUT IPortPinDMus **OutPin)
Definition: pin_dmus.cpp:634
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define UNIMPLEMENTED
Definition: debug.h:114
PKSPROPERTY_SET FilterPropertySet
Definition: interfaces.hpp:210
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
KSPIN_DESCRIPTOR * KsPinDescriptor
Definition: interfaces.hpp:200
IN BOOLEAN Wait
Definition: fatprocs.h:1529