AbstractVideoEncodeInputPin.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 #include "stdafx.h"
00032 #include "abstractvideoencodeinputpin.h"
00033 
00034 AbstractVideoEncodeInputPin::AbstractVideoEncodeInputPin(AbstractVideoEncodeFilter* inParentFilter, CCritSec* inFilterLock, AbstractVideoEncodeOutputPin* inOutputPin, CHAR* inObjectName, LPCWSTR inPinDisplayName)
00035         :       CBaseInputPin(inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName),
00036                 mOutputPin(inOutputPin),
00037                 mUptoFrame(0),
00038                 mBegun(false),
00039                 mParentFilter(inParentFilter)
00040         ,       mHeight(0)
00041         ,       mWidth(0)
00042         
00043 {
00044         //debugLog.open("C:\\temp\\aaein.log", ios_base::out);
00045         //ConstructCodec();
00046 
00047         //Set up the seeking path... this tells the output to deliver messages to this pin.
00048         IMediaSeeking* locSeeker = NULL;
00049         this->NonDelegatingQueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00050         mOutputPin->SetDelegate(locSeeker);
00051         
00052 }
00053 
00054 AbstractVideoEncodeInputPin::~AbstractVideoEncodeInputPin(void)
00055 {
00056         //debugLog.close();
00057         //DestroyCodec();
00058 }
00059 
00060 STDMETHODIMP AbstractVideoEncodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00061         if (riid == IID_IMediaSeeking) {
00062                 *ppv = (IMediaSeeking*)this;
00063                 ((IUnknown*)*ppv)->AddRef();
00064                 return NOERROR;
00065         }
00066 
00067         return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv); 
00068 }
00069 
00070 void AbstractVideoEncodeInputPin::ResetFrameCount() {
00071         mUptoFrame = 0;
00072         
00073 }
00074 bool AbstractVideoEncodeInputPin::SetSampleParams(IMediaSample* outMediaSample, unsigned long inDataSize, REFERENCE_TIME* inStartTime, REFERENCE_TIME* inEndTime) 
00075 {
00076         outMediaSample->SetTime(inStartTime, inEndTime);
00077         outMediaSample->SetMediaTime(NULL, NULL);
00078         outMediaSample->SetActualDataLength(inDataSize);
00079         outMediaSample->SetPreroll(FALSE);
00080         outMediaSample->SetDiscontinuity(FALSE);
00081         outMediaSample->SetSyncPoint(TRUE);
00082         return true;
00083 }
00084 
00085 HRESULT AbstractVideoEncodeInputPin::CompleteConnect (IPin *inReceivePin) {
00086         CAutoLock locLock(m_pLock);
00087         
00088         //When another filters output pin connects to us, we redirect all outr seek messages to them.
00089         IMediaSeeking* locSeeker = NULL;
00090         inReceivePin->QueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00091         SetDelegate(locSeeker);
00092         return CBaseInputPin::CompleteConnect(inReceivePin);
00093 }
00094 STDMETHODIMP AbstractVideoEncodeInputPin::Receive(IMediaSample* inSample) {
00095 
00096         //debugLog <<endl<< "Received sample..."<<endl;
00097         HRESULT locHR;
00098         BYTE* locBuff = NULL;
00099         locHR = inSample->GetPointer(&locBuff);
00100 
00101         if (FAILED(locHR)) {
00102                 //debugLog << "Failed to get pointer... bailing out"<<endl;
00103                 return locHR;
00104         } else {
00105                 __int64 locTimeStart;
00106                 __int64 locTimeEnd;
00107                 inSample->GetTime(&locTimeStart, &locTimeEnd);
00108                 inSample->GetMediaTime(&locTimeStart, &locTimeEnd);
00109                 long locResult = encodeData(locBuff, inSample->GetActualDataLength());
00110                 if (locResult >= 0) {
00111                         //debugLog << "Encode Data returns 0... OK"<<endl;
00112                         return S_OK;
00113                 } else {
00114                         //debugLog<< "Encode Data returns "<<locResult<<" FAILURE"<<endl;
00115                         return S_FALSE;
00116                 }
00117         }
00118 
00119         //debugLog<<"Receive falls through... returning OK"<<endl;
00120         return S_OK;
00121 }
00122 
00123 HRESULT AbstractVideoEncodeInputPin::CheckMediaType(const CMediaType *inMediaType) {
00124         //FIX::: Clean this up !
00125         
00126         if      ( (inMediaType->majortype == MEDIATYPE_Video) &&
00127                         (       inMediaType->subtype == MEDIASUBTYPE_YV12 ||
00128                                 inMediaType->subtype == MEDIASUBTYPE_IYUV ||
00129                                 inMediaType->subtype == MEDIASUBTYPE_YUY2 ||
00130                                 inMediaType->subtype == MEDIASUBTYPE_UYVY ||
00131                                 inMediaType->subtype == MEDIASUBTYPE_YVYU ||
00132                                 inMediaType->subtype == MEDIASUBTYPE_AYUV ||
00133                                 inMediaType->subtype == MEDIASUBTYPE_RGB32 ||
00134                                 inMediaType->subtype == MEDIASUBTYPE_RGB24
00135                         ) &&
00136                         (inMediaType->formattype == FORMAT_VideoInfo)
00137                 )
00138         {
00139                 return S_OK;
00140         } else {
00141                 return S_FALSE;
00142         }
00143 }
00144 
00145 STDMETHODIMP AbstractVideoEncodeInputPin::EndOfStream(void) {
00146         return mParentFilter->mOutputPin->DeliverEndOfStream();
00147 }
00148 
00149 STDMETHODIMP AbstractVideoEncodeInputPin::BeginFlush() {
00150         CAutoLock locLock(m_pLock);
00151         CBaseInputPin::BeginFlush();
00152         return mParentFilter->mOutputPin->DeliverBeginFlush();
00153 }
00154 STDMETHODIMP AbstractVideoEncodeInputPin::EndFlush() {
00155         CAutoLock locLock(m_pLock);
00156         CBaseInputPin::EndFlush();
00157         return mParentFilter->mOutputPin->DeliverEndFlush();
00158 
00159 }
00160 
00161 STDMETHODIMP AbstractVideoEncodeInputPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
00162         return mParentFilter->mOutputPin->DeliverNewSegment(tStart, tStop, dRate);
00163 }
00164 
00165 HRESULT AbstractVideoEncodeInputPin::SetMediaType(const CMediaType* inMediaType) {
00166         //FIX:::Error checking
00167         //RESOLVED::: Bit better.
00168 
00169         if  (   inMediaType->subtype == MEDIASUBTYPE_YV12 || 
00170                         inMediaType->subtype == MEDIASUBTYPE_IYUV ||
00171                         inMediaType->subtype == MEDIASUBTYPE_YUY2 ||
00172                         inMediaType->subtype == MEDIASUBTYPE_UYVY ||
00173                         inMediaType->subtype == MEDIASUBTYPE_YVYU ||
00174                         inMediaType->subtype == MEDIASUBTYPE_AYUV ||
00175                         inMediaType->subtype == MEDIASUBTYPE_RGB32 ||
00176                         inMediaType->subtype == MEDIASUBTYPE_RGB24
00177                 ) {
00178                 mVideoFormat = (VIDEOINFOHEADER*)inMediaType->pbFormat;
00179                 mPinInputType = *inMediaType;
00180                 //mParentFilter->mAudioFormat = AbstractAudioDecodeFilter::VORBIS;
00181         } else {
00182                 //Failed... should never be here !
00183                 throw 0;
00184         }
00185         return CBaseInputPin::SetMediaType(inMediaType);
00186 }
00187 
00188 HRESULT AbstractVideoEncodeInputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00189 
00190         if (inPosition < 0) {
00191                 return E_INVALIDARG;
00192         }
00193 
00194         switch (inPosition) {
00195                 case 0:
00196 
00197                         outMediaType->SetType(&MEDIATYPE_Video);
00198                         outMediaType->SetSubtype(&MEDIASUBTYPE_YV12);
00199                         //Don't set the format data here. That's up to our output pin/
00200                         return S_OK;
00201                 case 1:
00202                         outMediaType->SetType(&MEDIATYPE_Video);
00203                         outMediaType->SetSubtype(&MEDIASUBTYPE_YUY2);
00204                         return S_OK;
00205                 case 2:
00206                         outMediaType->SetType(&MEDIATYPE_Video);
00207                         outMediaType->SetSubtype(&MEDIASUBTYPE_RGB32);
00208                         return S_OK;
00209                 case 3:
00210                         outMediaType->SetType(&MEDIATYPE_Video);
00211                         outMediaType->SetSubtype(&MEDIASUBTYPE_RGB24);
00212                         return S_OK;
00213                 case 4:
00214                         outMediaType->SetType(&MEDIATYPE_Video);
00215                         outMediaType->SetSubtype(&MEDIASUBTYPE_AYUV);
00216                         return S_OK;
00217                 case 5:
00218                         outMediaType->SetType(&MEDIATYPE_Video);
00219                         outMediaType->SetSubtype(&MEDIASUBTYPE_UYVY);
00220                         return S_OK;
00221                 case 6:
00222                         outMediaType->SetType(&MEDIATYPE_Video);
00223                         outMediaType->SetSubtype(&MEDIASUBTYPE_YVYU);
00224                         return S_OK;
00225                 case 7:
00226                         outMediaType->SetType(&MEDIATYPE_Video);
00227                         outMediaType->SetSubtype(&MEDIASUBTYPE_IYUV);
00228                         return S_OK;
00229 
00230                         
00231 
00232 
00233                 default:
00234                         return VFW_S_NO_MORE_ITEMS;
00235         }
00236 }

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