Source Filters


This article details sample source filters. By definition, each of these source filter samples provides at least one output pin. (That is part of what makes them source filters as opposed to other kinds of filters.)

Contents of this article:

Asynchronous Reader Filter

The asynchronous reader filter, Async, shows how to implement "progressive download" in the DirectShow environment. Async implements the IAsyncReader interface, which is perhaps the most important aspect of asynchronous processing. It also implements the IFileSourceFilter interface and defines some helper classes to create filters that conform to the IAsyncReader interface.

The Memfile.exe application uses part of the Async sample code. This program reads a file into memory at a given rate (in kilobytes per second) and plays that file as it comes in.

Audio Synthesizer Filter

The audio synthesizer filter, Synth, demonstrates usage of the CSource and CSourceStream classes in an environment that derives its source from audio. You can use the Synth filter as a source filter to synthesize audio waveforms such as sine waveforms, square waveforms, sawtooth waveforms, and swept frequency waveforms.

The Synth source filter enables the user to set the waveform, frequency, number of channels, and other properties. The user can set these properties through the property page. To set either the upper or lower endpoint of the swept frequency range, hold down SHIFT while adjusting the frequency slider. The property page enables only the controls that affect the audio format—for example, channels, bits per sample, and sampling frequency—while the filter is in a stopped state.

This filter is available through the Filter Graph Editor when you choose Insert Filters from the Graph menu, and select the DirectShow Filters category.

Bouncing Ball Source Filter

The bouncing ball source filter, Ball, illustrates format negotiation. Ball also illustrates the use of the source filter base classes CSource and CSourceStream.

The code in Fball.h and Fball.cpp manages the filter interfaces. Those two files contain approximately the minimum code required for a source filter. The Ball.h and Ball.cpp files contain the code that bounces the ball.

This filter has a single output pin, which provides a video stream that shows a ball bouncing around in the frame. The Ball filter also accepts quality-management requests from the downstream graph, which illustrates a simple quality-management strategy. This filter implements the IQualityControl interface for that purpose.

This filter is available through the Filter Graph Editor when you choose Insert Filters from the Graph menu, and select the DirectShow Filters category.

Video Capture Filter

The VidCap sample video capture filter is not installed with DirectShow. You must install it by calling Regsvr32.exe for VidCap.ax. The sample video capture filter is not part of the run time, but is part of the SDK.

A video capture filter with the same capability as VidCap is installed with the DirectShow run time and can be seen in the Filter Graph Editor when you choose Insert Filters from the Graph menu, under the Video Capture Sources category. The VidCap sample is included so that you can view the source code for a video capture filter and see how to write capture filters.

Unlike ordinary DirectShow filters, special category filters, such as Video Capture Source filters, can work with more than one device.

The VidCap sample shows you how to handle special category filters, how to implement the COM interfaces for video capture, and how to implement miscellaneous other requirements for video capture.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.