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

来源:互联网 发布:互联网创业 知乎 编辑:程序博客网 时间:2024/04/28 08:07
随着3G网络的普及,像多媒体和流媒体这样的技术需求会越来越大,比如视频通话。但是国内在这方面的高级人才不多,给我们这些做技术的指明了一个方向。:)    在WindowsMobile下媒体播放器开发有两种选择,一种是扩展WindowsMediaPlayer(下文简称WMP),一种是完全自己开发播放器(使用DirectShow,或者使用开源库,比如解码MP3的libmad库)。开发播放器是个大骨头,要好好去啃啃,可惜现在没这样的项目需求。    这次要总结的仅仅是WindowsMobile6.0/6.1(下文简称WM6.0/6.1)下的WMP扩展,WM6.0/6.1使用的是WMP10版本,见下图。微软还未上市的WM6.5使用的WMP也是10版本,见下图。从图中可以看到菜单风格改了,其它基本没有变化。不知道在WMP扩展开发方面有没有变化。    言归正传,从网上下载WMP10SDK(只有桌面系统的SDK,没有Mobile版本的,而且文档只有英文的):    先总结下WMP在桌面操作系统的扩展开发。WindowsMediaPlayerMoible是其一个子集。  WindowsMediaPlayerSkins  微软在Moible上是完全支持皮肤的。如果你要想在Mobile上设计一个漂亮个性的WindowsMediaPlayer,需要注意设计好各部分 (如按钮可用和不可用时)的图片以及skindefinitionfile编写。下图展示的即时HTC一款WindowsMobile机子上的 WindowsMediaPlayer。关于更多内容请见SDK,SDK上有专门的篇幅讲解的,标题为:WindowsMediaPlayerforWindowsMobileSkins。  WindowsMediaPlayerPlug-ins  在Mobile上仅仅支持UserInterfacePlug-ins(以下红色标识的)。    ★DSPPlug-ins    -Providesanarchitecturethatenablestheusertoinstallandactivateplug- inprogramsthatadddigitalsignalprocessing(DSP)functionality.DSPplug- insareMicrosoftDirectXMediaObjects(DMOs)thatconnecttothePlayerbyusingCOMinterfaces.AtypicalDSPplug- inmightbeanaudioequalizeroravideotintcontrol.(用于数据信号处理,比如均衡器,如下图)    怎样让WMP知道你的存在?方法是调用IWMPMediaPluginRegistrar::WMPRegisterPlayerPlugin方法向WMP注册。    怎样与WMP进行数据通信?WMP通过提供一个分配好的inputbuffer向插件提供音频和视频数据,插件向outputbuffer(也是有WMP分配好的)中返回数据。WMP通过调用被插件具体实现了的方法来管理自己与插件之间的数据传递,流程如下:    1.WindowsMediaPlayercallsIMediaObject::ProcessInput,passingapointertoanIMediaBufferobjecttotheDSPplug-in.    2.TheDSPplug-inkeepsareferencecountontheinputbufferobject.TheDSPplug-inreturnsanappropriatesuccessorfailureHRESULT.     3.WindowsMediaPlayercallsIMediaObject::ProcessOutput,passingapointertoanarrayofDMO_OUTPUT_DATA_BUFFERstructures(whichcontainoutputbuffers)totheDSPplug-in.     4.TheDSPplug-inprocessesthedataintheinputbufferandthencopiesthedatatotheappropriateoutputbuffer.TheDSPplug-inreleasesthereferencecountontheinputbufferobjectwhenallthedatainthebufferhasbeenprocessed.TheDSPplug-inthenreturnsanappropriatesuccessorfailureHRESULT.    5.WindowsMediaPlayerrendersthecontentintheoutputbuffer.Thisprocessrepeatscontinuouslywhiletheplug-inisenabledandWindowsMediaPlayerhascontenttorender.    DoProcessOutput(在这个函数中对感兴趣的音频数据进行处理)iscalledeachtimeWindowsMediaPlayersuccessfullycallsIMediaObject::ProcessOutput.ItisthefunctionthatperformsthedigitalsignalprocessingtasksthatproducetheaudibleresultthattheDSPplug-inisintendedtoproduce.比如当前插件没有被激活时,应该像这样实现DoProcessOutPut方法://Testwhethertheplug-inisdisabledbytheuser.if(!m_bEnabled){//Justcopythedatawithoutchangingit.memcpy(pbOutputData,m_pbInputData,*cbBytesProcessed);    returnS_OK;}    相关接口和描述IMediaObjectManagesdataexchangewithWindowsMediaPlayerandperformsdigitalsignalprocessingtasks.DetaileddocumentationisincludedwiththeDirectXSDK.IWMPMediaPluginRegistrarManagesplug-inregistration.IWMPPluginManagestheconnectiontoWindowsMediaPlayer.IWMPPluginEnableStoreswhethertheplug-iniscurrentlyenabledbyWindowsMediaPlayer.IWMPServicesRetrievesinformationfromthePlayeraboutthecurrentstreamtimeandstreamstate.    相关枚举类型及描述WMPPlugin_CapsUsedwithIWMPPlugin::GetCapstoindicatewhethertheplug-incanconvertbetweenformats.WMPServices_StreamStateIndicatesthewhetherthestreamiscurrentlystopped,paused,orplaying.----------------------------------------------------------------------------------------------    ★CustomVisualizations     -WindowsMediaPlayerprovidesyourcodewithsnapshotsofaudiofrequencyandwaveformdataattimedintervalsmeasuredinfractionsofasecond.ThegraphicaloutputfromyourvisualizationisaMicrosoftWindowsdevicecontext.ThisisastandardWindowsdrawingsurfacethatyoucandrawuponeverytimeanaudiosnapshotisprovided. (用于根据音频信息输出相应的视觉效果,如下图)    相关接口及描述IWMPEffectsInterfaceAninterfacetocustomvisualizations.IWMPEffects2InterfaceAninterfacethatextendsIWMPEffects,allowinggreatercontrolovervisualizationbehavior.    相关结构体和枚举类型PlayerStateProvidessomebasicstatesofWindowsMediaPlayer.TimedLevelHoldsdatareturnedfromthespectrumfilter.----------------------------------------------------------------------------------------------    ★UserInterfacePlug-ins     -Providesavarietyofcontrolpanelsthatallowtheusertomodifyvariousaspectsoftheplayersuchasthevideoandgraphicequalizersettings.Skinsareonewaytoprovideadditionalfunctionality,buttheyrequirethedevelopertorecreatetheentireuserinterface(UI).Asanalternative,WindowsMediaPlayerallowsthecreationofcustomUIplug- insthatdisplayinthefullmodeoftheplayer.ThisfunctionalityisprovidedthroughaprogramminginterfacethatfollowsstandardMicrosoftComponentObjectModel(COM)guidelines. (它可以实现部分UI定制,弥补了皮肤必须全部定制UI的不足。插件必须以COM服务器的形式开发出来,所以你不光要实现IWMPPluginUI接口,还要实现作为COM服务器所需要的接口,如DllGetClassObject,DllCanUnloadNow,DllRegisterServer 等,使用ATL会更方便。)
原创粉丝点击