Fix native fault in WVMMediaSource::DecryptCallback

This change resolves a lifetime issue between the media extractor
and media sources.  The extractor was being passed as a context
object to a callout in the WV libs.  In some cases, a pointer to
the extractor would be delivered to the callout after the extractor
had been released.  This change assigns the responsibility of the
lifetime of the context object to the media source, to ensure that
a ref is always held on the context object during the lifetime of
the media source.

Change-Id: Ic7a57a1c8496a4798fe590ec356b8a19a4f69967
related-to-bug: 6502322
This commit is contained in:
Jeff Tinker
2012-05-16 11:11:14 -07:00
parent 79e250e999
commit e9c40a625c
5 changed files with 89 additions and 43 deletions

View File

@@ -8,6 +8,7 @@
#include "WVMMediaSource.h"
#include "WVMFileSource.h"
#include "WVMExtractorImpl.h"
#include "ClientContext.h"
#include "media/stagefright/foundation/ADebug.h"
#include "media/stagefright/MediaErrors.h"
#include "media/stagefright/MediaDefs.h"
@@ -66,6 +67,11 @@ void WVMMediaSource::delegateDataSource(sp<DataSource> dataSource)
mDataSource = dataSource;
}
void WVMMediaSource::delegateClientContext(sp<ClientContext> context)
{
mClientContext = context;
}
void WVMMediaSource::allocBufferGroup()
{
if (mGroup)
@@ -422,24 +428,25 @@ void WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void* out
//ALOGD("DecryptCallback(type=%d, in=%p, out=%p, len=%d, key=%d\n",
// (int)esType, input, output, length, key);
WVMExtractorImpl *extractor = (WVMExtractorImpl *)obj;
if (!extractor) {
ALOGE("WVMMediaSource::DecryptCallback - no extractor!");
ClientContext *clientContext = (ClientContext *)obj;
if (!clientContext) {
ALOGE("WVMMediaSource::DecryptCallback - no client context!");
return;
}
sp<WVMMediaSource> source;
if (esType == WV_EsSelector_Video)
source = extractor->getVideoSource();
source = clientContext->getVideoSource();
else
source = extractor->getAudioSource();
source = clientContext->getAudioSource();
DecryptContext &context = source->getDecryptContext();
OEMCrypto_UINT32 copied = length;
OEMCryptoResult result;
unsigned char *iv = NULL;
if (extractor->getCryptoPluginMode()) {
if (clientContext->getCryptoPluginMode()) {
// just determine crypto unit boundaries
if (key) {
source->addEncryptedSize(length);