// // Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine License // Agreement. // //#define LOG_NDEBUG 0 #define LOG_TAG "WVCdm" #include #include "WVCDMSingleton.h" #include "utils/Mutex.h" #include "utils/RefBase.h" namespace wvdrm { using android::Mutex; using android::sp; using android::wp; using wvcdm::WvContentDecryptionModule; using wvcdm::WvMetricsSnapshotQueue; Mutex cdmLock; // TODO(b/270166158): Make this a loadable/storable when provided // a special debug property. sp sMetricsQueue; // 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 sCdm; sp getCDM() { Mutex::Autolock lock(cdmLock); // This function is a critical section. if (sMetricsQueue == nullptr) { ALOGD("Instantiating CDM metrics queue"); sMetricsQueue = new WvMetricsSnapshotQueue(); } sp cdm = sCdm.promote(); if (cdm == NULL) { ALOGD("Instantiating CDM."); cdm = new WvContentDecryptionModule(sMetricsQueue.get()); sCdm = cdm; } return cdm; } } // namespace wvdrm