From 5cbc0ba29902cf099d0d824c4b011caad69196c6 Mon Sep 17 00:00:00 2001 From: Edwin Wong Date: Tue, 10 Jul 2012 19:52:56 -0700 Subject: [PATCH] Fixed sample video corrupted in MediaCodec mode. Change-Id: I1cdfae5fda3f4002f0c17105aa25f5d25683d58f related-to-bug: 6732061 --- proprietary/cryptoPlugin/WVCryptoPlugin.cpp | 37 +++++++++++-------- proprietary/cryptoPlugin/WVCryptoPlugin.h | 2 +- .../src/com/widevine/demo/MediaCodecView.java | 13 +++++++ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/proprietary/cryptoPlugin/WVCryptoPlugin.cpp b/proprietary/cryptoPlugin/WVCryptoPlugin.cpp index f52142b3..b5098114 100644 --- a/proprietary/cryptoPlugin/WVCryptoPlugin.cpp +++ b/proprietary/cryptoPlugin/WVCryptoPlugin.cpp @@ -87,7 +87,10 @@ bool WVCryptoPlugin::requiresSecureDecoderComponent(const char *mime) const { #endif } -status_t WVCryptoPlugin::decrypt( +// Returns negative values for error code and +// positive values for the size of decrypted data, which can be larger +// than the input length. +ssize_t WVCryptoPlugin::decrypt( bool secure, const uint8_t key[16], const uint8_t iv[16], @@ -101,7 +104,8 @@ status_t WVCryptoPlugin::decrypt( CHECK(mode == kMode_Unencrypted || mode == kMode_AES_WV); - size_t offset = 0; + size_t srcOffset = 0; + size_t dstOffset = 0; for (size_t i = 0; i < numSubSamples; ++i) { const SubSample &ss = subSamples[i]; @@ -119,7 +123,7 @@ status_t WVCryptoPlugin::decrypt( #ifdef REQUIRE_SECURE_BUFFERS // decrypt using OEMCrypto API, used for L1 devices - OEMCrypto_UINT32 dstLength = srcSize; + OEMCrypto_UINT32 dstSize = srcSize; OEMCryptoResult res; @@ -135,19 +139,19 @@ status_t WVCryptoPlugin::decrypt( //ALOGD("calling DecryptVideo, size=%d", srcSize); res = OEMCrypto_DecryptVideo( iv, - (const OEMCrypto_UINT8 *)srcPtr + offset, + (const OEMCrypto_UINT8 *)srcPtr + srcOffset, srcSize, (OEMCrypto_UINT32)dstPtr, - offset, - &dstLength); + dstOffset, + &dstSize); } else { //ALOGD("calling DecryptAudio: size=%d", srcSize); res = OEMCrypto_DecryptAudio( iv, - (const OEMCrypto_UINT8 *)srcPtr + offset, + (const OEMCrypto_UINT8 *)srcPtr + srcOffset, srcSize, - (OEMCrypto_UINT8 *)dstPtr + offset, - &dstLength); + (OEMCrypto_UINT8 *)dstPtr + dstOffset, + &dstSize); } if (res != OEMCrypto_SUCCESS) { @@ -155,24 +159,25 @@ status_t WVCryptoPlugin::decrypt( return -EINVAL; } - offset += dstLength; + dstOffset += dstSize; #else if (mode == kMode_Unencrypted) { - memcpy((char *)dstPtr + offset, (char *)srcPtr + offset, srcSize); + memcpy((char *)dstPtr + dstOffset, (char *)srcPtr + srcOffset, srcSize); } else { - status_t status = decryptSW(key, (uint8_t *)dstPtr + offset, - (const uint8_t *)srcPtr + offset, srcSize); + status_t status = decryptSW(key, (uint8_t *)dstPtr + dstOffset, + (const uint8_t *)srcPtr + srcOffset, srcSize); if (status != OK) { ALOGE("decryptSW returned %d", status); return status; } } - offset += srcSize; + dstOffset += srcSize; #endif - } + srcOffset += srcSize; + } // for each subsample - return OK; + return static_cast(dstOffset); } // SW AES CTS decrypt, used only for L3 devices diff --git a/proprietary/cryptoPlugin/WVCryptoPlugin.h b/proprietary/cryptoPlugin/WVCryptoPlugin.h index 26752787..9911c0e9 100644 --- a/proprietary/cryptoPlugin/WVCryptoPlugin.h +++ b/proprietary/cryptoPlugin/WVCryptoPlugin.h @@ -34,7 +34,7 @@ struct WVCryptoPlugin : public CryptoPlugin { virtual bool requiresSecureDecoderComponent(const char *mime) const; - virtual status_t decrypt( + virtual ssize_t decrypt( bool secure, const uint8_t key[kAES128BlockSize], const uint8_t iv[kAES128BlockSize], diff --git a/proprietary/samplePlayer/src/com/widevine/demo/MediaCodecView.java b/proprietary/samplePlayer/src/com/widevine/demo/MediaCodecView.java index cc410647..8badc4b3 100644 --- a/proprietary/samplePlayer/src/com/widevine/demo/MediaCodecView.java +++ b/proprietary/samplePlayer/src/com/widevine/demo/MediaCodecView.java @@ -207,6 +207,7 @@ class CodecState { } catch (MediaCodec.CryptoException e) { Log.d(TAG, "CryptoException w/ errorCode " + e.getErrorCode() + ", '" + e.getMessage() + "'"); + return false; } return true; @@ -527,6 +528,8 @@ class MediaCodecView extends SurfaceView if (isAudio) { mAudioTrackState = state; } + // set video view size + invalidate(); } public void start() { @@ -722,4 +725,14 @@ class MediaCodecView extends SurfaceView } return false; } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int width = 720; + int height = 480; + + Log.d(TAG, "setting size: " + width + 'x' + height); + setMeasuredDimension(width, height); + } + }