Replace generic OnEvent with actual event callbacks

Also pass session_id and event_listener to PolicyEngine to make it easier
to dispatch events from PolicyEngine.

Bug: 19771437

Merged from Widevine CDM repo:
https://widevine-internal-review.googlesource.com/#/c/13816/

Change-Id: I5723cb371cb3c43c945051af3402b09069ba5859
This commit is contained in:
KongQun Yang
2015-03-23 16:49:59 -07:00
parent 170485f771
commit 85e838b957
15 changed files with 371 additions and 463 deletions

View File

@@ -16,12 +16,14 @@ using video_widevine_server::sdk::LicenseIdentification;
class Clock;
class CryptoSession;
class WvCdmEventListener;
// This acts as an oracle that basically says "Yes(true) you may still decrypt
// or no(false) you may not decrypt this data anymore."
class PolicyEngine {
public:
explicit PolicyEngine(CryptoSession* crypto_session);
PolicyEngine(CdmSessionId session_id, WvCdmEventListener* event_listener,
CryptoSession* crypto_session);
virtual ~PolicyEngine();
// The value returned should be taken as a hint rather than an absolute
@@ -32,11 +34,9 @@ class PolicyEngine {
virtual bool CanDecrypt(const KeyId& key_id);
// OnTimerEvent is called when a timer fires. It notifies the Policy Engine
// that the timer has fired and that it should check whether any events have
// occurred since the last timer event. If so, it sets event_occurred to true
// and sets event to point to the event that occurred. If not, it sets
// event_occurred to false.
virtual void OnTimerEvent(bool* event_occurred, CdmEventType* event);
// that the timer has fired and dispatches the relevant events through
// |event_listener_|.
virtual void OnTimerEvent();
// SetLicense is used in handling the initial license response. It stores
// an exact copy of the policy information stored in the license.
@@ -126,6 +126,10 @@ class PolicyEngine {
int64_t next_renewal_time_;
int64_t policy_max_duration_seconds_;
// Used to dispatch CDM events.
CdmSessionId session_id_;
WvCdmEventListener* event_listener_;
MaxResEngine max_res_engine_;
scoped_ptr<Clock> clock_;

View File

@@ -13,8 +13,8 @@ class WvCdmEventListener {
WvCdmEventListener() {}
virtual ~WvCdmEventListener() {}
virtual void OnEvent(const CdmSessionId& session_id,
CdmEventType cdm_event) = 0;
virtual void OnSessionRenewalNeeded(const CdmSessionId& session_id) = 0;
virtual void OnSessionExpiration(const CdmSessionId& session_id) = 0;
private:
CORE_DISALLOW_COPY_AND_ASSIGN(WvCdmEventListener);

View File

@@ -53,11 +53,6 @@ enum CdmResponseType {
TypeName(const TypeName&); \
void operator=(const TypeName&)
enum CdmEventType {
LICENSE_EXPIRED_EVENT,
LICENSE_RENEWAL_NEEDED_EVENT
};
enum CdmLicenseType {
kLicenseTypeOffline,
kLicenseTypeStreaming,

View File

@@ -30,7 +30,8 @@ CdmSession::CdmSession(const CdmClientPropertySet* cdm_client_property_set,
event_listener_(event_listener),
license_parser_(new CdmLicense),
crypto_session_(new CryptoSession),
policy_engine_(new PolicyEngine(crypto_session_.get())),
policy_engine_(new PolicyEngine(session_id_, event_listener_,
crypto_session_.get())),
file_handle_(new DeviceFiles),
license_received_(false),
is_offline_(false),
@@ -519,9 +520,6 @@ void CdmSession::NotifyResolution(uint32_t width, uint32_t height) {
}
void CdmSession::OnTimerEvent(bool update_usage) {
bool event_occurred = false;
CdmEventType event;
if (update_usage && has_decrypted_since_last_report_) {
policy_engine_->DecryptionEvent();
has_decrypted_since_last_report_ = false;
@@ -529,17 +527,12 @@ void CdmSession::OnTimerEvent(bool update_usage) {
StoreLicense(DeviceFiles::kLicenseStateActive);
}
}
policy_engine_->OnTimerEvent(&event_occurred, &event);
if (event_occurred) {
if (event_listener_) event_listener_->OnEvent(session_id_, event);
}
policy_engine_->OnTimerEvent();
}
void CdmSession::OnKeyReleaseEvent(const CdmKeySetId& key_set_id) {
if (key_set_id_ == key_set_id) {
if (event_listener_)
event_listener_->OnEvent(session_id_, LICENSE_EXPIRED_EVENT);
if (event_listener_) event_listener_->OnSessionExpiration(session_id_);
}
}

View File

@@ -13,10 +13,13 @@
#include "properties.h"
#include "string_conversions.h"
#include "wv_cdm_constants.h"
#include "wv_cdm_event_listener.h"
namespace wvcdm {
PolicyEngine::PolicyEngine(CryptoSession* crypto_session)
PolicyEngine::PolicyEngine(CdmSessionId session_id,
WvCdmEventListener* event_listener,
CryptoSession* crypto_session)
: license_state_(kLicenseStateInitial),
can_decrypt_(false),
license_start_time_(0),
@@ -24,6 +27,8 @@ PolicyEngine::PolicyEngine(CryptoSession* crypto_session)
last_playback_time_(0),
next_renewal_time_(0),
policy_max_duration_seconds_(0),
session_id_(session_id),
event_listener_(event_listener),
max_res_engine_(crypto_session),
clock_(new Clock) {}
@@ -33,8 +38,7 @@ bool PolicyEngine::CanDecrypt(const KeyId& key_id) {
return can_decrypt_ && max_res_engine_.CanDecrypt(key_id);
}
void PolicyEngine::OnTimerEvent(bool* event_occurred, CdmEventType* event) {
*event_occurred = false;
void PolicyEngine::OnTimerEvent() {
int64_t current_time = clock_->GetCurrentTime();
// License expiration trumps all.
@@ -43,8 +47,7 @@ void PolicyEngine::OnTimerEvent(bool* event_occurred, CdmEventType* event) {
license_state_ != kLicenseStateExpired) {
license_state_ = kLicenseStateExpired;
can_decrypt_ = false;
*event = LICENSE_EXPIRED_EVENT;
*event_occurred = true;
if (event_listener_) event_listener_->OnSessionExpiration(session_id_);
return;
}
@@ -89,8 +92,7 @@ void PolicyEngine::OnTimerEvent(bool* event_occurred, CdmEventType* event) {
if (renewal_needed) {
UpdateRenewalRequest(current_time);
*event = LICENSE_RENEWAL_NEEDED_EVENT;
*event_occurred = true;
if (event_listener_) event_listener_->OnSessionRenewalNeeded(session_id_);
}
max_res_engine_.OnTimerEvent();

View File

@@ -114,7 +114,7 @@ class MockCryptoSession : public CryptoSession {
class MockPolicyEngine : public PolicyEngine {
public:
MockPolicyEngine() : PolicyEngine(NULL) {}
MockPolicyEngine() : PolicyEngine("mock_session_id", NULL, NULL) {}
// Leaving a place-holder for when PolicyEngine methods need to be mocked
};

View File

@@ -106,7 +106,8 @@ class MockCryptoSession : public CryptoSession {
class MockPolicyEngine : public PolicyEngine {
public:
MockPolicyEngine(CryptoSession* crypto) : PolicyEngine(crypto) {}
MockPolicyEngine(CryptoSession* crypto)
: PolicyEngine("mock_session_id", NULL, crypto) {}
};
class MockClock : public Clock {

File diff suppressed because it is too large Load Diff

View File

@@ -34,18 +34,6 @@ void PrintTo(const enum CdmResponseType& value, ::std::ostream* os) {
}
}
void PrintTo(const enum CdmEventType& value, ::std::ostream* os) {
switch (value) {
case LICENSE_EXPIRED_EVENT: *os << "LICENSE_EXPIRED_EVENT";
break;
case LICENSE_RENEWAL_NEEDED_EVENT: *os << "LICENSE_RENEWAL_NEEDED_EVENT";
break;
default:
*os << "Unknown CdmEventType";
break;
}
};
void PrintTo(const enum CdmLicenseType& value, ::std::ostream* os) {
switch (value) {
case kLicenseTypeOffline: *os << "kLicenseTypeOffline";

View File

@@ -10,7 +10,6 @@
namespace wvcdm {
void PrintTo(const enum CdmResponseType& value, ::std::ostream* os);
void PrintTo(const enum CdmEventType& value, ::std::ostream* os);
void PrintTo(const enum CdmLicenseType& value, ::std::ostream* os);
void PrintTo(const enum CdmSecurityLevel& value, ::std::ostream* os);
void PrintTo(const enum CdmCertificateType& value, ::std::ostream* os);