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 );