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 "abstractvideodecodeinputpin.h"
00034
00035
00036 AbstractVideoDecodeInputPin::AbstractVideoDecodeInputPin (AbstractVideoDecodeFilter* inParentFilter, CCritSec* inFilterLock, AbstractVideoDecodeOutputPin* 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
00043 , mHeight(0)
00044 , mWidth(0)
00045
00046 , mFrameDuration(0)
00047 , mFrameSize(0)
00048 , mFrameCount(0)
00049
00050 , mStreamLock(NULL)
00051 , mLastSeenStartGranPos(0)
00052 , mSeekTimeBase(0)
00053
00054 {
00055
00056
00057 mStreamLock = new CCritSec;
00058 mAcceptableMediaType = inAcceptMediaType;
00059
00060
00061
00062
00063 }
00064
00065 AbstractVideoDecodeInputPin::~AbstractVideoDecodeInputPin(void)
00066 {
00067
00068
00069 delete mStreamLock;
00070
00071 }
00072 STDMETHODIMP AbstractVideoDecodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00073
00074 if (riid == IID_IMediaSeeking) {
00075 *ppv = (IMediaSeeking*)this;
00076 ((IUnknown*)*ppv)->AddRef();
00077
00078 return NOERROR;
00079 }
00080
00081 return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv);
00082 }
00083
00084 HRESULT AbstractVideoDecodeInputPin::BreakConnect() {
00085 CAutoLock locLock(m_pLock);
00086
00087 ReleaseDelegate();
00088 return CBaseInputPin::BreakConnect();
00089 }
00090 HRESULT AbstractVideoDecodeInputPin::CompleteConnect (IPin *inReceivePin) {
00091 CAutoLock locLock(m_pLock);
00092
00093 IMediaSeeking* locSeeker = NULL;
00094 inReceivePin->QueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00095 SetDelegate(locSeeker);
00096 return CBaseInputPin::CompleteConnect(inReceivePin);
00097 }
00098 void AbstractVideoDecodeInputPin::ResetFrameCount() {
00099 mFrameCount = 0;
00100
00101 }
00102 bool AbstractVideoDecodeInputPin::SetSampleParams(IMediaSample* outMediaSample, unsigned long inDataSize, REFERENCE_TIME* inStartTime, REFERENCE_TIME* inEndTime)
00103 {
00104 outMediaSample->SetTime(inStartTime, inEndTime);
00105 outMediaSample->SetMediaTime(NULL, NULL);
00106 outMediaSample->SetActualDataLength(inDataSize);
00107 outMediaSample->SetPreroll(FALSE);
00108 outMediaSample->SetDiscontinuity(FALSE);
00109 outMediaSample->SetSyncPoint(FALSE);
00110 return true;
00111 }
00112
00113
00114 STDMETHODIMP AbstractVideoDecodeInputPin::Receive(IMediaSample* inSample) {
00115 CAutoLock locLock(mStreamLock);
00116
00117 HRESULT locHR;
00118 BYTE* locBuff = NULL;
00119 locHR = inSample->GetPointer(&locBuff);
00120
00121
00122 if (FAILED(locHR)) {
00123
00124 return locHR;
00125 } else {
00126
00127
00128 REFERENCE_TIME locStart = 0;
00129 REFERENCE_TIME locEnd = 0;
00130 inSample->GetTime(&locStart, &locEnd);
00131
00132
00133
00134 REFERENCE_TIME locTimeBase = 0;
00135 REFERENCE_TIME locDummy = 0;
00136 inSample->GetMediaTime(&locTimeBase, &locDummy);
00137 mSeekTimeBase = locTimeBase;
00138
00139
00140 if ((mLastSeenStartGranPos != locStart) && (locStart != -1)) {
00141 ResetFrameCount();
00142 mLastSeenStartGranPos = locStart;
00143 }
00144
00145
00146
00147
00148
00149 AM_MEDIA_TYPE* locMediaType = NULL;
00150 inSample->GetMediaType(&locMediaType);
00151 if (locMediaType == NULL) {
00152
00153 } else {
00154
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164 long locResult = decodeData(locBuff, inSample->GetActualDataLength(), locStart, locEnd);
00165 if (locResult == 0) {
00166
00167 return S_OK;
00168 } else {
00169
00170 return S_FALSE;
00171 }
00172 }
00173
00174
00175 return S_OK;
00176 }
00177
00178 HRESULT AbstractVideoDecodeInputPin::CheckMediaType(const CMediaType *inMediaType) {
00179
00180
00181 if ( (inMediaType->majortype == MEDIATYPE_Video) &&
00182 (inMediaType->subtype == mAcceptableMediaType->subtype) && (inMediaType->formattype == mAcceptableMediaType->formattype)
00183 )
00184 {
00185 return S_OK;
00186 } else {
00187 return S_FALSE;
00188 }
00189 }
00190
00191 STDMETHODIMP AbstractVideoDecodeInputPin::EndOfStream(void) {
00192 CAutoLock locLock(mStreamLock);
00193 return mParentFilter->mOutputPin->DeliverEndOfStream();
00194 }
00195
00196 STDMETHODIMP AbstractVideoDecodeInputPin::BeginFlush() {
00197 CAutoLock locLock(m_pLock);
00198 CBaseInputPin::BeginFlush();
00199 return mParentFilter->mOutputPin->DeliverBeginFlush();
00200 }
00201 STDMETHODIMP AbstractVideoDecodeInputPin::EndFlush() {
00202 CAutoLock locLock(m_pLock);
00203 mParentFilter->mOutputPin->DeliverEndFlush();
00204
00205 return CBaseInputPin::EndFlush();
00206
00207 }
00208
00209 STDMETHODIMP AbstractVideoDecodeInputPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
00210 CAutoLock locLock(mStreamLock);
00211
00212 CBasePin::NewSegment(tStart, tStop, dRate);
00213 return mParentFilter->mOutputPin->DeliverNewSegment(tStart, tStop, dRate);
00214 }
00215
00216 HRESULT AbstractVideoDecodeInputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00217
00218 if (inPosition < 0) {
00219 return E_INVALIDARG;
00220 }
00221
00222 switch (inPosition) {
00223 case 0:
00224
00225 outMediaType->SetType(&MEDIATYPE_Video);
00226 outMediaType->SetSubtype(&(mAcceptableMediaType->subtype));
00227
00228 return S_OK;
00229 default:
00230 return VFW_S_NO_MORE_ITEMS;
00231 }
00232 }