transfrm.cpp.svn-base
来自「ffshow源码」· SVN-BASE 代码 · 共 1,027 行 · 第 1/2 页
SVN-BASE
1,027 行
m_bQualityChanged = FALSE; return hr;}HRESULTCTransformFilter::NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate){ if (m_pOutput != NULL) { return m_pOutput->DeliverNewSegment(tStart, tStop, dRate); } return S_OK;}// Check streaming statusHRESULTCTransformInputPin::CheckStreaming(){ ASSERT(m_pTransformFilter->m_pOutput != NULL); if (!m_pTransformFilter->m_pOutput->IsConnected()) { return VFW_E_NOT_CONNECTED; } else { // Shouldn't be able to get any data if we're not connected! ASSERT(IsConnected()); // we're flushing if (m_bFlushing) { return S_FALSE; } // Don't process stuff in Stopped state if (IsStopped()) { return VFW_E_WRONG_STATE; } if (m_bRunTimeError) { return VFW_E_RUNTIME_ERROR; } return S_OK; }}// =================================================================// Implements the CTransformInputPin class// =================================================================// constructorCTransformInputPin::CTransformInputPin( const TCHAR *pObjectName, CTransformFilter *pTransformFilter, HRESULT * phr, LPCWSTR pName) : CBaseInputPin(pObjectName, pTransformFilter, &pTransformFilter->m_csFilter, phr, pName){ DbgLog((LOG_TRACE,2,TEXT("CTransformInputPin::CTransformInputPin"))); m_pTransformFilter = pTransformFilter; IsLockm_csReceiveRequired= TRUE;}#ifdef UNICODECTransformInputPin::CTransformInputPin( const CHAR *pObjectName, CTransformFilter *pTransformFilter, HRESULT * phr, LPCWSTR pName) : CBaseInputPin(pObjectName, pTransformFilter, &pTransformFilter->m_csFilter, phr, pName){ DbgLog((LOG_TRACE,2,TEXT("CTransformInputPin::CTransformInputPin"))); m_pTransformFilter = pTransformFilter; IsLockm_csReceiveRequired= TRUE;}#endif// provides derived filter a chance to grab extra interfacesHRESULTCTransformInputPin::CheckConnect(IPin *pPin){ HRESULT hr = m_pTransformFilter->CheckConnect(PINDIR_INPUT,pPin); if (FAILED(hr)) { return hr; } return CBaseInputPin::CheckConnect(pPin);}// provides derived filter a chance to release it's extra interfacesHRESULTCTransformInputPin::BreakConnect(){ // Can't disconnect unless stopped ASSERT(IsStopped()); m_pTransformFilter->BreakConnect(PINDIR_INPUT); return CBaseInputPin::BreakConnect();}// Let derived class know when the input pin is connectedHRESULTCTransformInputPin::CompleteConnect(IPin *pReceivePin){ HRESULT hr = m_pTransformFilter->CompleteConnect(PINDIR_INPUT,pReceivePin); if (FAILED(hr)) { return hr; } return CBaseInputPin::CompleteConnect(pReceivePin);}// check that we can support a given media typeHRESULTCTransformInputPin::CheckMediaType(const CMediaType* pmt){ // Check the input type HRESULT hr = m_pTransformFilter->CheckInputType(pmt); if (S_OK != hr) { return hr; } // if the output pin is still connected, then we have // to check the transform not just the input format if ((m_pTransformFilter->m_pOutput != NULL) && (m_pTransformFilter->m_pOutput->IsConnected())) { return m_pTransformFilter->CheckTransform( pmt, &m_pTransformFilter->m_pOutput->CurrentMediaType()); } else { return hr; }}// set the media type for this connectionHRESULTCTransformInputPin::SetMediaType(const CMediaType* mtIn){ // Set the base class media type (should always succeed) HRESULT hr = CBasePin::SetMediaType(mtIn); if (FAILED(hr)) { return hr; } // check the transform can be done (should always succeed) ASSERT(SUCCEEDED(m_pTransformFilter->CheckInputType(mtIn))); return m_pTransformFilter->SetMediaType(PINDIR_INPUT,mtIn);}// =================================================================// Implements IMemInputPin interface// =================================================================// provide EndOfStream that passes straight downstream// (there is no queued data)STDMETHODIMPCTransformInputPin::EndOfStream(void){ CAutoLock lck1(&m_pTransformFilter->m_csReceiveProtector); CAutoLock lck2(&m_pTransformFilter->m_csReceive); HRESULT hr = CheckStreaming(); if (S_OK == hr) { hr = m_pTransformFilter->EndOfStream(); } return hr;}// enter flushing state. Call default handler to block Receives, then// pass to overridable method in filterSTDMETHODIMPCTransformInputPin::BeginFlush(void){ CAutoLock lck(&m_pTransformFilter->m_csFilter); // Are we actually doing anything? ASSERT(m_pTransformFilter->m_pOutput != NULL); if (!IsConnected() || !m_pTransformFilter->m_pOutput->IsConnected()) { return VFW_E_NOT_CONNECTED; } HRESULT hr = CBaseInputPin::BeginFlush(); if (FAILED(hr)) { return hr; } return m_pTransformFilter->BeginFlush();}// leave flushing state.// Pass to overridable method in filter, then call base class// to unblock receives (finally)STDMETHODIMPCTransformInputPin::EndFlush(void){ CAutoLock lck(&m_pTransformFilter->m_csFilter); // Are we actually doing anything? ASSERT(m_pTransformFilter->m_pOutput != NULL); if (!IsConnected() || !m_pTransformFilter->m_pOutput->IsConnected()) { return VFW_E_NOT_CONNECTED; } HRESULT hr = m_pTransformFilter->EndFlush(); if (FAILED(hr)) { return hr; } return CBaseInputPin::EndFlush();}// here's the next block of data from the stream.// AddRef it yourself if you need to hold it beyond the end// of this call.HRESULTCTransformInputPin::ReceiveSub(IMediaSample * pSample){ HRESULT hr; ASSERT(pSample); // check all is well with the base class hr = CBaseInputPin::Receive(pSample); if (S_OK == hr) { hr = m_pTransformFilter->Receive(pSample); } return hr;}HRESULTCTransformInputPin::Receive(IMediaSample * pSample){ if(IsLockm_csReceiveRequired){ // default CAutoLock(&m_pTransformFilter->m_csReceiveProtector); CAutoLock(&m_pTransformFilter->m_csReceive); return ReceiveSub(pSample); } else{ // InputPin of TffdshowDecVideo doesn't want to lock m_csReceive. return ReceiveSub(pSample); }}// override to pass downstreamSTDMETHODIMPCTransformInputPin::NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate){ // Save the values in the pin CBasePin::NewSegment(tStart, tStop, dRate); return m_pTransformFilter->NewSegment(tStart, tStop, dRate);}// =================================================================// Implements the CTransformOutputPin class// =================================================================// constructorCTransformOutputPin::CTransformOutputPin( TCHAR *pObjectName, CTransformFilter *pTransformFilter, HRESULT * phr, LPCWSTR pPinName) : CBaseOutputPin(pObjectName, pTransformFilter, &pTransformFilter->m_csFilter, phr, pPinName), m_pPosition(NULL){ DbgLog((LOG_TRACE,2,TEXT("CTransformOutputPin::CTransformOutputPin"))); m_pTransformFilter = pTransformFilter;}#ifdef UNICODECTransformOutputPin::CTransformOutputPin( CHAR *pObjectName, CTransformFilter *pTransformFilter, HRESULT * phr, LPCWSTR pPinName) : CBaseOutputPin(pObjectName, pTransformFilter, &pTransformFilter->m_csFilter, phr, pPinName), m_pPosition(NULL){ DbgLog((LOG_TRACE,2,TEXT("CTransformOutputPin::CTransformOutputPin"))); m_pTransformFilter = pTransformFilter;}#endif// destructorCTransformOutputPin::~CTransformOutputPin(){ DbgLog((LOG_TRACE,2,TEXT("CTransformOutputPin::~CTransformOutputPin"))); if (m_pPosition) m_pPosition->Release();}STDAPI CreatePosPassThru( LPUNKNOWN pAgg, BOOL bRenderer, IPin *pPin, IUnknown **ppPassThru);// overriden to expose IMediaPosition and IMediaSeeking control interfacesSTDMETHODIMPCTransformOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv){ CheckPointer(ppv,E_POINTER); ValidateReadWritePtr(ppv,sizeof(PVOID)); *ppv = NULL; if (riid == IID_IMediaPosition || riid == IID_IMediaSeeking) { // we should have an input pin by now ASSERT(m_pTransformFilter->m_pInput != NULL); if (m_pPosition == NULL) { HRESULT hr = CreatePosPassThru( GetOwner(), FALSE, (IPin *)m_pTransformFilter->m_pInput, &m_pPosition); if (FAILED(hr)) { return hr; } } return m_pPosition->QueryInterface(riid, ppv); } else { return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv); }}// provides derived filter a chance to grab extra interfacesHRESULTCTransformOutputPin::CheckConnect(IPin *pPin){ // we should have an input connection first ASSERT(m_pTransformFilter->m_pInput != NULL); if ((m_pTransformFilter->m_pInput->IsConnected() == FALSE)) { return E_UNEXPECTED; } HRESULT hr = m_pTransformFilter->CheckConnect(PINDIR_OUTPUT,pPin); if (FAILED(hr)) { return hr; } return CBaseOutputPin::CheckConnect(pPin);}// provides derived filter a chance to release it's extra interfacesHRESULTCTransformOutputPin::BreakConnect(){ // Can't disconnect unless stopped ASSERT(IsStopped()); m_pTransformFilter->BreakConnect(PINDIR_OUTPUT); return CBaseOutputPin::BreakConnect();}// Let derived class know when the output pin is connectedHRESULTCTransformOutputPin::CompleteConnect(IPin *pReceivePin){ HRESULT hr = m_pTransformFilter->CompleteConnect(PINDIR_OUTPUT,pReceivePin); if (FAILED(hr)) { return hr; } return CBaseOutputPin::CompleteConnect(pReceivePin);}// check a given transform - must have selected input type firstHRESULTCTransformOutputPin::CheckMediaType(const CMediaType* pmtOut){ // must have selected input first ASSERT(m_pTransformFilter->m_pInput != NULL); if ((m_pTransformFilter->m_pInput->IsConnected() == FALSE)) { return E_INVALIDARG; } return m_pTransformFilter->CheckTransform( &m_pTransformFilter->m_pInput->CurrentMediaType(), pmtOut);}// called after we have agreed a media type to actually set it in which case// we run the CheckTransform function to get the output format type againHRESULTCTransformOutputPin::SetMediaType(const CMediaType* pmtOut){ HRESULT hr = NOERROR; ASSERT(m_pTransformFilter->m_pInput != NULL); ASSERT(m_pTransformFilter->m_pInput->CurrentMediaType().IsValid()); // Set the base class media type (should always succeed) hr = CBasePin::SetMediaType(pmtOut); if (FAILED(hr)) { return hr; }#ifdef DEBUG if (FAILED(m_pTransformFilter->CheckTransform(&m_pTransformFilter-> m_pInput->CurrentMediaType(),pmtOut))) { DbgLog((LOG_ERROR,0,TEXT("*** This filter is accepting an output media type"))); DbgLog((LOG_ERROR,0,TEXT(" that it can't currently transform to. I hope"))); DbgLog((LOG_ERROR,0,TEXT(" it's smart enough to reconnect its input."))); }#endif return m_pTransformFilter->SetMediaType(PINDIR_OUTPUT,pmtOut);}// pass the buffer size decision through to the main transform classHRESULTCTransformOutputPin::DecideBufferSize( IMemAllocator * pAllocator, ALLOCATOR_PROPERTIES* pProp){ return m_pTransformFilter->DecideBufferSize(pAllocator, pProp);}// return a specific media type indexed by iPositionHRESULTCTransformOutputPin::GetMediaType( int iPosition, CMediaType *pMediaType){ ASSERT(m_pTransformFilter->m_pInput != NULL); // We don't have any media types if our input is not connected if (m_pTransformFilter->m_pInput->IsConnected()) { return m_pTransformFilter->GetMediaType(iPosition,pMediaType); } else { return VFW_S_NO_MORE_ITEMS; }}// Override this if you can do something constructive to act on the// quality message. Consider passing it upstream as well// Pass the quality mesage on upstream.STDMETHODIMPCTransformOutputPin::Notify(IBaseFilter * pSender, Quality q){ UNREFERENCED_PARAMETER(pSender); ValidateReadPtr(pSender,sizeof(IBaseFilter)); // First see if we want to handle this ourselves HRESULT hr = m_pTransformFilter->AlterQuality(q); if (hr!=S_FALSE) { return hr; // either S_OK or a failure } // S_FALSE means we pass the message on. // Find the quality sink for our input pin and send it there ASSERT(m_pTransformFilter->m_pInput != NULL); return m_pTransformFilter->m_pInput->PassNotify(q);} // Notify// the following removes a very large number of level 4 warnings from the microsoft// compiler output, which are not useful at all in this case.#pragma warning(disable:4514)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?