Delete Singleton on Library Unload

(This is a merge of http://go/wvgerrit/14531)

As an optimization, the Media Server now unloads our library when not
in use. This has exposed a bug by which we were never deleting the CDM
singleton. Fix is to make WvContentDecryptionModule an Android smart
pointer ref base and then make sure all the plugins store a strong
pointer to it. The singleton is a weak pointer, so when the last
plugin is cleaned up, the CDM will be as well. And on the off chance
that the library isn't immediately unloaded, the singleton code will
generate a new CDM next time one is needed.

Bug: 21153732
Change-Id: Ifaf02fa9afe0a70a8b53e8b92ee0a3d1359ca001
This commit is contained in:
John "Juce" Bruce
2015-06-03 15:57:00 -07:00
parent a54ae37ceb
commit a8328dd2f9
7 changed files with 25 additions and 11 deletions

View File

@@ -9,21 +9,30 @@
#include "WVCDMSingleton.h"
#include "utils/Mutex.h"
#include "utils/RefBase.h"
namespace wvdrm {
using wvcdm::WvContentDecryptionModule;
using android::Mutex;
using android::sp;
using android::wp;
Mutex cdmLock;
WvContentDecryptionModule* cdm = NULL;
// The strong pointers that keep this object alive live in the plugin objects.
// If all the plugins are deleted, the CDM will be deleted, and subsequent
// invocations of this code will construct a new CDM.
wp<WvContentDecryptionModule> sCdm;
WvContentDecryptionModule* getCDM() {
Mutex::Autolock lock(cdmLock);
sp<WvContentDecryptionModule> getCDM() {
Mutex::Autolock lock(cdmLock); // This function is a critical section.
sp<WvContentDecryptionModule> cdm = sCdm.promote();
if (cdm == NULL) {
ALOGD("Instantiating CDM.");
cdm = new WvContentDecryptionModule();
sCdm = cdm;
}
return cdm;