共用方式為


Intelligent Connect

 
Microsoft DirectShow 9.0

Intelligent Connect

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 methods:

The 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 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 Render method gets stuck, it might back up and try again, using a different set of filters.

To connect each output pin, the Render method does the following:

  1. If the pin supports the IStreamBuilder interface, the Filter Graph Manager delegates the entire process to the pin's IStreamBuilder::Render method. By exposing this interface, the pin assumes responsibility for building the remainder of the graph, down to the renderer. However, very few pins support this interface.
  2. 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. (Also, see Dynamic Graph Building.)
  3. If the filter graph contains any filters with unconnected input pins, the Filter Graph Manager tries them next. You can force the Render method to try a particular filter by adding that filter to the graph before calling Render.
  4. Finally, the Filter Graph Manager searches the registry, using the IFilterMapper2::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 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 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:

  1. Use IStreamBuilder.
  2. Try cached filters.
  3. Try filters in the graph.
  4. Look up filters in the registry.

The 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. For details, see Registering a Custom File Type. 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 RenderFile method builds a default playback graph from a file name. Internally, this method uses AddSourceFilter to locate the correct source filter, and Render to build the rest of the graph.

The Connect method connects an output pin to an input pin. This method adds intermediate filters if needed, using a variation of the algorithm described for the Render method:

  1. Try a direct connection between the filters, with no intermediate filters.
  2. Try cached filters.
  3. Try filters in the graph.
  4. Look up filters in the registry.

See Also