Multimedia programming of WinCE Based on DirectShow

Source: Internet
Author: User

Multimedia programming of WinCE Based on DirectShow
By drizzle QQ: 253786989

(1) Introduction


DirectShow is an application interface (API) developed by Microsoft to process multimedia files. It is based on the COM (Component Object Model) framework.

The link between applications and DirectShow and some software and hardware components is shown in MSDN.

, DirectShow mainly consists of Filters and Filter Graph Manager. Among them, there are many Filters. Source Filters are called Source Filters. They are mainly used to introduce Source data streams from multimedia files (from local sources or the Internet. Transform Filters is called a transmission filter to process source data streams, such as encoding/decoding (including soft decoding and hard decoding), conversion format, and decompression. Rendering Filters is a Rendering filter that forwards the processed data to related hardware for playback. For example, you can use DirectDraw to control the display graphics of the video card and use DirectSound to control the sound card for sound. In addition, DirectShow also contains many other filters, which will be detailed later.

The Source Filters, Transform Filters, and Rendering Filters are combined in a filter chart. DirectShow is done by concatenating the Filters that complete their respective division of labor. Filter Graph Manager is called a Filter Graph management object. It coordinates different Filters, establishes a reference clock for Filters, and uses a queue mechanism to pass DirectShow events to applications.

In the figure, each filter contains private objects called Pin, which are derived from IPin. There are two types of Pin: Input Pin and output Pin. For example, the multimedia data stream enters Source Filters from the input Pin, and then connects the output Pin of Source Filters to the input Pin of Transform Filters. After the multimedia data stream is processed by Source Filters, it enters the Transform Filters through the Pin connection.

(2) DirectShow interface

There are dozens of DirectShow interfaces on the WM/WinCE platform. The following are common interfaces and methods used in these interfaces.

A) IGraphBuilder: This interface is used to create a filter graph.

The commonly used method is RenderFile, which is used to render objects of the specified type.

B) IMediaControl: Controls multimedia data streams in the Filter Graph.

Common methods are as follows: Run to start playing, Pause to Pause playing, and Stop to Stop playing.

C) IMediaEvent, IMediaEventEx: Process events generated by the Filter Graph. Applications use this interface to obtain events that occur during playback, such as EC_COMPLETE. For example, setpolicywindow specifies the window for processing the event, GetEvent gets the event, and FreeEventParams releases the resources associated with the event parameters.

D) IVideoWindow: Used to set the properties of a multimedia playback window. For example, put_Owner specifies the parent window of the video playback window, put_FullScreenMode specifies the full-screen playback mode, SetWindowPosition specifies the position of the video window, put_Visible shows or hides the video window, And get_Visible indicates whether the current video window is visible, put_WindowStyle sets the video window style attribute. put_MessageDrain specifies a window to receive mouse and keyboard messages from the video window.

E) IMediaSeeking: Controls the playback position and other attributes of multimedia data streams. The main methods include SetPositions, SetPositions, SetRate, and GetCurrentPositions, getDuration obtains the total time length of a multimedia file in nanoseconds.

F) IBasicAudio: Controls the audio volume and balance. The main methods are put_Volume, get_Volume, put_Balance, and get_Balance.

G) IBasicVideo: Controls video attributes. The main method is get_BitRate to get the bit rate of the video stream and GetVideoSize to get the video size.

(3) WinCE Components

The same program and code. It can be used normally on some platforms, playing audio and video files, collecting camera images, and so on. But some platforms cannot. The reason is that when the WinCE system is customized, the Media components added by each manufacturer are different, so the multimedia capabilities of the WinCE platform of different manufacturers are different.

The Media Components in WinCE7 are as follows:

A) audio codecs and Renderer

For example, to play music in MP3 format, you must check MP3 Codec.

B) Video codecs and Renderer

C) DirectShow

This includes the Core Components and filters of DirectShow. DirectShow uses filters to complete core functions. If the DirectShow component is not added, use the SDK exported by the system. It is likely that our DirectShow application compilation will fail. Even if the compilation is successful, it cannot work normally.

In addition, there are Media Formats, Media Library, Media Renderer, Windows Media Player and other related components. For more information, see the Wince7 help documentation. The following is a brief introduction to the relevant components to be added using DirectShow:

(4) enumerate the filters registered in the system

