Fixed sample video corrupted in MediaCodec mode.

Change-Id: I1cdfae5fda3f4002f0c17105aa25f5d25683d58f
related-to-bug: 6732061
This commit is contained in:
Edwin Wong
2012-07-10 19:52:56 -07:00
parent c152d6fd0f
commit 5cbc0ba299
3 changed files with 35 additions and 17 deletions

View File

@@ -87,7 +87,10 @@ bool WVCryptoPlugin::requiresSecureDecoderComponent(const char *mime) const {
#endif #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, bool secure,
const uint8_t key[16], const uint8_t key[16],
const uint8_t iv[16], const uint8_t iv[16],
@@ -101,7 +104,8 @@ status_t WVCryptoPlugin::decrypt(
CHECK(mode == kMode_Unencrypted || mode == kMode_AES_WV); 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) { for (size_t i = 0; i < numSubSamples; ++i) {
const SubSample &ss = subSamples[i]; const SubSample &ss = subSamples[i];
@@ -119,7 +123,7 @@ status_t WVCryptoPlugin::decrypt(
#ifdef REQUIRE_SECURE_BUFFERS #ifdef REQUIRE_SECURE_BUFFERS
// decrypt using OEMCrypto API, used for L1 devices // decrypt using OEMCrypto API, used for L1 devices
OEMCrypto_UINT32 dstLength = srcSize; OEMCrypto_UINT32 dstSize = srcSize;
OEMCryptoResult res; OEMCryptoResult res;
@@ -135,19 +139,19 @@ status_t WVCryptoPlugin::decrypt(
//ALOGD("calling DecryptVideo, size=%d", srcSize); //ALOGD("calling DecryptVideo, size=%d", srcSize);
res = OEMCrypto_DecryptVideo( res = OEMCrypto_DecryptVideo(
iv, iv,
(const OEMCrypto_UINT8 *)srcPtr + offset, (const OEMCrypto_UINT8 *)srcPtr + srcOffset,
srcSize, srcSize,
(OEMCrypto_UINT32)dstPtr, (OEMCrypto_UINT32)dstPtr,
offset, dstOffset,
&dstLength); &dstSize);
} else { } else {
//ALOGD("calling DecryptAudio: size=%d", srcSize); //ALOGD("calling DecryptAudio: size=%d", srcSize);
res = OEMCrypto_DecryptAudio( res = OEMCrypto_DecryptAudio(
iv, iv,
(const OEMCrypto_UINT8 *)srcPtr + offset, (const OEMCrypto_UINT8 *)srcPtr + srcOffset,
srcSize, srcSize,
(OEMCrypto_UINT8 *)dstPtr + offset, (OEMCrypto_UINT8 *)dstPtr + dstOffset,
&dstLength); &dstSize);
} }
if (res != OEMCrypto_SUCCESS) { if (res != OEMCrypto_SUCCESS) {
@@ -155,24 +159,25 @@ status_t WVCryptoPlugin::decrypt(
return -EINVAL; return -EINVAL;
} }
offset += dstLength; dstOffset += dstSize;
#else #else
if (mode == kMode_Unencrypted) { if (mode == kMode_Unencrypted) {
memcpy((char *)dstPtr + offset, (char *)srcPtr + offset, srcSize); memcpy((char *)dstPtr + dstOffset, (char *)srcPtr + srcOffset, srcSize);
} else { } else {
status_t status = decryptSW(key, (uint8_t *)dstPtr + offset, status_t status = decryptSW(key, (uint8_t *)dstPtr + dstOffset,
(const uint8_t *)srcPtr + offset, srcSize); (const uint8_t *)srcPtr + srcOffset, srcSize);
if (status != OK) { if (status != OK) {
ALOGE("decryptSW returned %d", status); ALOGE("decryptSW returned %d", status);
return status; return status;
} }
} }
offset += srcSize; dstOffset += srcSize;
#endif #endif
} srcOffset += srcSize;
} // for each subsample
return OK; return static_cast<ssize_t>(dstOffset);
} }
// SW AES CTS decrypt, used only for L3 devices // SW AES CTS decrypt, used only for L3 devices

View File

@@ -34,7 +34,7 @@ struct WVCryptoPlugin : public CryptoPlugin {
virtual bool requiresSecureDecoderComponent(const char *mime) const; virtual bool requiresSecureDecoderComponent(const char *mime) const;
virtual status_t decrypt( virtual ssize_t decrypt(
bool secure, bool secure,
const uint8_t key[kAES128BlockSize], const uint8_t key[kAES128BlockSize],
const uint8_t iv[kAES128BlockSize], const uint8_t iv[kAES128BlockSize],

View File

@@ -207,6 +207,7 @@ class CodecState {
} catch (MediaCodec.CryptoException e) { } catch (MediaCodec.CryptoException e) {
Log.d(TAG, "CryptoException w/ errorCode " Log.d(TAG, "CryptoException w/ errorCode "
+ e.getErrorCode() + ", '" + e.getMessage() + "'"); + e.getErrorCode() + ", '" + e.getMessage() + "'");
return false;
} }
return true; return true;
@@ -527,6 +528,8 @@ class MediaCodecView extends SurfaceView
if (isAudio) { if (isAudio) {
mAudioTrackState = state; mAudioTrackState = state;
} }
// set video view size
invalidate();
} }
public void start() { public void start() {
@@ -722,4 +725,14 @@ class MediaCodecView extends SurfaceView
} }
return false; 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);
}
} }