Microsoft DirectX 8.0

Introduction to DirectShow Application Programming

This article introduces the basic terms and concepts needed to write a Microsoft® DirectShow® application. It also introduces some of the terminology used in DirectShow. After reading this section, you will be ready to write your first DirectShow application.

This article contains the following sections.

Filter Graphs

The basic building block of DirectShow is a software component called a filter. A filter generally performs a single operation on a multimedia stream. For example, there are DirectShow filters that

Filters receive input and produce output. For example, if a filter decodes MPEG-1 video, the input is the MPEG-encoded stream and the output is an uncompressed RGB video stream.

To perform a given task, an application connects several filters so that the output from one filter becomes the input for another. A set of connected filters is called a filter graph. As an illustration of this concept, the following diagram shows a filter graph for playing an AVI file.

Filter Graph to Play an AVI File

Your application does not have to manage the individual filters in a filter graph. Instead, DirectShow provides a high-level component called the Filter Graph Manager. The Filter Graph Manager controls the flow of data through the graph. Your application makes high-level API calls such as "Run" (to move data through the graph) or "Stop" (to stop the flow of data). If you require more direct control of stream operations, you can access the filters directly through COM interfaces. The Filter Graph Manager also passes event notifications to the application, so that your application can respond to events, such as the end of a stream.

In addition, the Filter Graph Manager simplifies the process of building a filter graph. For example, you can specify a file name, and the Filter Graph Manager will build a graph to play that file.

Writing a DirectShow Application

A typical DirectShow application performs three basic steps, as illustrated in the following diagram.

Typical DirectShow Application

  1. Creates an instance of the Filter Graph Manager, using the CoCreateInstance function.
  2. Uses the Filter Graph Manager to build a filter graph. (You might use other DirectShow helper components as well.)
  3. Controls the filter graph and responds to events.

To get started with DirectShow, read How to Play a File. It presents a simple console application that plays a file. This application is the DirectShow equivalent of the classic "Hello World" program. Setting the Video Window and Responding to Events expand the program into a simple Windows application.