Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / multimedia / DirectX

DirectShow Filters (For Beginners)

2.36/5 (20 votes)
23 Sep 2007CPOL4 min read 1  
DirectShow filters are described in an easy to understand way.

Introduction

DirectShow filters are COM components which are connected together to build a filter graph. A filter graph is a complete mechanism (different filters connected together) which is needed to run a media file. Normally, a filter is capable of doing a single work, meaning a filter is an entity which is fully capable of processing media file data. Therefore, if you want to process the media file data, the most powerful technique is to build your own filter which can perform the required job.

Modular Design

Another benefit of building your own filter is that, internally, DirectShow has a modular design, meaning it is made up of small components working together to do a job. This design frees the developer from many worries. If you build your own filter (according to specifications), you don't need to worry about the other parts of the filter graph. If your filter works OK, then every thing will be OK. Otherwise, you are confirmed that your own filter is malfunctioning and not any other filter, because the other filters are already tested by the respective developers.

Data Flow in the Filter Graph

Data flows in the filter graph from one filter to another. The filter which gives the data is called the upstream filter and the filter which takes that data is called a downstream filter. The data flows from upstream filter to downstream filter, and this is called upstream filter push data (see Transport for push and pull).

Filter Types

Normally, filters are divided in three categories:

  1. Source filters
  2. Transform filters
  3. Renderer filters

Let us see them briefly.

Source Filters

These are the source of data that flow inside the filter graph. They provide data to the downstream filters (or downstream filter snatches data from the source filter, see Transport below). They come in three categories: capture source filters, file source filters, creator source filters. Capture source filters are those that get data form capture devices, such as camcorders or web cams. File source filters are those that get data from stored files. And the last, creator source filters are the type of filters that create data themselves to be flown in the filter graph.

Transform Filters

This is the category of filters which is used and created most. Any filter other then the source filter and renderer filter (see below) is called a transform filter. They get data from a source filter or any other filter upstream, and do the custom operation over data and pushes that data downstream. The custom operation here means the work they are made for; some parse data, others decode data, or any operation you want to be done over data.

Renderer Filters

The data in the filter graph flows from the source filter through the transform filters towards the renderer filter. This is the filter which sits at the end of the filter graph. The examples are filters which show video over screen, or write data to a file.

Connecting Filters

A filter is a COM component which has input and output pins. These are also COM components. All data travels through these pins. The output pin of the upstream filter is connected to the input pin of the downstream filter.

Connection Requirements

It is not so easy to connect any two filter pins. There must be a negotiation of some requirements. The actual negotiation work is done by the pins, which must be met before a connection takes place.

What are these requirements and why must they be met. Let us see:

The requirements are:

  1. Media type(s)
  2. Transport
  3. Allocators

Let us briefly see what they are.

Media Types

When two pins connect, they must agree on the format of the data which will be passed so that when actual data flow begins, the downstream filter can understand the format of data that the upstream filter is giving it.

Transport

The two also must agree on the protocol or the mechanism which will be used to exchange data. The most common transport is local memory. There are two mechanisms for local memory transport: push and pull. In the push model, data flows from the upstream filter to the downstream filter. And, in the pull model, the downstream filter pulls the data from the upstream filter. The pull model is only used in file source filters the filter read data from the file(s). All others use the push model.

Allocators

Allocators are also COM components which are responsible for managing the buffers which are used for data exchange.

More Info

You can visit my site www.tanvon.com on ongoing work in DirectShow.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)