📄 inputpin.cpp
字号:
/*+++ *******************************************************************\
*
* Copyright and Disclaimer:
*
* ---------------------------------------------------------------
* This software is provided "AS IS" without warranty of any kind,
* either expressed or implied, including but not limited to the
* implied warranties of noninfringement, merchantability and/or
* fitness for a particular purpose.
* ---------------------------------------------------------------
*
* Copyright (c) 2008 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#pragma warning(disable : 4996)
#include <streams.h>
#pragma warning(default : 4996)
#include "guiids.h"
#include "inputpin.h"
#include "outputpin.h"
#include "Y8Filter.h"
//**********************************************************************
// input pin functions
//**********************************************************************
//
// Constructor
//
CInputPin::CInputPin(CY8Filter *pFilter,
HRESULT *phr,
LPCWSTR pPinName) :
CBaseInputPin(
NAME("CInputPin"),
pFilter,
pFilter->getCriticalSection(),
phr,
pPinName),
m_pFilter(pFilter)
{
} // (Constructor)
//
// Destructor does nothing
//
CInputPin::~CInputPin()
{
} // (Destructor)
//
// CheckMediaType
//
// Check that we can support a given proposed type
//
HRESULT CInputPin::CheckMediaType(const CMediaType *pmt)
{
// Reject non-video types
if (pmt->majortype != MEDIATYPE_Video )
{
return S_FALSE;
}
if(pmt->subtype != MEDIASUBTYPE_CXY8 && pmt->subtype != MEDIASUBTYPE_UYVY)
{
return S_FALSE;
}
return S_OK;
} // CheckMediaType
//SetMediaType
HRESULT CInputPin::SetMediaType(const CMediaType *pMediaType)
{
if(pMediaType->formattype == FORMAT_VideoInfo)
{
m_pFilter->setInputFormat((VIDEOINFOHEADER*)pMediaType->pbFormat);
}
//Get the output pin
CBasePin* p_out_pin = m_pFilter->GetPin(OUTPUT_PIN_INDEX);
//If the output pin is connected, we need to reconnect it so that the format
// applies to the downstream filter correctly
if(p_out_pin->IsConnected())
{
//Note that neither the filter graph or the connected pin need to be released
// since the calls below do not add references to them.
//Get the filter graph
IFilterGraph* p_filter_graph = m_pFilter->GetFilterGraph();
//Get the pin connected to our output pin
IPin* p_connected_pin = p_out_pin->GetConnected();
if(p_filter_graph && p_connected_pin)
{
//Disconnect the pins
p_filter_graph->Disconnect(p_connected_pin);
p_filter_graph->Disconnect(p_out_pin);
//Get the output pin's media type
CMediaType media_type;
p_out_pin->GetMediaType(0, &media_type);
//Reconnect the pins with the new media type
p_filter_graph->ConnectDirect(p_out_pin, p_connected_pin, &media_type);
}
}
p_out_pin->SetMediaType(pMediaType);
return CBaseInputPin::SetMediaType(pMediaType);
}
//
// Active
//
// Implements the remaining IMemInputPin virtual methods
//
HRESULT CInputPin::Active(void)
{
return CBaseInputPin::Active();
} // Active
//
// Inactive
//
// Called when the filter is stopped
//
HRESULT CInputPin::Inactive(void)
{
return CBaseInputPin::Inactive();
} // Inactive
HRESULT CInputPin::Notify(IBaseFilter * pSender, Quality q){
return CBaseInputPin::Notify(pSender,q);
}
//
// Receive
//
// Here's the next block of data from the stream
//
HRESULT CInputPin::Receive(IMediaSample * pSample)
{
CAutoLock lck(&_critical_section);
LPBYTE p_input_buffer;
HRESULT hr = pSample->GetPointer(&p_input_buffer);
//Get input sample size
DWORD input_buffer_size = pSample->GetActualDataLength();
IMediaSample *pOutSample;
COutputPin* p_out_pin = (COutputPin*)m_pFilter->GetPin(OUTPUT_PIN_INDEX);
if(FAILED(p_out_pin->GetDeliveryBuffer(&pOutSample , NULL,NULL,0)))
{
return E_POINTER;
}
//Time stamp the sample
REFERENCE_TIME tStart,tStop;
hr = pSample->GetTime(&tStart,&tStop);
if ( (hr == S_OK) || (hr == VFW_S_NO_STOP_TIME))
{
pOutSample->SetTime(&tStart,&tStop);
}
if(pSample->IsDiscontinuity() == S_OK)
{
pOutSample->SetDiscontinuity(TRUE);
}
if (pSample->IsSyncPoint() == S_OK)
{
pOutSample->SetSyncPoint(TRUE);
}
if(S_OK == pSample->IsPreroll())
{
pOutSample->SetPreroll(TRUE);
}
// Copy the media type
AM_MEDIA_TYPE *pMediaType;
if(S_OK == pSample->GetMediaType(&pMediaType))
{
pOutSample->SetMediaType(pMediaType);
DeleteMediaType(pMediaType);
}
// Copy the sample media times
REFERENCE_TIME TimeStart, TimeEnd;
if(pSample->GetMediaTime(&TimeStart,&TimeEnd) == NOERROR)
{
pOutSample->SetMediaTime(&TimeStart,&TimeEnd);
}
DWORD output_buffer_size = pOutSample->GetSize();
if (!output_buffer_size)
{
pOutSample->Release();
return S_OK;
}
DWORD width = m_pFilter->getWidth();
DWORD height = m_pFilter->getHeight();
//Make sure the buffer is big enough
if(output_buffer_size < (width*height*2))
{
pOutSample->Release();
return S_FALSE;
}
if(input_buffer_size < (width*height))
{
pOutSample->Release();
return S_FALSE;
}
PBYTE p_output_buffer;
if(FAILED(pOutSample->GetPointer(&p_output_buffer)))
{
pOutSample->Release();
return E_POINTER;
}
m_pFilter->convertBuffer(
p_input_buffer,
p_output_buffer,
input_buffer_size,
output_buffer_size,
&(this->m_mt));
pOutSample->SetActualDataLength(output_buffer_size);
p_out_pin->Deliver(pOutSample);
pOutSample->Release();
return S_OK;
} // Receive
HRESULT CInputPin::EndOfStream()
{
COutputPin* p_out_pin = (COutputPin*)m_pFilter->GetPin(OUTPUT_PIN_INDEX);
p_out_pin->DeliverEndOfStream();
return CBasePin::EndOfStream();
} //CompleteConnect
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -