I have posted earlier about enumerating the DirectShow filters registered on a client computer.
And another post a enumerating the Pins a DirectShow Filter have.
But this time I am posting about enumerating the DirectShow filters in a specific Filter Graph. A DirectShow filter graph can be created in a number of ways, the easiest is through intelligent connect way, just call IGraphBuilder::RenderFile on a media file and all the graph will be built for you.
Now after the filter graph built it is not known which filters are inserted in the filter graph by the Filter Graph Manager, the filters in a filter graph can be easily seen through the GraphEdit if you register the filter graph in the Running Object Table (ROT). At the time let us explore the filter graph through the code.
HRESULT EnumFilters (IFilterGraph *pGraph)
{
IEnumFilters *pEnum = NULL;
IBaseFilter *pFilter;
ULONG cFetched;
HRESULT hr = pGraph->EnumFilters(&pEnum);
if (FAILED(hr)) return hr;
while(pEnum->Next(1, &pFilter, &cFetched) == S_OK)
{
FILTER_INFO FilterInfo;
hr = pFilter->QueryFilterInfo(&FilterInfo);
if (FAILED(hr))
{
MessageBox(NULL, TEXT("Could not get the filter info"),
TEXT("Error"), MB_OK | MB_ICONERROR);
continue; // Maybe the next one will work.
}
MessageBox(NULL, FilterInfo.achName, TEXT("Filter Name"), MB_OK);
// The FILTER_INFO structure holds a pointer to the Filter Graph
// Manager, with a reference count that must be released.
if (FilterInfo.pGraph != NULL)
{
FilterInfo.pGraph->Release();
}
pFilter->Release();
}
pEnum->Release();
return S_OK;
}
If you have read few previous posts of this blog then it will not be difficult to understand the code.
The IFilterGraph::EnumFilters gives us a enumerator which can be used to enumerate all the filters in the filter graph. The IBaseFilter::QueryFilterInfo helps us to know the filter name and wether it is the member of a filter graph or not.