TVStreamSinkPins.cpp
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:4k
源码类别:
P2P编程
开发平台:
Visual C++
- /*
- * Openmysee
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
- #include "stdafx.h"
- #include "TVstreamsinkpins.h"
- #include "TVstreamsink.h"
- #include "CaptureServer.h"
- // { Implementation of CTVStreamSinkInputPin
- CTVStreamSinkInputPin::CTVStreamSinkInputPin( CTVStreamSink *pFilter,
- CCritSec *pLock,
- HRESULT *phr,
- LPCWSTR pName,
- BOOL isAudio )
- : CRenderedInputPin(_T(isAudio ? "TVSink Audio Input Pin" : "TVSink Video Input Pin"),
- (CBaseFilter *)pFilter, pLock, phr, pName)
- {
- m_pFilter = pFilter;
- m_SampleHeader.bAudioSample = isAudio;
- }
- CTVStreamSinkInputPin::~CTVStreamSinkInputPin()
- {
- }
- #ifdef GENERATE_SMALL_ZZL
- int audio_smple_count = 0;
- #endif
- STDMETHODIMP CTVStreamSinkInputPin::Receive(IMediaSample *pSample)
- {
- CheckPointer(pSample, E_POINTER);
- CAutoLock lock(&m_ReceiveLock);
- REFERENCE_TIME start, end;
- PBYTE pbData;
- HRESULT hr;
- if(FAILED(hr = pSample->GetPointer(&pbData)))
- return hr;
- if(FAILED(hr = pSample->GetTime(&start, &end)))
- return hr;
- assert(end >= start || end-start <= UINT_MAX);
- // Sample头信息
- m_SampleHeader.start = start;
- m_SampleHeader.length = static_cast<UINT>(end - start);
- m_SampleHeader.size = pSample->GetActualDataLength() + sizeof(SampleHeader);
- m_SampleHeader.bDiscontinuity = (pSample->IsDiscontinuity() == S_OK);
- m_SampleHeader.bPreroll = (pSample->IsPreroll() == S_OK);
- m_SampleHeader.bSyncPoint = (pSample->IsSyncPoint() == S_OK);
- // size must be less than 2^28
- assert(m_SampleHeader.size < 268435456);
- // 保存Sample
- if(!m_pFilter->cs.PutSample(m_SampleHeader, pbData))
- return E_FAIL;
- #ifdef GENERATE_SMALL_ZZL
- if(m_SampleHeader.bAudioSample) {
- audio_smple_count++;
- if(audio_smple_count < 4) {
- if(!m_pFilter->cs.PutSample(m_SampleHeader, pbData))
- return E_FAIL;
- }
- }
- #endif
- return S_OK;
- }
- STDMETHODIMP CTVStreamSinkInputPin::EndOfStream(void)
- {
- HRESULT hr;
- CAutoLock lock(&m_ReceiveLock);
- hr = CRenderedInputPin::EndOfStream();
- //因为在pGen下,该函数
- BOOL lbDisplayDialog = FALSE;
- if (S_OK == hr)
- {
- CAutoLock lolock(&m_pFilter->m_Lock);
- m_pFilter->m_iIsStop ++;
- if (2 == m_pFilter->m_iIsStop || 1 == m_pFilter->m_iIsStop
- &&TRUE == m_pFilter->cs.m_bIsOnlyOnePin)
- {
- m_pFilter->cs.Stop();
- m_pFilter->m_iState = 1;
- //MessageBox(NULL,"转换结束","ZZL转化Graph",MB_OK|MB_ICONINFORMATION);
- }
- }
- return hr;
- }
- STDMETHODIMP CTVStreamSinkInputPin::ReceiveCanBlock()
- {
- return S_FALSE;
- }
- HRESULT CTVStreamSinkInputPin::CheckMediaType(const CMediaType *pmt)
- {
- CAutoLock lock(&m_ReceiveLock);
- if (TRUE == m_SampleHeader.bAudioSample)
- {
- if(MEDIATYPE_AnalogVideo == pmt->majortype
- || MEDIATYPE_File == pmt->majortype
- || MEDIATYPE_ScriptCommand == pmt->majortype
- || MEDIATYPE_Text == pmt->majortype
- || MEDIATYPE_Timecode == pmt->majortype
- || MEDIATYPE_Video == pmt->majortype)
- {
- return E_FAIL;
- }
- }
- else
- {
- if (MEDIATYPE_AnalogAudio == pmt->majortype
- || MEDIATYPE_Audio == pmt->majortype
- || MEDIATYPE_File == pmt->majortype
- || MEDIATYPE_ScriptCommand == pmt->majortype
- || MEDIATYPE_Text == pmt->majortype
- || MEDIATYPE_Timecode == pmt->majortype)
- {
- return E_FAIL;
- }
- }
- if(!pmt)
- return ((CTVStreamSink*)m_pFilter)->WriteFormatTypeHeader(&m_mt, m_SampleHeader.bAudioSample);
- else
- return ((CTVStreamSink*)m_pFilter)->WriteFormatTypeHeader(const_cast<CMediaType *>(pmt), m_SampleHeader.bAudioSample);
- }
- // Implementation of CTVStreamSinkInputPin }