diff --git a/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp b/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp index 328f7001aeb7..51dfec0b7f18 100644 --- a/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp +++ b/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp @@ -13,11 +13,14 @@ #include "gmp-api/gmp-decryption.h" #include "gmp-api/gmp-video-codec.h" #include "gmp-api/gmp-platform.h" +#include "mozilla/StaticPtr.h" static const GMPPlatformAPI* sPlatform = nullptr; namespace mozilla { +StaticRefPtr sCDMWrapper; + GMPErr GMPGetCurrentTime(GMPTimestamp* aOutTime) { return sPlatform->getcurrenttime(aOutTime); } @@ -88,19 +91,19 @@ WidevineAdapter::GMPGetAPI(const char* aAPIName, void** aPluginAPI, uint32_t aDecryptorId) { - Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p", - aAPIName, aHostAPI, aPluginAPI, this, aDecryptorId); + Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p) this=0x%p", + aAPIName, aHostAPI, aPluginAPI, this); if (!strcmp(aAPIName, GMP_API_DECRYPTOR)) { - if (WidevineDecryptor::GetInstance(aDecryptorId)) { - // We only support one CDM instance per PGMPDecryptor. Fail! - Log("WidevineAdapter::GMPGetAPI() Tried to create more than once CDM per IPDL actor! FAIL!"); + if (sCDMWrapper) { + // We only support one CDM instance per GMP process. Fail! + Log("WidevineAdapter::GMPGetAPI() Tried to create more than once CDM per process! FAIL!"); return GMPQuotaExceededErr; } auto create = reinterpret_cast( PR_FindFunctionSymbol(mLib, "CreateCdmInstance")); if (!create) { - Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p FAILED to find CreateCdmInstance", - aAPIName, aHostAPI, aPluginAPI, this, aDecryptorId); + Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p) this=0x%p FAILED to find CreateCdmInstance", + aAPIName, aHostAPI, aPluginAPI, this); return GMPGenericErr; } @@ -113,24 +116,24 @@ WidevineAdapter::GMPGetAPI(const char* aAPIName, &GetCdmHost, decryptor)); if (!cdm) { - Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p FAILED to create cdm", - aAPIName, aHostAPI, aPluginAPI, this, aDecryptorId); + Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p) this=0x%p FAILED to create cdm", + aAPIName, aHostAPI, aPluginAPI, this); return GMPGenericErr; } Log("cdm: 0x%x", cdm); - RefPtr wrapper(new CDMWrapper(cdm)); - decryptor->SetCDM(wrapper, aDecryptorId); + sCDMWrapper = new CDMWrapper(cdm); + decryptor->SetCDM(RefPtr(sCDMWrapper)); *aPluginAPI = decryptor; } else if (!strcmp(aAPIName, GMP_API_VIDEO_DECODER)) { - RefPtr wrapper = WidevineDecryptor::GetInstance(aDecryptorId); - if (!wrapper) { - Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p No cdm for video decoder", - aAPIName, aHostAPI, aPluginAPI, thiss, aDecryptorId); + if (!sCDMWrapper) { + Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p) this=0x%p No cdm for video decoder", + aAPIName, aHostAPI, aPluginAPI, this); return GMPGenericErr; } *aPluginAPI = new WidevineVideoDecoder(static_cast(aHostAPI), - wrapper); + RefPtr(sCDMWrapper)); + } return *aPluginAPI ? GMPNoErr : GMPNotImplementedErr; } diff --git a/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp b/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp index 80e4f36aace3..1c43ba43a987 100644 --- a/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp +++ b/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp @@ -16,19 +16,6 @@ using namespace std; namespace mozilla { -static map> sDecryptors; - -/* static */ -RefPtr -WidevineDecryptor::GetInstance(uint32_t aInstanceId) -{ - auto itr = sDecryptors.find(aInstanceId); - if (itr != sDecryptors.end()) { - return itr->second; - } - return nullptr; -} - WidevineDecryptor::WidevineDecryptor() : mCallback(nullptr) @@ -43,11 +30,9 @@ WidevineDecryptor::~WidevineDecryptor() } void -WidevineDecryptor::SetCDM(RefPtr aCDM, uint32_t aInstanceId) +WidevineDecryptor::SetCDM(RefPtr aCDM) { mCDM = aCDM; - mInstanceId = aInstanceId; - sDecryptors[mInstanceId] = aCDM; } void @@ -225,12 +210,7 @@ void WidevineDecryptor::DecryptingComplete() { Log("WidevineDecryptor::DecryptingComplete() this=%p", this); - // Drop our references to the CDMWrapper. When any other references - // held elsewhere are dropped (for example references held by a - // WidevineVideoDecoder, or a runnable), the CDMWrapper destroys - // the CDM. mCDM = nullptr; - sDecryptors.erase(mInstanceId); mCallback = nullptr; Release(); } diff --git a/dom/media/gmp/widevine-adapter/WidevineDecryptor.h b/dom/media/gmp/widevine-adapter/WidevineDecryptor.h index d5185192b581..68fc35cbc864 100644 --- a/dom/media/gmp/widevine-adapter/WidevineDecryptor.h +++ b/dom/media/gmp/widevine-adapter/WidevineDecryptor.h @@ -24,9 +24,7 @@ public: WidevineDecryptor(); - void SetCDM(RefPtr aCDM, uint32_t aDecryptorId); - - static RefPtr GetInstance(uint32_t aDecryptorId); + void SetCDM(RefPtr aCDM); // GMPDecryptor void Init(GMPDecryptorCallback* aCallback, @@ -126,7 +124,6 @@ private: std::map mPromiseIdToNewSessionTokens; bool mDistinctiveIdentifierRequired = false; bool mPersistentStateRequired = false; - uint32_t mInstanceId = 0; }; } // namespace mozilla