Merge "Fixed sample video corrupted in MediaCodec mode." into jb-dev

This commit is contained in:
Edwin Wong
2012-07-13 15:11:04 -07:00
committed by Android (Google) Code Review
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

View File

@@ -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],

View File

@@ -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);
}
}