Changes for calling the level 1 decrypt callout

Change-Id: Iccf76b59a64491952ee11ee2ed1a0e707a529f88
This commit is contained in:
Jeffrey Tinker
2011-08-30 17:59:53 -07:00
parent ceac204c61
commit f5fa8f2017
6 changed files with 145 additions and 3 deletions

View File

@@ -48,6 +48,11 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
mPts(0)
{
_ah010(_cb);
#ifdef REQUIRE_SECURE_BUFFERS
if (esSelector == WV_EsSelector_Video) {
OEMCrypto_Initialize();
}
#endif
}
// Since the WVMExtractor lifetime is short, we delegate ownership of some resources
@@ -246,6 +251,10 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
return err;
}
#ifdef REQUIRE_SECURE_BUFFERS
sDecryptContext[mESSelector].Initialize(mediaBuf);
#endif
size_t bytesRead;
bool auStart;
size_t offset = 0;
@@ -332,12 +341,21 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
if (seekNextSync && ((keyTime < seekTimeUs) || !syncFrame)) {
// drop frames up to next sync if requested
usleep(10000);
#ifdef REQUIRE_SECURE_BUFFERS
sDecryptContext[mESSelector].Initialize(mediaBuf);
#endif
continue;
}
if (offset + bytesRead < mediaBuf->size())
break;
#ifdef REQUIRE_SECURE_BUFFERS
LOGD("buffer overflow");
mediaBuf->release();
return ERROR_IO;
#endif
//LOGD("Resizing...");
// This buffer is too small, allocate a larger buffer twice the size
@@ -391,6 +409,42 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
return OK;
}
#ifdef REQUIRE_SECURE_BUFFERS
WVMMediaSource::DecryptContext WVMMediaSource::sDecryptContext[2] = {};
void WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void* output,
size_t length, int key)
{
//LOGD("DecryptCallback(type=%d, in=%p, out=%p, len=%d, key=%d\n",
// (int)esType, input, output, length, key);
DecryptContext &context = sDecryptContext[esType];
OEMCrypto_UINT32 copied = length;
OEMCryptoResult result;
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);
} else {
result = OEMCrypto_DecryptAudio(iv, (OEMCrypto_UINT8 *)input, length,
(OEMCrypto_UINT8 *)context.mMediaBuf->data() + context.mOffset,
&copied);
}
if (result != OEMCrypto_SUCCESS) {
LOGD("OEMCrypto decrypt failure: %d", result);
}
context.mOffset += copied;
}
#endif
WVMMediaSource::~WVMMediaSource()
{
//LOGD("WVMMediaSource::~WVMMediaSource()");
@@ -402,6 +456,9 @@ WVMMediaSource::~WVMMediaSource()
if (mESSelector == WV_EsSelector_Video) {
if (mSession != NULL) {
WV_Teardown(mSession);
#ifdef REQUIRE_SECURE_BUFFERS
OEMCrypto_Terminate();
#endif
}
WVMExtractorImpl::cleanup();
}