26 jui '05 - 365 W - + 24 - 29 Filters development

Filters are the active components of DirectShow. They read, transform, display and save the multimedia data.

Filters are in fact special DLLs. Except for trivial functions, their development requires an in-depth knowledge of the various DirectShow mechanisms :

Moreover, a good knowledge of COM and OO programming are absolute prerequisites.

Base Classes

The SDK provides base classes enabling the development of filters with (limited) effort
  1. A Filter hierarchy
  2. A Pin hierarchy
  3. Helper classes

Steps in filter development

  1. Selection of a base class for the filter (and other elements)
  2. Derive your class from the selected base class
  3. Definition of the interface Add necessary elements (Pins)
  4. Code abstract methods (PURE)
  5. (if necessary) overload virtual methods
  6. Code the interface
  7. Code the filter functions
  8. Develop property pages (optional)
  9. Add the GUID (filter, interface, pages)
  10. Build the .ax file
  11. Register the filter

Coding of the filter function is in bold, because this is really there that you write the specific code that will perform your processing function !

Threading

There are usually at least two threads at the level of a filter :
  1. The Graph control Thread
  2. The streaming Thread
  3. Sometimes many more

Threading and Critical Section

It is therefore necessary to protect the streaming Thread against state changes during the processing of data.
It is also necessary to protect the Filter state with a critical section.
Two helper classes facilitate this work (in C++) :

Never, ever, call a graph method from the Streaming Thread (certain deadlock).


Selection of a base class

Usually this rather simple, depending on the intended result : use a Transform or a TransInPlace base class if your filter is a transform filter.
For specific cases however (e.g. 2 input pin tranform filter), very often, you will start from CBaseFilter !! (this will often prove much easier than overloading lots of methods in more complex classes).
The next step consists in following systematically the instructions from the DirectShow Reference BaseClasses documentation regarding the implementation of abstract methods and overload of virtual ones. It is better (highly recommended) to re-use the code of the examples (and also the base classes)

(to be continued)