Microsoft DirectX 8.1 (C++)

CBasePin Connection Process

The Filter Graph Manager initiates all pin connections. When two pins connect, one pin is the connecting pin and the other is the receiving pin. The Filter Graph Manager calls the connecting pin's IPin::Connect method. It specifies the receiving pin and possibly a media type for the connection. The connecting pin completes the connection by calling the receiving pin's IPin::ReceiveConnection method. The receiving pin can accept or reject the connection.

If the Filter Graph Manager specifies a media type, the pins try to connect with that type. Otherwise, the pins negotiate the type. If they cannot agree on a type, the connection fails. The Filter Graph Manager may also specify a partial media type, with the value GUID_NULL for the major type, subtype, or format. The pins try to match whichever portions of the media type are specified, and GUID_NULL acts as a wildcard.

In the Microsoft® DirectShow® implementation, the connecting pin is always an output pin, and the receiving pin is always an input pin.

How CBasePin Implements IPin::Connect

The CBasePin::Connect method starts by verifying that the pin can accept a connection. For example, it checks that the pin is not already connected. Then it delegates the rest of the connection process to AgreeMediaType, a protected class method. Everything that follows is performed by AgreeMediaType.

If the media type is fully specified, the pin calls the AttemptConnection method. Otherwise, the pin tries media types in the following order:

  1. The receiving pin's preferred types.
  2. The connecting pin's preferred types.

Note   You can reverse the order by setting the CBasePin::m_bTryMyTypesFirst flag to TRUE.

In each case, the pin calls IPin::EnumMediaTypes, which retrieves an enumerator object. It passes the enumerator object to the CBasePin::TryMediaTypes method. This method loops through all the media types provided by the enumerator, and calls AttemptConnection with each type.

Within the AttemptConnection method, the connecting pin calls the following methods:

Note the following:

If any of these steps fails, the pin calls the CBasePin::BreakConnect method to undo whatever steps were taken by CheckConnect.

On the receiving side, ReceiveConnection calls the receiving pin's CheckConnect, CheckMediaType, and CompleteConnect methods. If any of these fail, the connection attempt also fails.