Chapter 1: DirectShow Concepts

Part I

The Basics

Chapter 1

DirectShow Concepts

From the viewpoint of the application programmer, Microsoft DirectShow is composed of two types of classes of objects: filters, the atomic entities of DirectShow; and filter graphs, collections of filters connected together to provide specific functionality. Just as atoms are composed of electrons, protons, and neutrons, filters are composed of pins, which can either receive an input stream or send an output stream to another filter. Conceptually, filters can be thought of as function calls in a DirectShow programming language, while a filter graph is the program composed of those function calls. Here is what it might look like, in pseudo C++ code:

FilterGraph() { SourceFilter(); // A source filter TranformFilter(); // Usually, a transform filter  // As many other filters as needed RendererFilter(); // A renderer filter }

As is the case in most programming languages, the DirectShow filter graphs execute sequentially, from the first filter to the last. Data enters at the first filter in the filter graph, passes along to the second filter, and so on. What makes a DirectShow filter graph different from a common C++ program is that it also executes continuously. When a filter graph starts its execution, data begins to flow across the filters in a filter graph like a waterfall descending a series of stairs. This data flow is commonly known as a stream. This stream is operated on by all filters in a filter graph simultaneously. Chapter 10 contains a detailed exploration of exactly how data flows across a filter graph and how DirectShow adjusts its operation to keep the filter graph from running dry or being overwhelmed with a data stream.

One important point distinguishes a DirectShow filter graph from an ordinary computer program: a filter graph can have multiple streams flowing across it and multiple paths through the filter graph. For example, a DirectShow application can simultaneously capture video frames from a webcam and audio from a microphone. This data enters the filter graph through two independent source filters, which would likely later be multiplexed together into a single audio/video stream. In another case, you might want to split a stream into two identical streams. One stream could be sent to a video renderer filter, which would draw it upon the display, while the other stream could be written to disk. Both streams execute simultaneously; DirectShow sends the same bits to the display and to the disk.

DirectShow filters make computations and decisions internally for instance, they can change the values of bits in a stream but they cannot make decisions that affect the structure of the filter graph. A filter simply passes its data along to the next filter in the filter graph. It can t decide to pass its data to filter A if some condition is true or filter B if the condition is false. This means that the behavior of a filter graph is completely predictable; the way it behaves when it first begins to operate on a data stream is the way it will always operate.

Although filter graphs are entirely deterministic, it is possible to modify the elements within a filter graph programmatically. A C++ program could create filter graph A if some condition is true and filter graph B if it s false. Or both could be created during program initialization (so that the program could swap between filter graph A and filter graph B on the fly) as the requirements of the application change. Program code can also be used to modify the individual filters within a filter graph, an operation that can change the behavior of a filter graph either substantially or subtly. So, although filter graphs can t make decisions on how to process their data, program code can be used to simulate that capability.

For example, consider a DirectShow application that can capture video data from one of several different sources, say from a digital camcorder and a webcam. Once the video has been captured, it gets encoded into a compact Windows Media file, which could then be dropped into an e-mail message for video e-mail. Very different source and transform filters are used to capture and process a video stream from a digital camcorder than those used with a webcam, so the same filter graph won t work for both devices. In this case, program logic within the application could detect which input device is being used perhaps based on a menu selection and could then build the appropriate filter graph. If the user changes the selection from one device to another, program logic could rebuild the filter graph to suit the needs of the selected device.



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