Sunday, September 25, 2011

Microsoft DirectShow Capabilities

Microsoft DirectShow is a rich set of API(Application Programming Interface) s which can be used to control multimedia streams from devices such as Microphone, Line input, Digital Cam Coders, DVH-S VCR and many other multimedia devices. Capabilities of the DirectShow can be divided into 03 categories.

  1. Capture capabilities
  2. Transform capabilities
  3. Rendering capabilities

Capture capabilities
  • Capture audio from microphone, line input
  • Control a digital camcorder, VCR
  • Capture both audio and video from web cam, or video camera
  • Open a media file and control it as a live media stream

Transform capabilities
  • Convert color video to Black & White
  • Re size video images
  • Add an echo effect to audio stream
  • Splitting media streams to audio and video streams and multiplexing (adding) two media streams into one
Rendering Capabilities
  • Render a media stream into a display, speaker or a device
  • Write the media stream into a disk or a camcorder for further processing

These different capabilities can be used in different applications. Windows Movie Maker is a perfect example where DirectShow functionality is heavily used.

Microsoft DirectShow Programming Tutorial - Part I



As per the Microsft's definition Microsoft® DirectShow® is an architecture for streaming media on the Microsoft Windows® platform
DirectShow provides for high-quality capture and playback of multimedia streams. It supports a wide variety of formats, including Advanced Systems Format (ASF), Motion Picture Experts Group (MPEG), Audio-Video Interleaved (AVI), MPEG Audio Layer-3 (MP3), and WAV sound files. It supports capture from digital and analog devices based on the Windows Driver Model (WDM) or Video for Windows. It automatically detects and uses video and audio acceleration hardware when available, but also supports systems without acceleration hardware.
The basic building block of the DirectShow API architecture is a filter. 
"Filter is a unit which performs a single operation on a multimedia stream."
Examples for the filter are 
  1. Filter for read files
  2. Filter for decoding a particular media stream format, such as MPEG-1 video
  3. Filter for passing data to the graphics or sound card
Filters are used to manage and manipulate data. These are used to perform actions such as parsing, decoding, formatting or rendering on a multimedia stream.
To perform a given task, we need to connect several filters such that output of one filter is an input for another filter.
"Set of connected filters is called a filter graph"

Filter Graph Manager (FGM)

As you have seen in the first part of this tutorial  the atomic module of the direct show is a filter. Set of connected filters are used for processing a multimedia stream. This is called a filter graph. Most important feature of the DirectShow API is the Filter Graph Manager (FGM) which handles all the required operations for handling a filter graph.

If you are processing a multimedia stream with DirectShow, you don't need to look after each and every filter. FGM controls the flow of data through the filter graph. You only need to call high level API calls such as

  • Run - to move the data through the filter graph
  • Stop - to stop the data flow
FGM will take care about all the required operations with the filters. 
If the user wants to handle the filters on his own, then user can use the "COM" interface to interact with filters. 
Another thing that FGM does is that passing the event notifications to the application, so that user application can respond to events such as
  • end of the stream
  • pause
  • stop
This process is done with the help of the Operating systems Message Queue. If end of the stream event is happened, OS will pass that message to the FGM. Then it will pass the relevant message to the application.

to be contd ...

How to play a media file with DirectShow


 Hello World in DirectShow Programming

Every directshow application must perform the following basic tasks.
  1. Creates an instance of the FGM
  2. Build a fliter graph using the FGM
  3. controls the filter graph and responds to events
Following example code will give an insight into a simple directshow application, which uses the above mentioned tasks.

  • Creating an instance of the FGM
IGraphBuilder Interface is used to create an instance of the FGM.

IGraphBuilder *pGraph;
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
                    IID_IGraphBuilder, (void **)&pGraph);

  • Building a filter graph with the FGM
IMediaControl Interface is used to handle the media stream in the filter graph

IMediaControl *pMediaControl;

  • Run the filter graph using the FGM
RenderFile method is used to read the video stream into the filter.
Run method is used to run the media stream through the filter graph

pGraph->RenderFile(L"\\Hello_World.avi", NULL);
pMediaControl->Run();

The Full Source code sample is found on http://msdn.microsoft.com/en-us/library/aa916490.aspx