2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/backpln/portcls/port_wavertstream.cpp
5 * PURPOSE: WaveRTStream helper object
6 * PROGRAMMER: Johannes Anderwald
11 class CPortWaveRTStreamInit
: public IPortWaveRTStreamInit
14 STDMETHODIMP
QueryInterface( REFIID InterfaceId
, PVOID
* Interface
);
16 STDMETHODIMP_(ULONG
) AddRef()
18 InterlockedIncrement(&m_Ref
);
21 STDMETHODIMP_(ULONG
) Release()
23 InterlockedDecrement(&m_Ref
);
32 IMP_IPortWaveRTStreamInit
;
33 CPortWaveRTStreamInit(IUnknown
*OuterUnknown
) {}
34 virtual ~CPortWaveRTStreamInit() {}
43 CPortWaveRTStreamInit::QueryInterface(
48 DPRINT("IPortWaveRTStream_fnQueryInterface entered\n");
50 if (IsEqualGUIDAligned(refiid
, IID_IPortWaveRTStream
) ||
51 IsEqualGUIDAligned(refiid
, IID_IUnknown
))
53 *Output
= PVOID(PPORTWAVERTSTREAM(this));
54 PUNKNOWN(*Output
)->AddRef();
55 return STATUS_SUCCESS
;
57 return STATUS_UNSUCCESSFUL
;
63 CPortWaveRTStreamInit::AllocatePagesForMdl(
64 IN PHYSICAL_ADDRESS HighAddress
,
67 return MmAllocatePagesForMdl(RtlConvertUlongToLargeInteger(0), HighAddress
, RtlConvertUlongToLargeInteger(0), TotalBytes
);
72 CPortWaveRTStreamInit::AllocateContiguousPagesForMdl(
73 IN PHYSICAL_ADDRESS LowAddress
,
74 IN PHYSICAL_ADDRESS HighAddress
,
79 PHYSICAL_ADDRESS Address
;
81 Buffer
= MmAllocateContiguousMemorySpecifyCache(TotalBytes
, LowAddress
, HighAddress
, RtlConvertUlongToLargeInteger(0), MmNonCached
);
84 DPRINT1("MmAllocateContiguousMemorySpecifyCache failed\n");
88 Address
= MmGetPhysicalAddress(Buffer
);
90 MmFreeContiguousMemorySpecifyCache(Buffer
, TotalBytes
, MmNonCached
);
92 Mdl
= MmAllocatePagesForMdl(Address
, HighAddress
, RtlConvertUlongToLargeInteger(0), TotalBytes
);
95 DPRINT1("MmAllocatePagesForMdl failed\n");
99 if (MmGetMdlByteCount(Mdl
) < TotalBytes
)
101 DPRINT1("ByteCount %u Required %u\n", MmGetMdlByteCount(Mdl
), TotalBytes
);
102 MmFreePagesFromMdl(Mdl
);
107 DPRINT("Result %p\n", Mdl
);
113 CPortWaveRTStreamInit::MapAllocatedPages(
114 IN PMDL MemoryDescriptorList
,
115 IN MEMORY_CACHING_TYPE CacheType
)
117 return MmMapLockedPagesSpecifyCache(MemoryDescriptorList
, KernelMode
, CacheType
, NULL
, 0, NormalPagePriority
);
122 CPortWaveRTStreamInit::UnmapAllocatedPages(
123 IN PVOID BaseAddress
,
124 IN PMDL MemoryDescriptorList
)
126 MmUnmapLockedPages(BaseAddress
, MemoryDescriptorList
);
131 CPortWaveRTStreamInit::FreePagesFromMdl(
132 IN PMDL MemoryDescriptorList
)
134 MmFreePagesFromMdl(MemoryDescriptorList
);
135 ExFreePool(MemoryDescriptorList
);
140 CPortWaveRTStreamInit::GetPhysicalPagesCount(
141 IN PMDL MemoryDescriptorList
)
143 return ADDRESS_AND_SIZE_TO_SPAN_PAGES(0, MmGetMdlByteCount(MemoryDescriptorList
));
148 CPortWaveRTStreamInit::GetPhysicalPageAddress(
149 IN PPHYSICAL_ADDRESS Address
,
150 IN PMDL MemoryDescriptorList
,
155 PHYSICAL_ADDRESS Result
, Addr
;
157 Pages
= ADDRESS_AND_SIZE_TO_SPAN_PAGES(0, MmGetMdlByteCount(MemoryDescriptorList
));
160 DPRINT1("OutOfBounds: Pages %u Index %u\n", Pages
, Index
);
161 return RtlConvertUlongToLargeInteger(0);
164 Buffer
= (PVOID
)UlongToPtr(PtrToUlong(MmGetSystemAddressForMdlSafe(MemoryDescriptorList
, LowPagePriority
)) + Index
* PAGE_SIZE
);
166 Addr
= MmGetPhysicalAddress(Buffer
);
167 Address
->QuadPart
= Addr
.QuadPart
;
168 Result
.QuadPart
= (PtrToUlong(Address
));
176 PPORTWAVERTSTREAM
*OutStream
)
179 CPortWaveRTStreamInit
* This
= new(NonPagedPool
, TAG_PORTCLASS
) CPortWaveRTStreamInit(NULL
);
181 return STATUS_INSUFFICIENT_RESOURCES
;
183 Status
= This
->QueryInterface(IID_IPortWaveRTStream
, (PVOID
*)OutStream
);
185 if (!NT_SUCCESS(Status
))
191 *OutStream
= (PPORTWAVERTSTREAM
)This
;