我写了个resizer filter ,在函数CheckInputType(const CMediaType *mtIn)里指定了只接受RGB24,所以input output 针都是 RGB24 格式的.但分辨率和 biSizeImage 不同. 输出后出现花屏或花屏,求指点?
HRESULT CMyTransformFilter::Transform(IMediaSample *pIn, IMediaSample *pOut)
{
CheckPointer(pIn,E_POINTER);
CheckPointer(pOut,E_POINTER);
BYTE *pDibBitsIn,*pDibBitsOut;
HGDIOBJ OldObjectIn,OldObjectOut;
HDC hdcIn,hdcOut,hdc;
BYTE *pBufferIn,*pBufferOut;
VIDEOINFOHEADER* pVIIn = (VIDEOINFOHEADER*)m_pInput->CurrentMediaType().Format( );
VIDEOINFOHEADER* pVIOut=(VIDEOINFOHEADER*)m_pOutput->CurrentMediaType().Format();
pVIOut->rcTarget.right=(LONG)m_iWidth;pVIOut->rcTarget.bottom=(LONG)m_iHeight;
pIn->GetPointer(&pBufferIn);
pOut->GetPointer(&pBufferOut);
hdcIn=CreateCompatibleDC(NULL);
hdcOut=CreateCompatibleDC(NULL);
HBITMAP hDIBIn=CreateDIBitmap(hdcIn,&pVIIn->bmiHeader,CBM_INIT,(void*)pBufferIn,(BITMAPINFO*)&pVIIn->bmiHeader,DIB_RGB_COLORS);
HBITMAP hDIBOut=CreateDIBitmap(hdcOut,&pVIOut->bmiHeader,0,NULL,NULL,DIB_RGB_COLORS);
OldObjectIn=SelectObject(hdcIn,hDIBIn);
OldObjectOut=SelectObject(hdcOut,hDIBOut);
StretchBlt(hdcOut,0,0,m_iWidth,m_iHeight,hdcIn,0,0,m_iWidthIn,m_iHeightIn,SRCCOPY);
SelectObject(hdcIn,OldObjectIn);
SelectObject(hdcOut,OldObjectOut);
GetDIBits(hdcOut, hDIBOut, 0, m_iHeight, (PVOID)pBufferOut,(BITMAPINFO *)&pVIOut->bmiHeader, DIB_RGB_COLORS);
DeleteObject(hDIBIn);
DeleteObject(hDIBOut);
DeleteDC(hdcIn);
DeleteDC(hdcOut);
pOut->SetActualDataLength((long)pVIOut->bmiHeader.biSizeImage);
REFERENCE_TIME TimeStart, TimeEnd;
if (NOERROR == pIn->GetTime(&TimeStart, &TimeEnd)) {
pOut->SetTime(&TimeStart, &TimeEnd);
}
LONGLONG MediaStart, MediaEnd;
if (pIn->GetMediaTime(&MediaStart,&MediaEnd) == NOERROR) {
pOut->SetMediaTime(&MediaStart,&MediaEnd);
}
HRESULT hr = pIn->IsSyncPoint();
if (hr == S_OK) {
pOut->SetSyncPoint(TRUE);
}
else if (hr == S_FALSE) {
pOut->SetSyncPoint(FALSE);
}
else { // an unexpected error has occured...
return E_UNEXPECTED;
}
hr = pIn->IsPreroll();
if (hr == S_OK) {
pOut->SetPreroll(TRUE);
}
else if (hr == S_FALSE) {
pOut->SetPreroll(FALSE);
}
else { // an unexpected error has occured...
return E_UNEXPECTED;
}
hr = pIn->IsDiscontinuity();
if (hr == S_OK) {
pOut->SetDiscontinuity(TRUE);
}
else if (hr == S_FALSE) {
pOut->SetDiscontinuity(FALSE);
}
else { // an unexpected error has occured...
return E_UNEXPECTED;
}
return S_OK;
}
------解决方案--------------------------------------------------------
1.确认resize后的图像正确。
2.通知render格式改变。参考
------解决方案--------------------------------------------------------
你后面要接render,render会自己调整尺寸的,宽度会增加,多余宽度是显存对齐用的,你需要逐行逐行拷贝。
------解决方案--------------------------------------------------------
关键是你看你的输出PIN上的width和HEIGHT是否是你resize后的大小,另外确定DecideBufferSize分配的sample大小是resize后的buffer大小,最后就是输出buffer中的数据copy是否正确
------解决方案--------------------------------------------------------
搂住请参考这个帖子
http://topic.csdn.net/u/20101202/16/1f35d89a-8047-418f-b5d1-663a3f159d4e