AbstractTransformInputPin.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 "AbstractTransformInputPin.h"
00034 
00035 
00036 AbstractTransformInputPin::AbstractTransformInputPin (AbstractTransformFilter* inParentFilter, CCritSec* inFilterLock, AbstractTransformOutputPin* inOutputPin, CHAR* inObjectName, LPCWSTR inPinDisplayName, vector<CMediaType*> inAcceptableMediaTypes)
00037         :       CBaseInputPin (inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName)
00038 
00039         ,       mOutputPin (inOutputPin)
00040         ,       mParentFilter (inParentFilter)
00041         
00042         ,       mAcceptableMediaTypes(inAcceptableMediaTypes)
00043 
00044 
00045 {
00046         mStreamLock = new CCritSec;                     //Deleted in destructor.
00047 }
00048 
00049 STDMETHODIMP AbstractTransformInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00050 {
00051         //TODO::: This really shouldn't be exposed on an input pin
00052         if (riid == IID_IMediaSeeking) {
00053                 *ppv = (IMediaSeeking*)this;
00054                 ((IUnknown*)*ppv)->AddRef();
00055                 return NOERROR;
00056         }
00057 
00058         return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv); 
00059 }
00060 
00061 HRESULT AbstractTransformInputPin::BreakConnect() 
00062 {
00063         CAutoLock locLock(m_pLock);
00064         //Release the seeking delegate
00065         ReleaseDelegate();
00066         return CBaseInputPin::BreakConnect();
00067 }
00068 HRESULT AbstractTransformInputPin::CompleteConnect (IPin *inReceivePin) 
00069 {
00070         CAutoLock locLock(m_pLock);
00071         
00072         IMediaSeeking* locSeeker = NULL;
00073         inReceivePin->QueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00074         SetDelegate(locSeeker);
00075         return CBaseInputPin::CompleteConnect(inReceivePin);
00076 }
00077 AbstractTransformInputPin::~AbstractTransformInputPin(void)
00078 {
00079 
00080         delete mStreamLock;
00081         for (size_t i = 0; i < mAcceptableMediaTypes.size(); i++) {
00082                 delete mAcceptableMediaTypes[i];
00083         }
00084 
00085 }
00086 
00087 
00088 bool AbstractTransformInputPin::SetSampleParams(IMediaSample* outMediaSample, unsigned long inDataSize, REFERENCE_TIME* inStartTime, REFERENCE_TIME* inEndTime) 
00089 {
00090         outMediaSample->SetTime(inStartTime, inEndTime);
00091         outMediaSample->SetMediaTime(NULL, NULL);
00092         outMediaSample->SetActualDataLength(inDataSize);
00093         outMediaSample->SetPreroll(FALSE);
00094         outMediaSample->SetDiscontinuity(FALSE);
00095         outMediaSample->SetSyncPoint(TRUE);
00096         return true;
00097 }
00098 
00099 
00100 STDMETHODIMP AbstractTransformInputPin::Receive(IMediaSample* inSample) 
00101 {
00102         CAutoLock locLock(mStreamLock);
00103 
00104         HRESULT locHR = CheckStreaming();
00105 
00106         if (locHR == S_OK) {
00107                 BYTE* locBuff = NULL;
00108                 locHR = inSample->GetPointer(&locBuff);
00109 
00110                 if (locHR != S_OK) {
00111                         //TODO::: Do a debug dump or something here with specific error info.
00112                         return locHR;
00113                 } else {
00114                         HRESULT locResult = TransformData(locBuff, inSample->GetActualDataLength());
00115                         if (locResult == S_OK) {
00116                                 return S_OK;
00117                         } else {
00118                                 return S_FALSE;
00119                         }
00120                 }
00121         } else {
00122                 //Not streaming - Bail out.
00123                 return S_FALSE;
00124         }
00125 }
00126 
00127 HRESULT AbstractTransformInputPin::CheckMediaType(const CMediaType *inMediaType) 
00128 {
00129         //TO DO::: Neaten this up.
00130         for (size_t i = 0; i < mAcceptableMediaTypes.size(); i++) {
00131                 if      (               (inMediaType->majortype == mAcceptableMediaTypes[i]->majortype) 
00132                                 &&      (inMediaType->subtype == mAcceptableMediaTypes[i]->subtype) 
00133                                 &&      (inMediaType->formattype == mAcceptableMediaTypes[i]->formattype)
00134                         )
00135                 {
00136                         return S_OK;
00137                 } 
00138         }
00139         //If it matched none... return false.
00140         return S_FALSE;
00141 }
00142 
00143 STDMETHODIMP AbstractTransformInputPin::EndOfStream(void) {
00144         CAutoLock locLock(mStreamLock);
00145         
00146         return mParentFilter->mOutputPin->DeliverEndOfStream();
00147 }
00148 
00149 STDMETHODIMP AbstractTransformInputPin::BeginFlush() {
00150         CAutoLock locLock(m_pLock);
00151 
00152         CBaseInputPin::BeginFlush();
00153         return mParentFilter->mOutputPin->DeliverBeginFlush();
00154 }
00155 STDMETHODIMP AbstractTransformInputPin::EndFlush() {
00156         CAutoLock locLock(m_pLock);
00157 
00158         mParentFilter->mOutputPin->DeliverEndFlush();
00159         return CBaseInputPin::EndFlush();
00160 }
00161 
00162 STDMETHODIMP AbstractTransformInputPin::NewSegment(REFERENCE_TIME inStartTime, REFERENCE_TIME inStopTime, double inRate) {
00163         CAutoLock locLock(mStreamLock);
00164 
00165         //This is called on BasePin and not BaseInputPin because the implementation is not overriden in BaseOutputPin.
00166         CBasePin::NewSegment(inStartTime, inStopTime, inRate);
00167         return mParentFilter->mOutputPin->DeliverNewSegment(inStartTime, inStopTime, inRate);
00168 }
00169 
00170 HRESULT AbstractTransformInputPin::GetMediaType(int inPosition, CMediaType *outMediaType) 
00171 {
00172         //TODO::: Check for NULL Pointer.
00173         if (inPosition < 0) {
00174                 return E_INVALIDARG;
00175         } else  if (((size_t)inPosition) < mAcceptableMediaTypes.size()) {
00176                 outMediaType->SetType(&(mAcceptableMediaTypes[inPosition]->majortype));
00177                 outMediaType->SetSubtype(&(mAcceptableMediaTypes[inPosition]->subtype));
00178                 //Don't set the format data here... its up to the connecting output pin
00179                 // to do this, and we will verify it in CheckMediaType
00180                 return S_OK;
00181         } else {
00182                 return VFW_S_NO_MORE_ITEMS;
00183         }
00184 
00185 }

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