Intelligent Connect
A version of this page is also available for
4/8/2010
Intelligent Connect is the mechanism the Filter Graph Manager uses to build filter graphs. It consists of several related algorithms that select filters and add them to the filter graph. For application programming, you rarely need to know the details of Intelligent Connect. Read this section if you are having trouble building a certain filter graph and want to troubleshoot the problem, or if you are writing your own filter and want to make it available for automatic graph building.
Intelligent Connect involves the following IGraphBuilder Interface methods:
- IGraphBuilder::Render
- IGraphBuilder::AddSourceFilter
- IGraphBuilder::RenderFile
- IGraphBuilder::Connect
The IGraphBuilder::Render method builds a subsection of a graph. It starts from an unconnected output pin and works downstream, adding new filters as needed. The starting filter must already be in the graph. At each step, the IGraphBuilder::Render method searches for a filter that can connect to the previous filter. The stream can branch if a connecting filter has multiple output pins. The search stops when every stream has a renderer. If the IGraphBuilder::Render method gets stuck, it might back up and try again, using a different set of filters.
To connect each output pin, the IGraphBuilder::Render method does the following:
- The Filter Graph Manager tries to use filters that are cached in memory, if any. Throughout the Intelligent Connect process, the Filter Graph Manager may cache filters from earlier steps in the process.
- If the filter graph contains any filters with unconnected input pins, the Filter Graph Manager tries them next. You can force the IGraphBuilder::Render method to try a particular filter by adding that filter to the graph before calling IGraphBuilder::Render.
- Finally, the Filter Graph Manager searches the registry, using the IFilterMapper::EnumMatchingFilters method. It tries to match the output pin's preferred media types against media types listed in the registry.
Each filter is registered with a merit, a numerical value that indicates how preferable the filter is, relative to other filters. The IFilterMapper::EnumMatchingFilters method returns filters in order of merit, with a minimum merit of MERIT_DO_NOT_USE + 1. It ignores filters with a merit of MERIT_DO_NOT_USE or less. Filters are also grouped into categories, defined by GUID. Categories themselves have merit, and the IFilterMapper::EnumMatchingFilters method ignores any category with a merit of MERIT_DO_NOT_USE or less, even if the filters in that category have higher merit values.
To summarize, the Render method tries filters in the following order:
- Try cached filters.
- Try filters in the graph.
- Look up filters in the registry.
The IGraphBuilder::AddSourceFilter method adds a source filter that can render a specified file. First it looks in the registry and matches against the protocol (such as https://), the file extension, or a set of predetermined check bytes, which are bytes at particular offsets in the file that match certain patterns.
Assuming that the method locates an appropriate source filter, it then creates an instance of that filter, adds it to the graph, and calls the filter's IFileSourceFilter::Load method with the file name.
The IGraphBuilder::RenderFile method builds a default playback graph from a file name. Internally, this method uses IGraphBuilder::AddSourceFilter to locate the correct source filter, and IGraphBuilder::Render to build the rest of the graph.
The IGraphBuilder::Connect method connects and output pin to an input pin. This method adds intermediate filters if needed, using a variation of the algorithm described for the IGraphBuilder::Render method:
- Try a direct connection between the filters, with no intermediate filters.
- Try cached filters.
- Try filters in the graph.
- Look up filters in the registry.