How MediaCodec finds the codec inside the framework in Android?

拜拜、爱过 提交于 2019-12-03 07:15:23

Let's take the flow step by step.

  1. MediaCodec::CreateByType will create a new MediaCodec object

  2. MediaCodec constructor would create a new ACodec object and store it as mCodec

  3. When MediaCodec::init is invoked, it internally instructs the underlying ACodec to allocate the OMX component through mCodec->initiateAllocateComponent.

  4. ACodec::initiateAllocateComponent would invoke onAllocateComponent

  5. ACodec::UninitializedState::onAllocateComponent would invoke OMXCodec::findMatchingCodecs to find the codecs matching the MIME type passed from the caller.

  6. In OMXCodec::findMatchingCodecs, there is a call to retrieve an instance of MediaCodecList as MediaCodecList::getInstance().

  7. In MediaCodecList::getInstance, there is a check if there is an existing MediaCodecList or else a new object of MediaCodecList is created.

  8. In the constructor of MediaCodecList, there is a call to parseXMLFile with the file name as /etc/media_codecs.xml.

  9. parseXMLFile reads the contents and stores the different component names etc into MediaCodecList which can be used for any other codec instance too. The helper function employed for the parsing is startElementHandler . A function of interest could be addMediaCodec.

Through these steps, the XML file contents are translated into a list which can be employed by any other module. MediaCodecList is exposed at Java layer too as can be referred from here.

I have skipped a few hops wherein MediaCodec and ACodec employ messages to actually communicate and invoke methods, but the flow presented should give a good idea about the underlying mechanism.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!