tanvon++

September 7, 2008

Enumerating the DirectShow Filter Pin

When it comes the time of connecting the DirectShow filters manually in DirectShow Filter Graph, at that time we admire the benefits of the Intelligent Connect. To connect a filter manually we have to built the entire filter graph with coding.

First of all a source filer have to be created the filter graph

IGraphBuilder *  pGB;
CoCreateInstance(CLSID_FilterGraph,NULL,
               CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void**)&pGB);

then a Source Filter have to be added the filter graph, wether with CoCreateInstance() or with System Device Enumerator, All filters can’t be created with CoCreateInstance, Normally the filters which are wrapper to devices have to be created with the System Device Enumerator. But here a source filter is being added that will read the media data from a file from the disk.

IBaseFilter * pSF;
    pGB->AddSourceFilter(L"c:\\media\\video\\ruby.avi", L"Source Filter",
                                                                  &pSF);
    IEnumPins * pEP;
    pSF->EnumPins(&pEP);
    IPin * pOutPin;
    while(pEP->Next(1,&pOutPin,0) == S_OK)
    {
        PIN_DIRECTION pDir;
        pOutPin->QueryDirection(&pDir);
        if(pDir == PINDIR_OUTPUT)
            break;// success
        pOutPin->Release();
    }
    pEP->Release();

Now how to enumerate the pins, IBaseFilter has a method which makes it easy to enumerate the pins a filter have.

HRESULT EnumPins(
  IEnumPins **ppEnum
);

which gives us IEnumPins interface, with this interface you can easily enumerate the pins a filter have wether these are input pins or output pins. you first call Next then check for the pin direction.

HRESULT QueryDirection(
  PIN_DIRECTION *pPinDir
);

For direction checking  QueryDirection is called this method tells us the pin direction.

Now you can call IGraphBuilder::Render to built the entire graph.

HRESULT Render(
  IPin *ppinOut
);
this method takes the output pin to be rendered.
or you can call IGraphBuilder::Connect to directly connect the 
output pin to a downstream filters input pin.
HRESULT Connect(
  IPin *ppinOut,
  IPin *ppinIn
);

August 15, 2008

Intelligent Connect

Filed under: DirectShow, DirectShow Filters — Tags: , , — tanvon malik @ 4:57 pm

As a member of yahoo group asked about the so called non-intelligent connect .
Adding and connecting distinct filter in the filter graph manually.
Actually there are many small functions which need to be taken care, So this
may take a little longer to understand, So keep reading this series of blog entries about
connecting filter without intelligent connect in DirectShow.

Intelligent Connect
 There are some intelligent algorithms behind this, Which
share the burden of the programmer. Suppose for a little time what
hassle is hidden behind it. Once the  IGraphBuilder::RenderFile()
is called the Filter Graph Manager searches for the suitable source filter
which can read and understand the format of media file. Then it tries to
search for a filter which can decode or parse that data (this data is called Media Samples in the DirectShow)
which the source filter will handle to it (through transport), The media sample format which is said the Media Type in the DirectShow
must be same that both filters will understand otherwise the connection will fail,
and Filter Graph Manager will drop that filter and will search for another filter which
will handle the samples with the specified Media Type.
Then Filter Graph Manager will try to load other filters to complete the Filter Graph.
At the end it will load the default Renderer to Display the contents on the screen.
and will connect that with the entire filter graph build previously.

Blog at WordPress.com.