Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenport_wavertstream.cpp
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS Kernel Streaming 00004 * FILE: drivers/wdm/audio/backpln/portcls/port_wavertstream.cpp 00005 * PURPOSE: WaveRTStream helper object 00006 * PROGRAMMER: Johannes Anderwald 00007 */ 00008 00009 #include "private.hpp" 00010 00011 class CPortWaveRTStreamInit : public IPortWaveRTStreamInit 00012 { 00013 public: 00014 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface); 00015 00016 STDMETHODIMP_(ULONG) AddRef() 00017 { 00018 InterlockedIncrement(&m_Ref); 00019 return m_Ref; 00020 } 00021 STDMETHODIMP_(ULONG) Release() 00022 { 00023 InterlockedDecrement(&m_Ref); 00024 00025 if (!m_Ref) 00026 { 00027 delete this; 00028 return 0; 00029 } 00030 return m_Ref; 00031 } 00032 IMP_IPortWaveRTStreamInit; 00033 CPortWaveRTStreamInit(IUnknown *OuterUnknown) {} 00034 virtual ~CPortWaveRTStreamInit() {} 00035 00036 protected: 00037 LONG m_Ref; 00038 00039 }; 00040 00041 NTSTATUS 00042 NTAPI 00043 CPortWaveRTStreamInit::QueryInterface( 00044 IN REFIID refiid, 00045 OUT PVOID* Output) 00046 { 00047 00048 DPRINT("IPortWaveRTStream_fnQueryInterface entered\n"); 00049 00050 if (IsEqualGUIDAligned(refiid, IID_IPortWaveRTStream) || 00051 IsEqualGUIDAligned(refiid, IID_IUnknown)) 00052 { 00053 *Output = PVOID(PPORTWAVERTSTREAM(this)); 00054 PUNKNOWN(*Output)->AddRef(); 00055 return STATUS_SUCCESS; 00056 } 00057 return STATUS_UNSUCCESSFUL; 00058 } 00059 00060 00061 PMDL 00062 NTAPI 00063 CPortWaveRTStreamInit::AllocatePagesForMdl( 00064 IN PHYSICAL_ADDRESS HighAddress, 00065 IN SIZE_T TotalBytes) 00066 { 00067 return MmAllocatePagesForMdl(RtlConvertUlongToLargeInteger(0), HighAddress, RtlConvertUlongToLargeInteger(0), TotalBytes); 00068 } 00069 00070 PMDL 00071 NTAPI 00072 CPortWaveRTStreamInit::AllocateContiguousPagesForMdl( 00073 IN PHYSICAL_ADDRESS LowAddress, 00074 IN PHYSICAL_ADDRESS HighAddress, 00075 IN SIZE_T TotalBytes) 00076 { 00077 PMDL Mdl; 00078 PVOID Buffer; 00079 PHYSICAL_ADDRESS Address; 00080 00081 Buffer = MmAllocateContiguousMemorySpecifyCache(TotalBytes, LowAddress, HighAddress, RtlConvertUlongToLargeInteger(0), MmNonCached); 00082 if (!Buffer) 00083 { 00084 DPRINT("MmAllocateContiguousMemorySpecifyCache failed\n"); 00085 return NULL; 00086 } 00087 00088 Address = MmGetPhysicalAddress(Buffer); 00089 00090 MmFreeContiguousMemorySpecifyCache(Buffer, TotalBytes, MmNonCached); 00091 00092 Mdl = MmAllocatePagesForMdl(Address, HighAddress, RtlConvertUlongToLargeInteger(0), TotalBytes); 00093 if (!Mdl) 00094 { 00095 DPRINT("MmAllocatePagesForMdl failed\n"); 00096 return NULL; 00097 } 00098 00099 if (MmGetMdlByteCount(Mdl) < TotalBytes) 00100 { 00101 DPRINT("ByteCount %u Required %u\n", MmGetMdlByteCount(Mdl), TotalBytes); 00102 MmFreePagesFromMdl(Mdl); 00103 ExFreePool(Mdl); 00104 return NULL; 00105 } 00106 00107 DPRINT("Result %p\n", Mdl); 00108 return Mdl; 00109 } 00110 00111 PVOID 00112 NTAPI 00113 CPortWaveRTStreamInit::MapAllocatedPages( 00114 IN PMDL MemoryDescriptorList, 00115 IN MEMORY_CACHING_TYPE CacheType) 00116 { 00117 return MmMapLockedPagesSpecifyCache(MemoryDescriptorList, KernelMode, CacheType, NULL, 0, NormalPagePriority); 00118 } 00119 00120 VOID 00121 NTAPI 00122 CPortWaveRTStreamInit::UnmapAllocatedPages( 00123 IN PVOID BaseAddress, 00124 IN PMDL MemoryDescriptorList) 00125 { 00126 MmUnmapLockedPages(BaseAddress, MemoryDescriptorList); 00127 } 00128 00129 VOID 00130 NTAPI 00131 CPortWaveRTStreamInit::FreePagesFromMdl( 00132 IN PMDL MemoryDescriptorList) 00133 { 00134 MmFreePagesFromMdl(MemoryDescriptorList); 00135 ExFreePool(MemoryDescriptorList); 00136 } 00137 00138 ULONG 00139 NTAPI 00140 CPortWaveRTStreamInit::GetPhysicalPagesCount( 00141 IN PMDL MemoryDescriptorList) 00142 { 00143 return ADDRESS_AND_SIZE_TO_SPAN_PAGES(0, MmGetMdlByteCount(MemoryDescriptorList)); 00144 } 00145 00146 PHYSICAL_ADDRESS 00147 NTAPI 00148 CPortWaveRTStreamInit::GetPhysicalPageAddress( 00149 IN PPHYSICAL_ADDRESS Address, 00150 IN PMDL MemoryDescriptorList, 00151 IN ULONG Index) 00152 { 00153 PVOID Buffer; 00154 ULONG Pages; 00155 PHYSICAL_ADDRESS Result, Addr; 00156 00157 Pages = ADDRESS_AND_SIZE_TO_SPAN_PAGES(0, MmGetMdlByteCount(MemoryDescriptorList)); 00158 if (Pages <= Index) 00159 { 00160 DPRINT("OutOfBounds: Pages %u Index %u\n", Pages, Index); 00161 return RtlConvertUlongToLargeInteger(0); 00162 } 00163 00164 Buffer = (PUCHAR)MmGetSystemAddressForMdlSafe(MemoryDescriptorList, LowPagePriority) + (Index * PAGE_SIZE); 00165 00166 Addr = MmGetPhysicalAddress(Buffer); 00167 Address->QuadPart = Addr.QuadPart; 00168 Result.QuadPart = (ULONG_PTR)Address; 00169 00170 return Result; 00171 } 00172 00173 00174 NTSTATUS 00175 NewPortWaveRTStream( 00176 PPORTWAVERTSTREAM *OutStream) 00177 { 00178 NTSTATUS Status; 00179 CPortWaveRTStreamInit* This = new(NonPagedPool, TAG_PORTCLASS) CPortWaveRTStreamInit(NULL); 00180 if (!This) 00181 return STATUS_INSUFFICIENT_RESOURCES; 00182 00183 Status = This->QueryInterface(IID_IPortWaveRTStream, (PVOID*)OutStream); 00184 00185 if (!NT_SUCCESS(Status)) 00186 { 00187 delete This; 00188 return Status; 00189 } 00190 00191 *OutStream = (PPORTWAVERTSTREAM)This; 00192 return Status; 00193 } Generated on Sun May 27 2012 04:28:36 for ReactOS by
1.7.6.1
|