3. Constructing Filter Graph 3.3.1. Component DirectShow for building Graph provides a series of components for building FILTER GRAPH, including: * Filter Graph Manager. This object is used to control Filter Graph, supporting many interfaces such as IgraphBuilder, IMEDIACONTROL, and IMEDIAEVENTEX. All DirectShow applications need to be used in some places, although in some cases, other objects have created Filter Graph Manager for the application. * Capture Graph Builder. This object provides additional methods for building Filter Graph. It was originally designed to build a GRAPH that provides video capture (this is the origin of its name), but it is also useful for building many other types of Filter Graph. It supports the ICAPTUREGRAPHBUILDER2 interface. * FILTER MAPPER and System Device Enumerator. These objects are used to find Filter that is registered or represents hardware drives in the system. * DVD Graph Builder. This object constructs Filter Graph with playback and navigation DVD. It supports the IDVDGRAPHBUILDER interface. Script-based applications can use the MSWeBDVD ActiveX control to control DVD playback. * Video Control. WinXP provides this ActiveX control to manipulate data and analog TVs in DirectShow. Intelligent Connect Intelligent Connection This term covers a series of Filter Graph Manager to build all or part of the Filter GRAPH algorithm. At any time, when Filter Graph Manager needs to add Filter to complete the graph, it will do the following things: 1. If there is a Filter existing in graph, and this filter has at least one INPUT PIN, Filter Graph Manager test Try this Filter. 2. Otherwise, the Filter Graph Manager can accept the Filter of the appropriate media type when you find a connection in the registered FILTER. Every Filter registers has a MERIT value, which is used to mark which filter is easier to select by Filter Graph Manager to complete the graph. Filter Graph Manager is selected by the order of MERIT values. The larger the MERIT value, the greater the chance to be selected. For each stream type (such as audio, video, midi), the default RENDERER has a very high MERIT value, the decoder is also, the dedicated Filter has a low MERIT value. If Filter Graph Manager is trapped because of the selected Filter inappropriate, it will return to try another Filter combination.
3.3.2 GRAP Construction Overview Creates a Filter Graph, starting from creating a Filter Graph Manager instance:
IGraphBuilder * Pigb; HRESULT HR = CocreateInstance (CLSID_FILTERGRAPH, NULL, CLSCTX_INPROC_SERVER, IID_IGRAPHBUILDER, (Void **) & Pigb);
Filter Graph Manager supports the following graph build methods:
* IFiltergraph :: ConnectDirect, direct connection between two PINs, returns a failed * iFiltergraph :: Connect, connect two PIN, if possible, connect them directly, other Filter To complete the connection.
* IGRAPHBUILDER :: Render, start the rest of the Graph build from an output PIN. This method will automatically add a must-have Filter after the output PIN until the renderer filter.
* IGraphbuilder :: Renderfile, build a complete file playback Graph.
* IGRAPHBUILDER :: AddFilter Add a Filter to the graph. It does not connect Filter and the Filter must have been created before calling this method. Creating a Filter can be used with a CocreateInstance method or use the Filter Mapper or System Device ENUMERATOR.
These methods provide three ways to build Graph:
1.Filter Graph Manager builds the entire graph
2. Filter Graph Manager build part of graph
3. Application builds the entire graph
Filter Graph Manager builds the entire graph
If you just want to play back a known format file, such as AVI, MPEG, WAV, or MP3, use the renderfile method.
The renderfile method first looks for Filter registered in the system to analyze source files, which uses protocol names (such as http: //), file extensions, or files to determine which source filter.
Filter Graph Manager uses an iterative process to complete the remaining Graph build. During this iteration, it lists the media types supported by the Filter's output PIN, and searches for the input PIN of which has been registered FILTER accepts the media type. It uses a series of rules to narrow the scope of the Filter and scheduled priority:
* Filter Category (category) Identifies the general function of Filter
* Media Type Description FILTER can accept or output which data type
* MERIT value determines the order of the Filter being tried. If the two FILTERs have the same Filter category and support the same input type, the Filter Graph Manager selects the one of the MERIT value. Some Filter deliberately give a small MERIT value because it is designed for special purposes, which can only be added to the graph.
Filter Graph Manager uses the Filter Mapper object to search for registered filters.
Each Filter is added, and the Filter Graph Manager tries to connect it to the output PIN of the previous Filter. They negotiate decide whether they can connect, if they can, which media type is used to connect. If the new Filter can't connect, Filter Graph Manager discards it and try it, this process has continued until every stream is render.
Filter Graph Manager builds part of graph
If not just play a file, then your application must do some graph buildings. For example, a video acquisition application must first select a source filter and add it to the graph. If you need to write data into an AVI file, you have to add an AVI MUX and File Write Filter. However, it is often possible to let Filter Graph Manager to complete the entire GRAPH, for example, you can use the Render method to preview. Application builds the entire graph
In some occasions, your application needs to add and connect each filter to build Graph. In this case, you are likely to know which filters need to be added to Graph. Using this way, the application adds Connect or ConnectDirect to connect them by calling the AddFilter method, then enumerate the PIN on the Filter.
3.3.3. Smart Connection Intelligent Connection is a mechanism for Filter Graph Manager to build FILTER GRAPH. It contains a series of algorithms related to selecting Filter and adds them to graph. As an application developer, you don't need to know the details of the smart connection. If you encounter problems when building a Filter Graph and want to solve it, or you are writing your own Filter and hopes that it can be built automatically, read this section. The method involves the following intelligent connection IGraphBuilder: * IGraphBuilder :: Render * IGraphBuilder :: AddSourceFilter * IGraphBuilder :: RenderFile * IGraphBuilder :: Connect Render method for constructing a portion of the graph, which is not already connected from one output pin along the direction of data flow starts down , Add the necessary filter, the beginning of the Filter must have been added to the graph. The render method searches for a filter that can connect to the previous Filter. If the file on the new connection has multiple output PIN, the data stream is automatically diverted, and the search until every stream is renderer. If the Render method searches the Filter that cannot be used, it will return to try another Filter. To connect each output PIN, the render method does the following: 1. If the PIN supports the ISTREAMBUILDER interface, Filter Graph Manager allows the PIN's ISTREAMBUILDER:: Render method to complete the process. By exposing this interface, the PIN assumes all the works that build the remainder of the Graph. However, there are only a small number of Filter supports this interface. 2. Filter Graph Manager tries to use any Filter in the cache. In the entire process of intelligent connections, Filter Graph Manager can cache the Filter early. 3. If the Filter Graph contains any Filter with unconnected input PIN, Filter Graph Manager will try to connect it as the next Filter. You can force the render method to try this filter by adding a specific filter before calling Render. 4. Finally, Filter Graph Manager uses the iFTERMAPPER2 :: EnummatchingFilters method to find all media types that match the output PIN according to the list of registered media types (high and low alignment). Each registered filter has a MERIT value. This is a number used to represent the Filter priority. The higher the maximum priority, the Filter set returned by the enummatchingfilters method is arranged in accordance with the MERIT value, until the minimum MERIT value MERIT_DO_NOT_USE 1 It ignores MERIT_DO_NOT_USR or smaller Filter. Filter also classifies through GUID, and the category itself has a MERIT value. Enummatchingfilters method ignores any MERIT value for MERIT_DO_NOT_USE or a smaller category, even in that category has a high MERIT value.