- Do not use global DrmManagerClient
- Release the DrmManagerClient and DecryptHandle in DataSource
Fix for bug 3429811
Change-Id: I549f72b75225751877eb0e630ce8098f8ec6316f
diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h
index d4f1733..f95e56a 100644
--- a/include/media/stagefright/DataSource.h
+++ b/include/media/stagefright/DataSource.h
@@ -75,7 +75,7 @@
static void RegisterDefaultSniffers();
// for DRM
- virtual DecryptHandle* DrmInitialization(DrmManagerClient *client) {
+ virtual DecryptHandle* DrmInitialization() {
return NULL;
}
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) {};
diff --git a/include/media/stagefright/FileSource.h b/include/media/stagefright/FileSource.h
index 72a0403..51a4343 100644
--- a/include/media/stagefright/FileSource.h
+++ b/include/media/stagefright/FileSource.h
@@ -38,7 +38,7 @@
virtual status_t getSize(off64_t *size);
- virtual DecryptHandle* DrmInitialization(DrmManagerClient *client);
+ virtual DecryptHandle* DrmInitialization();
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client);
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 11ac56c..a777558 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -392,7 +392,6 @@
if (mDecryptHandle != NULL) {
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
Playback::STOP, 0);
- mDrmManagerClient->closeDecryptSession(mDecryptHandle);
mDecryptHandle = NULL;
mDrmManagerClient = NULL;
}
diff --git a/media/libstagefright/DRMExtractor.cpp b/media/libstagefright/DRMExtractor.cpp
index 3c98932..4b83568 100644
--- a/media/libstagefright/DRMExtractor.cpp
+++ b/media/libstagefright/DRMExtractor.cpp
@@ -38,12 +38,12 @@
namespace android {
-DrmManagerClient* gDrmManagerClient = NULL;
-
class DRMSource : public MediaSource {
public:
DRMSource(const sp<MediaSource> &mediaSource,
- DecryptHandle* decryptHandle, int32_t trackId, DrmBuffer* ipmpBox);
+ DecryptHandle *decryptHandle,
+ DrmManagerClient *managerClient,
+ int32_t trackId, DrmBuffer *ipmpBox);
virtual status_t start(MetaData *params = NULL);
virtual status_t stop();
@@ -57,6 +57,7 @@
private:
sp<MediaSource> mOriginalMediaSource;
DecryptHandle* mDecryptHandle;
+ DrmManagerClient* mDrmManagerClient;
size_t mTrackId;
mutable Mutex mDRMLock;
size_t mNALLengthSize;
@@ -69,13 +70,16 @@
////////////////////////////////////////////////////////////////////////////////
DRMSource::DRMSource(const sp<MediaSource> &mediaSource,
- DecryptHandle* decryptHandle, int32_t trackId, DrmBuffer* ipmpBox)
+ DecryptHandle *decryptHandle,
+ DrmManagerClient *managerClient,
+ int32_t trackId, DrmBuffer *ipmpBox)
: mOriginalMediaSource(mediaSource),
mDecryptHandle(decryptHandle),
+ mDrmManagerClient(managerClient),
mTrackId(trackId),
mNALLengthSize(0),
mWantsNALFragments(false) {
- gDrmManagerClient->initializeDecryptUnit(
+ mDrmManagerClient->initializeDecryptUnit(
mDecryptHandle, trackId, ipmpBox);
const char *mime;
@@ -100,7 +104,7 @@
DRMSource::~DRMSource() {
Mutex::Autolock autoLock(mDRMLock);
- gDrmManagerClient->finalizeDecryptUnit(mDecryptHandle, mTrackId);
+ mDrmManagerClient->finalizeDecryptUnit(mDecryptHandle, mTrackId);
}
status_t DRMSource::start(MetaData *params) {
@@ -140,7 +144,7 @@
decryptedDrmBuffer.data = new char[len];
DrmBuffer *pDecryptedDrmBuffer = &decryptedDrmBuffer;
- if ((err = gDrmManagerClient->decrypt(mDecryptHandle, mTrackId,
+ if ((err = mDrmManagerClient->decrypt(mDecryptHandle, mTrackId,
&encryptedDrmBuffer, &pDecryptedDrmBuffer)) != DRM_NO_ERROR) {
if (decryptedDrmBuffer.data) {
@@ -234,12 +238,12 @@
DRMExtractor::DRMExtractor(const sp<DataSource> &source, const char* mime)
: mDataSource(source),
- mDecryptHandle(NULL) {
+ mDecryptHandle(NULL),
+ mDrmManagerClient(NULL) {
mOriginalExtractor = MediaExtractor::Create(source, mime);
mOriginalExtractor->setDrmFlag(true);
- DrmManagerClient *client;
- source->getDrmInfo(&mDecryptHandle, &client);
+ source->getDrmInfo(&mDecryptHandle, &mDrmManagerClient);
}
DRMExtractor::~DRMExtractor() {
@@ -260,7 +264,8 @@
ipmpBox.data = mOriginalExtractor->getDrmTrackInfo(trackID, &(ipmpBox.length));
CHECK(ipmpBox.length > 0);
- return new DRMSource(originalMediaSource, mDecryptHandle, trackID, &ipmpBox);
+ return new DRMSource(originalMediaSource, mDecryptHandle, mDrmManagerClient,
+ trackID, &ipmpBox);
}
sp<MetaData> DRMExtractor::getTrackMetaData(size_t index, uint32_t flags) {
@@ -271,22 +276,10 @@
return mOriginalExtractor->getMetaData();
}
-static Mutex gDRMSnifferMutex;
bool SniffDRM(
const sp<DataSource> &source, String8 *mimeType, float *confidence,
sp<AMessage> *) {
- {
- Mutex::Autolock autoLock(gDRMSnifferMutex);
- if (gDrmManagerClient == NULL) {
- gDrmManagerClient = new DrmManagerClient();
- }
-
- if (gDrmManagerClient == NULL) {
- return false;
- }
- }
-
- DecryptHandle *decryptHandle = source->DrmInitialization(gDrmManagerClient);
+ DecryptHandle *decryptHandle = source->DrmInitialization();
if (decryptHandle != NULL) {
if (decryptHandle->decryptApiType == DecryptApiType::CONTAINER_BASED) {
diff --git a/media/libstagefright/FileSource.cpp b/media/libstagefright/FileSource.cpp
index 98d5b50..b8e75fd 100644
--- a/media/libstagefright/FileSource.cpp
+++ b/media/libstagefright/FileSource.cpp
@@ -60,6 +60,17 @@
delete[] mDrmBuf;
mDrmBuf = NULL;
}
+
+ if (mDecryptHandle != NULL) {
+ // To release mDecryptHandle
+ mDrmManagerClient->closeDecryptSession(mDecryptHandle);
+ mDecryptHandle = NULL;
+ }
+
+ if (mDrmManagerClient != NULL) {
+ delete mDrmManagerClient;
+ mDrmManagerClient = NULL;
+ }
}
status_t FileSource::initCheck() const {
@@ -113,11 +124,14 @@
return OK;
}
-DecryptHandle* FileSource::DrmInitialization(DrmManagerClient* client) {
- if (client == NULL) {
+DecryptHandle* FileSource::DrmInitialization() {
+ if (mDrmManagerClient == NULL) {
+ mDrmManagerClient = new DrmManagerClient();
+ }
+
+ if (mDrmManagerClient == NULL) {
return NULL;
}
- mDrmManagerClient = client;
if (mDecryptHandle == NULL) {
mDecryptHandle = mDrmManagerClient->openDecryptSession(
@@ -125,6 +139,7 @@
}
if (mDecryptHandle == NULL) {
+ delete mDrmManagerClient;
mDrmManagerClient = NULL;
}
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp
index 741aa1c..c7b99b9 100644
--- a/media/libstagefright/NuCachedSource2.cpp
+++ b/media/libstagefright/NuCachedSource2.cpp
@@ -477,8 +477,8 @@
restartPrefetcherIfNecessary_l(true /* ignore low water threshold */);
}
-DecryptHandle* NuCachedSource2::DrmInitialization(DrmManagerClient* client) {
- return mSource->DrmInitialization(client);
+DecryptHandle* NuCachedSource2::DrmInitialization() {
+ return mSource->DrmInitialization();
}
void NuCachedSource2::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) {
diff --git a/media/libstagefright/NuHTTPDataSource.cpp b/media/libstagefright/NuHTTPDataSource.cpp
index 653c85e..af04f93 100644
--- a/media/libstagefright/NuHTTPDataSource.cpp
+++ b/media/libstagefright/NuHTTPDataSource.cpp
@@ -79,6 +79,16 @@
}
NuHTTPDataSource::~NuHTTPDataSource() {
+ if (mDecryptHandle != NULL) {
+ // To release mDecryptHandle
+ mDrmManagerClient->closeDecryptSession(mDecryptHandle);
+ mDecryptHandle = NULL;
+ }
+
+ if (mDrmManagerClient != NULL) {
+ delete mDrmManagerClient;
+ mDrmManagerClient = NULL;
+ }
}
status_t NuHTTPDataSource::connect(
@@ -486,11 +496,14 @@
}
}
-DecryptHandle* NuHTTPDataSource::DrmInitialization(DrmManagerClient* client) {
- if (client == NULL) {
+DecryptHandle* NuHTTPDataSource::DrmInitialization() {
+ if (mDrmManagerClient == NULL) {
+ mDrmManagerClient = new DrmManagerClient();
+ }
+
+ if (mDrmManagerClient == NULL) {
return NULL;
}
- mDrmManagerClient = client;
if (mDecryptHandle == NULL) {
/* Note if redirect occurs, mUri is the redirect uri instead of the
@@ -500,6 +513,7 @@
}
if (mDecryptHandle == NULL) {
+ delete mDrmManagerClient;
mDrmManagerClient = NULL;
}
diff --git a/media/libstagefright/include/DRMExtractor.h b/media/libstagefright/include/DRMExtractor.h
index cafc812..9881cc1 100644
--- a/media/libstagefright/include/DRMExtractor.h
+++ b/media/libstagefright/include/DRMExtractor.h
@@ -46,6 +46,7 @@
sp<MediaExtractor> mOriginalExtractor;
DecryptHandle* mDecryptHandle;
+ DrmManagerClient* mDrmManagerClient;
DRMExtractor(const DRMExtractor &);
DRMExtractor &operator=(const DRMExtractor &);
diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h
index 28840be..022804c 100644
--- a/media/libstagefright/include/NuCachedSource2.h
+++ b/media/libstagefright/include/NuCachedSource2.h
@@ -37,7 +37,7 @@
virtual status_t getSize(off64_t *size);
virtual uint32_t flags();
- virtual DecryptHandle* DrmInitialization(DrmManagerClient *client);
+ virtual DecryptHandle* DrmInitialization();
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client);
virtual String8 getUri();
////////////////////////////////////////////////////////////////////////////
diff --git a/media/libstagefright/include/NuHTTPDataSource.h b/media/libstagefright/include/NuHTTPDataSource.h
index c8e93be..a99e84a 100644
--- a/media/libstagefright/include/NuHTTPDataSource.h
+++ b/media/libstagefright/include/NuHTTPDataSource.h
@@ -31,7 +31,7 @@
// false otherwise.
bool estimateBandwidth(int32_t *bandwidth_bps);
- virtual DecryptHandle* DrmInitialization(DrmManagerClient *client);
+ virtual DecryptHandle* DrmInitialization();
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client);
virtual String8 getUri();