2,543
社区成员
发帖
与我相关
我的任务
分享
// 媒体改变
STDMETHODIMP CVideoProcessorOutputPin::ChangeMediaType(const AM_MEDIA_TYPE *pmt)
{
CheckPointer(m_Connected, E_POINTER);
CheckPointer(pmt, E_POINTER);
HRESULT hr = m_Connected->QueryAccept(pmt);
if(FAILED(hr))
{
return hr;
}
hr = m_Connected->ReceiveConnection(this, pmt);
if(FAILED(hr))
{
return hr;
}
CMediaType mt = *pmt;
SetMediaType(&mt);
hr = m_pAllocator->Decommit();
if(FAILED(hr))
{
return hr;
}
hr = CompleteConnect(m_Connected);
if(FAILED(hr))
{
return hr;
}
hr = m_pAllocator->Commit();
if(FAILED(hr))
{
return hr;
}
return S_OK;
}
// 分配空间 (这个只处理YV12)
HRESULT CVideoProcessor::DecideBufferSize(IMemAllocator *pAllocator, ALLOCATOR_PROPERTIES *pprop)
{
CheckPointer(pAllocator, E_POINTER);
CheckPointer(pprop, E_POINTER);
int width = m_nWidthOut ? m_nWidthOut : m_nWidthIn;
int height = m_nHeightOut ? m_nHeightOut : m_nHeightIn;
pprop->cbBuffer = width * height * 3 / 2;
pprop->cBuffers = 1;
ALLOCATOR_PROPERTIES Actual;
HRESULT hr = pAllocator->SetProperties(pprop, &Actual);
if(FAILED(hr))
{
return E_UNEXPECTED;
}
m_nWidthOutRender = 0;
return S_OK;
}
HRESULT CVideoProcessor::Receive(IMediaSample *pSample)
{
...
if(m_bOutSizeChanged)
{
CMediaType mt;
... // 设置媒体类型
HRESULT hr = ((CVideoProcessorOutputPin *)m_pOutput)->ChangeMediaType(&mt);
if(SUCCEEDED(hr))
{
IMediaSample *pOutSample = NULL;
hr = m_pOutput->GetDeliveryBuffer(&pOutSample, NULL, NULL, 0);
if(SUCCEEDED(hr))
{
pmt = NULL;
hr = pOutSample->GetMediaType(&pmt);
if(SUCCEEDED(hr) && pmt)
{
if(pmt->formattype == FORMAT_VideoInfo)
{
VIDEOINFOHEADER* hrIn = (VIDEOINFOHEADER*)pmt->pbFormat;
m_nWidthOutRender = hrIn->bmiHeader.biWidth;
}
else if(pmt->formattype == FORMAT_VideoInfo2)
{
VIDEOINFOHEADER2* hrIn = (VIDEOINFOHEADER2*)pmt->pbFormat;
m_nWidthOutRender = hrIn->bmiHeader.biWidth;
}
DeleteMediaType(pmt);
}
pOutSample->Release();
}
int nWidth = m_nWidthOut ? m_nWidthOut : m_nWidthIn;
int nHeight = m_nHeightOut ? m_nHeightOut : m_nHeightIn;
NotifyEvent(EC_VIDEO_SIZE_CHANGED, MAKELPARAM(nWidth, nHeight), 0);
}
}
...
}