Generate a general filter table

Source: Internet
Author: User
To create a filter table, you must start from creating an instance of the filter table manager, as shown below:

Igraphbuilder * pigb;
Hresult hR = cocreateinstance (clsid_filtergraph,
Null, clsctx_inproc_server, iid_igraphbuilder,
(Void **) & pigb );

The filter table manager supports the following list generation methods:

  • Ifiltergraph: connectdirect method. Try to establish a direct connection between two plugs. If the plug cannot be connected, the method fails.
  • Igraphabuilder: connet method. You can also connect two plugs. It connects directly as much as possible. If you cannot connect directly, it uses an intermediary filter to complete the connection.
  • Igraphbuilder: render method, which is started by an output plug to generate the entire table. This method adds the required filter until it reaches a restoration filter.
  • Igraphbuilder: renderfile method to generate a complete file player table. It uses the igraphbuilder: addsourcefilter method to add a Source Filter Based on the file type, and then uses igraphbuilder: render to generate other parts of the table.
  • Ifiltergraph: addfilter method to add a filter to the table. It does not connect this filter to other filters. The application must first create a filter instance. You can use cocreateinstance, or use the filter image and system device to list the object.

These methods provide three basic ways for table creation:

1. The application instructs the filter table manager to automatically generate all tables.

2. The application and table manager work together to generate tables.

3. The application independently adds and connects each filter to generate the entire table.

Method 1: Filter table manager generates all tables

This method can be used when you simply want to play a file or some recognizable formats (such as Avi, MPEG, WAV, or mp3. This technology has examples in the article

Filter found

The first step of the filter table manager is to discover and create the required filter. It first selects a filter based on the data media type. This is because the two filters can be connected only when their plug processes the same media type. The filter table manager searches for a combination of media types and file extensions in the registry to determine media types. For example, .wma、.aviand .wav. If there is no combination of this extension, the filter table manager searches for the unique "Validation byte" in the file ". From these validation bytes, you can determine the DirectShow media type and the corresponding source filter. Internally, the renderfile method calls igraphbuilder: addsourcefilter to complete this task.

If a source filter of a name object is found, you can read files of the specified type. The filter table manager uses cocreateinstance and the returned guid to create a filter instance. For most file types, the source filter is used as the file source (synchronization) filter. The filter table manager then calls the ifiltergraph: addfilter method to add the filter to the filter table. When the filter is notified of adding data to the table, it creates one or more output plugs that match the file type to be read.

After the plug is created, the table manager checks the media types supported by each plug, and then checks the Registry again to find a filter. This filter must be able to access the media type of the input plug. When it finds a suitable filter, it is added to the table. All DirectShow filters have a unique guid in the Windows registry. They store other information, including the filter type, media type, and merit. The filter table manager uses this information to determine which filter to create.

The category identifies the general function of the filter, used to limit the search range.

The media type describes the types of data that can be accessed by the filter, which can be used as the input, which can be sent, and the output.

The merit value indicates whether this filter should be taken into account during Automatic Table Generation. If two filters have similar media type information in the system, the filter table manager selects the one with a high merit value. Some filters specifically give a lower merit value because they are designed for a dedicated filter table. This filter must be separately added to the table by the application.

To search for the Registry, the filter table manager creates an instance of the DirectShow filter mapper object and calls the ifiltermapper2: enummatchingfilters method to perform the search. This method matches the DirectShow filter with the media type, number of plugs, merit, and other conditions. It returns a standard com ienummoniker object, which contains the names of all the filters that match the search criteria. (The use of name objects enables this method to query objects without creating instances, and the listed objects are not necessarily real COM objects, such as hardware devices .)

Connection Filter

When each filter is added, it configures its own plug and prepares to connect to the previous filter (upstream filter. The filter table manager calls the igraphbuilder: connect method to connect the output plug of the upstream filter and the input plug of the downstream filter. The two plugs communicate with each other to determine the media type of the connection and determine which plug provides the memory allocation object.

Completion table

After the two plug-ins are connected, the filter table manager checks the media types supported by the new filter output plug and searches for filters that can process this media type. This process repeats until all the necessary filters are added to the table. In a file playback table, the second filter is generally a decomposition filter, which reads unprocessed data streams, such as AVI or MPEG, and then is divided into audio streams and video streams, create an output plug for each stream. If the data in the stream is compressed, the next filter of the stream is the decompression tool, followed by a restoration tool.

After the table is generated, the application only needs to obtain the imediacontrol interface from the filter table manager, and then call the imediacontrol: Run method to start playing the file.

Method 2: the application and the filter table manager work together to generate a table.

In addition to simple file restoration, if you want to do other things, you need your application to do at least some table generation work. For example, if you want to generate a filter table that converts an AVI file to an ASF file, you can still call igraphbuilder: renderfile to allow the filter table manager to create an AVI playing table, however, you must modify the table to output an ASF file. This requires disconnecting, removing the video and audio reducers (by calling ifiltergraph: removefilter), and replacing them with ASF write filters.

Another thing you have to do is add an intermediary filter to convert a stream from one media type to another. Applications can directly add mediation filters or use the igraphbuilder: connet method. When this method is called, the filter table manager first tries to connect directly to the filter. If the media type cannot be unified, the manager searches for the mediation filter. As long as the table manager finds a filter that can process a given media type, it first tries to connect to the filter that has been added to the table. To disable table manager from inserting an intermediary filter, use the ifiltergraph: connetdirect method.

In the preceding example, the application generates a downstream part of the table. In other cases, the application may need to generate the upstream part of the table. At this point, once you have added and connected the parts that must be manually added, you can use the igraphbuilder: render method to indicate that the table manager completes the other parts of the table from the specified output plug. If a filter has more than one output plug, the application must call render for each plug.

Method 3: the application itself generates the entire table

In some cases, your application may need to add and connect each filter independently to generate the entire table. In this case, you may know which filters should be added to the table, so you do not need to use the filter image object to explore the filter. You can use the addfilter method to add filters to the table and connect them using connect or connectdirect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.