Microsoft® DirectShow™ is an architecture that controls and processes streams of multimedia data through custom or built-in filters. You can also use the set of media streaming interfaces to stream media data without creating filters. See Use Multimedia Streaming in DirectShow Applications for more information.
In addition to the architecture and the set of classes and interfaces to support it, DirectShow is also a run time that uses this architecture to enable users to play digital movies and sound encoded in various formats, including MPEG, AVI, MOV (Apple® QuickTime®) and WAV-formatted files. The DirectShow run time is a control (.ocx), called the ActiveMovie Control, and a set of dynamic-link libraries (DLLs) that enable you to play back supported media files.
DirectShow playback uses video and audio hardware cards that support the Microsoft DirectX® set of application programming interfaces (APIs). The video and audio capture capability lets you programmatically control your system's video and audio capture hardware, as well as video and audio compressors and decompressors (codecs). The Plug and Play capability lets DirectShow automatically retrieve and use your filters, once you register their properties.
Use the DirectShow architecture for most new multimedia applications for Windows® 95 or Windows NT®. With a few exceptions, it replaces multimedia playback services, APIs, and architectures provided by Microsoft in earlier versions of the Windows Software Development Kit (SDK). However, libraries will continue to be available and supported for applications that use the earlier Microsoft multimedia playback services, such as Microsoft Video for Windows.
Contents of this article:
DirectShow Architecture
The DirectShow architecture defines how to control and process streams of multimedia data using modular components called filters. The filters have input or output pins, or both, and are connected to each other in a configuration called a filter graph. Applications use an object called the filter graph manager to assemble the filter graph and move data through it. By default, the filter graph manager automatically handles data flow for you; for example, it automatically inserts the proper codec if needed, and it automatically connects a transform filter's output pin to the default rendering filter. You can always specify your own filters and connections if you don't want to use the default configuration.
The filter graph manager provides a set of Component Object Model (COM) interfaces so that applications can access the filter graph. Applications can directly call the filter graph manager interfaces to control the media stream or retrieve filter events, or they can use the ActiveMovie Control to play back media files.
Thus, you can access DirectShow through the COM interface, the ActiveMovie Control, or media control interfaces (MCI), as shown in the following illustration.
Because of the DirectShow architecture's flexible, modular design, filter graphs have many potential uses and applications. Examples include filter graphs that implement video capture, control remote devices such as VCRs, or enable MIDI recording and editing.
Choosing the Right Programming Model
DirectShow is accessible at several levels, and the approach you use depends on what you need and how much programming you want to do. You might plan to rewrite an existing multimedia program, write a new multimedia program, or add multimedia capabilities to an existing program. Typically, existing applications that use the MCI command set are easily ported, whereas applications that access lower-level multimedia services require more time to rewrite. You can quickly add DirectShow playback services to new applications by using the ActiveMovie Control, or with a few direct functions that call the COM interfaces. C or C++ programmers can write filters that change or enhance multimedia data already managed by existing filter graphs.
This section contains the following topics.
Rewriting Existing Applications
If you have an application that plays AVI-encoded movies and sounds and want to adapt it to use DirectShow to play AVI files, porting is straightforward if your application uses MCI commands or the Microsoft Video for Windows® API. Your choice depends on the services the application uses and your goals. If your application uses MCI commands, you can use the MCI subset that DirectShow provides. In the majority of cases, this will be a straightforward upgrade that maintains AVI playback and adds MPEG and QuickTime playback capabilities to your application. If your existing C-based application uses Video for Windows API, you can replace most of these with calls to the COM interfaces.
Writing New Applications
You can take a variety of approaches when writing a new application with DirectShow. For example, if you only want to add MPEG playback to your application, you can incorporate the ActiveMovie Control into your application or directly access the COM interfaces on the filter graph manager. Both Microsoft Visual Basic® version 5.x and later and Microsoft Visual C++® version 5.x and later allow access to the ActiveMovie Control or the COM interfaces. Filters within a filter graph are typically written in C++ using the DirectShow class library.
If your application must process the media stream in some way or capture a media stream, you can incorporate both the filter graph manager and a custom filter into your application. The instantiated filter graph manager generates and manages the filter graph. You can insert the custom filter into a preconfigured filter graph (which you create and save by using the Filter Graph Editor tool in the DirectShow SDK). You also could insert the filter into an existing filter graph at run time.
Playing Back Files Over the Internet
The ActiveMovie Control is incorporated into Microsoft Internet Explorer so that you can place the control on a Web page and program it by using Microsoft Visual Basic® Scripting Edition (VBScript) commands. To a programmer, the ActiveMovie Control is another ActiveX™ Control, one that has real-time playback capability. Real-time playback means that the ActiveMovie Control can play video or audio files over the Internet while the file is downloading, rather than requiring the user to wait until the whole file is downloaded to begin playback.
The same filter graphs constructed to play media from files can play media from the Internet by simply changing the source filter. Take, for example, a filter graph that plays MPEG movies from a disk file. The first filter in the graph might be a file reader filter. By replacing this filter with a filter capable of reading from an Internet URL address, you can play MPEG movies from the Internet. Both file and URL reader source filters just deliver an unparsed stream of data. A parser filter pulls the data from the reader, parses it into separate streams of video, audio, text, or other data types, and pushes it downstream. This filter remains unchanged regardless of whether the source filter is a file or URL reader filter.
The source filter that reads from an Internet server is called the File Source (URL) filter. DirectShow provides this as a built-in filter. It knows how to read, but not parse, data from a URL address. Therefore, a media parser follows the File Source (URL) filter in the filter graph. For MPEG sources, this parser is built into the MPEG splitter filter. Other media types have their own parser filters (for example, a QuickTime parser).
The source filter that reads from files is the File Source (Async) filter. DirectShow also provides this as a built-in filter. It does no parsing on its own but simply reads data off a disk to play back. Most DirectShow filter graphs use this source filter.
The architecture's modularity allows most of the same components to be reused between file and Internet playback. This modularity also means that if you want to render a new type of data, often you only need to write a parser and renderer, and you can still use the existing file or URL filter.
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.