Wednesday, December 05, 2007

How to set output pin's media type as YUY2 ?...


we have to override the getmediaType() fn
HRESULT CRGBToYUV::GetMediaType(int iPosition, CMediaType *pMediaType)
{
// Is the input pin connected
if (m_pInput->IsConnected() == FALSE)
{
return E_UNEXPECTED;
}
// This should never happen
if (iPosition < 0)
{
return E_INVALIDARG;
}
// Do we have more items to offer
if (iPosition > 0) {
return VFW_S_NO_MORE_ITEMS;
}


CMediaType mt = m_pInput->CurrentMediaType();

VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*) mt.pbFormat;


VIDEOINFO *pvi = (VIDEOINFO*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFO));
if (pvi == 0)
return(E_OUTOFMEMORY);


ZeroMemory(pvi, pMediaType->cbFormat);
//pvi->AvgTimePerFrame = m_rtFrameLength;

pvi->bmiHeader.biWidth = vih->bmiHeader.biWidth;
pvi->bmiHeader.biHeight = vih->bmiHeader.biHeight;

m_iImageWidth = vih->bmiHeader.biWidth;
m_iImageHeight = vih->bmiHeader.biHeight;

pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y','2');//MAKEFOURCC('U', 'Y', 'V', 'Y');
pvi->bmiHeader.biBitCount = 16;
pvi->bmiHeader.biSizeImage = GetBitmapSize(&pvi->bmiHeader);
// Clear source and target rectangles
SetRectEmpty(&(pvi->rcSource)); // we want the whole image area rendered
SetRectEmpty(&(pvi->rcTarget)); // no particular destination rectangle

pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);

// Work out the GUID for the subtype from the header info.
const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
pMediaType->SetSubtype(&SubTypeGUID);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);

m_pRGBBuffer = new BYTE[pvi->bmiHeader.biWidth *pvi->bmiHeader.biHeight *3];
m_pYUVBuffer = new BYTE[pvi->bmiHeader.biWidth *pvi->bmiHeader.biHeight * 2];

return NOERROR;
}

0 Comments:

Post a Comment

<< Home