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.
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.
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.
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.
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.
Use the following sequence of calls to get the application-created DirectDraw parameters used by the Overlay Mixer filter.
Use the following sequence of calls to get the application-created DirectDraw parameters used by the Overlay Mixer filter.
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.
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.
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.
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).
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.
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.
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).
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.
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.
Top of Page
© 2000 Microsoft and/or its suppliers. All rights reserved. Terms of Use.