Android:如何将解码器集成到多媒体框架 [英] Android: How to integrate a decoder to multimedia framework
问题描述
最近我成功地将视频解码器移植到了 android.还将输出转储到表面视图并使用本机 API 检查输出.现在下一个任务是实现播放、暂停、流媒体等,即媒体播放器的其他功能.这样做将是一个返工,因为所有这些功能都已经在 android 多媒体框架中定义了.听说我们可以把我们的解码器做成一个插件,集成到Android的多媒体框架中.尽管我在谷歌上搜索过相同的内容,但我几乎找不到任何有关相同的信息.所以我恳请任何读者为上述问题提出一些相关的链接或解决方案.提前致谢,等待您的回复.
Recently i have ported a video decoder to android successfully. Also dumped the output on a surfaceview and checked the output using native API's. Now the next task is to implement play, pause, streaming etc. i.e. the other features of the media player. Doing this will be a rework as all these functionalities are already defined in the android multimedia framework. I heard that we can make our decoder as a plug-in and integrate it into Android's multimedia framework. Although i googled regarding the same, i could hardly find any info regarding the same. So i kindly request any of the readers to suggest some relavent links or solution for the above problem. Thanks in advance, waiting for your reply.
推荐答案
在Android SF框架中,编解码器是通过media_codecs.xml
注册的.在标准的 android 发行版中,可以在 这里.所有视听组件都注册为 OMX
组件.
In Android SF framework, the codecs are registered through media_codecs.xml
. In standard android distribution, an example media_codecs.xml
can be found here. All audio-visual components are registered as OMX
components.
1.编解码器注册
要注册您的视频解码器,您必须在 <Decoders>
列表下添加一个新条目.为确保始终拾取您的编解码器,请确保将您的编解码器列为特定 MIME
类型的第一个条目.H.264 解码器的示例条目如下所示.
To register your video decoder, you would have to add a new entry under <Decoders>
list. To ensure that your codec is always picked up, please ensure that your codec is listed as the first entry for the specific MIME
type. An example entry for a H.264 decoder could be as below.
<Decoders>
<MediaCodec name="OMX.ABC.XYZ.H264.DECODER" type="video/avc" >
<Quirk name="requires-allocate-on-input-ports" />
<Quirk name="requires-allocate-on-output-ports" />
</MediaCodec>
<MediaCodec name="OMX.google.h264.decoder" type="video/avc" />
在哪里,
a.OMX.ABC.XYZ.H264.Decoder
是您的组件的名称
a.OMX.ABC.XYZ.H264.Decoder
is the name of your component
b.video/avc
是组件的 MIME
类型.在本例中,它表示 AVC/H.264 视频解码器.
b. video/avc
is the MIME
type of your component. In this example, it denotes a AVC / H.264 video decoder.
c.接下来的 2 个语句表示组件的 quirks
或 特殊要求.在给定的示例中,requires-allocate-on-input-ports
向 Stagefright
框架表明组件更愿意在其所有输入端口上分配缓冲区.类似地,另一个 quirk
通知该组件也将更喜欢分配它的输出端口.系统支持的quirks
列表,可以参考OMXCodec.cpp 文件.这些怪癖转化为标志,然后由框架读取以创建和初始化组件.
c.The next 2 statements denote the quirks
or special requirements of your components. In the given example, requires-allocate-on-input-ports
indicates to the Stagefright
framework that the component prefers to allocate the buffers on all it's input ports. Similarly, the other quirk
is informing that the component will also prefer to allocate on it's output ports. For a list of supported quirks
in the system, you could refer to the function OMXCodec::getComponentQuirks
in OMXCodec.cpp file. These quirks translate into flags which are then read by the framework to create and initialize the components.
在示例插图中,您的 OMX
组件在 default Google 实现的视频解码器之前注册.
In the example illustration, it is shown that your OMX
component is registered prior to the default Google implemented video decoder.
注意:如果您在终端设备上尝试此操作,则必须确保此条目反映在最终的
NOTE: If you trying this on an end device, you will have to ensure that this entry is reflected in the final media_codecs.xml
file.
<强>2.OMX 核心注册
要创建您的组件并确保调用正确的工厂方法,您可能需要将您的 OMX
核心注册到 Stagefright
框架.
To create your component and ensure that the correct factory method is invoked, you may have to register your OMX
Core with the Stagefright
framework.
要注册一个新内核,您必须创建一个名为 libstagefrighthw.so
的新库,该库位于您的终端系统的 /system/lib
中.该库必须公开一个 createOMXPlugin
符号,dlsym
将查看该符号.
To register a new core, you will have to create a new library named libstagefrighthw.so
which will be located at /system/lib
in your end system. This library will have to expose a createOMXPlugin
symbol which will be looked by dlsym
.
OMX
核心的注册如下: OMXMaster
调用 addVendorPlugin
内部调用 addPlugin("libstagefrighthw.so")代码>.在
addPlugin
中,将查找 createOMXPlugin
,使用它初始化 makeComponentInstance
、destroyComponentInstance
等的其他函数指针.
The registration of the OMX
core is thus: OMXMaster
invokes addVendorPlugin
which internally invokes addPlugin("libstagefrighthw.so")
. In addPlugin
, the createOMXPlugin
will be looked up using which the other function pointers for makeComponentInstance
, destroyComponentInstance
etc are initialized.
OMX
核心初始化后,您就可以在 android 框架中运行您自己的组件了.OMXMaster
的参考可以在 这里.
Once the OMX
core is initialized, you are ready to run your own your component within the android framework. The reference for OMXMaster
can be found here.
通过这些更改,您的视频解码器将集成到 android stagefright 框架中.
With these changes, your video decoder is integrated into the android stagefright framework.
这篇关于Android:如何将解码器集成到多媒体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!