Merge "Make Properties::Init() Take Action Only Once"

This commit is contained in:
John Bruce
2019-01-17 00:30:07 +00:00
committed by Android (Google) Code Review
3 changed files with 17 additions and 6 deletions

View File

@@ -7,6 +7,7 @@
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include "cdm_client_property_set.h"
@@ -30,11 +31,14 @@ typedef std::map<CdmSessionId, CdmClientPropertySet*>
// Setter methods are provided but their only planned use is for testing.
class Properties {
public:
// Called at least once before any properties are used. Depending on the
// platform, this function may be called multiple times. It is called each
// time a CdmEngine is created, and when running unit tests it is called in
// many tests' SetUp function.
static void Init();
static void Init() {
std::unique_lock<std::mutex> lock(init_mutex_);
if (!is_initialized_) {
InitOnce();
is_initialized_ = true;
}
}
static inline bool oem_crypto_use_secure_buffers() {
return oem_crypto_use_secure_buffers_;
@@ -108,6 +112,11 @@ class Properties {
#endif
private:
// Called at least once before any properties are used.
static void InitOnce();
static std::mutex init_mutex_;
static bool is_initialized_;
static bool oem_crypto_use_secure_buffers_;
static bool oem_crypto_use_fifo_;
static bool oem_crypto_use_userspace_buffers_;

View File

@@ -11,6 +11,8 @@ const char* kSecurityLevelDirs[] = {"L1/", "L3/"};
} // namespace
namespace wvcdm {
std::mutex Properties::init_mutex_;
bool Properties::is_initialized_ = false;
bool Properties::oem_crypto_use_secure_buffers_;
bool Properties::oem_crypto_use_fifo_;
bool Properties::oem_crypto_use_userspace_buffers_;

View File

@@ -43,7 +43,7 @@ bool GetAndroidProperty(const char* key, std::string* value) {
namespace wvcdm {
void Properties::Init() {
void Properties::InitOnce() {
oem_crypto_use_secure_buffers_ = kPropertyOemCryptoUseSecureBuffers;
oem_crypto_use_fifo_ = kPropertyOemCryptoUseFifo;
oem_crypto_use_userspace_buffers_ = kPropertyOemCryptoUseUserSpaceBuffers;