00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "stdafx.h"
00033 #include "abstractaudiodecodeinputpin.h"
00034
00035
00036 AbstractAudioDecodeInputPin::AbstractAudioDecodeInputPin (AbstractAudioDecodeFilter* inParentFilter, CCritSec* inFilterLock, AbstractAudioDecodeOutputPin* inOutputPin, CHAR* inObjectName, LPCWSTR inPinDisplayName, CMediaType* inAcceptMediaType)
00037 : CBaseInputPin (inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName)
00038 , mOutputPin (inOutputPin)
00039 , mParentFilter (inParentFilter)
00040
00041 , mBegun (false)
00042 , mUptoFrame (0)
00043 , mFrameSize (0)
00044 , mNumChannels (0)
00045 , mSampleRate (0)
00046
00047 , mLastSeenStartGranPos (0)
00048 , mSeekTimeBase (0)
00049 , mChainTimeBase (0)
00050 {
00051
00052
00053
00054 mAcceptableMediaType = inAcceptMediaType;
00055 mStreamLock = new CCritSec;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 }
00082
00083 STDMETHODIMP AbstractAudioDecodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00084 {
00085 if (riid == IID_IMediaSeeking) {
00086 *ppv = (IMediaSeeking*)this;
00087 ((IUnknown*)*ppv)->AddRef();
00088 return NOERROR;
00089 }
00090
00091 return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv);
00092 }
00093
00094 HRESULT AbstractAudioDecodeInputPin::BreakConnect()
00095 {
00096 CAutoLock locLock(m_pLock);
00097
00098 ReleaseDelegate();
00099 return CBaseInputPin::BreakConnect();
00100 }
00101 HRESULT AbstractAudioDecodeInputPin::CompleteConnect (IPin *inReceivePin)
00102 {
00103 CAutoLock locLock(m_pLock);
00104
00105 IMediaSeeking* locSeeker = NULL;
00106 inReceivePin->QueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00107 SetDelegate(locSeeker);
00108 return CBaseInputPin::CompleteConnect(inReceivePin);
00109 }
00110 AbstractAudioDecodeInputPin::~AbstractAudioDecodeInputPin(void)
00111 {
00112
00113
00114 delete mStreamLock;
00115 delete mAcceptableMediaType;
00116 mAcceptableMediaType = NULL;
00117 }
00118
00119
00120 void AbstractAudioDecodeInputPin::ResetFrameCount()
00121 {
00122 mUptoFrame = 0;
00123
00124 }
00125 void AbstractAudioDecodeInputPin::ResetTimeBases()
00126 {
00127 mLastSeenStartGranPos = 0;
00128 }
00129 bool AbstractAudioDecodeInputPin::SetSampleParams(IMediaSample* outMediaSample, unsigned long inDataSize, REFERENCE_TIME* inStartTime, REFERENCE_TIME* inEndTime)
00130 {
00131 outMediaSample->SetTime(inStartTime, inEndTime);
00132 outMediaSample->SetMediaTime(NULL, NULL);
00133 outMediaSample->SetActualDataLength(inDataSize);
00134 outMediaSample->SetPreroll(FALSE);
00135 outMediaSample->SetDiscontinuity(FALSE);
00136 outMediaSample->SetSyncPoint(TRUE);
00137 return true;
00138 }
00139
00140
00141 STDMETHODIMP AbstractAudioDecodeInputPin::Receive(IMediaSample* inSample)
00142 {
00143 CAutoLock locLock(mStreamLock);
00144
00145 HRESULT locHR = CheckStreaming();
00146
00147 if (locHR == S_OK) {
00148 BYTE* locBuff = NULL;
00149 locHR = inSample->GetPointer(&locBuff);
00150
00151 if (FAILED(locHR)) {
00152 return locHR;
00153 } else {
00154
00155 REFERENCE_TIME locStart = 0;
00156 REFERENCE_TIME locEnd = 0;
00157
00158
00159 REFERENCE_TIME locTimeBase = 0;
00160 REFERENCE_TIME locDummy = 0;
00161 inSample->GetMediaTime(&locTimeBase, &locDummy);
00162 mSeekTimeBase = locTimeBase;
00163
00164
00165 inSample->GetTime(&locStart, &locEnd);
00166
00167
00168
00169
00170
00171 if ((mLastSeenStartGranPos != locStart) && (locStart != -1)) {
00172
00173 ResetFrameCount();
00174 }
00175
00176 mLastSeenStartGranPos = locStart;
00177
00178
00179 long locResult = decodeData(locBuff, inSample->GetActualDataLength());
00180 if (locResult == 0) {
00181
00182
00183 return S_OK;
00184 } else {
00185
00186 return S_FALSE;
00187 }
00188 }
00189 } else {
00190
00191 return locHR;
00192 }
00193
00194 return S_OK;
00195 }
00196
00197 HRESULT AbstractAudioDecodeInputPin::CheckMediaType(const CMediaType *inMediaType) {
00198
00199 if ( (inMediaType->majortype == MEDIATYPE_Audio) &&
00200 (inMediaType->subtype == mAcceptableMediaType->subtype) && (inMediaType->formattype == mAcceptableMediaType->formattype)
00201 )
00202 {
00203 return S_OK;
00204 } else {
00205 return S_FALSE;
00206 }
00207 }
00208
00209 STDMETHODIMP AbstractAudioDecodeInputPin::EndOfStream(void) {
00210 CAutoLock locLock(mStreamLock);
00211
00212 return mParentFilter->mOutputPin->DeliverEndOfStream();
00213 }
00214
00215 STDMETHODIMP AbstractAudioDecodeInputPin::BeginFlush() {
00216 CAutoLock locLock(m_pLock);
00217
00218 CBaseInputPin::BeginFlush();
00219 return mParentFilter->mOutputPin->DeliverBeginFlush();
00220 }
00221 STDMETHODIMP AbstractAudioDecodeInputPin::EndFlush() {
00222 CAutoLock locLock(m_pLock);
00223
00224 mParentFilter->mOutputPin->DeliverEndFlush();
00225 return CBaseInputPin::EndFlush();
00226 }
00227
00228 STDMETHODIMP AbstractAudioDecodeInputPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
00229 CAutoLock locLock(mStreamLock);
00230 ResetFrameCount();
00231
00232
00233 CBasePin::NewSegment(tStart, tStop, dRate);
00234 return mParentFilter->mOutputPin->DeliverNewSegment(tStart, tStop, dRate);
00235 }
00236
00237 HRESULT AbstractAudioDecodeInputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00238
00239 if (inPosition < 0) {
00240 return E_INVALIDARG;
00241 }
00242
00243 switch (inPosition) {
00244 case 0:
00245
00246 outMediaType->SetType(&MEDIATYPE_Audio);
00247 outMediaType->SetSubtype(&(mAcceptableMediaType->subtype));
00248
00249 return S_OK;
00250 default:
00251 return VFW_S_NO_MORE_ITEMS;
00252 }
00253 }