问题描述
我需要(后来JB现在,ICS)开发自定义的包装的视频codeC,并将其集成到机器人。我们要使用的SIM一些自定义的解密密钥(不要问!)。最好的方法(这将允许它一起工作的其他非加密的媒体,并使用标准的媒体播放器或其他)似乎是确定自己的MIME类型,并链接到一个定制的包装codeC,可以做自定义解密,然后再传递到一个真正的codeC的数据。 (比方说,文件类型为 .MP4
现在。)
I need to develop a custom 'wrapper' video codec and integrate it into android (JB for now, ICS later). We want to use some custom decryption keys from the SIM (don't ask!). The best method (that would allow it to work alongside other non-encrypted media and to use the standard media player or other) seems to be to define our own mime-type, and link that to a custom wrapper codec that can do the custom decryption, and then pass the data on to a real codec. (Let's say the filetype is .mp4
for now.)
(另一种可能是写我们自己的媒体播放器,但我们宁愿不走这条路线,因为我们真的希望出现无缝地与其他媒体的媒体)
(An alternative might be to write our own media player, but we'd rather not go down that route because we really want the media to appear seamlessly alongside other media)
我一直在试图按照本指南:<一href="http://stackoverflow.com/questions/15334509/android-how-to-integrate-a-de$c$cr-to-multimedia-framework">how整合脱codeR成多媒体框架
I've been trying to follow this guide:how to integrate a decoder into multimedia framework
-
我无法与OMX核心登记 - 我可以建立
libstagefright.so
从Android源键入使stagefright
,但在引导他说,使用libstagefrighthw.so
这似乎适合JB,但我不知道如何构建这个,它似乎并没有得到使用使stagefright建
除非我做错了什么?
I'm having trouble with OMX Core registration - I can build the
libstagefright.so
from the android source by typingmake stagefright
but in the guide he says to use thelibstagefrighthw.so
which seems appropriate for JB, but I'm not sure how to build this, it doesn't seem to get built from usingmake stagefright
unless I'm doing something wrong?
另一个问题是,即使我得到的自定义包装codeC注册的,我不知道如何去传递数据开了一个真正的codeC。
The other problem is that even if I do get the custom wrapper codec registered, I'm not sure how to go about passing the data off to a real codec.
如果任何人有任何建议(!或者可以给一些孩子一步一步的指示),我真的很AP preciate它 - 截止日期是相当紧张的概念验证,我所知甚少codeCS或媒体框架...
If anyone has any suggestions (or can give some baby step by step instructions!), I'd really appreciate it - the deadline is quite tight for the proof of concept and I know very little about codecs or the media framework...
非常感谢。(PS我并不想进入有关DRM和模拟孔等一个泥斗..,谢谢)
Many Thanks.(p.s. I don't want to get into a mud fight about drm and analogue holes etc.., thanks)
推荐答案
在这篇文章中,我使用 H.264
作为一个例子,但该解决方案(S)可扩展,以支持其他codeCS像 MPEG-4
, VC-1
, VP8
等,有2个可能的解决方案来解决你的问题,而我争取之下,每一个都有自己的优点和缺点,以帮助您做出明智的决策。
In this post, I am using H.264
as an example, but the solution(s) can be extended to support other codecs like MPEG-4
, VC-1
, VP8
etc. There are 2 possible solutions to solve your problem, which I am enlisting below, each with their own pros and cons to help you take an informed decision.
解决方案1:延长codeC,以支持新的模式
在软糖
,人们可以注册相同的 OMX
组件与同一 MIME
类型,2种不同成分的名称即, OMX.ABC.XYZ
和 OMX.ABC.XYZ.secure
。前者是用于普通重放和是较常用的组分。后者用于在解析器即 MediaExtractor
表示安全内容的presence。在 OMX codeC:创建
,在 findMatching codeCS
返回codeCS名单,我们可以观察到的选择,选择 .secure
组件作为<一个href="http://androidxref.com/4.2.2_r1/xref/frameworks/av/media/libstagefright/OMX$c$cc.cpp#319">here.
In JellyBean
, one could register the same OMX
component with same MIME
types as 2 different component names viz., OMX.ABC.XYZ
and OMX.ABC.XYZ.secure
. The former is used for normal playback and is the more commonly used component. The latter is used when the parser i.e. MediaExtractor
indicates the presence of secure content. In OMXCodec::Create
, after findMatchingCodecs
returns a list of codecs, we can observe the choice to select .secure
component as here.
执行步骤:的
-
在你的平台上,注册另一个组件的一些新的扩展,比如
OMX.H264.DE codeR.decrypt
或类似的东西。更改只需要在media_ codecs.xml
。是否注册一个新的工厂方法或有一个共同的工厂方法是你的选择的选择。
In your platform, register another component with some new extension like
OMX.H264.DECODER.decrypt
or something similar. Change is required only inmedia_codecs.xml
. The choice of whether to register a new factory method or have a common factory method is your choice.
从解析器,你遇到的具体使用情况时,设置一个新的标志,如 kKeyDecryptionRequired
。为此,您需要定义一个新的标志<$c$c>Metadata.h和在一个相应怪癖<一href="http://androidxref.com/4.2.2_r1/xref/frameworks/av/include/media/stagefright/OMX$c$cc.h#89"><$c$c>OMX$c$cc.h.
From your parser, when you encounter the specific use-case, set a new flag like kKeyDecryptionRequired
. For this you will have to define a new flag in Metadata.h
and a corresponding quirk in OMXCodec.h
.
修改 OMX codeC ::创建
方法追加 .decrypt
后缀类似到 .secure
后缀如上图所示。
Modify the OMXCodec::create
method to append a .decrypt
suffix similar to the .secure
suffix as shown above.
随着 OMX codeC的所有更改
,元
, MediaExtractor
模块,你将有你的平台上只有重建 libstagefright.so
并更换一样。
With all changes in OMXCodec
, Metadata
, MediaExtractor
modules, you will have to rebuild only libstagefright.so
and replace the same on your platform.
瞧!您的整合应该是完整的。现在到了组件内部的主要挑战。作为组件实现的一部分,你应该能够一个普通的组件创建和 .decrypt
组件创建区分。
Voila!! your integration should be complete. Now comes the main challenge inside the component. As part of the component implementation, you should be able to differentiate between an ordinary component creation and .decrypt
component creation.
从运行的角度来看,假设你的组件是知道的事实,这是一个 .decrypt
组件或没有,你可以处理解密
为 OMX_EmptyThisBuffer
电话,在那里你可以解密数据,然后将它传递给底层codeC的一部分。
From a runtime perspective, assuming that your component is aware of the fact that it is a .decrypt
component or not, you could handle the decryption
as part of the OMX_EmptyThisBuffer
call, where you could decrypt the data and then pass it to underlying codec.
优点:易于集成,最小的Android框架的变化,可扩展到其他codeCS,没有新的 MIME
键入需要注册。
Pros: Easy to integrate, Minimal changes in Android framework, Scalable to other codecs, No new MIME
type registration required.
缺点::您需要跟踪机器人的未来版本,特别是在新的怪癖,旗帜和选择 .decrypt
扩展。如果谷歌决定采用类似的东西,你必须去适应/相应地修改您的解决方案。
Cons: You need to track the future revisions of android, specifically on the new quirks, flags and choice of .decrypt
extension. If Google decides to employ something similar, you will have to adapt / modify your solution accordingly.
解决方案2:注册新的MIME类型
这是你的问题,目前尚不清楚,如果你能定义 MIME
键入与否,因此,我捕捉步骤清晰。
From your question, it is not clear if you were able to define the MIME
type or not and hence, I am capturing the steps for clarity.
执行步骤:
-
注册一个新的
MIME
在MediaDefs
键入如here.例如,你可以使用一个新的MIME
键入为为const char * MEDIA_MIMETYPE_VIDEO_AVC_ENCRYPT =视频/ AVC-加密;
Register a new
MIME
type atMediaDefs
as shown here. For example, you could employ a newMIME
type asconst char *MEDIA_MIMETYPE_VIDEO_AVC_ENCRYPT = "video/avc-encrypt";
填写您的新组件与此更新 MIME
键入 media_ codecs.xml
。请注意,您必须确保组件怪癖也相应处理。
Register your new component with this updated MIME
type in media_codecs.xml
. Please note that you will have to ensure that the component quirks are also handled accordingly.
在 OMX codeC :: setVideoOutputFormat
方法实现,你就必须引入处理新 MIME 类型如图所示为
H.264
<一个href="http://androidxref.com/4.2.2_r1/xref/frameworks/av/media/libstagefright/OMX$c$cc.cpp#1181">here.请注意,你将不得不处理在 OMX codeC
类似的修改,以支持新的 MIME
键入
In
OMXCodec::setVideoOutputFormat
method implementation, you will have to introduce the support for handling your new MIME
type as shown for H.264
here. Please note that you will have to handle similar changes in OMXCodec
to support the new MIME
type.
在
MediaExtractor
,你将有信号的 MIME
键入使用新定义的类型的视频
的轨道。有了这些变化,你的组件将被选中,并创建。
In
MediaExtractor
, you will have to signal the MIME
type for the video
track using the newly defined type. With these changes, your component will be selected and created.
但是,的挑战依然存在:当执行解密?对于这一点,你可以和在previous节即说明处理相同的
OMX_EmptyThisBuffer
调用的一部分使用相同的解决方案。
However, the challenge still remains: Where to perform the decryption? For this, you could as well employ the same solution as described in the previous section i.e. handle the same as part of
OMX_EmptyThisBuffer
call.
优点:没有,我能想到的。
缺点:首先,解决方案是不可扩展的。你将不得不继续增加新的
MIME
的类型,并保持修改 Stagefright
框架。其次,改变 OMX codeC
将需要在 MediaExtractor
相应的变化。因此,即使你最初的重点是 MP4
提取,如果你想扩展解决方案到其他容器格式,如 AVI
, MKV
,你将不得不包括对新 MIME
在这些提取类型的支持。
Cons: First, solution is not scalable. You will have to keep adding newer
MIME
types and keep modifying the Stagefright
framework. Next, the changes in OMXCodec
will require corresponding changes in MediaExtractor
. Hence, even though your initial focus is on MP4
extractor, if you wish to extend the solution to other container formats like AVI
, MKV
, you will have to include the support for new MIME
types in these extractors.
最后,的一些注意事项。
作为preferred的解决方案,我将建议方案1,因为它是容易和简单。
As a preferred solution, I would recommend Solution 1 as it is easy and simple.
我还没有在
触及A codeC
根据实施codeC。不过,我觉得方案一将是一个更为简单的解决方案,即使是将来需要这种支持来实现。
I haven't touched upon
ACodec
based implementation of the codec. However, I do feel that Solution 1 would be a far more easier solution to implement even if such a support is required in future.
如果您不修改
OMX
核心,你应该不需要修改 libstagefrighthw.so
。仅供参考,这通常由供应商实现他们的供应商特定模块的一部分,在厂商/&LT; XYZ&GT; /硬件/...
。你需要检查你的平台供应商的片源 libstagefrighthw.so
。
If you aren't modifying the
OMX
core, you shouldn't require to modify the libstagefrighthw.so
. Just FYI, this is typically implemented by the vendors as part of their vendor specific modules as in vendor/<xyz>/hardware/...
. You need to check with your platform provider on the sources for libstagefrighthw.so
.
这篇关于自定义包装codeC集成到Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!