[DirectShow] 011 - 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.

智能连接是 Filter Grap Manager 用来生成 filter graph 的机制。它由一些运算法则组成,这些运算法则与选择 filter 并把 filter 添加到 filter graph 中有关。对于应用程序,几乎不需要知道只能连接的详细信息。如果在生成某一 filter graph 的时候遇到了麻烦,并且想解决这些麻烦,或者需要编写自己的 filter ,并想让 filter 能够自动生成 graph ,那么阅读接下来的内容。

Intelligent Connect involves the following IGraphBuilder methods:

智能连接牵涉到一下 IGraphBuilder 方法:

·         IGraphBuilder::Render

·         IGraphBuilder::AddSourceFilter

·         IGraphBuilder::RenderFile

·         IGraphBuilder::Connect

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.

Render 方法生成 graph 的一部分。它从一个无连接的输出 pin 开始并使下游工作,当需要的时候添加新的 filter 。开始的 filter 必须已经在 graph 中。在每一步中, Render 方法都会搜索一个能够与前一个 filter 连接的 filter 。如果 filter 有多个输出 pin ,那么数据流可以分支。当每一个数据流都展现,搜索就停止了。如果 Render 无法继续下去,它可以会退回然后使用别的 filter 集合重新尝试。

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.

Render 方法按照下列步骤来连接每一个输出 pin

1.      如果 pin 支持 IStreamBuilder 接口, Filter Graph Manager 把整个处理过程委托给 IStreamBuilder::Render 方法。通过暴露这个接口, pin 承担生成 graph 剩余部分的责任。然而,很少有 pin 支持这个接口。

2.      Filter Graph Manager 尝试使用内存中的 filter 。在这个只能连接的过程中, Filter Graph Manager 会缓存之前步骤的 filter

3.      如果 filter graph 包含一些 filter 的输入 pin 没有连接,那么 Filter Graph Manager 尝试他们。你可以强制 Render 方法尝试在 Render 之前加入到 graph 中的特殊的 filter

4.      最后, Filter Graph Manager 使用 IFilterMapper2::EnumMatchingFilters 方法搜索注册表,它尝试对照注册表的媒体类型表来匹配 pin 的首选媒体类型。

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.

每一个 filter 都注册了一个 merit ,这个值标识哪一个 filter 的更好。 EnumMatchingFilters 方法按 merit 顺序返回 filter ,最小值是 MERIT_DO_NOT_USE + 1 ,忽略 MERIT_DO_NOT_USE 或更小的。 Filter 被分类,种类由 GUID 定义。种类也有 merit EnumMatchingFilters 方法忽略 merit 小于或等于 MERIT_DO_NOT_USE 的种类。哪怕种类中的 filter merit 高于 MERIT_DO_NOT_USE

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.

总结 Render 方法尝试 filter 的顺序如下:

1.      使用 IStreamBuilder

2.      尝试内存中的 filter

3.      尝试 graph 中的 filter

4.      搜索注册表中的 filter

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 http:// ), 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.

AddSourceFilter 方法添加一个能展现指定文件的 source filter 。首先它会在注册表中查找匹配的协议、文件扩展或者预先检查字节集合。如果这个方法指定了一个合适的 source filter ,它将创建这个 filter 的实例,添加到 graph 中,通过文件名调用 IFileSourceFilter::Load.

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.

RenderFile 方法通过文件名生成一个默认的回放 graph 。这个方法使用 AddSourceFilter 指定当前 source filter ,并调用 Render 生成 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.

Connect 方法连接一个输出 pin 到一个输出 pin 。如果有需要,这个方法将添加一个中间 filter

1.      不使用中间 filter 尝试直接连接两个 filter

2.      尝试缓存 filter

3.      尝试 graph 中的 filter

4.      查找注册表中的 filter

 

 

 

 

 

 

你可能感兴趣的:(DirectX)