1 /* 2 Copyright (c) 2006-2008 dogbert <dogber1@gmail.com> 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 1. Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 2. Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 3. The name of the author may not be used to endorse or promote products 14 derived from this software without specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef _MINWAVE_HPP_ 29 #define _MINWAVE_HPP_ 30 31 #define PC_IMPLEMENTATION // for the implementation of IDMAChannel 32 33 #include "common.hpp" 34 #include "property.h" 35 36 class CMiniportWaveStreamCMI; 37 38 class CMiniportWaveCMI: 39 #ifdef WAVERT 40 public IMiniportWaveRT, 41 #else 42 public IMiniportWaveCyclic, 43 #endif 44 public IMiniportWaveCMI, 45 public CUnknown 46 { 47 private: 48 PCMIADAPTER CMIAdapter; // Adapter common object. 49 #ifdef WAVERT 50 PPORTWAVERT Port; 51 #else 52 PPORTWAVECYCLIC Port; 53 PDMACHANNEL DMAChannel[3]; 54 UInt32 notificationInterval; 55 #endif 56 CMI8738Info *cm; 57 UInt32 requestedChannelCount; 58 UInt32 requestedChannelMask; 59 60 61 CMiniportWaveStreamCMI *stream[3]; 62 bool isStreamRunning[3]; 63 KMUTEX mutex; 64 65 NTSTATUS processResources(PRESOURCELIST resourceList); 66 67 NTSTATUS isFormatAllowed(UInt32 sampleRate, BOOLEAN multiChan, BOOLEAN AC3); 68 NTSTATUS validateFormat(PKSDATAFORMAT format, ULONG PinID, BOOLEAN capture); 69 #ifndef WAVERT 70 NTSTATUS newDMAChannel(PDMACHANNEL *dmaChannel, UInt32 bufferLength); 71 #endif 72 NTSTATUS loadChannelConfigFromRegistry(); 73 NTSTATUS storeChannelConfigToRegistry(); 74 public: 75 DECLARE_STD_UNKNOWN(); 76 DEFINE_STD_CONSTRUCTOR(CMiniportWaveCMI); 77 ~CMiniportWaveCMI(); 78 #ifdef WAVERT 79 IMP_IMiniportWaveRT; 80 #else 81 IMP_IMiniportWaveCyclic; 82 #endif 83 84 STDMETHODIMP_(void) ServiceWaveISR(UInt32 streamIndex); 85 STDMETHODIMP_(void) powerUp(); 86 STDMETHODIMP_(void) powerDown(); 87 88 friend NTSTATUS NTAPI PropertyHandler_ChannelConfig(PPCPROPERTY_REQUEST PropertyRequest); 89 friend class CMiniportWaveStreamCMI; 90 }; 91 92 93 class CMiniportWaveStreamCMI: 94 #ifdef WAVERT 95 public IMiniportWaveRTStream, 96 #else 97 public IMiniportWaveCyclicStream, 98 #endif 99 public IDrmAudioStream, 100 public CUnknown 101 { 102 private: 103 CMiniportWaveCMI *Miniport; 104 #ifdef WAVERT 105 PPORTWAVERTSTREAM Port; 106 PMDL audioBufferMDL; 107 UInt32 dmaAddress; 108 UInt32 dmaMemorySize; 109 #else 110 PDMACHANNEL DMAChannel; 111 PSERVICEGROUP ServiceGroup; // For notification. 112 #endif 113 114 bool isCaptureStream;// Capture or render. 115 UInt32 streamIndex; 116 UInt32 channelNumber; // hardware channel number: 0/A or 1/B 117 KSSTATE state; // Stop, pause, run. 118 UInt32 periodSize; // process n frames until the interrupt is fired in frames, NOT in bytes 119 UInt32 dmaSize; // size of the DMA buffer in frames, NOT in bytes 120 UInt32 currentChannelCount, currentSampleRate, currentResolution; 121 bool enableAC3Passthru, enableSPDIF; 122 123 NTSTATUS prepareStream(); 124 NTSTATUS setDACChannels(); 125 NTSTATUS setupSPDIFPlayback(bool enableSPDIF); 126 NTSTATUS setupAC3Passthru(); 127 128 public: 129 DECLARE_STD_UNKNOWN(); 130 DEFINE_STD_CONSTRUCTOR(CMiniportWaveStreamCMI); 131 ~CMiniportWaveStreamCMI(); 132 #ifdef WAVERT 133 IMP_IMiniportWaveRTStream; 134 #else 135 IMP_IMiniportWaveCyclicStream; 136 #endif 137 138 IMP_IDrmAudioStream; 139 140 #ifdef WAVERT 141 NTSTATUS Init(CMiniportWaveCMI* Miniport_, UInt32 streamIndex_, bool isCaptureStream_, PKSDATAFORMAT DataFormat, PPORTWAVERTSTREAM PortStream_); 142 #else 143 NTSTATUS Init(CMiniportWaveCMI* Miniport_, UInt32 streamIndex_, bool isCaptureStream_, PKSDATAFORMAT DataFormat, PDMACHANNEL DMAChannel_, PSERVICEGROUP* OutServiceGroup); 144 #endif 145 friend class CMiniportWaveCMI; 146 }; 147 148 NTSTATUS CreateMiniportWaveStreamCMI(CMiniportWaveStreamCMI **MiniportWaveStreamCMI, PUNKNOWN pUnknownOuter, POOL_TYPE PoolType); 149 150 #endif //_MINWAVE_HPP_ 151