It may be until now, there is no game that played a game has not been exposed to Microsoft DirectX. Because most of the games today are developed with DirectX.
In contrast, DirectShow is just a subset of DirectX. DirectX also includes a collection of DirectSound, Direct3D. DirectShow is mainly used to handle some multimedia tasks related to audio and video, such as audio and video acquisition, playback, etc. After the New Year, the video signal is required in Win32 in a project. I have done GDI before, but the efficiency is low, and the effect is very bad, so I decided to accelerate, how to accelerate, the answer is in DirectShow.
1, DirectShow structure
We know that the Windows operating system only uses two privileges (0 and 3) in the CPU. 0 is a kernel mode that can directly access hardware; 3 is user mode, it cannot directly access hardware. The basic working unit of DirectShow is Filter (filter), a filter is like a screen, which typically has an input pin (PIN) and output pins, and data flows from the output port from the output port from the input pin. The filter in DirectShow is generally divided into the following 3 classes:
1) Source Filter (for providing original multimedia data, such as a video file)
2) Transform filter (used to process multimedia data from Source Filter, such as MPEG-4 decoder)
3) Rendering Filter (for display, playback, and storage multimedia data to users, such as file writer)
To complete a specific multimedia function, you must form a specific Filter Graph with the corresponding FILTER. Multimedia data flows in Graph and put it back to the user when reaching rendering filter.
How do user applications control Filter Graph? He must create a corresponding Filter Graph Manager, the application sends the corresponding command to Manager, and then receives the corresponding Event from Manager, and finally make a corresponding response.
Each Filter has the ability to operate hardware, which is why DirectShow can use multimedia so efficiently.
DirectShow's structural schematic is as follows:
2. Write a simple application using DirectShow
The general steps to write applications using DirectShow are as follows:
1) Construction of the corresponding Filter Graph according to the function completed by the system.
2) Build each Filter in the Graph and connect them.
3) Creating a Filter Graph Manager, using Application Controls Manager to control the entire process.
4) DirectShow is based on COM (component object model), so the COM library must be initialized before writing Filter.
Below is a completely playing AVI file applet, with an annotated steps for programming.
#include
int main () {IGraphBuilder * pGraph = NULL; // Filter Graph interface for creating IMediaControl * pControl = NULL; // for transmitting Command IMediaEvent * pEvent = NULL to Filter Graph Manager; // Filter Graph Manager for receiving Event // Initialize the COM Library. HRESULT HR = Coinitialize (NULL); // Initialization COM Library
IF (FAILED (HR)) {FPRINTF (stderr, "could not init the com library!"); return 0;}
// Create a Filter Graph Manager
HR = COCREATEINSTANCE (CLSID_FILTERGRAPH, NULL, CLSCTX_INPROC_SERVER, IID_IGRAPHBUILDER, (Void **) & PGRAPH);
IF (FAILED (HR)) {FPRINTF (stderr, "could not create filter graph manager!"); return 0;}
// Query and get the interface pointer hr = pgraph-> queryinterface (IID_IMEDIACONTROL, (void **) & pControl); hr = pgraph-> queryinterface (IID_IMEDIAEVENT, (Void **) & pevent;
The // renderfile library function is a few a few can automatically create a graph-based page, so I will save this step HR = PGRAPH-> Renderfile (L "E: //football.avi", null);
IF (succeededed (hr)) {hr = pControl-> Run ();
IF (Succeeded (HR)) {// Waiting for Video End Long Evcode; PEVENT-> WaitForCompletion (Infinite, & Evcode);
// Unlimited waiting
}
PCONTROL-> Release (); pevent-> release (); pgraph-> release ();
// Release the interface
Couninitialize (); // 载 COM library
Return 0;}