简体   繁体   English

使用MediaCodec将加密的数据解密并解码到SurfaceTexture

[英]Decrypt & Decode encrypted data to a SurfaceTexture using MediaCodec

Is it possible to decrypt and decode data using MediaCodec API? 是否可以使用MediaCodec API解密和解码数据? I want to decrypt and decode the data which is encrypted by widevine or other DRM mechanism. 我想对通过Widevine或其他DRM机制加密的数据进行解密和解码。 The basic thing I want to try is I configured the MediaCodec with Surface which is created from SurfaceTexure. 我想尝试的基本方法是使用从SurfaceTexure创建的Surface配置MediaCodec。 MediaCodec->configure(..????., with mediacrypto instance, ...) I'm not sure if I can pass SurfaceTexture in this case? MediaCodec->configure(..????., with mediacrypto instance, ...)在这种情况MediaCodec->configure(..????., with mediacrypto instance, ...)我不确定是否可以传递SurfaceTexture? Or any secure configure I should do? 还是我应该做的任何安全配置?

MediaCodec->start()
MediaCodec->queuesecureinputbuffer(...,with cryptoinfo,...)
MediaCodec->dequeoutputbuffer() to get the decoded data back....

The sample I could find is to directly render decrypted data onto a SurfaceView. 我可以找到的示例是将解密的数据直接呈现到SurfaceView上。

But I just want to get the decoded buffer or a SurfaceTexture which is rendered by the MediaCodec. 但我只想获取解码的缓冲区或由MediaCodec呈现的SurfaceTexture。

If I didn't set any secure configure such as MediaFormat->SetFeatureEnabled("secure-playback", true) ; 如果我没有设置任何安全配置,例如MediaFormat->SetFeatureEnabled("secure-playback", true) ; use OMX.qcom.video.decoder.avc to create the decoder. 使用OMX.qcom.video.decoder.avc创建解码器。 I will get such error, 我会得到这样的错误,

E/OMX-VDEC-1080P(23290): 
E/OMX-VDEC-1080P(23290): ERROR: Sending OMX_EventError to Client
E/        (23290): not in avi mode
E/ACodec  ( 1930): [OMX.qcom.video.decoder.avc] ERROR(0x80001009)
E/ACodec  ( 1930): signalError(omxError 0x80001009, internalError -2147483648)
E/MediaCodec( 1930): Codec reported err 0x80001009, actionCode 0, while in state 6
W/System.err( 1930): java.lang.IllegalStateException
W/System.err( 1930):  at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
W/System.err( 1930):  at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:1033)

Once I set the secure config and use MediaCodec::CreateByCodecName(with ".secure" appended) I will get this kind of error... 一旦我设置了安全配置并使用MediaCodec :: CreateByCodecName(附加了“ .secure”),我将得到这种错误...

E/ACodec: native window could not be authenticated
E/ACodec: Failed to allocate buffers after transitioning to IDLE state (error 0xffffffff)
E/ACodec: signalError(omxError 0x80001001, internalError -1)

It depends to some extent on the device's hardware, but generally speaking, DRM-protected video can only be sent to a SurfaceView. 它在某种程度上取决于设备的硬件,但通常来说,受DRM保护的视频只能发送到SurfaceView。 Further, the SurfaceView's Surface must be on a hardware overlay. 此外,SurfaceView的Surface必须位于硬件覆盖上。

DRM-protected video is decrypted by the video decoder hardware, and the decoded frames are written to memory that is inaccessible to software. 受DRM保护的视频由视频解码器硬件解密,并将解码后的帧写入软件无法访问的内存中。 Not even the Linux kernel can read from it. 甚至Linux内核都无法读取它。 The frames are passed by handle to Hardware Composer, which tells the display hardware to show them on an overlay plane. 这些帧通过句柄传递给Hardware Composer,后者告诉显示硬件在覆盖平面上显示它们。

Because the memory is only accessible to the video decoder and the display, it can't be accessed by the GPU, which means the data can't be used as a GLES external texture. 由于内存只能由视频解码器和显示器访问,因此GPU无法访问该内存,这意味着数据不能用作GLES外部纹理。 The frame cannot be composited with GLES, so if HWC isn't able to allocate an overlay the video will not appear. 该帧无法与GLES合成,因此,如果HWC无法分配叠加层,则视频将不会出现。 (For more about HWC and composition, see the graphics arch doc .) (有关HWC和组成的更多信息,请参阅图形拱文档 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM