Add CryptoPluginMode to WV extractor
Allows the WV extractor to run in a mode that is compatible with
the DRM CryptoPlugin HAL API, where decryption is deferred
until the encrypted data is sent through the CryptoPlugin to
the codec.
This patch does:
(1) Adds a flag mCryptoPluginMode that controls this behavior
[Note: need framework support to enable/disable this]
(2) Accumulates information in track metadata to delineate
crypto unit boundaries for the CryptoPlugin
related-to-bug: 5986621
Change-Id: I3318d5cde38c7b02a7bdb56aca9aece852c9781c
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "media/stagefright/foundation/ADebug.h"
|
||||
#include "media/stagefright/MediaErrors.h"
|
||||
#include "media/stagefright/MediaDefs.h"
|
||||
#include "media/stagefright/MetaData.h"
|
||||
#include "media/hardware/CryptoAPI.h"
|
||||
#include "AndroidHooks.h"
|
||||
|
||||
namespace android {
|
||||
@@ -112,19 +114,11 @@ status_t WVMMediaSource::start(MetaData *)
|
||||
ALOGE("WV_Play returned status %d in WVMMediaSource::start\n", result);
|
||||
return ERROR_IO;
|
||||
}
|
||||
|
||||
#ifndef REQUIRE_SECURE_BUFFERS
|
||||
allocBufferGroup();
|
||||
#else
|
||||
if (mIsLiveStream) {
|
||||
allocBufferGroup();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
// audio
|
||||
allocBufferGroup();
|
||||
}
|
||||
|
||||
if (!mGroup)
|
||||
allocBufferGroup();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -239,7 +233,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
}
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
sDecryptContext[mESSelector].Initialize(mediaBuf);
|
||||
mDecryptContext.Initialize(mediaBuf);
|
||||
mEncryptedSizes.clear();
|
||||
#endif
|
||||
|
||||
size_t bytesRead;
|
||||
@@ -302,7 +297,7 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
if (mESSelector == WV_EsSelector_Video && !mIsLiveStream) {
|
||||
bytesRead = sDecryptContext[mESSelector].mOffset;
|
||||
bytesRead = mDecryptContext.mOffset;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -326,7 +321,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
// drop frames up to next sync if requested
|
||||
usleep(10000);
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
sDecryptContext[mESSelector].Initialize(mediaBuf);
|
||||
mDecryptContext.Initialize(mediaBuf);
|
||||
mEncryptedSizes.clear();
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
@@ -365,6 +361,14 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
|
||||
mediaBuf->set_range(0, bytesRead + offset);
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
if (!mIsLiveStream && mEncryptedSizes.size()) {
|
||||
mediaBuf->meta_data()->setData(kKeyEncryptedSizes, 0, &mEncryptedSizes[0],
|
||||
mEncryptedSizes.size() * sizeof(size_t));
|
||||
mediaBuf->meta_data()->setInt32(kKeyCryptoMode, CryptoPlugin::kMode_AES_WV);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// debug code - log packets to files
|
||||
char filename[32];
|
||||
@@ -397,41 +401,54 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
|
||||
WVMMediaSource::DecryptContext WVMMediaSource::sDecryptContext[2] = {};
|
||||
|
||||
WVStatus WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void* output, size_t length,
|
||||
int key, unsigned long long dts, unsigned long long pts, bool au_end)
|
||||
int key, unsigned long long dts, unsigned long long pts, bool au_end,
|
||||
void *obj)
|
||||
{
|
||||
//ALOGD("DecryptCallback(type=%d, in=%p, out=%p, len=%d, key=%d\n",
|
||||
// (int)esType, input, output, length, key);
|
||||
DecryptContext &context = sDecryptContext[esType];
|
||||
WVMExtractorImpl *extractor = (WVMExtractorImpl *)obj;
|
||||
sp<WVMMediaSource> source;
|
||||
if (esType == WV_EsSelector_Video)
|
||||
source = extractor->getVideoSource();
|
||||
else
|
||||
source = extractor->getAudioSource();
|
||||
DecryptContext &context = source->getDecryptContext();
|
||||
|
||||
OEMCrypto_UINT32 copied = length;
|
||||
OEMCryptoResult result;
|
||||
WVStatus status;
|
||||
WVStatus status = WV_Status_OK;
|
||||
unsigned char *iv = NULL;
|
||||
|
||||
if (key)
|
||||
iv = context.mIV;
|
||||
|
||||
if (esType == WV_EsSelector_Video) {
|
||||
result = OEMCrypto_DecryptVideo(iv, (OEMCrypto_UINT8 *)input, length,
|
||||
(OEMCrypto_UINT32)(char *)context.mMediaBuf->data(),
|
||||
context.mOffset, &copied);
|
||||
if (extractor->getCryptoPluginMode()) {
|
||||
// just determine crypto unit boundaries
|
||||
if (key) {
|
||||
source->addEncryptedSize(length);
|
||||
}
|
||||
} else {
|
||||
result = OEMCrypto_DecryptAudio(iv, (OEMCrypto_UINT8 *)input, length,
|
||||
(OEMCrypto_UINT8 *)context.mMediaBuf->data() + context.mOffset,
|
||||
&copied);
|
||||
}
|
||||
// do decrypt
|
||||
if (key)
|
||||
iv = context.mIV;
|
||||
|
||||
if (result == OEMCrypto_SUCCESS) {
|
||||
status = WV_Status_OK;
|
||||
}
|
||||
else {
|
||||
status = WV_Status_Unknown;
|
||||
ALOGD("OEMCrypto decrypt failure: %d", result);
|
||||
}
|
||||
if (esType == WV_EsSelector_Video) {
|
||||
result = OEMCrypto_DecryptVideo(iv, (OEMCrypto_UINT8 *)input, length,
|
||||
(OEMCrypto_UINT32)(char *)context.mMediaBuf->data(),
|
||||
context.mOffset, &copied);
|
||||
} else {
|
||||
result = OEMCrypto_DecryptAudio(iv, (OEMCrypto_UINT8 *)input, length,
|
||||
(OEMCrypto_UINT8 *)context.mMediaBuf->data() + context.mOffset,
|
||||
&copied);
|
||||
}
|
||||
|
||||
context.mOffset += copied;
|
||||
if (result == OEMCrypto_SUCCESS) {
|
||||
status = WV_Status_OK;
|
||||
} else {
|
||||
status = WV_Status_Unknown;
|
||||
ALOGD("OEMCrypto decrypt failure: %d", result);
|
||||
}
|
||||
|
||||
context.mOffset += copied;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user