Refactor WvCdmEventListener and some cleanups
Bug: 19771437 It is a merge of below CLs from Widevine CDM repo: Clean up CdmSession and PolicyEngine testing injection https://widevine-internal-review.googlesource.com/#/c/13700 Refactor WvCdmEventListener handling https://widevine-internal-review.googlesource.com/#/c/13702 Change-Id: I356b90000c056113d394926862b859aab380d305
This commit is contained in:
@@ -23,68 +23,32 @@ const size_t kKeySetIdLength = 14;
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
typedef std::set<WvCdmEventListener*>::iterator CdmEventListenerIter;
|
||||
|
||||
CdmSession::CdmSession(const CdmClientPropertySet* cdm_client_property_set) {
|
||||
CryptoSession* crypto_session = new CryptoSession();
|
||||
Create(new CdmLicense(), crypto_session, new PolicyEngine(crypto_session),
|
||||
new DeviceFiles(), cdm_client_property_set);
|
||||
}
|
||||
|
||||
CdmSession::CdmSession(CdmLicense* license_parser,
|
||||
CryptoSession* crypto_session,
|
||||
PolicyEngine* policy_engine, DeviceFiles* file_handle,
|
||||
const CdmClientPropertySet* cdm_client_property_set) {
|
||||
Create(license_parser, crypto_session, policy_engine, file_handle,
|
||||
cdm_client_property_set);
|
||||
}
|
||||
|
||||
void CdmSession::Create(CdmLicense* license_parser,
|
||||
CryptoSession* crypto_session,
|
||||
PolicyEngine* policy_engine, DeviceFiles* file_handle,
|
||||
const CdmClientPropertySet* cdm_client_property_set) {
|
||||
// Just return on failures. Failures will be signaled in Init.
|
||||
if (NULL == license_parser) {
|
||||
LOGE("CdmSession::Create: License parser not provided");
|
||||
return;
|
||||
}
|
||||
if (NULL == crypto_session) {
|
||||
LOGE("CdmSession::Create: Crypto session not provided");
|
||||
return;
|
||||
}
|
||||
if (NULL == policy_engine) {
|
||||
LOGE("CdmSession::Create: Policy engine not provided");
|
||||
return;
|
||||
}
|
||||
if (NULL == file_handle) {
|
||||
LOGE("CdmSession::Create: Device files not provided");
|
||||
return;
|
||||
}
|
||||
initialized_ = false;
|
||||
session_id_ = GenerateSessionId();
|
||||
license_parser_.reset(license_parser);
|
||||
crypto_session_.reset(crypto_session);
|
||||
file_handle_.reset(file_handle);
|
||||
policy_engine_.reset(policy_engine);
|
||||
license_received_ = false;
|
||||
is_offline_ = false;
|
||||
is_release_ = false;
|
||||
is_initial_usage_update_ = true;
|
||||
is_usage_update_needed_ = false;
|
||||
is_initial_decryption_ = true;
|
||||
has_decrypted_since_last_report_ = false;
|
||||
requested_security_level_ = kLevelDefault;
|
||||
if (NULL != cdm_client_property_set) {
|
||||
if (QUERY_VALUE_SECURITY_LEVEL_L3.compare(
|
||||
cdm_client_property_set->security_level()) == 0) {
|
||||
CdmSession::CdmSession(const CdmClientPropertySet* cdm_client_property_set,
|
||||
WvCdmEventListener* event_listener)
|
||||
: initialized_(false),
|
||||
session_id_(GenerateSessionId()),
|
||||
event_listener_(event_listener),
|
||||
license_parser_(new CdmLicense),
|
||||
crypto_session_(new CryptoSession),
|
||||
policy_engine_(new PolicyEngine(crypto_session_.get())),
|
||||
file_handle_(new DeviceFiles),
|
||||
license_received_(false),
|
||||
is_offline_(false),
|
||||
is_release_(false),
|
||||
security_level_(kSecurityLevelUninitialized),
|
||||
requested_security_level_(kLevelDefault),
|
||||
is_initial_decryption_(true),
|
||||
has_decrypted_since_last_report_(false),
|
||||
is_initial_usage_update_(true),
|
||||
is_usage_update_needed_(false) {
|
||||
if (cdm_client_property_set) {
|
||||
if (cdm_client_property_set->security_level() ==
|
||||
QUERY_VALUE_SECURITY_LEVEL_L3) {
|
||||
requested_security_level_ = kLevel3;
|
||||
security_level_ = kSecurityLevelL3;
|
||||
}
|
||||
Properties::AddSessionPropertySet(session_id_, cdm_client_property_set);
|
||||
}
|
||||
security_level_ =
|
||||
GetRequestedSecurityLevel() == kLevel3 ? kSecurityLevelL3
|
||||
: kSecurityLevelUninitialized;
|
||||
app_id_.clear();
|
||||
}
|
||||
|
||||
CdmSession::~CdmSession() { Properties::RemoveSessionPropertySet(session_id_); }
|
||||
@@ -546,15 +510,6 @@ bool CdmSession::DeleteLicense() {
|
||||
}
|
||||
}
|
||||
|
||||
bool CdmSession::AttachEventListener(WvCdmEventListener* listener) {
|
||||
std::pair<CdmEventListenerIter, bool> result = listeners_.insert(listener);
|
||||
return result.second;
|
||||
}
|
||||
|
||||
bool CdmSession::DetachEventListener(WvCdmEventListener* listener) {
|
||||
return (listeners_.erase(listener) == 1);
|
||||
}
|
||||
|
||||
void CdmSession::NotifyResolution(uint32_t width, uint32_t height) {
|
||||
policy_engine_->NotifyResolution(width, height);
|
||||
}
|
||||
@@ -573,19 +528,14 @@ void CdmSession::OnTimerEvent(bool update_usage) {
|
||||
policy_engine_->OnTimerEvent(&event_occurred, &event);
|
||||
|
||||
if (event_occurred) {
|
||||
for (CdmEventListenerIter iter = listeners_.begin();
|
||||
iter != listeners_.end(); ++iter) {
|
||||
(*iter)->OnEvent(session_id_, event);
|
||||
}
|
||||
if (event_listener_) event_listener_->OnEvent(session_id_, event);
|
||||
}
|
||||
}
|
||||
|
||||
void CdmSession::OnKeyReleaseEvent(const CdmKeySetId& key_set_id) {
|
||||
if (key_set_id_ == key_set_id) {
|
||||
for (CdmEventListenerIter iter = listeners_.begin();
|
||||
iter != listeners_.end(); ++iter) {
|
||||
(*iter)->OnEvent(session_id_, LICENSE_EXPIRED_EVENT);
|
||||
}
|
||||
if (event_listener_)
|
||||
event_listener_->OnEvent(session_id_, LICENSE_EXPIRED_EVENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,4 +560,20 @@ CdmResponseType CdmSession::ReleaseCrypto() {
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
void CdmSession::set_license_parser(CdmLicense* license_parser) {
|
||||
license_parser_.reset(license_parser);
|
||||
}
|
||||
|
||||
void CdmSession::set_crypto_session(CryptoSession* crypto_session) {
|
||||
crypto_session_.reset(crypto_session);
|
||||
}
|
||||
|
||||
void CdmSession::set_policy_engine(PolicyEngine* policy_engine) {
|
||||
policy_engine_.reset(policy_engine);
|
||||
}
|
||||
|
||||
void CdmSession::set_file_handle(DeviceFiles* file_handle) {
|
||||
file_handle_.reset(file_handle);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user