Windows Mobile多媒体开发总结之Media Player Plugins

随着3G网络的普及,像多媒体和流媒体这样的技术需求会越来越大,比如视频通话。但是国内在这方面的高级人才不多,给我们这些做技术的指明了一个方向。:)

在Windows Mobile下媒体播放器开发有两种选择,一种是扩展Windows Media Player(下文简称WMP),一种是完全自己开发播放器(使用DirectShow,或者使用开源库,比如解码MP3的libmad库)。开发播放器是个大骨头,要好好去啃啃,可惜现在没这样的项目需求。

这次要总结的仅仅是Windows Mobile 6.0/6.1(下文简称WM6.0/6.1)下的WMP扩展,WM6.0/6.1使用的是WMP10版本,见下图。
CEZoom1 CEZoom4
微软还未上市的WM6.5使用的WMP也是10版本,见下图。从图中可以看到菜单风格改了,其它基本没有变化。不知道在WMP扩展开发方面有没有变化。
CEZoom2 CEZoom3

言归正传,从网上下载WMP 10 SDK(只有桌面系统的SDK,没有Mobile版本的,而且文档只有英文的):
http://msdn.microsoft.com/en-us/windowsmedia/bb190309.aspx

先总结下WMP在桌面操作系统的扩展开发。Windows Media Player Mobile是其一个子集。

Windows Media Player Skins

微软在Mobile上是完全支持皮肤的。如果你要想在Mobile上设计一个漂亮个性的Windows Media Player,需要注意设计好各部分(如按钮可用和不可用时)的图片以及skin definition file编写。下图展示的即时HTC一款Windows Mobile机子上的Windows Media Player。关于更多内容请见SDK,SDK上有专门的篇幅讲解的,标题为:Windows Media Player for Windows Mobile Skins。
HTC-Diamond-Windows-Media-Player-Skin-0

Windows Media Player Plug-ins

在Mobile上仅仅支持User Interface Plug-ins(以下红色标识的)。

★DSP Plug-ins

-> Provides an architecture that enables the user to install and activate plug-in programs that add digital signal processing (DSP) functionality. DSP plug-ins are Microsoft DirectX Media Objects (DMOs) that connect to the Player by using COM interfaces. A typical DSP plug-in might be an audio equalizer or a video tint control.(用于数据信号处理,比如均衡器,如下图)
dsp-dfx

怎样让WMP知道你的存在?方法是调用IWMPMediaPluginRegistrar::WMPRegisterPlayerPlugin方法向WMP注册。

怎样与WMP进行数据通信?WMP通过提供一个分配好的input buffer向插件提供音频和视频数据,插件向output buffer(也是有WMP分配好的)中返回数据。
WMP通过调用被插件具体实现了的方法来管理自己与插件之间的数据传递,流程如下:

1.Windows Media Player calls IMediaObject::ProcessInput, passing a pointer to an IMediaBuffer object to the DSP plug-in.

2.The DSP plug-in keeps a reference count on the input buffer object. The DSP plug-in returns an appropriate success or failure HRESULT.

3.Windows Media Player calls IMediaObject::ProcessOutput, passing a pointer to an array of DMO_OUTPUT_DATA_BUFFER structures (which contain output buffers) to the DSP plug-in.

4.The DSP plug-in processes the data in the input buffer and then copies the data to the appropriate output buffer. The DSP plug-in releases the reference count on the input buffer object when all the data in the buffer has been processed. The DSP plug-in then returns an appropriate success or failure HRESULT.

5.Windows Media Player renders the content in the output buffer.
This process repeats continuously while the plug-in is enabled and Windows Media Player has content to render.

DoProcessOutput(在这个函数中对感兴趣的音频数据进行处理) is called each time Windows Media Player successfully calls IMediaObject::ProcessOutput. It is the function that performs the digital signal processing tasks that produce the audible result that the DSP plug-in is intended to produce.
比如当前插件没有被激活时,应该像这样实现DoProcessOutPut方法:
// Test whether the plug-in is disabled by the user.
if (!m_bEnabled)
{
    // Just copy the data without changing it.
    memcpy(pbOutputData, m_pbInputData, *cbBytesProcessed);

    return S_OK;
}

相关接口和描述
IMediaObject    Manages data exchange with Windows Media Player and performs digital signal processing tasks. Detailed documentation is included with the DirectX SDK.
IWMPMediaPluginRegistrar    Manages plug-in registration.
IWMPPlugin    Manages the connection to Windows Media Player.
IWMPPluginEnable    Stores whether the plug-in is currently enabled by Windows Media Player.
IWMPServices    Retrieves information from the Player about the current stream time and stream state.

