AbstractAudioEncodeInputPin.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 "abstractaudioencodeinputpin.h"
00034 
00035 //#include <mtype.h>
00036 AbstractAudioEncodeInputPin::AbstractAudioEncodeInputPin(AbstractAudioEncodeFilter* inParentFilter, CCritSec* inFilterLock, AbstractAudioEncodeOutputPin* inOutputPin, CHAR* inObjectName, LPCWSTR inPinDisplayName)
00037         :       CBaseInputPin(inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName),
00038                 mOutputPin(inOutputPin),
00039                 mUptoFrame(0),
00040                 mBegun(false),
00041                 mParentFilter(inParentFilter)
00042         
00043 {
00044         //debugLog.open("C:\\temp\\aaein.log", ios_base::out);
00045         //ConstructCodec();
00046 
00047         //Set the seek delegate... make the outpin pin send stuff to this pin.
00048         IMediaSeeking* locSeeker = NULL;
00049         this->NonDelegatingQueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00050         mOutputPin->SetDelegate(locSeeker);
00051 
00052 }
00053 
00054 STDMETHODIMP AbstractAudioEncodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00055 {
00056         if (riid == IID_IMediaSeeking) {
00057                 *ppv = (IMediaSeeking*)this;
00058                 ((IUnknown*)*ppv)->AddRef();
00059                 return NOERROR;
00060         }
00061 
00062         return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv); 
00063 }
00064 
00065 HRESULT AbstractAudioEncodeInputPin::CompleteConnect (IPin *inReceivePin) {
00066         //CAutoLock locLock(mFilterLock);
00067         
00068         IMediaSeeking* locSeeker = NULL;
00069         inReceivePin->QueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00070         SetDelegate(locSeeker);
00071         return CBaseInputPin::CompleteConnect(inReceivePin);
00072 }
00073 AbstractAudioEncodeInputPin::~AbstractAudioEncodeInputPin(void)
00074 {
00075         //debugLog.close();
00076         //DestroyCodec();
00077 }
00078 
00079 
00080 void AbstractAudioEncodeInputPin::ResetFrameCount() {
00081         mUptoFrame = 0;
00082         
00083 }
00084 bool AbstractAudioEncodeInputPin::SetSampleParams(IMediaSample* outMediaSample, unsigned long inDataSize, REFERENCE_TIME* inStartTime, REFERENCE_TIME* inEndTime) 
00085 {
00086         outMediaSample->SetTime(inStartTime, inEndTime);
00087         outMediaSample->SetMediaTime(NULL, NULL);
00088         outMediaSample->SetActualDataLength(inDataSize);
00089         outMediaSample->SetPreroll(FALSE);
00090         outMediaSample->SetDiscontinuity(FALSE);
00091         outMediaSample->SetSyncPoint(TRUE);
00092         return true;
00093 }
00094 
00095 
00096 STDMETHODIMP AbstractAudioEncodeInputPin::Receive(IMediaSample* inSample) {
00097 
00098         //debugLog <<endl<< "Received sample..."<<endl;
00099         HRESULT locHR;
00100         BYTE* locBuff = NULL;
00101         locHR = inSample->GetPointer(&locBuff);
00102 
00103         if (FAILED(locHR)) {
00104                 //debugLog << "Failed to get pointer... bailing out"<<endl;
00105                 return locHR;
00106         } else {
00107                 
00108                 long locResult = encodeData(locBuff, inSample->GetActualDataLength());
00109                 if (locResult >= 0) {
00110                         //debugLog << "Encode Data returns 0... OK"<<endl;
00111                         return S_OK;
00112                 } else {
00113                         //debugLog<< "Encode Data returns "<<locResult<<" FAILURE"<<endl;
00114                         return S_FALSE;
00115                 }
00116         }
00117 
00118         //debugLog<<"Receive falls through... returning OK"<<endl;
00119         return S_OK;
00120 }
00121 
00122 HRESULT AbstractAudioEncodeInputPin::CheckMediaType(const CMediaType *inMediaType) {
00123         //FIX::: Clean this up !
00124         
00125         if      (       (inMediaType->majortype == MEDIATYPE_Audio) &&
00126                         (inMediaType->subtype == MEDIASUBTYPE_PCM) &&
00127                         (inMediaType->formattype == FORMAT_WaveFormatEx)
00128                 )
00129         {
00130                 return S_OK;
00131         } else {
00132                 return S_FALSE;
00133         }
00134 }
00135 
00136 STDMETHODIMP AbstractAudioEncodeInputPin::EndOfStream(void) {
00137         return mParentFilter->mOutputPin->DeliverEndOfStream();
00138 }
00139 
00140 STDMETHODIMP AbstractAudioEncodeInputPin::BeginFlush() {
00141         CAutoLock locLock(m_pLock);
00142         CBaseInputPin::BeginFlush();
00143         return mParentFilter->mOutputPin->DeliverBeginFlush();
00144 }
00145 STDMETHODIMP AbstractAudioEncodeInputPin::EndFlush() {
00146         CAutoLock locLock(m_pLock);
00147         CBaseInputPin::EndFlush();
00148         return mParentFilter->mOutputPin->DeliverEndFlush();
00149 
00150 }
00151 
00152 STDMETHODIMP AbstractAudioEncodeInputPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
00153         return mParentFilter->mOutputPin->DeliverNewSegment(tStart, tStop, dRate);
00154 }
00155 
00156 HRESULT AbstractAudioEncodeInputPin::SetMediaType(const CMediaType* inMediaType) {
00157         //FIX:::Error checking
00158         //RESOLVED::: Bit better.
00159 
00160         if (inMediaType->subtype == MEDIASUBTYPE_PCM) {
00161                 mWaveFormat = (WAVEFORMATEX*)inMediaType->pbFormat;
00162                 //mParentFilter->mAudioFormat = AbstractAudioDecodeFilter::VORBIS;
00163         } else {
00164                 //Failed... should never be here !
00165                 throw 0;
00166         }
00167         return CBaseInputPin::SetMediaType(inMediaType);
00168 }
00169 
00170 HRESULT AbstractAudioEncodeInputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00171 
00172         if (inPosition < 0) {
00173                 return E_INVALIDARG;
00174         }
00175 
00176         switch (inPosition) {
00177                 case 0:
00178 
00179                         outMediaType->SetType(&MEDIATYPE_Audio);
00180                         outMediaType->SetSubtype(&MEDIASUBTYPE_PCM);
00181                         //Don't set the format data here. That's up to our output pin/
00182                         return S_OK;                    
00183                 default:
00184                         return VFW_S_NO_MORE_ITEMS;
00185         }
00186 }

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