A null-transform filter helps retrieve the raw camera frame buffer as well as perform necessary conversion in the buffer data.
Compilation
The class-library solution must be built in release mode and must export itself via COM using a module definition file. It can either be deployed by Visual Studio by setting COM Self Register to TRUE or by using regsvrce.exe
To prevent compile errors about string types, go to Project Properties>Configuration Properties>C/C++>Language and change Treat wchar_t as built-in type to No
To control which media type the filter will accept and which will be rejected, modify the function CheckInputType. Return S_OK to accept the media and S_FALSE to reject.
HRESULT CheckInputType(const CMediaType* mtIn)
{
if (mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_YV12)
return S_OK;
else
return S_FALSE;
}
The DLL exports 2 interfaces:
DEFINE_GUID(CLSID_NullNull, 0xba1864f4, 0x6988, 0x4e86, 0xb2, 0x8f, 0x60, 0x33, 0x5b, 0xae, 0x85, 0x5f);
DEFINE_GUID(IID_ITransformFilter, 0x6b652fff, 0x11fe, 0x4fce, 0x92, 0xad, 0x02, 0x66, 0xb5, 0xd7, 0xc7, 0x8f);
CLSID_NullNull identifies the filter when added to the graph whereas IID_ITransformFilter defines an interface providing a call-back function which will invokes when the camera data is available. To create a new GUID, use the Visual Studio menu Tools->Create GUID
To add the filter to the graph, use:
CComPtr<IBaseFilter> pNullTransform;
hr = pNullTransform.CoCreateInstance(CLSID_NullNull);
hr = pFilterGraph->AddFilter(pNullTransform, L"NullNull");
To get the callback function when the camera data is available. CameraSampleReceived will be called when a frame is received from the camera
hr = pNullTransform->QueryInterface(IID_ITransformFilter, (void**)&pTransform);
hr = pTransform->SetCallback(&CameraSampleReceived);
HRESULT CameraSampleReceived(IMediaSample *pSample, int width, int height)
{
}
The source code can be download here
See also