Creating a New Filter Graph and Adding Filters
Microsoft DirectShow 9.0 |
Creating a New Filter Graph and Adding Filters
- Note This topic is deprecated. It applies to Visual Basic 6.0. DirectShow is not supported for Visual Basic .NET or C#.
The following code fragment demonstrates how to create the new (empty) filter graph object.
Dim g_objMC as FilgraphManager Set g_objMC = New FilgraphManager ' create the new filter graph
When you choose to create an empty filter graph and add individual filters, you must know the filter type. In general, there are three categories of filters: source filters, transform filters, and renderer filters. The procedure for adding source filters uses a different method than the procedure for adding transform and renderer filters.
Add source filters to the filter graph by calling the FilgraphManager.AddSourceFilter method and supplying the name of a file of the specified source type or stored filter graph.
Dim objFilter As Object ' temporary object for valid syntax; not used CommonDialog1.ShowOpen ' get the name of the source or filter graph file g_objMC.AddSourceFilter CommonDialog1.filename, objFilter
Add transform and renderer filters to the filter graph by calling the IRegFilterInfo.Filter method. The IRegFilterInfo object can be obtained from the FilgraphManager.RegFilterCollection property, which represents the collection of filter objects registered with the system and available for use.
After creating the filter graph and obtaining the FilgraphManager object, use the following procedure to add filters.
- Obtain the list of registered filters by getting the FilgraphManager.RegFilterCollection property.
- Search through the collection for the desired filter. Each element in the collection is an IRegFilterInfo object.
- Add the filter to the filter graph by calling the IRegFilterInfo.Filter method.
The following code illustrates steps 1 and 2:
' code fragment that populates the registered filter list box ' global variable g_objRegFilters is set to FilgraphManager.RegFilterCollection ' Set g_objRegFilters = g_objMC.RegFilterCollection Dim filter As IRegFilterInfo listRegFilters.Clear If Not g_objRegFilters Is Nothing Then For Each filter In g_objRegFilters ' for each filter in collection listRegFilters.AddItem filter.Name ' add name to the list box Next filter End If
The following code illustrates step 3:
Dim filter As IRegFilterInfo ' find the selected filter and add it to the graph ' g_objRegFilters is the FilgraphManager object's RegFilterCollection property For Each filter In g_objRegFilters If filter.Name = listRegFilters.Text Then ' the selected filter? Dim f As IFilterInfo ' yes filter.filter f ' add to the filter graph, return IFilterInfo f If f.IsFileSource Then CommonDialog1.ShowOpen f.filename = CommonDialog1.filename End If Exit For End If Next filter