Add mutex to CdmEngine for use of usage_session_.

[ Merge of http://go/wvgerrit/169430 ]

Bug: 263314813
Test: GtsMediaTestCases
Test: request_license_test
Change-Id: I0859865d26b14d492832001e55897f89853577f1
This commit is contained in:
Alex Dale
2023-03-30 13:47:04 -07:00
parent f1272a7e35
commit d66177a257
2 changed files with 15 additions and 8 deletions

View File

@@ -454,7 +454,10 @@ class CdmEngine {
// API will release the handle to previously active secure stop license. // API will release the handle to previously active secure stop license.
std::unique_ptr<CdmSession> usage_session_; std::unique_ptr<CdmSession> usage_session_;
std::unique_ptr<UsagePropertySet> usage_property_set_; std::unique_ptr<UsagePropertySet> usage_property_set_;
int64_t last_usage_information_update_time_; int64_t last_usage_information_update_time_ = 0;
// Should be acquired before changes to |usage_property_set_| or
// |usage_session_|.
std::mutex usage_session_mutex_;
// Protect release_key_sets_ from non-thread-safe operations. // Protect release_key_sets_ from non-thread-safe operations.
std::mutex release_key_sets_lock_; std::mutex release_key_sets_lock_;

View File

@@ -64,18 +64,17 @@ class UsagePropertySet : public CdmClientPropertySet {
CdmEngine::CdmEngine(wvutil::FileSystem* file_system, CdmEngine::CdmEngine(wvutil::FileSystem* file_system,
std::shared_ptr<metrics::EngineMetrics> metrics) std::shared_ptr<metrics::EngineMetrics> metrics)
: metrics_(metrics), : metrics_(metrics), file_system_(file_system), spoid_(EMPTY_SPOID) {
file_system_(file_system),
spoid_(EMPTY_SPOID),
usage_session_(),
usage_property_set_(),
last_usage_information_update_time_(0) {
assert(file_system); assert(file_system);
Properties::Init(); Properties::Init();
} }
CdmEngine::~CdmEngine() { CdmEngine::~CdmEngine() {
usage_session_.reset(); {
std::unique_lock<std::mutex> lock(usage_session_mutex_);
usage_session_.reset();
}
std::unique_lock<std::recursive_mutex> lock(session_map_lock_); std::unique_lock<std::recursive_mutex> lock(session_map_lock_);
session_map_.Terminate(); session_map_.Terminate();
} }
@@ -1489,6 +1488,7 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
int* error_detail, int* error_detail,
CdmUsageReport* usage_report) { CdmUsageReport* usage_report) {
LOGI("app_id = %s, ssid = %s", IdToString(app_id), IdToString(ssid)); LOGI("app_id = %s, ssid = %s", IdToString(app_id), IdToString(ssid));
std::unique_lock<std::mutex> lock(usage_session_mutex_);
if (!usage_property_set_) { if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet()); usage_property_set_.reset(new UsagePropertySet());
} }
@@ -1598,6 +1598,7 @@ CdmResponseType CdmEngine::GetUsageInfo(
LOGD("OKP fallback to L3"); LOGD("OKP fallback to L3");
requested_security_level = kLevel3; requested_security_level = kLevel3;
} }
std::unique_lock<std::mutex> lock(usage_session_mutex_);
if (!usage_property_set_) { if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet()); usage_property_set_.reset(new UsagePropertySet());
} }
@@ -1660,6 +1661,7 @@ CdmResponseType CdmEngine::RemoveAllUsageInfo(
const std::string& app_id, CdmSecurityLevel cdm_security_level) { const std::string& app_id, CdmSecurityLevel cdm_security_level) {
LOGI("app_id = %s, security_level = %s", IdToString(app_id), LOGI("app_id = %s, security_level = %s", IdToString(app_id),
CdmSecurityLevelToString(cdm_security_level)); CdmSecurityLevelToString(cdm_security_level));
std::unique_lock<std::mutex> lock(usage_session_mutex_);
if (!usage_property_set_) { if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet()); usage_property_set_.reset(new UsagePropertySet());
} }
@@ -1733,6 +1735,7 @@ CdmResponseType CdmEngine::RemoveUsageInfo(
const std::string& app_id, const CdmSecureStopId& provider_session_token) { const std::string& app_id, const CdmSecureStopId& provider_session_token) {
LOGI("app_id = %s, pst = %s", IdToString(app_id), LOGI("app_id = %s, pst = %s", IdToString(app_id),
IdToString(provider_session_token)); IdToString(provider_session_token));
std::unique_lock<std::mutex> lock(usage_session_mutex_);
if (!usage_property_set_) { if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet()); usage_property_set_.reset(new UsagePropertySet());
} }
@@ -1777,6 +1780,7 @@ CdmResponseType CdmEngine::RemoveUsageInfo(
CdmResponseType CdmEngine::ReleaseUsageInfo(const CdmKeyResponse& message) { CdmResponseType CdmEngine::ReleaseUsageInfo(const CdmKeyResponse& message) {
LOGI("message_size = %zu", message.size()); LOGI("message_size = %zu", message.size());
std::unique_lock<std::mutex> lock(usage_session_mutex_);
if (!usage_session_) { if (!usage_session_) {
LOGE("Usage session not initialized"); LOGE("Usage session not initialized");
return CdmResponseType(RELEASE_USAGE_INFO_ERROR); return CdmResponseType(RELEASE_USAGE_INFO_ERROR);