Directshow Intelligent Connect

Hi guys,

I am trying to create an image filter for Directshow and want it to be connected automatically in Intelligent Connect mechanism.

The Directshow document say that:

4. If the filter graph contains any filters with unconnected input pins, the Filter Graph Manager tries them next. You can force the Render method to try a particular filter by adding that filter to the graph before calling Render.

I’ve tried to follow above direction but my transform filter is not get connected in the graph (Directshow not call any method of the filter except Stop).

The code to force **Directshow ** try connecting to my transform filter is:

CMyTranformFilter* myFilter = new CMyTranformFilter(NULL, &hr);
    hr = g_pGraph->AddFilter(myFilter, L"My Transform filter");

    // Render the preview pin on the video capture filter
    // Use this instead of g_pGraph->RenderFile
    hr = g_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
        pSrcFilter, NULL, NULL);

Here is my transform filter:
Not any method below is getting called. Is my understanding is correct? What is the approach to get my filter involve in rendering process?

class CMyTranformFilter : public CTransformFilter
{
public:
    CMyTranformFilter(__inout_opt LPUNKNOWN punk, HRESULT* hr) :
        CTransformFilter("My Transform filter", punk, CLSID_MYTRANFORMFILTER)
    {

    }
    ~CMyTranformFilter() {
    }

    HRESULT Transform(IMediaSample * pIn, IMediaSample *pOut) {
        return E_NOTIMPL;
    }

    // check if you can support mtIn
    HRESULT CheckInputType(const CMediaType* mtIn) {
        return E_NOTIMPL;
    }

    // check if you can support the transform from this input to this output
    HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut) {
        return E_NOTIMPL;
    }

    // this goes in the factory template table to create new instances
    // static CCOMObject * CreateInstance(__inout_opt LPUNKNOWN, HRESULT *);

    // call the SetProperties function with appropriate arguments
    HRESULT DecideBufferSize(
        IMemAllocator * pAllocator,
        __inout ALLOCATOR_PROPERTIES *pprop) {
        return E_NOTIMPL;
    }

    // override to suggest OUTPUT pin media types
    HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType) {
        return E_NOTIMPL;
    }
};

Your filter doesn’t get selected because you’re returning an error for every CheckInputType ahd CheckTransform call. You are not allowed to return E_NOTIMPL for those. That’s the way the intelligent connect process works: DirectShow loads every filter in the registry and tries to connect it to the graph. The first one that agrees to accept the format gets linked into the graph.

The samples are very clear about what these have to return. Don’t ignore them.

@Tim_Roberts , Sorry for my explanation. It might make you misunderstood.
I’ve just create a dump filter to check how Intelligent Connect work.
The problem is Intelligent Connect does not call any my filter’s method.
(I set break points to all my filter’s method but they are never get hit)

I just inserted your exact code into one of my test apps, and CheckInputType gets called several dozen times before the connection is rejected. Perhaps you should use OutputDebugString instead of relying on breakpoints.

1 Like

Yes, you’re are right. I missed setting the break point in CheckInputType function. I am sorry for my silly question.