MFC下Filter的编写和Win32下Filter的编写极其相似,但又存在很多不同点,在Win32中需要去实现CreateInstance函数,而在MFC直接用NEW 动态产生,不过这并不代表不需要去维护Filter对象计数,因此在MFC 下Filter中依然需要调用AddRef函数来维护这个平衡;其它还不需要实现注册表注册等功能,如下代码;
////////////////////////////////////////////////////////////////////////////////
CAppTransform::CAppTransform(LPUNKNOWN pUnkOuter, HRESULT *phr) :
CTransInPlaceFilter(NAME("App Transform"), pUnkOuter, GUID_NULL, phr)
{
}
HRESULT CAppTransform::Transform(IMediaSample *pSample)
{
// Override to do something inside the application
// Such as grabbing a poster frame...
// ...
return S_OK;
}
// Check if we can support this specific proposed type and format
HRESULT CAppTransform::CheckInputType(const CMediaType *pmt)
{
// We accept a series of raw media types
if (pmt->majortype == MEDIATYPE_Video &&
(pmt->subtype == MEDIASUBTYPE_RGB32 ||
pmt->subtype == MEDIASUBTYPE_RGB24 ||
pmt->subtype == MEDIASUBTYPE_RGB565 ||
pmt->subtype == MEDIASUBTYPE_RGB555 ||
pmt->subtype == MEDIASUBTYPE_UYVY ||
pmt->subtype == MEDIASUBTYPE_YUY2))
{
return NOERROR;
}
return E_FAIL;
}