Partager via


DirectShow Helper Functions

If you do anything more complicated in DirectShow than call RenderFile, you generally end up writing graph-walking code. (Find this pin on this filter, connect it to that pin on that filter.) The DirectShow samples in the Windows SDK include some helper functions for writing just this sort of fiddly code. For example, suppose you want to find the media type on the output pin of the MPEG-1 splitter. We know the MPEG-1 splitter exposes IAMStreamSelect, so we can write:

     #include <dshowutil.h>
    CComPtr<IAMStreamSelect> pSelect;
    CComPtr<IPin> pPin;
     hr = FindFilterInterface(pGraph, &pSelect);
     CComQIPtr<IBaseFilter> pFilter(pSelect);
     hr = FindConnectedPin(pFilter, PINDIR_OUTPUT, &pPin);

    hr = pPin->ConnectionMediaType(&mt);

FindInterface enumerates filters looking for a filter that supports IAMStreamSelect (the interface type is a template parameter), and FindConnectedPin finds the first connected pin with direction equal to PINDIR_OUTPUT.

These helper functions are located in the Samples\Multimedia\DirectShow\Common folder of the SDK. In the Windows SDK for Windows Vista, there is a separate cpp file (dshowutil.cpp). In the upcoming Windows SDK for Windows Server 2008 (now in RC0), I inlined all of the functions and got rid of the cpp file. Many of the helper functions are also presented as code examples in the SDK documentation.

(These functions are published as sample code. Caveat emptor!)

Feedback and suggestions for improvement are welcome. (And bug reports of course!)


This posting is provided "AS IS" with no warranties, and confers no rights.