⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compedpin.cpp

📁 对比两个AVI文件的psnr值的VC源代码
💻 CPP
字号:
// AudioPin.cpp: implementation of the CCompedPin class.
//
//////////////////////////////////////////////////////////////////////
#include <streams.h>
#include "CompedPin.h"
#include "AviPsnrFilter.h"
#include "DelegateFilter.h"
#include <dvdmedia.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define VEDIOLENTH 1000
CCompedPin::CCompedPin(CDelegatorFilter *pDelegateWriter,
                  LPUNKNOWN pUnk,
                  CBaseFilter *pFilter,
                  CCritSec *pLock,
                  CCritSec *pReceiveLock,
                  HRESULT *phr):

    CRenderedInputPin(NAME("CTTLAviWriteAudioPin"),
                  pFilter,                   // Filter
                  pLock,                     // Locking
                  phr,                       // Return code
                  L"CompressedInput"),
	m_pDelegator(pDelegateWriter),
	m_pReceiveLock(pReceiveLock)
{

}

CCompedPin::~CCompedPin()
{

}

HRESULT CCompedPin::CheckMediaType(const CMediaType *pmt)
{
	CAutoLock lock_it(m_pLock);
	if (*pmt->Type() == MEDIATYPE_Video) {
		if (*pmt->FormatType() == FORMAT_VideoInfo) {
			VIDEOINFOHEADER* videoFormat = (VIDEOINFOHEADER*) pmt->Format();
			m_FourCC = videoFormat->bmiHeader.biCompression;
			if(m_pDelegator->m_nWidth==0&&m_pDelegator->m_nHeight == 0)
			{
				m_pDelegator->m_nWidth = videoFormat->bmiHeader.biWidth;
				m_pDelegator->m_nHeight = videoFormat->bmiHeader.biHeight;
			}
			else
			{
				if(m_pDelegator->m_nWidth != videoFormat->bmiHeader.biWidth)
					return VFW_E_TYPE_NOT_ACCEPTED;
				if(m_pDelegator->m_nHeight != videoFormat->bmiHeader.biHeight)
					return VFW_E_TYPE_NOT_ACCEPTED;
				
				if(m_pDelegator->AllocBuffer()==0)
					return VFW_E_TYPE_NOT_ACCEPTED;
			}

			if(videoFormat->AvgTimePerFrame == 0)
				m_pDelegator->m_dbFramerate =0;
			else
				m_pDelegator->m_dbFramerate = (double)10000000/videoFormat->AvgTimePerFrame;
			return S_OK; 
		}
		
		if (*pmt->FormatType() == FORMAT_VideoInfo2) {
			VIDEOINFOHEADER2* videoFormat = (VIDEOINFOHEADER2*) pmt->Format();
			m_FourCC = videoFormat->bmiHeader.biCompression;
			if(m_pDelegator->m_nWidth==0&&m_pDelegator->m_nHeight == 0)
			{
				m_pDelegator->m_nWidth = videoFormat->bmiHeader.biWidth;
				m_pDelegator->m_nHeight = videoFormat->bmiHeader.biHeight;
			}
			else
			{
				if(m_pDelegator->m_nWidth != videoFormat->bmiHeader.biWidth)
					return VFW_E_TYPE_NOT_ACCEPTED;
				if(m_pDelegator->m_nHeight != videoFormat->bmiHeader.biHeight)
					return VFW_E_TYPE_NOT_ACCEPTED;

			}
			if(videoFormat->AvgTimePerFrame == 0)
				m_pDelegator->m_dbFramerate =0;
			else
				m_pDelegator->m_dbFramerate = (double)10000000/videoFormat->AvgTimePerFrame;
			return S_OK; 
		}
	}
	return VFW_E_TYPE_NOT_ACCEPTED;
}

STDMETHODIMP CCompedPin::Receive(IMediaSample *pSample)
{
	CheckPointer(pSample,E_POINTER);
	if (m_pDelegator->m_bStopped)
		return NOERROR;
	HRESULT hr=S_OK;

	//如果压缩视频流来的太快,等待
	while(m_pDelegator->m_nCompCount>m_pDelegator->m_nSrcCount)
		Sleep(2);

	DWORD dwlen = pSample->GetActualDataLength();
	LPBYTE pData;
	pSample->GetPointer(&pData);
	m_pDelegator->GiveFrame(pData, dwlen, 1);
	return hr;
}

STDMETHODIMP CCompedPin::EndOfStream(void)
{
	CAutoLock lock(m_pReceiveLock);

	m_pDelegator->m_bSourceEnd = TRUE;
	
	if (m_pDelegator->m_bSourceEnd&&m_pDelegator->m_bCompedEnd)
	{

		HRESULT hr = m_pDelegator->m_pFilter->NotifyEvent(EC_COMPLETE, S_OK, (LONG_PTR)(IBaseFilter *)m_pDelegator->m_pFilter);
		m_pDelegator->ReleaseAviRs();
	}

	return CRenderedInputPin::EndOfStream();
}

STDMETHODIMP CCompedPin::ReceiveCanBlock()
{
    return S_FALSE;
}

HRESULT CCompedPin::BreakConnect()
{
	if (m_pDelegator->m_pPosition != NULL) {
		m_pDelegator->m_pPosition->ForceRefresh();
	}
    return CRenderedInputPin::BreakConnect();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -