Friday, March 30, 2007

Directshow source filter Error

I developed the source filter for displaying numbers on the screen...

The code related to this ...


HRESULT CMySourceStream::GetMediaType(CMediaType* pMediaType)
{
try
{

HRESULT hr = S_OK;

CheckPointer(pMediaType,E_POINTER);
OutputDebugString("\n CMySourceStream::GetMediaType() fn");
ZeroMemory(pMediaType,sizeof(CMediaType));

VIDEOINFO *pvi = (VIDEOINFO*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFO));

pvi->bmiHeader.biCompression = BI_RGB;
pvi->bmiHeader.biBitCount = 24;
pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pvi->bmiHeader.biWidth = 300;
pvi->bmiHeader.biHeight = 300;

pvi->bmiHeader.biPlanes = 1;
pvi->bmiHeader.biSizeImage = pvi->bmiHeader.biWidth * pvi->bmiHeader.biHeight * (pvi->bmiHeader.biBitCount/8);
pvi->bmiHeader.biClrImportant = 0;

SetRectEmpty(&(pvi->rcSource));
SetRectEmpty(&(pvi->rcTarget));
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);

//pMediaType->SetSubtype(&MEDIASUBTYPE_Vi)
const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
pMediaType->SetSubtype(&SubTypeGUID);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);

m_bmpInfo.bmiHeader = pvi->bmiHeader;

return hr;
}
catch(...)
{
OutputDebugString("\n Errror in CMySourceStream::GetMediaType() fn");
return E_FAIL;

}
}



But I faced the following problem...

---------------------------
GraphEdit
---------------------------
Sorry, the Filter Graph cannot render this pin.

Class not registered (Return code: 0x80040154)
---------------------------
OK
---------------------------

Solution :
--------------
1.I added the checkMediaType() fn as follows...

CheckMediaType() is an important Function for any filter....

without it, the filter will not work...


HRESULT CMySourceStream::CheckMediaType(const CMediaType *pMediaType)
{
CheckPointer(pMediaType,E_POINTER);
try
{

OutputDebugString("\n CheckMediaType fn...");
if((*(pMediaType->Type()) != MEDIATYPE_Video) || // we only output video
!(pMediaType->IsFixedSize())) // in fixed size samples
{
return E_INVALIDARG;
}

// Check for the subtypes we support
const GUID *SubType = pMediaType->Subtype();
if (SubType == NULL)
return E_INVALIDARG;

if(*SubType != MEDIASUBTYPE_RGB24)
{
return E_INVALIDARG;
}

// Get the format area of the media type
VIDEOINFO *pvi = (VIDEOINFO *) pMediaType->Format();

if(pvi == NULL)
return E_INVALIDARG;

if(pvi->bmiHeader.biBitCount==24)
return NOERROR;
else
return E_INVALIDARG;
}
catch(...)
{
OutputDebugString("\n Exception in CheckMediaType() fn...");
return E_INVALIDARG;
}


}

No comments: