AbstractVideoDecodeInputPin.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh
00003 //
00004 //Redistribution and use in source and binary forms, with or without
00005 //modification, are permitted provided that the following conditions
00006 //are met:
00007 //
00008 //- Redistributions of source code must retain the above copyright
00009 //  notice, this list of conditions and the following disclaimer.
00010 //
00011 //- Redistributions in binary form must reproduce the above copyright
00012 //  notice, this list of conditions and the following disclaimer in the
00013 //  documentation and/or other materials provided with the distribution.
00014 //
00015 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00016 //  may be used to endorse or promote products derived from this software 
00017 //  without specific prior written permission.
00018 //
00019 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00022 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00023 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 //===========================================================================
00031 
00032 #include "stdafx.h"
00033 #include "abstractvideodecodeinputpin.h"
00034 
00035 //#include <mtype.h>
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         //debugLog.open("G:\\logs\\avdInputPin.log", ios_base::out);
00056         //ConstructCodec();
00057         mStreamLock = new CCritSec;                             //Deleted in destructor
00058         mAcceptableMediaType = inAcceptMediaType;
00059 
00060         //IMediaSeeking* locSeeker = NULL;
00061         //this->NonDelegatingQueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00062         //mOutputPin->SetDelegate(locSeeker);
00063 }
00064 
00065 AbstractVideoDecodeInputPin::~AbstractVideoDecodeInputPin(void)
00066 {
00067         //debugLog.close();
00068         //DestroyCodec();
00069         delete mStreamLock;
00070         
00071 }
00072 STDMETHODIMP AbstractVideoDecodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00073         //debugLog<<"Query Interface"<<endl;
00074         if (riid == IID_IMediaSeeking) {
00075                 *ppv = (IMediaSeeking*)this;
00076                 ((IUnknown*)*ppv)->AddRef();
00077                 //debugLog<<"Queried for IMediaSeeking"<<endl;
00078                 return NOERROR;
00079         }
00080 
00081         return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv); 
00082 }
00083 
00084 HRESULT AbstractVideoDecodeInputPin::BreakConnect() {
00085         CAutoLock locLock(m_pLock);
00086         //Need a lock ??
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         //debugLog<<"Receive "<<endl;
00117         HRESULT locHR;
00118         BYTE* locBuff = NULL;
00119         locHR = inSample->GetPointer(&locBuff);
00120 
00121 
00122         if (FAILED(locHR)) {
00123                 //debugLog<<"Receive : Get pointer failed..."<<locHR<<endl;     
00124                 return locHR;
00125         } else {
00126                 //debugLog<<"Receive : Get pointer succeeds..."<<endl;  
00127                 //New start time hacks
00128                 REFERENCE_TIME locStart = 0;
00129                 REFERENCE_TIME locEnd = 0;
00130                 inSample->GetTime(&locStart, &locEnd);
00131                 //Error chacks needed here
00132                 
00133                 //More work arounds for that stupid granule pos scheme in theora!
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                 //End of additions
00146 
00147 
00148 
00149                 AM_MEDIA_TYPE* locMediaType = NULL;
00150                 inSample->GetMediaType(&locMediaType);
00151                 if (locMediaType == NULL) {
00152                         //debugLog<<"No dynamic change..."<<endl;
00153                 } else {
00154                         //debugLog<<"Attempting dynamic change..."<<endl;
00155                 }
00156                 //if (locMediaType != NULL) {
00157                 
00158                         //VIDEOINFOHEADER* locVideoHeader = (VIDEOINFOHEADER*)locMediaType->pbFormat;
00159                         //mHeight = 288; //locVideoHeader->bmiHeader.biHeight;
00160                         //mWidth =  384; //locVideoHeader->bmiHeader.biWidth;
00161                 //}
00162 
00163                 
00164                 long locResult = decodeData(locBuff, inSample->GetActualDataLength(), locStart, locEnd);
00165                 if (locResult == 0) {
00166                         //debugLog<<"Receive : Decode OK"<<endl;        
00167                         return S_OK;
00168                 } else {
00169                         //debugLog<<"Receive : Decode OK"<<endl;        
00170                         return S_FALSE;
00171                 }
00172         }
00173 
00174         
00175         return S_OK;
00176 }
00177 
00178 HRESULT AbstractVideoDecodeInputPin::CheckMediaType(const CMediaType *inMediaType) {
00179         //FIX::: Clean this up !
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         //This breaks it for some reason... though something similar in the audio component works fine.
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                         //Don't set the format data here. That's up to our output pin/
00228                         return S_OK;                    
00229                 default:
00230                         return VFW_S_NO_MORE_ITEMS;
00231         }
00232 }

Generated on Tue Feb 15 14:54:17 2005 for oggdsf by  doxygen 1.3.9