I found this nice example on the internet explaining how directshow works.
http://alax.info/trac/public/browser/trunk/Utilities/SetLifeCamStudioResolutionSample/SetLifeCamStudioResolutionSample.cpp
In that example there is two samplegrabbers. One called NON-RGB grabber, and one called RGB-grabber.
The first one: (NON-RGB)
#pragma region Non-RGB Sample Grabber
{
CComPtr<IBaseFilter> pBaseFilter;
ATLENSURE_SUCCEEDED(pBaseFilter.CoCreateInstance(__uuidof(SampleGrabber)));
ATLENSURE_SUCCEEDED(pFilterGraph->AddFilter(pBaseFilter, L"Non-RGB Sample Grabber")); // This will connect in MJPG format
const CComQIPtr<ISampleGrabber> pSampleGrabber = pBaseFilter;
ATLASSERT(pSampleGrabber);
#if TRUE
// NOTE: IFilterGraph::Connect would do just fine, but with a real capture device, if we prefer having Smart Tee added, we need to use
// Capture Graph Builder (only here)
CComPtr<ICaptureGraphBuilder2> pCaptureGraphBuilder;
ATLENSURE_SUCCEEDED(pCaptureGraphBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2));
ATLENSURE_SUCCEEDED(pCaptureGraphBuilder->SetFiltergraph(pFilterGraph));
ATLENSURE_SUCCEEDED(pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, NULL, pCurrentOutputPin, NULL, pBaseFilter));
#else
ATLENSURE_SUCCEEDED(pFilterGraph->Connect(pCurrentOutputPin, GetPin(pBaseFilter, 0)));
#endif
MessageBox(GetActiveWindow(), _T("After Non-RGB Sample Grabber Connected"), _T("Debug"), MB_OK);
pCurrentOutputPin = GetPin(pBaseFilter, 1);
}
#pragma endregion
the second: (RGB)
#pragma region RGB Sample Grabber
{
CComPtr<IBaseFilter> pBaseFilter;
ATLENSURE_SUCCEEDED(pBaseFilter.CoCreateInstance(__uuidof(SampleGrabber)));
ATLENSURE_SUCCEEDED(pFilterGraph->AddFilter(pBaseFilter, L"RGB Sample Grabber"));
const CComQIPtr<ISampleGrabber> pSampleGrabber = pBaseFilter;
ATLASSERT(pSampleGrabber);
AM_MEDIA_TYPE MediaType;
ZeroMemory(&MediaType, sizeof MediaType);
MediaType.majortype = MEDIATYPE_Video;
MediaType.subtype = MEDIASUBTYPE_RGB24;
ATLENSURE_SUCCEEDED(pSampleGrabber->SetMediaType(&MediaType));
ATLENSURE_SUCCEEDED(pFilterGraph->Connect(pCurrentOutputPin, GetPin(pBaseFilter, 0)));
MessageBox(GetActiveWindow(), _T("After RGB Sample Grabber Connected"), _T("Debug"), MB_OK);
pCurrentOutputPin = GetPin(pBaseFilter, 1);
}
#pragma endregion
The method "setmediatype()" is used only in the "RGB" version. But i wonder. On MSDN page is says that setmediatype() says what type of data that is avaiable to in input pin of the sample grabber filter. And if it possible to use the sample grabber without seting the media type, why should I set it to anything?
Questions:
Do sample grabber do any type of media converting?
Why should I set the media type of the sample grabber?
If the mediatype form the cam is set to MJPG, and I set the media type to RGB24 in the samplegrabber, what happens?
Could there be any performance difference of using one over another? To increase the performance (fps) of the software, should I remove one of the sample grabbers?
Thanks!