Add support for crypto HAL on L3 devices DO NOT MERGE
Includes widevine library release version 4.5.0.7571 Change-Id: I9e574d5606576aab376d0524a4bf1a81e5a61678 related-to-bug: 6427322 related-to-bug: 6427274
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
|
||||
|
||||
using namespace android;
|
||||
|
||||
static sp<DecryptHandle> sDecryptHandle;
|
||||
@@ -33,6 +32,7 @@ static void _cb1(char *data, unsigned long size)
|
||||
if (sDrmManagerClient != NULL) {
|
||||
sDrmManagerClient->initializeDecryptUnit(sDecryptHandle, 0, &buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int _cb2(char *in, char *out, int length, char *iv)
|
||||
@@ -141,6 +141,10 @@ void WVMExtractorImpl::Initialize()
|
||||
//ALOGD("WVMExtractorImpl::Initialize setting DecryptCallback\n");
|
||||
callbacks.decrypt = WVMMediaSource::DecryptCallback;
|
||||
}
|
||||
#else
|
||||
if (!mIsLiveStream && mClientContext->getCryptoPluginMode()) {
|
||||
callbacks.decrypt = WVMMediaSource::DecryptCallback;
|
||||
}
|
||||
#endif
|
||||
result = WV_Initialize(&callbacks);
|
||||
|
||||
@@ -351,8 +355,6 @@ status_t WVMExtractorImpl::readMetaData()
|
||||
mClientContext->setVideoSource(mVideoSource);
|
||||
mVideoSource->delegateClientContext(mClientContext);
|
||||
|
||||
mFileMetaData->setCString(kKeyMIMEType, "video/wvm");
|
||||
|
||||
mHaveMetaData = true;
|
||||
|
||||
mInfoListener->configureHeartbeat();
|
||||
@@ -361,6 +363,26 @@ status_t WVMExtractorImpl::readMetaData()
|
||||
// In crypto plugin mode, need to trigger the drm plugin to begin
|
||||
// license use on playback since the media player isn't involved.
|
||||
sDrmManagerClient->setPlaybackStatus(sDecryptHandle, Playback::START, 0);
|
||||
|
||||
#ifndef REQUIRE_SECURE_BUFFERS
|
||||
if (!mIsLiveStream) {
|
||||
// Get the content key for crypto plugin mode on L3 devices
|
||||
char keyBuffer[AES_BLOCK_SIZE];
|
||||
char nullBuffer[0];
|
||||
DrmBuffer nullDrmBuffer(nullBuffer, 0);
|
||||
DrmBuffer keyDrmBuffer(keyBuffer, sizeof(keyBuffer));
|
||||
DrmBuffer *keyDrmBufferPtr = &keyDrmBuffer;
|
||||
|
||||
status_t status = sDrmManagerClient->decrypt(sDecryptHandle, 0, &nullDrmBuffer,
|
||||
&keyDrmBufferPtr, &nullDrmBuffer);
|
||||
if (status != OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
mVideoSource->SetCryptoPluginKey(keyBuffer);
|
||||
mAudioSource->SetCryptoPluginKey(keyBuffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return OK;
|
||||
@@ -467,11 +489,7 @@ sp<MetaData> WVMExtractorImpl::getTrackMetaData(size_t index, uint32_t flags)
|
||||
}
|
||||
|
||||
sp<MetaData> WVMExtractorImpl::getMetaData() {
|
||||
status_t err;
|
||||
if ((err = readMetaData()) != OK) {
|
||||
return new MetaData;
|
||||
}
|
||||
|
||||
mFileMetaData->setCString(kKeyMIMEType, "video/wvm");
|
||||
return mFileMetaData;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
|
||||
mNewSegment(false),
|
||||
mCryptoInitialized(false),
|
||||
mIsStalled(false),
|
||||
mStripADTS(false),
|
||||
mGroup(NULL),
|
||||
mKeyTime(0),
|
||||
mDts(0),
|
||||
@@ -53,6 +54,11 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
|
||||
}
|
||||
}
|
||||
}
|
||||
mStripADTS = true;
|
||||
#else
|
||||
if (cryptoPluginMode) {
|
||||
mStripADTS = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -171,19 +177,21 @@ sp<MetaData> WVMMediaSource::getFormat()
|
||||
{
|
||||
Mutex::Autolock autoLock(mLock);
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
if (!mIsLiveStream) {
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
if (mESSelector == WV_EsSelector_Video) {
|
||||
mTrackMetaData->setInt32(kKeyRequiresSecureBuffers, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Only support AAC on android for now, so assume the audio
|
||||
// track is AAC and notify the audio codec it has ADTS framing
|
||||
if (mESSelector == WV_EsSelector_Audio) {
|
||||
mTrackMetaData->setInt32(kKeyIsADTS, 1);
|
||||
if (mStripADTS) {
|
||||
// Only support AAC on android for now, so assume the audio
|
||||
// track is AAC and notify the audio codec it has ADTS framing
|
||||
if (mESSelector == WV_EsSelector_Audio) {
|
||||
mTrackMetaData->setInt32(kKeyIsADTS, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return mTrackMetaData;
|
||||
}
|
||||
@@ -260,10 +268,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
mDecryptContext.Initialize(mediaBuf);
|
||||
mEncryptedSizes.clear();
|
||||
#endif
|
||||
|
||||
size_t bytesRead;
|
||||
bool auStart;
|
||||
@@ -351,10 +357,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
// drop frames up to next sync if requested
|
||||
mIsStalled = true;
|
||||
usleep(10000);
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
mDecryptContext.Initialize(mediaBuf);
|
||||
mEncryptedSizes.clear();
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -394,13 +398,15 @@ 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);
|
||||
}
|
||||
|
||||
#ifndef REQUIRE_SECURE_BUFFERS
|
||||
mediaBuf->meta_data()->setData(kKeyCryptoKey, 0, mCryptoPluginKey, sizeof(mCryptoPluginKey));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
// debug code - log packets to files
|
||||
@@ -432,7 +438,6 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
return OK;
|
||||
}
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
|
||||
void WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void* output,
|
||||
size_t length, int key, void *obj)
|
||||
@@ -453,10 +458,7 @@ void WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void* out
|
||||
source = clientContext->getAudioSource();
|
||||
|
||||
DecryptContext &context = source->getDecryptContext();
|
||||
|
||||
OEMCrypto_UINT32 copied = length;
|
||||
OEMCryptoResult result;
|
||||
unsigned char *iv = NULL;
|
||||
uint32_t copied = length;
|
||||
|
||||
if (clientContext->getCryptoPluginMode()) {
|
||||
// just determine crypto unit boundaries
|
||||
@@ -465,7 +467,12 @@ void WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void* out
|
||||
}
|
||||
memcpy((uint8_t *)context.mMediaBuf->data() + context.mOffset, input, length);
|
||||
} else {
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
// do decrypt
|
||||
OEMCryptoResult result;
|
||||
unsigned char *iv = NULL;
|
||||
|
||||
if (key)
|
||||
iv = context.mIV;
|
||||
|
||||
@@ -482,10 +489,10 @@ void WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void* out
|
||||
if (result != OEMCrypto_SUCCESS) {
|
||||
ALOGD("OEMCrypto decrypt failure: %d", result);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
context.mOffset += copied;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
WVMMediaSource::~WVMMediaSource()
|
||||
|
||||
@@ -47,7 +47,8 @@ public:
|
||||
|
||||
int64_t getTime() { return mKeyTime; }; // usec.
|
||||
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
static const int kCryptoBlockSize = 16;
|
||||
|
||||
class DecryptContext {
|
||||
public:
|
||||
void Initialize(MediaBuffer *mediaBuf) {
|
||||
@@ -57,16 +58,19 @@ public:
|
||||
}
|
||||
MediaBuffer *mMediaBuf;
|
||||
size_t mOffset;
|
||||
static const int kCryptoBlockSize = 16;
|
||||
unsigned char mIV[kCryptoBlockSize];
|
||||
};
|
||||
|
||||
static void DecryptCallback(WVEsSelector esType, void* input, void* output, size_t length,
|
||||
int key, void *context);
|
||||
DecryptContext& getDecryptContext() { return mDecryptContext; }
|
||||
|
||||
void SetCryptoPluginKey(const char key[kCryptoBlockSize]) {
|
||||
memcpy(mCryptoPluginKey, key, sizeof(mCryptoPluginKey));
|
||||
}
|
||||
|
||||
private:
|
||||
DecryptContext mDecryptContext;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual ~WVMMediaSource();
|
||||
@@ -85,6 +89,7 @@ private:
|
||||
bool mNewSegment;
|
||||
bool mCryptoInitialized;
|
||||
bool mIsStalled;
|
||||
bool mStripADTS;
|
||||
|
||||
MediaBufferGroup *mGroup;
|
||||
|
||||
@@ -97,6 +102,7 @@ private:
|
||||
sp<ClientContext> mClientContext;
|
||||
|
||||
Vector<size_t> mEncryptedSizes;
|
||||
char mCryptoPluginKey[kCryptoBlockSize];
|
||||
|
||||
void allocBufferGroup();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user