The Filter Graph

The Filter Graph

On the first page, I mentioned that a media application uses DirectShow to connect together various COM Objects called filters which are designed to process, or manipulate, a video or audio data stream in some way. I also mentioned that filters come in three basic types: Source filters (such as a device's driver), transform filters (such as an AVI-to- MPEG compressor) and renderer filters (such as the VideoWindow we saw on the previous page).

The filters connect together by means of 'Pins'. Source filters will have at least one Output Pin, transform filters will have at least one Input Pin and one Output Pin and renderer filters will have at least one Input Pin.

The picture below shows a typical example of how the filters might be connected together.

A complete collection of filters such as this is known as a Filter Graph and applications build them to suit their particular requirements by using a DirectShow Object called the Filter Graph Manager - or, more correctly, the application creates an instance of the Filter Graph Manager and then uses it to create the Filter Graph.

The Filter Graph Manager can be used to add filters individually to a Filter Graph but the Filter Graph Manager contains logic called Intelligent Connect which can be used to allow it to search your computer's registry for suitable filters and connect them automatically. This is a very powerful feature because it allows an application's functionality to "grow" if a user should add more filters. For example, many third-party applications - such a WinAmp etc - will add filters of their own and list them in the registry. Provided a filter has been written to the DirectShow specification, it's use may be enlisted in any other application in which DirectShow's Intelligent Connect feels it would be useful.

The Filter Graph Manager's Intelligent Connect is invoked by calling its Render or RenderFile method. Consider the simple video file player shown on the previous page. Its Filter Graph might look something like this:

However, suppose the file we played also had an audio track. The Filter Graph would now need to include audio filters and may look something like this:

Suppose the file we chose was an MPEG instead of an AVI, a different set of filters would be needed again, and so on. By using Intelligent Connect and the Filter Graph Manager's RenderFile method, we allow the application to automatically create a Filter Graph specifically for the chosen file format - provided the system has filters for it - and save ourselves a lot of hard work as well!

As I mentioned above, the Filter Graph Manager can also add filters manually to a Filter Graph and there are many other methods and events associated with it. We'll look at some of them later.

Graph Edit

Because the Filter Graph Manager's Render and RenderFile methods create the Filter Graph automatically, we can't be certain exactly which filters it has included so it would be useful if we could view the Filter Graph that's been created. Microsoft have produced a very useful tool called "GraphEdit". Although it's only officially available as part of the DirectShow SDK (Software Development Kit), various versions of it are invariably to be found on the internet. I won't provide a link here because it's easy to locate and download a recent version by searching Google for 'GraphEdit'.

A useful feature of GraphEdit is that it can "snoop" on the Filter Graph that's been created by another application. Let's return to our simple Delphi media file player we created earlier and see how to use GraphEdit with it.


Here's our simple application with Delphi's Object Inspector showing the FilterGraph1 component.

Note that I've set the GraphEdit property to True. The default value is False but, as we want to inspect the Filter Graph with the GraphEdit tool, we need to set the property to True.

We could also have set it in code of course:

   FilterGraph1.GraphEdit:= True;

We'll run our program, open different types of media files and use GraphEdit to see what Filter Graph the FilterGraph1.RenderFile() method has created.

previous page | next page

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

This site and its contents are © Copyright 2005 - All Rights Reserved.