Microsoft DirectX 9.0

Introduction to DirectShow Filter Development

This section gives a brief outline of the tasks involved in developing a custom DirectShow filter. It also provides links to topics that discuss these tasks in greater detail. Before reading this section, read the topics in About DirectShow, which describe the overall DirectShow architecture.

DirectShow Base Class Library

The DirectShow SDK includes a set of C++ classes for writing filters. Although they are not required, these classes are the recommended way to write a new filter. To use the base classes, compile them into a static library and link the .lib file to your project, as described in Building DirectShow Filters

The base class library defines a root class for filters, the CBaseFilter class. Several other classes derive from CBaseFilter, and are specialized for particular kinds of filters. For example, the CTransformFilter class is designed for transform filters. To create a new filter, implement a class that inherits from one of the filter classes. For example, your class declaration might be as follows:

class CMyFilter : public CTransformFilter
    /* Declare variables and methods that are specific to your filter.
    /* Override various methods in CTransformFilter */

For more information about the DirectShow base classes, see the following topics:

Creating Pins

A filter must create one or more pins. The number of pins can be fixed at design time, or the filter can create new pins as needed. Pins generally derive from the CBasePin class, or from a class that inherits CBasePin, such as CBaseInputPin. The filter's pins should be declared as member variables in the filter class. Some of the filter classes already define the pins, but if your filter inherits directly from CBaseFilter, you must declare the pins in your derived class.

Negotiating Pin Connections

When the Filter Graph Manager tries to connect two filters, the pins must agree on various things. If they cannot, the connection attempt fails. Generally, pins negotiate the following:

The base classes implement a framework for these negotiations. You must complete the details by overriding various methods in the base class. The set of methods that you must override depends on the class and on the functionality of your filter. For more information, see How Filters Connect.

Processing and Delivering Data

The primary function of most filters is to process and deliver media data. How that occurs depends on the type of filter:

Other tasks related to streaming include flushing data from the graph, handling the end of the stream, and responding to seek requests. For more information about these issues, see the following topics:

Supporting COM

DirectShow filters are COM objects, typically packaged in DLLs. The base class library implements a framework for supporting COM. It is described in the section DirectShow and COM.