IAMGraphBuilderCallback and Intelligent Connect tuning

There was a question asked about how IAMGraphBuilderCallback interface is used to prevent from particular filter insertion during Intelligent Connect.

First of all, there is sample code at The March Hare‘s website:

The IAMGraphBuilderCallback class can be used to remove problematic dshow filters when building a graph with intelligent connect.  This sample does not provide the UI to blacklist filters but will give you a better head start than the information in the documentation.  See the header file for an example of how to use it in your code.  Add your own code to the SelectedFilter or CreatedFilter methods to remove any unwanted filters.

The idea behind the method can be easily illustrated with a code snippet. Each time Filter Graph Manager considers trying a filter, before its instantiation it calls (if provided) IAMGraphBuilderCallback::SelectedFilter method, where there is an option to reject it (before it even was instantiated using CoCreateInstance).

The code snippet below checks selected filter and instructs to reject it if it is an FFDshow Audio Decoder filter.

// IAMGraphBuilderCallback
STDMETHOD(SelectedFilter)(IMoniker* pMoniker) throw()
{
    ATLTRACE(atlTraceCOM, 4, _T("...\n"));
    _ATLTRY
    {
        ATLASSERT(pMoniker);
        const CStringW sMonikerDisplayName = _FilterGraphHelper::GetMonikerDisplayName(pMoniker, NULL);
        ATLTRACE(atlTraceGeneral, 4, _T("sMonikerDisplayName %ls\n"), sMonikerDisplayName);
        static const LPCTSTR g_pszFfdshowAudioDecoderClassIdentifier = _T("{0F40E1E5-4F79-4988-B1A9-CC98794E6B55}");
        if(sMonikerDisplayName.Find(CStringW(g_pszFfdshowAudioDecoderClassIdentifier)) >= 0)
            return E_FAIL; // Die!
    }
    _ATLCATCH(Exception)
    {
        return Exception;
    }
    return S_OK;
}

Leave a Reply