C/C++-based Sample Applications

This article details sample applications that are written in C++ or C. The sample applications implement media players or perform other application-related functions. The differences between them are mainly the different programming languages, API, or frameworks used.

Some of these samples use the Microsoft® Foundation Classes (MFC).

This article contains the following sections.

AMCap Sample (DirectShow Capture Application)

The Microsoft® DirectShow® capture sample, AMCap, demonstrates the basics of capturing audio and video from a hardware source to a specified output file or to a preview window.

To see a list of the hardware capture devices on your system, choose the Devices menu; DirectShow uses the ICreateDevEnum interface to create the list of devices that appears. After choosing a device, choose the Set Frame Rate command from the Capture menu and set the desired frame rate; the default value is 30 frames per second. To set an output file for your capture, pick the Set Capture File command from the File menu. DirectShow uses the File Writer filter to associate your specified file with the capture session.

If you want to turn audio capturing on or off, choose the Capture Audio command from the Capture menu. To turn capture previewing on or off, choose the Preview command from the Options menu. When you are ready to begin capturing, choose the Start Capture command from the Capture menu. If you want to save your captured data to a file other than the specified output file, choose the Save Captured Video As command from the File menu.

Note: Before you begin capturing for the first time, choose Allocate File Space from the File menu to preallocate the capture file. Preallocating the file improves capture performance. AMCap calls AllocCapFile to preallocate the capture file.

Sample Locations

CPlay Sample (C/COM-based Media Player Application)

This C/COM-based media player sample, CPlay, is a simple application that renders multimedia files using DirectShow from within the C language. The CPlay sample does not use Microsoft Foundation Classes (MFC). If you want to see a sample that uses MFC, see MFCPlay Sample (C++/COM-based Media Player Application). The CPlay sample shows how to utilize the DirectShow components without using the base classes provided with DirectShow. The sample creates a filter graph (by calling CoCreateInstance to get a pointer to the IGraphBuilder interface), and requests the filter graph to render a file. The filter graph is then controlled by using the IMediaControl interface. This sample also uses the IMediaEvent and IMediaPosition interfaces.

CPlay is a minimal application that implements the following menu commands: Open, Play, Pause, Stop, and Exit on the File menu, and About on the Help menu.

Sample Locations

DDrawXcl Sample (DirectDraw Exclusive Mode Video Playback Application)

In DirectShow 6.x, you can play back video from AVI and MPEG files, as well as DVD titles, even in Microsoft® DirectDraw® exclusive full-screen mode. This enables game developers and interactive content developers to create content in full-screen mode and still play back video within it; for example, to play a movie in a certain room within a game.

DirectShow 6.x includes several new components that together offer this capability.

A sample application, DDrawXcl, has also been added to the SDK samples. This application consists of:

After successfully building the sample, run the application and choose File from the Options menu to load an AVI or MPEG file, or choose DVD from the Options menu to load a DVD file. Then choose Start Play from the Options menu. The sample application will perform the following steps.

  1. Switch into exclusive full-screen mode at 800 × 600 resolution with 256 colors (this mode was picked arbitrarily), and create a primary surface with one back buffer.
  2. Build a filter graph to play back the selected type of video by using the DirectDraw object and surface provided by the application, start playing the multimedia file, and set a timer to fire every 0.1 second.
  3. On the timer event, draw the color key of the required dimension on the back buffer, draw a ball that can be moved by using keystrokes, draw an updated number of flips done, and then flip the surfaces.

For more information on how to get application-created DirectDraw parameters used by the Overlay Mixer filter, as well as miscellaneous information, see the following topics.

How to Get DirectDraw Parameters for DVD

Use the following sequence of calls to get the application-created DirectDraw parameters used by the Overlay Mixer filter.

  1. Create the DVD graph builder object. For an example, see the CDVDPlayer::BuildGraph function in the Vidplay.cpp file.
  2. Call the IDvdGraphBuilder::GetDvdInterface method for the IDDrawExclModeVideo interface. This returns the IDDrawExclModeVideo interface of the Overlay Mixer in the DVD playback filter graph.
  3. Call IDDrawExclModeVideo::SetDDrawObject to set the DirectDraw object.
  4. Call IDDrawExclModeVideo::SetDDrawSurface to set the DirectDraw surface.
  5. Call IDvdGraphBuilder::RenderDvdVideoVolume to build the DVD graph.
  6. Call IDvdGraphBuilder::GetDvdInterface to get an IMixerPinConfig or IMixerPinConfig2 interface pointer to the first (and only) input pin of the Overlay Mixer.
  7. Get color key and other information by using the IMixerPinConfig::GetColorKey method and similar methods, such as GetZOrder, GetBlendingParameter, and so on.
  8. Call IDDrawExclModeVideo::SetCallbackInterface with a pointer to the object that implements the IDDrawExclModeVideoCallback interface.
  9. Get the native video size and aspect ratio through the IDDrawExclModeVideo::GetNativeVideoProps method. Transform the width and height based on the retrieved aspect ratio, and set the final video size and position by using the IDDrawExclModeVideo::SetDrawParameters method.

