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).

Contents of this article:

C/COM-based Media Player

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 the Microsoft Foundation Classes (MFC). If you want to see a sample that uses MFC, see C++/COM-based Media Player. 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 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.

DirectShow Capture

The 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.

DVD Sample Player

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 allows 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 to run this sample.

C++/COM-based Media Player

The C++/COM-based media player sample, MFCPlay, is a simple application that renders multimedia files using DirectShow from within C++ and the Microsoft Foundation Classes (MFC). It demonstrates how to interface to the DirectShow components by using the interfaces provided with DirectShow and the 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 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.

MPEG Property Page Display

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. Once 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.

Indeo Player

The Intel® Indeo player sample, IPlay, renders multimedia files using DirectShow and demonstrates the Indeo Video Interactive application programming interfaces (API). The IPlay sample demonstrates how to access the advanced features of the Indeo Video Interactive (IVI) codec. It is a simple application written in C++ using the 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 makes use of the following interfaces. IGraphBuilder to create a filter graph and render a file, IFilterGraph to enumerate the filters in the filter graph, IMediaControl to play/pause/stop the playback, IMediaEvent to be notified of EC_COMPLETE (playback complete) and other events, IMediaPosition to set the time that the media stream begins, IVideoWindow to set the window size/caption/position, and IBasicVideo to get the native window size. It also implements and uses the IIndeoDecode interface (not part of DirectShow itself).

InWindow Simple Playback in a Window

The InWindow application is a "bare-bones" sample which shows minimal code required to play back a media file into a specific window. It builds upon the PlayFile Simple Playback Application. Like PlayFile it provides a file open dialog which allows you to open media files. It also uses IGraphBuilder, IMediaEventEx, and IMediaControl as PlayFile does. InWindow expands upon the PlayFile functionality by calling IVideoWindow::put_Owner, IVideoWindow::put_WindowStyle, and IVideoWindow::SetWindowPosition to direct playback into the main application window.

PlayFile Simple Playback Application

The PlayFile application is a "bare-bones" sample which shows minimal code required to play back a media file. It provides a file open dialog which allows you to open files including file types such as AVI, MPEG (MPG), MOV, and QT. PlayFile uses IGraphBuilder::RenderFile 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 or not the playback window is visible. Video follows the default behavior and plays back in a separate window rather than into the main application window.

See InWindow Simple Playback in a Window for a sample that builds upon PlayFile and plays back video into the main application window.

ShowStrm Application

The ShowStrm application demonstrates how to get the DirectDraw Surface to blit a multimedia stream. It is a console application that send the movie out 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

VidClip 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.

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

On the File menu, you can use the Settings option to set the height, width, depth, and compression for the stream data. You can use the Save option to save the settings to a file in your project.

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