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
}
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<ssize_t>(dstOffset);
}
// SW AES CTS decrypt, used only for L3 devices