您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > Android 系统下Stagefright Player框架介绍
Android系统下StagefrightPlayer框架介绍Stagefright在Android多媒体架构中的位置Android中OpenMax的基本层次结构TIOpenMaxIL层实现的结构组件实现类MediaPlayer实现类MediaPlayerService实现类Clientmediaplayerserivce进程客户进程openmaxIL调用子系统TimedEventQueue::threadEntry()实现类StagefrightPlayer结构AwesomePlayernotify创建&调用创建&调用sendEventnotifyListener_l结构OMXCodec创建&调用消息实现类OMX结构OMXNodeInstance结构OMXMaster结构SECOMXPlugin调用创建&调用core子系统CallbackDispatcher::threadEntry调用CallbackDispatcher::post发消息结构OMXCodecObserver::onMessage调用调用创建创建创建调用调用子系统消息处理线程SEC_OMX_MessageHandlerThread子系统buffer处理线程SEC_OMX_BufferProcessThreadOMXClient调用调用实现类OMX结构OMXNodeInstance::onMessage调用结构OMXCodec::on_message调用结构OMXNodeInstance::kCallbacksopenmaxIL适配层端口端口调用structMediaSourceclassMediaPlayerInterfaceclassMediaPlayerBaseClassBnMediaPlayerClassBnMediaPlayerServiceClassBnMediaPlayerClientclassBnOMXstructOMXPluginBasestructOMXPluginBaseclassBnOMXObserver实现类MPEG4Source实现类MPEG4Extractor实现类FileSourcestructMediaSourceclassMediaExtractorclassDataSourcesniffgetTrack输入数据预处理SetdatasourceMediaPlayerBnMediaPlayerClientBpMediaPlayerServiceBpMediaPlayerClientMediaPlayerServiceBnMediaPlayerServiceBpMediaPlayerBnMediaPlayerclassClient进程A进程BSetdatasource-组件注册OMXClientOMXOMXMasterOMXcore(libvmc_omx_core.so)newOMXSEC_OMX_InitOMXcomponent(/system/etc/vmcomxreg.cfg)SECOMXPluginnewOMXMasternewSECOMXPluginAwesomePlayerconnectVMC_OMX_COMPONENT_Library_RegisterOpenmax适配层OpenmaxIL实现enumerateComponentsSEC_OMX_ComponentNameEnumgComponentListmPlugins;mPluginByComponentName;mPluginByInstance;preparePrepare-组件加载OMXCodecOMXOMXMasterOMXcore(libvmc_omx_core.so)allocateNodeSEC_OMX_GetHandleOMXcomponent(/system/etc/vmcomxreg.cfg)SECOMXPluginmakeComponentInstance(OMXNodeInstance::kCallbacks)OMX_COMPONENTTYPEnewOMXNodeInstancemakeComponentInstanceAwesomePlayerCreatenode_idVMC_OMX_ComponentInitOpenmax适配层OpenmaxIL实现SetCallbacksnewCallbackDispatcher组件的结构图OpenmaxIL操作流程Prepare-组件启动OMXCodecOMXOMXNodeInstancegetParameterOMXcomponent(/system/etc/vmcomxreg.cfg)getParameterOMX_GetParameterAwesomePlayerstartallocateBuffer/useBufferallocateBuffer/useBufferOMX_AllocateBuffer/OMX_UseBuffersendCommand(OMX_CommandStateSet,OMX_StateIdle)sendCommandOMX_SendCommandinitOpenmax适配层OpenmaxIL实现kCallbacks.OnEvent(OMX_EventCmdComplete,OMX_CommandStateSet)sendCommand(OMX_CommandStateSet,OMX_StateExecuting)sendCommandOMX_SendCommandkCallbacks.OnEvent(OMX_EventCmdComplete,OMX_CommandStateSet)while(mState!=EXECUTING)状态转换playBuffer操作流程(1)Buffer操作流程(2)初始化状态:在OMXCodec::read函数中,会把所有的输入输出buffer都传递给OMXComponent;之后等待有输出buffer可用。输入buffer操作:当OMXComponent使用完一个输入buffer时,通过回调函数通知上层;在上层的对应处理函数中,继续填充该buffer,并传递给OMXComponent。如此循环。输出buffer操作:当OMXComponent使用完一个输出buffer时,通过回调函数通知上层;在上层的对应处理函数中,唤醒OMXCodec::read函数。OMXCodec::read函数将获取到buffer送给render去显示,并记录该buffer信息。再次,调用OMXCodec::read函数获取一个输出buffer,送给render去显示。之后,调用OMXCodec::signalBufferReturned函数,将上一个buffer传递给OMXComponent使用。Buffer操作流程(3)Buffer操作流程(4)在OMXComponent中对buffer的处理通过两个队列和一个线程来完成。输入buffer被放到输入buffer队列中,输出buffer被放到输出buffer队列中。在线程中,从输入输出buffer队列中取出buffer,调用编解码程序处理。输入输出buffer用完后,调用用户设置的回调函数通知用户。组件中buffer处理线程流程性能优化seekOMXCodecOMXOMXNodeInstancesendCommand(OMX_CommandFlushkPortIndexInput)OMXcomponent(/system/etc/vmcomxreg.cfg)sendCommandkCallbacks.OnEvent(OMX_EventCmdComplete,OMX_CommandFlush)sendCommandAwesomePlayerreadsendCommandsendCommandsendCommand(OMX_CommandFlushkPortIndexOutput)kCallbacks.OnEvent(OMX_EventCmdComplete,OMX_CommandFlush)emptyBufferemptyBufferOMX_EmptyThisBufferfillBufferfillBufferOMX_FillThisBufferdrainInputBuffers()fillOutputBuffers()pause正常播放结束drainInputBufferif(mSignalledEOS){return;}signalEOS=true;mSignalledEOS=true;if(signalEOS)flags|=OMX_BUFFERFLAG_EOS;on_messagecaseomx_message::FILL_BUFFER_DONE:if(flags&OMX_BUFFERFLAG_EOS){mNoMoreOutputData=true;}OMXCodec::readIf(mNoMoreOutputData&&mSignalledEOS)ReturnERROR_END_OF_STREAMAwesomePlayer::postStreamDoneEvent_l(err);AwesomePlayer::onStreamDone()if(mStreamDoneStatus==ERROR_END_OF_STREAM)notifyListener_l(MEDIA_PLAYBACK_COMPLETE);pause_l(true);组件封装messageQhMessageHandlerSEC_OMX_MessageHandlerThreadUseBuffer=&SEC_OMX_UseBuffer;AllocateBuffer=&SEC_OMX_AllocateBuffer;FreeBuffer=&SEC_OMX_FreeBuffer;ComponentTunnelRequest=&SEC_OMX_ComponentTunnelRequest;GetParameter=&VMC_Mpeg4Dec_GetParameter;SetParameter=&VMC_Mpeg4Dec_SetParameter;SetConfig=&VMC_Mpeg4Dec_SetConfig;GetExtensionIndex=&VMC_Mpeg4Dec_GetExtensionIndex;ComponentRoleEnum=&VMC_Mpeg4Dec_ComponentRoleEnum;ComponentDeInit=&VMC_OMX_ComponentDeinit;GetComponentVersion=&SEC_OMX_GetComponentVersion;SendCommand=&SEC_OMX_SendCommand;GetConfig=&SEC_OMX_GetConfig;GetExtensionIndex=&SEC_OMX_GetExtensionIndex;GetState=&SEC_OMX_GetState;SetCallbacks=&SEC_OMX_SetCallbacks;UseEGLImage=&SEC_OMX_UseEGLImage;EmptyThisBuffer=&SEC_OMX_EmptyThisBuffer;FillThisBuffer=&SEC_OMX_FillThisBuffer;sec_mfc_componentInit=&VMC_Mpeg4Dec_Init;sec_mfc_componentTerminate=&VMC_Mpeg4Dec_Terminate;sec_mfc_bufferProcess=&VMC_Mpeg4Dec_bufferProcess
本文标题:Android 系统下Stagefright Player框架介绍
链接地址:https://www.777doc.com/doc-5940330 .html