相关枚举类型及描述
WMPPlugin_Caps    Used with IWMPPlugin::GetCaps to indicate whether the plug-in can convert between formats.
WMPServices_StreamState    Indicates the whether the stream is currently stopped, paused, or playing.
----------------------------------------------------------------------------------------------

★Custom Visualizations

-> Windows Media Player provides your code with snapshots of audio frequency and waveform data at timed intervals measured in fractions of a second. The graphical output from your visualization is a Microsoft Windows device context. This is a standard Windows drawing surface that you can draw upon every time an audio snapshot is provided. (用于根据音频信息输出相应的视觉效果,如下图)
060227_eq1

相关接口及描述
IWMPEffects    Interface An interface to custom visualizations.
IWMPEffects2    Interface An interface that extends IWMPEffects, allowing greater control over visualization behavior.

相关结构体和枚举类型
PlayerState    Provides some basic states of Windows Media Player.
TimedLevel    Holds data returned from the spectrum filter.
----------------------------------------------------------------------------------------------

User Interface Plug-ins

-> Provides a variety of control panels that allow the user to modify various aspects of the player such as the video and graphic equalizer settings. Skins are one way to provide additional functionality, but they require the developer to recreate the entire user interface (UI). As an alternative, Windows Media Player allows the creation of custom UI plug-ins that display in the full mode of the player. This functionality is provided through a programming interface that follows standard Microsoft Component Object Model (COM) guidelines. (它可以实现部分UI定制,弥补了皮肤必须全部定制UI的不足。插件必须以COM服务器的形式开发出来,所以你不光要实现IWMPPluginUI接口,还要实现作为COM服务器所需要的接口,如DllGetClassObject, DllCanUnloadNow, DllRegisterServer等,使用ATL会更方便。)

  • Display Area Plug-ins
  • Settings Area Plug-ins
  • Metadata Area Plug-ins
  • Separate Window Plug-ins
  • Background Plug-ins(Windows Mobile下仅仅支持这种,还不清楚6.5以上版本是否会支持更多)

    相关接口及描述
    WMPNotifyPluginAddRemove    An independent function used to notify Windows Media Player that a plug-in has been installed or uninstalled.
    IWMPPluginUI下的方法: 
        Create    Called by Windows Media Player to instantiate the plug-in user interface. 
        Destroy    Called by Windows Media Player to shut down the plug-in user interface.
        DisplayPropertyPage    Called by Windows Media Player to request that the plug-in display its property page.
        GetProperty    Called by Windows Media Player to retrieve name/value property pairs from the plug-in. 
        SetCore    Called by Windows Media Player to provide plug-in access to the core Windows Media Player APIs. (这是个关键方法,你想要通过这个方法获得一个WMP接口指针,然后你可以通过这个指针进一步获得像IWMPControls、IWMPSettings这样的接口指针,这些接口指针提供了控制WMP的方法。 )
        SetProperty    Called by Windows Media Player to set name/value property pairs for the plug-in. 
        TranslateAccelerator    Called as part of the Windows Media Player message loop to allow the plug-in to intercept and respond to keyboard events.

    注册表键位置(每次WMP启动的时候会遍历这个位置,WMP通过这个位置继续找到你的DLL文件以便加载) 
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\UIPlugins\{ClassId}
    ----------------------------------------------------------------------------------------------

    ★Rendering Plug-ins

    -> Microsoft Windows Media Player provides an architecture that enables you to develop plug-ins that decode (if necessary) and render custom data contained in a Windows Media format stream.

    相关接口及描述
    IWMPMediaPluginRegistrar    Manages plug-in registration.
    IWMPNodeRealEstate    Obtains a rendering area from Windows Media Player.
    IWMPNodeRealEstateHost    Requests state changes from Windows Media Player.
    IWMPNodeWindowed    Stores a handle to the parent window used for rendering.
    IWMPNodeWindowedHost        Sends Windows messages from the plug-in to Windows Media Player.
    IWMPNodeWindowless    Stores a device context handle used by Windows Media Player when rendering in windowless mode.
    IWMPNodeWindowlessHost    Provides methods to direct Windows Media Player to update the rendering area in windowless mode.
    IWMPPlugin    Manages the connection to Windows Media Player.
    IWMPPluginEnable    Stores whether the plug-in is currently enabled by the user.
    IWMPServices    Retrieves information from Windows Media Player about the current stream time and stream state.
    IWMPWindowMessageSink    Receives messages when in windowless mode.

    相关枚举类型及描述
    WMPPlugin_Caps    Used with IWMPPlugin::GetCaps to indicate whether the plug-in can convert between formats.
    WMPServices_StreamState    Indicates the whether the stream is currently stopped, paused, or playing.

     

  • 你可能感兴趣的:(Windows Mobile)