Microsoft DirectX 9.0

Connecting Filter Pins

After adding individual filters to the filter graph, you can establish connections between the filters by explicitly connecting each pin, or by automatically generating all connections that are needed downstream from a specific pin.

In both cases, you must traverse the hierarchy of Microsoft® DirectShow® objects to obtain the IPinInfo object that represents a pin of the filter object. This involves finding the desired filter in the filter collection of the filter graph object, then finding the desired pin in the pin collection of the filter object.

This section contains the following topics.

Listing Filters in the Filter Graph

All filters in the filter graph are available in a collection that you can access using the FilgraphManager.FilterCollection property.

' refresh a list box that contains the current filters in the graph 
    listFilters.Clear 
    For Each objFI In g_objMC.FilterCollection 
        listFilters.AddItem objFI.Name ' add to list box 
    Next objFI 

Listing Pins Defined for a Filter

You can access the pins defined for a filter object through the IFilterInfo.Pins property. The Pins property is a collection of individual IPinInfo objects.

After you obtain an individual IPinInfo object from the collection, you can access its properties and call its methods, as shown in the following code fragment.

For Each objPin In g_objSelFilter.Pins 
    If objPin.Name = listPins.Text Then  ' selected pin? 
        Set g_objSelPin = objPin ' yes, update information 
        ' ... perform operations using that pin 
    End If 
Next objPin 

After you have obtained the pin object, you can explicitly connect to one other pin or automatically generate all subsequent pin connections needed to render the pin.

Explicitly Connecting Two Pins

The IPinInfo object provides three methods to connect pins: Connect, ConnectDirect, and ConnectWithType. Connect adds other transform filters as needed, ConnectDirect does not add transform filters, and ConnectWithType performs the connection only if the specified pin matches the specified media type.

    frmSelectPin.OtherDir = g_objSelPin.Direction 
    Set frmSelectPin.Graph = g_objMC  ' give that form a copy of the graph 
    Set frmSelectPin.SelFilter = g_objSelFilter  ' and the current filter 
    frmSelectPin.RefreshFilters  ' display available filters to connect 
    frmSelectPin.Show 1  ' display the form 
    If frmSelectPin.bOK Then ' user has selected one--used OK button 
        Dim objPI As IPinInfo 
        Set objPI = frmSelectPin.SelPin ' get the new pin from the form 
        g_objSelPin.Connect objPI  ' connect the two pins 
        RefreshFilters  ' display the latest pin information 
    End If 

Automatically Connecting Pins

Call the IPinInfo.Render method to automatically generate all portions of the filter graph that are needed downstream from that pin.

The term downstream refers to all connections needed to construct a complete path from that pin to a renderer filter. For example, consider the representation of the filter graph by the GraphEdit utility, which shows connections as moving from the source filter at the left to the renderer filter at the right. The Render method adds all required filters and connections to the right of the specified pin.

' call IPinInfo.Render
' complete the graph downstream from this pin 
' g_objSelPin refers to the pin selected in the list box labeled 'Pins' 
    g_objSelPin.Render