How to Get DirectDraw Parameters for AVI and MPEG

Use the following sequence of calls to get the application-created DirectDraw parameters used by the Overlay Mixer filter.

  1. Create an empty filter graph. For an example, see the CFilePlayer::Initialize function in the Vidplay.cpp file.
  2. Call IGraphBuilder::RenderFile on the specified file to build the graph.
  3. Instantiate the Overlay Mixer filter and add it to the graph. For an example, see the CFilePlayer::AddOvMToGraph function in the Vidplay.cpp file.
  4. Call IDDrawExclModeVideo::SetDDrawObject to set the DirectDraw object.
  5. Call IDDrawExclModeVideo::SetDDrawSurface to set the DirectDraw surface.
  6. Connect the decoded video to the Overlay Mixer's first input pin.
  7. Remove the Video Renderer filter (it's only a windowless playback case).
  8. Get the IMixerPinConfig or IMixerPinConfig2 interface from the first input pin of the Overlay Mixer to get the color key through the GetColorKey method.
  9. Call IDDrawExclModeVideo::SetCallbackInterface with a pointer to the object that implements the IDDrawExclModeVideoCallback interface.
  10. Get the native video size and aspect ratio through the IDDrawExclModeVideo::GetNativeVideoProps method. Transform the width and height based on the retrieved aspect ratio, and set the final video size and position by using the IDDrawExclModeVideo::SetDrawParameters method.

Miscellaneous Issues

The object implementing the IDDrawExclModeVideoCallback interface is implemented in the COverlayCallback class in the Ddrawobj.cpp file. It stops color keying of the video area on the back buffer when it gets the COverlayCallback::OnUpdateOverlay call with input parameter bBefore=TRUE. The color keying is turned on again when another OnUpdateOverlay call is made with bBefore=FALSE and the dwFlags parameter indicating that the overlay is visible. (For the definition of this method, see IDDrawExclModeVideoCallback::OnUpdateOverlay.)

The SetDDrawObject and SetDDrawSurface methods can be called only when the pins of the Overlay Mixer are not connected. Otherwise, the calls will fail.

The application has to draw the color key at the correct position on the primary surface (actually, the back buffer of the primary surface) to get the video to appear. In the exclusive mode, the Overlay Mixer doesn't draw the color key at all.

In the case of DVD playback, after the DirectDraw object and surface are set through the SetDDrawObject and SetDDrawSurface methods, the graph is dismantled to avoid an inconsistent graph state. Call RenderDvdVideoVolume to rebuild the graph using the new DirectDraw parameters.

For DVDs, the subpicture and line 21 (closed caption) data are intentionally not rendered in exclusive full-screen mode. The DVD graph builder should not return S_FALSE simply because it cannot render these.

The following list describes issues specific to the DDrawXcl sample.

Sample Locations

Dvdsampl Sample (DVD Player Application)

The DirectShow DVD sample player, Dvdsampl, is a simple application that plays DVD Video content. It uses the IDvdGraphBuilder interface to build a DVD filter graph and to obtain interface pointers for IAMLine21Decoder, IDvdControl, and IDvdInfo. It uses those interfaces and enables you to turn closed captioning on and off, play in full-screen mode, and display and select from DVD menus.

Note  Your system must include DVD playback hardware and a DirectShow-compatible MPEG-2 decoder to run this sample.

Sample Locations

InWindow Sample (Window Playback Application)

The InWindow application is a simple sample that shows minimal code required to play back a media file into a specific window. It builds on the PlayFile sample. Like PlayFile, it provides a file Open dialog box that enables you to open media files. It also uses IGraphBuilder, IMediaEventEx, and IMediaControl as PlayFile does. InWindow expands on the PlayFile functionality by calling IVideoWindow::put_Owner, IVideoWindow::put_WindowStyle, and IVideoWindow::SetWindowPosition to direct playback into the main application window.

Sample Locations

IPlay Sample (Indeo Player Application)

The Intel® Indeo player sample, IPlay, uses DirectShow to render multimedia files and demonstrates the Indeo Video Interactive application programming interfaces (API). IPlay demonstrates how to access the advanced features of the Indeo Video Interactive (IVI) codec. It is a simple application written in C++ using Microsoft Foundation Classes (MFC). If the file is an IVI format file, it enables controls for the IVI advanced features. The advanced features include local decoding, a decoding time limit, and the ability to adjust brightness, saturation, and contrast.

The Ax_spec.h file defines the interfaces of the IVI codec. The CIPlayDoc::OnOpenDocument function demonstrates how to determine if a file is an IVI format file. The CIPlayDoc::Getxxx and CIPlayDoc::Setxxx functions demonstrate how to get and set the IVI playback parameters for the advanced features.

This sample uses the following interfaces:

IPlay also implements and uses the IIndeoDecode interface (not part of DirectShow).

Sample Locations

MFCPlay Sample (C++/COM-based Media Player Application)

The C++/COM-based media player sample, MFCPlay, is a simple application that renders multimedia files using DirectShow from within C++ and Microsoft Foundation Classes (MFC). It demonstrates how to connect the DirectShow components by using the interfaces provided with DirectShow and MFC. The sample creates a filter graph (by calling CoCreateInstance to get a pointer to the IGraphBuilder interface), and requests the filter graph to render a file. The filter graph is then controlled by using the IMediaControl interface. This sample also uses the IMediaEvent and IMediaPosition interfaces.

The MFCPlay application implements the following menu commands: Open, Play, Pause, Stop, and Exit on the File menu, and About on the Help menu.

Sample Locations

MPEGProp Sample (MPEG Property Page Display Application)

The MPEGProp sample application demonstrates how to display a filter's property page.

When you open MPEGProp, choose Open from the File menu and select an MPEG media file from the standard Open dialog box. After you select an appropriate file, MPEGProp calls CoCreateInstance to create a new filter graph and renders the chosen source file. MPEGProp calls IFilterGraph::FindFilterByName to locate the MPEG Video Codec filter, and then calls OleCreatePropertyFrame with the codec pointer to display the filter's property page.

Sample Locations

PlayFile Sample (Simple Playback Application)

The PlayFile application is a simple sample that shows minimal code required to play back a media file. It provides a file Open dialog box that enables you to open files including file types such as AVI, MPEG, MOV, and QT. PlayFile uses the IGraphBuilder::RenderFile method to render the filter graph for the chosen media file, IMediaEventEx to handle signaling of events, IMediaControl::Run to play the resulting filter graph, and IMediaControl::Stop to stop playback. The sample calls IVideoWindow to control whether the playback window is visible. Video follows the default behavior and plays back in a separate window rather than in the main application window.

For a sample that builds on PlayFile and plays back video into the main application window, see InWindow Sample (Window Playback Application).

Sample Locations

ShowStrm Sample (Multimedia Streaming Application)

The ShowStrm application demonstrates how to use a DirectDraw surface to blit a multimedia stream. It is a console application that sends a movie out to the surface when invoked from the command line with the following syntax.

SHOWSTRM Name_of_Movie

For example, to play Angry.avi, you could use the command:

C:\>SHOWSTRM angry.avi

This sample demonstrates the IAMMultiMediaStream and IMultiMediaStream interfaces.

Sample Locations

VidClip Sample (Video Editing Application)

The VidClip application demonstrates how to use the multimedia streaming interfaces and how to support rudimentary video editing. The VidClip sample reads from multiple streams and writes to a single stream. For more information on the multimedia streaming interfaces, see List of Multimedia Streaming Interfaces.

On the Video menu in the VidClip application, choose the Add Clip command to add clips to your list; you can include start and stop times, if you want to add only a portion of a clip. Choose the Edit Clip command to edit existing clips in the list, and the Delete Clip command to delete clips. The Make a Movie command combines the clips into one stream.

On the File menu, choose the Settings command to set the height, width, depth, and compression for the stream data. Choose the Save command to save the settings to a file in your project.

Sample Locations


Top of Page Top of Page
© 2000 Microsoft and/or its suppliers. All rights reserved. Terms of Use.