Question

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!

Was it helpful?

Solution

Sample Grabber Filter does not do any conversion. This is why it is flexible to accept variety of formats, video and audio included, without being aware of individual format specific.

When you set media type on Sample Grabber, you force it to use this type only. To only accept this type and reject other. Together with Intelligent Connect, this works in a way that DirectShow might provide additional filters to convert to requested format, if possible. It is typically possible with 24-bit RGB because it is a sort of "universal uncompressed video format". This is why is is safe to set media type to 24-bit RGB and in the same time it is going to fail with almost any compressed video format (unless source already can supply exactly a match).

Note that if Intelligent Connect supplies additional conversion filters, they are attached upstream to Sample Grabber, not inside it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top