Use the DirectShow IEnumRegFilters interface to enumerate the filters registered in the system. The following code is implemented:

HRESULT hr = 0; IFilterMapper * pMapper = NULL; IEnumRegFilters * pEnum = NULL; REGFILTER * pRegFilter = NULL; ULONG cFetched = 0; // initialize the COM environment CoInitialize (NULL ); // obtain the IFilterMapper interface hr = CoCreateInstance (CLSID_FilterMapper, NULL, CLSCTX_INPROC, IID_IFilterMapper, (void **) & pMapper); if (FAILED (hr )) {MessageBox (TEXT ("failed to get the IFilterMapper interface! "); Return;} // obtain the IEnumRegFilters interface hr = pMapper-> EnumMatchingFilters (& pEnum, 0, FALSE, GUID_NULL, GUID_NULL, FALSE, FALSE, GUID_NULL, GUID_NULL ); if (FAILED (hr) {MessageBox (TEXT ("FAILED to get the IEnumRegFilters interface! "); Return ;}// enumerate the filtersCString strFilters, strTemp; while (pEnum-> Next (1, & pRegFilter, & cFetched) = S_ OK) registered in the system) {for (int I = 0; I <cFetched; ++ I) {strTemp. format (TEXT ("% s \ r \ n"), (pRegFilter + I)-> Name);} strFilters + = strTemp; // release the memory CoTaskMemFree (pRegFilter );} setDlgItemText (IDC_FILTERS, strFilters); // Release the interface pEnum-> Release (); pMapper-> Release (); // Release the COM environment CoUninitialize ();

Running result

(5) initialize the DirectShow interface

The following code demonstrates how to obtain the commonly used DirectShow interfaces mentioned in (2). If these interfaces are obtained successfully, the next task is to use the methods provided by these interfaces to play and control video files. When writing a DirectShow application, you must # include <dshow. h> and reference strmiids. lib. If the system prompts that dshow. h cannot be found, it is likely that the sdk used is not supported, that is, the wince platform corresponding to the sdk does not add relevant components of DirectShow.

// Step 2: Create the IGraphBuilder interface hResult = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **) & m_pGB); if (hResult! = S_ OK) {return FALSE;} // Step 2: Use the IGraphBuilder interface to render the video file hResult = m_pGB-> RenderFile (strFileName, NULL); if (hResult! = S_ OK) {return FALSE;} // Step 2: Obtain the media playback control interface IMediaControlhResult = m_pGB-> QueryInterface (IID_IMediaControl, (void **) & m_pMC); if (hResult! = S_ OK) {return FALSE;} // Step 2: Obtain the media playback position search interface IMediaSeekinghResult = m_pGB-> QueryInterface (IID_IMediaSeeking, (void **) & m_pMS ); if (hResult! = S_ OK) {return FALSE;} // you can specify the time unit guid_timeFormat = TIME_FORMAT_MEDIA_TIME; m_pMS-> SetTimeFormat (& guid_timeFormat); // Step 3: obtain the media event interface IMediaEventExhResult = m_pGB-> QueryInterface (IID_IMediaEventEx, (void **) & m_pME); if (hResult! = S_ OK) {return FALSE;} // Step 4: Obtain the IVideoWindow interface hResult = m_pGB-> QueryInterface (IID_IVideoWindow, (void **) & m_pVW); if (hResult! = S_ OK) {return FALSE;} // Step 4: obtain the basic Video Stream interface IBasicVideohResult = m_pGB-> QueryInterface (IID_IBasicVideo, (void **) & m_pBV); if (hResult! = S_ OK) {return FALSE;} // Step 4: obtain the basic audio stream interface IBasicAudiohResult = m_pGB-> QueryInterface (IID_IBasicAudio, (void **) & m_pBA); if (hResult! = S_ OK) {return FALSE ;}

(6) Summary

Through the above learning, you can write multimedia applications after familiarizing yourself with the commonly used DirectShow interfaces and interfaces. You can first find some encapsulated DirectShow c ++ wrapper on the codeproject, pudn, and other websites, and take a closer look at how the mature libraries are encapsulated, how to initialize and use those DirectShow interfaces, and then modify them to meet your needs or enhance their functions. This makes it faster to get started.

Multimedia programming of WinCE Based on DirectShow
By drizzle QQ: 253786989

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.