Fourth, DirectShow program development DirectShow is based on COM component technology, so developing the DirectShow program must master COM component technology. DirectShow is closely linked to COM, and all parts and functions are constructed and implemented by COM interfaces. It is quite flexible in development, and there is no fixed mode, which usually uses different COM interfaces with different needs. However, several important interfaces do often need: IGRAPHBUILDER interface, which is the most reused COM interface, used to create Filter Graph Manager; IMEDIACONTROL interface, used to control streaming media in filter graphics (Filter Graph) Flow, such as streaming start and stop; iMediaEvent interface, the interface is used to create a flag information of events when some events occur in Filter Graph and transmit it to the application. A typical DirectShow application is often followed: 1) Creating a Filter Graph Manager instance () through the API function cocreateInstance (); 2) Get the pointer to the Filter Graph and IMEDIAEvent components by calling the queryinterface () function; 3) Filter Graph performs control and responds to events. The following will give a simple example to explain how to decode playback of multimedia streams using DirectShow technology. First, a single document application named MediaPlay define a function of a name for MediaPlay, the specific implementation code of this function is:
void PlayMovie (LPTSTR lpszMovie) {IMediaControl * pMC = NULL; IGraphBuilder * pGB = NULL; IMediaEventEx * pME = NULL; long evCode; // something to hold a returned event code hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IMediaControl, ( Void **); hr = pmc-> queryinterface (IID_IGRAPHBUILDER, (Void **) & PGB); hr = pmc-> queryinterface (IID_IMEDIAEVENTEX, (void **) & PME); hr = pgb-> renderfile (LPSzMovie, NULL); HR = PMC-> Run (); hr = pme-> WaitForcompletion (Infinite, & Evcode); if (PMC) PMC-> Release (); if (PGB) PGB-> Release (); if (PME) PME-> release ();