Connections Between Filters

Connections Between Filters

Although every DirectShow filter has pins, it isn t always possible to connect an input pin to an output pin. When two filters are connecting to each other, they have to reach an agreement about what kind of stream data they ll pass between them. For example, there are many video formats in wide use, such as DV (digital video), MPEG-1, MPEG-2, QuickTime, and so on. A transform filter that can handle DV might not be able handle any other video format. Therefore, a source filter that creates an MPEG-2 stream (perhaps read from a DVD) should not be connected to that transform filter because the stream data would be unusable.

The pins on a DirectShow filter handle the negotiation between filters and ensure that the pin types are compatible before a connection is made between any two filters. Every filter is required to publish the list of media types it can send or receive and a set of transport mechanisms describing how each filter wants the stream to travel from output pin to input pin. (Both media types and transport mechanisms will be covered in detail in Part III.)

When a DirectShow filter graph attempts to connect the output pin of one filter to the input pin of another, the negotiation process begins. The filter graph examines the media types that the output pin can transmit and compares these with the media types that the input pin can receive. If there aren t any matches, the pins can t be connected and the connection operation fails.

Next the pins have to agree on a transport mechanism. Once again, if they can t agree, the connection operation fails. Finally one of the pins has to create an allocator, an object that creates and manages the buffers of stream data that the output pin uses to pass data along to the input pin. The allocator can be owned by either the output pin or the input pin; it doesn t matter, so long as they re in agreement.

If all these conditions have been satisfied, the pins are connected. This connection operation must be repeated for each filter in the graph until there s a complete, uninterrupted stream from source filter, through any transform filters, to a renderer filter. When the filter graph is started, a data stream will flow from the output pin of one filter to the input pin of the other through the entire span of the filter graph.

Intelligent Connect

One of the greatest strengths of DirectShow is its ability to handle the hard work of supporting multiple media formats. Most of the time it s not necessary for the programmer to be concerned with what kinds of streams run through a filter graph. Yet to connect two pins, DirectShow filters must have clear agreement on the media types they re handling. How can both statements be true simultaneously? Intelligent Connect automates the connection process between two pins. You can connect two pins directly, so long as their media types agree. In a situation in which the media types are not compatible, you ll often need one (or several) transform filters between the two pins so that they can be connected together. Intelligent Connect does the work of adding and connecting the intermediate transform filters to the filter graph.

For example, a filter graph might have a source filter that produces a stream of DV data perhaps it s connected to a camcorder. This filter graph has a renderer filter that writes a file to disk. These two filters have nothing in common. They don t share any common media types because the DV data is encoded and interleaved and must be decoded and de-interleaved before it can be written to a file. With Intelligent Connect, the filter graph can try combinations of intermediate transform filters to determine whether there s a way to translate the output requirements of the pin on the source filter into the input requirements of the render filter. The filter graph can do this because it has access to all possible DirectShow filters. It can make inquiries to each filter to determine whether a transform filter can transform one media type to another which might be an intermediate type transform that type into still another, and so on, until the input requirements of the renderer filter have been met. A DirectShow filter graph can look very Rube Goldberg esque by the time the filter graph succeeds in connecting two pins, but from the programmer s point of view, it s a far easier operation. And if an Intelligent Connect operation fails, it s fairly certain there s no possible way to connect two filters. The Intelligent Connect capability of DirectShow is one of the ways that DirectShow hides the hard work of media processing from the programmer.



Programming Microsoft DirectShow for Digital Video and Television
Programming Microsoft DirectShow for Digital Video and Television (Pro-Developer)
ISBN: 0735618216
EAN: 2147483647
Year: 2002
Pages: 108
Authors: Mark D. Pesce

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net