Modular Design

Modular Design

The basic power and flexibility of DirectShow derives directly from its modular design. DirectShow defines a standard set of Component Object Model (COM) interfaces for filters and leaves it up to the programmer to arrange these components in some meaningful way. Filters hide their internal operations; the programmer doesn t need to understand or appreciate the internal complexities of the Audio Video Interleaved (AVI) file format, for example, to create an AVI file from a video stream. All that s required is the appropriate sequence of filters in a filter graph. Filters are atomic objects within DirectShow, meaning they reveal only as much of themselves as required to perform their functions.

Because they are atomic objects, filters can be thought of and treated just like puzzle pieces. The qualities that each filter possesses determine the shape of its puzzle piece, and that, in turn, determines which other filters it can be connected to. As long as the pieces match up, they can be fitted together into a larger scheme, the filter graph.

All DirectShow filters have some basic properties that define the essence of their modularity. Each filter can establish connections with other filters and can negotiate the types of connections it s willing to accept from other filters. A filter designed to process MP3 audio doesn t have to accept a connection from a filter that produces AVI video and probably shouldn t. Each filter can receive some basic messages run, stop, and pause that control the execution of the filter graph. That s about it; there s not much more a filter needs to be ready to go. As long as the filter defines these properties publicly through COM, DirectShow will treat it as a valid element in a filter graph.

This modularity makes designing custom DirectShow filters a straightforward process. The programmer s job is to design a COM object with the common interfaces for a DirectShow filter, plus whatever custom processing the filter requires. A custom DirectShow filter might sound like a complex affair, but it s really a routine job, one that will be covered extensively in the examples in Part III.

The modularity of DirectShow extends to the filter graph. Just as the internals of a filter can be hidden from the programmer, the internals of a filter graph can be hidden from view. When the filter graph is treated as a module, it can assume responsibility for connecting filters together in a meaningful way. It s possible to create a complete, complex filter graph by adding a source filter and a renderer filter to the filter graph. These filters are then connected with a technique known as Intelligent Connect. Intelligent Connectexamines the filters in the filter graph, determines the right way to connect them, adds any necessary conversion filters, and makes the connections all without any intervention from the programmer. Intelligent Connect can save you an enormous amount of programming time because DirectShow does the tedious work of filter connection for you.

There is a price to be paid for this level of automation: the programmer won t know exactly which filters have been placed into the filter graph or how they re connected. Some users will have installed multiple MPEG decoders such as one for a DVD player and another for a video editing application. Therefore, these systems will have multiple filters to perform a particular function. With Intelligent Connect, you won t know which filter DirectShow has chosen to use (at least, when a choice is available). It s possible to write code that will make inquiries to the filter graph and map out the connections between all the filters in the filter graph, but it s more work to do that than to build the filter graph from scratch. So, modularity has its upsides ease of use and extensibility and its downsides hidden code.

Hiding complexity isn t always the best thing to do, and you might choose to build DirectShow filter graphs step by step, with complete control over the construction process. Overall, the modular nature of DirectShow is a huge boon for the programmer, hiding gory details behind clean interfaces. This modularity makes DirectShow one of the very best examples of object-oriented programming (OOP), which promises reusable code and clean module design, ideals that are rarely achieved in practice. DirectShow achieves this goal admirably, as you ll see.



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