Filters

Filters

Filters are the basic units of DirectShow programs, the essential components of the filter graph. A filter is an entity complete unto itself. Although a filter can have many different functions, it must have some method to receive or transmit a stream of data. Each filter has at least one pin, which provides a connection point from that filter to other filters in the filter graph. Pins come in two varie ties: input pins can receive a stream, while output pins produce a stream that can be sent along to another filter.

Filter Types

There are three basic classes of DirectShow filters, which span the path from input, through processing, to output (or, as it s often referred to, rendering). All DirectShow filters fall into one of these broad categories. A filter produces a stream of data, operates on that stream, or renders it to some output device.

Source Filters

Any DirectShow filter that produces a stream is known as a source filter. The stream might originate in a file on the hard disk, or it might come from a live device, such as a microphone, webcam, or digital camcorder. If the stream comes from disk, it could be a pre-recorded WAV (sound), AVI (movie), or Windows Media file. Alternately, if the source is a live device, it could be any of the many thousands of Windows-compatible peripherals. DirectShow is closely tied in to the Windows Driver Model (WDM), and all WDM drivers for installed multimedia devices are automatically available to DirectShow as source filters. So, for example, webcams with properly installed Windows drivers become immediately available for use as DirectShow source filters. Source filters that translate live devices into DirectShow streams are known as capture source filters. Chapter 12 covers the software design of a source filter in detail.

Transform Filters

Transform filters are where the interesting work gets done in DirectShow. A transform filter receives an input stream from some other filter (possibly a source filter), performs some operation on the stream, and then passes the stream along to another filter. Nearly any imaginable operation on an audio or video stream is possible within a transform filter. A transform filter can parse (interpret) a stream of data, encode it (perhaps converting WAV data to MP3 format) or decode it, or add a text overlay to a video sequence. DirectShow includes a broad set of transform filters, such as filters for encoding and decoding various types of video and audio formats.

Transform filters can also create a tee in the stream, which means that the input stream is duplicated and placed on two (or more) output pins. Other transform filters take multiple streams as input and multiplex them into a single stream. Using a transform filter multiplexer, separate audio and video streams can be combined into a video stream with a soundtrack.

Renderer Filters

A renderer filter translates a DirectShow stream into some form of output. One basic renderer filter can write a stream to a file on the disk. Other renderer filters can send audio streams to the speakers or video streams to a window on the desktop. The Direct in DirectShow reflects the fact that DirectShow renderer filters use DirectDraw and DirectSound, supporting technologies that allow DirectShow to efficiently pass its renderer filter streams along to graphics and sound cards. This ability means that DirectShow s renderer filters are very fast and don t get tied up in a lot of user-to-kernel mode transitions. (In operating system parlance, this process means moving the data from an unprivileged level in an operating system to a privileged one where it has access to the various output devices.)

A filter graph can have multiple renderer filters. It is possible to put a video stream through a tee, sending half of it to a renderer filter that writes it to a file, and sending the other half to another renderer filter that puts it up on the display. Therefore, it is possible to monitor video operations while they re happening, even if they re being recorded to disk an important feature we ll be using later on.

The Complete Picture

All DirectShow filter graphs consist of combinations of these three types of filters, and every DirectShow filter graph will have at least one source filter, one renderer filter, and (possibly) several transform filters. In each filter graph, a source filter creates a stream that is then operated on by any number of transform filters and is finally output through a renderer filter. These filters are connected together through their pins, which provide a well-defined interface point for transfer of stream data between filters.



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