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:
KongQun Yang
2015-03-16 19:46:11 -07:00
parent 69d7ffb22d
commit fddbc89136
16 changed files with 237 additions and 494 deletions

View File

@@ -32,11 +32,13 @@ class CdmEngine {
// Session related methods
virtual CdmResponseType OpenSession(const CdmKeySystem& key_system,
const CdmClientPropertySet* property_set,
WvCdmEventListener* event_listener,
CdmSessionId* session_id);
virtual CdmResponseType CloseSession(const CdmSessionId& session_id);
virtual CdmResponseType OpenKeySetSession(
const CdmKeySetId& key_set_id, const CdmClientPropertySet* property_set);
const CdmKeySetId& key_set_id, const CdmClientPropertySet* property_set,
WvCdmEventListener* event_listener);
virtual CdmResponseType CloseKeySetSession(const CdmKeySetId& key_set_id);
// License related methods
@@ -138,25 +140,17 @@ class CdmEngine {
virtual bool IsKeyLoaded(const KeyId& key_id);
virtual bool FindSessionForKey(const KeyId& key_id, CdmSessionId* sessionId);
// Event listener related methods.
// We assume that the WvCdmEventListener is asynchronous -- i.e. an event
// should be dispatched to another thread which actually does the work. In
// particular, if a synchronous listener calls OpenSession or CloseSession,
// the thread will dead lock.
// Returns false if listener already attached.
virtual bool AttachEventListener(const CdmSessionId& session_id,
WvCdmEventListener* listener);
// Returns true if listener was detached.
virtual bool DetachEventListener(const CdmSessionId& session_id,
WvCdmEventListener* listener);
// Used for notifying the Max-Res Engine of resolution changes
virtual void NotifyResolution(const CdmSessionId& session_id, uint32_t width,
uint32_t height);
// Timer expiration method. This method is not re-entrant -- there can be
// only one timer.
// This method triggers appropriate event callbacks from |event_listener_|,
// which is assumed to be asynchronous -- i.e. an event should be dispatched
// to another thread which does the actual work. In particular, if a
// synchronous listener calls OpenSession or CloseSession, the thread will
// dead lock.
virtual void OnTimerEvent();
private:

View File

@@ -21,7 +21,8 @@ class WvCdmEventListener;
class CdmSession {
public:
explicit CdmSession(const CdmClientPropertySet* cdm_client_property_set);
CdmSession(const CdmClientPropertySet* cdm_client_property_set,
WvCdmEventListener* event_listener);
virtual ~CdmSession();
virtual CdmResponseType Init();
@@ -74,10 +75,6 @@ class CdmSession {
virtual bool IsKeyLoaded(const KeyId& key_id);
// See comments for CdmEngine::AttachEventListener/DetachEventListener.
virtual bool AttachEventListener(WvCdmEventListener* listener);
virtual bool DetachEventListener(WvCdmEventListener* listener);
// Used for notifying the Policy Engine of resolution changes
virtual void NotifyResolution(uint32_t width, uint32_t height);
@@ -112,10 +109,7 @@ class CdmSession {
bool DeleteLicense();
private:
// Internal constructor
void Create(CdmLicense* license_parser, CryptoSession* crypto_session,
PolicyEngine* policy_engine, DeviceFiles* file_handle,
const CdmClientPropertySet* cdm_client_property_set);
friend class CdmSessionTest;
// Generate unique ID for each new session.
CdmSessionId GenerateSessionId();
@@ -123,9 +117,17 @@ class CdmSession {
CdmResponseType StoreLicense();
bool StoreLicense(DeviceFiles::LicenseState state);
// These setters are for testing only. Takes ownership of the pointers.
void set_license_parser(CdmLicense* license_parser);
void set_crypto_session(CryptoSession* crypto_session);
void set_policy_engine(PolicyEngine* policy_engine);
void set_file_handle(DeviceFiles* file_handle);
// instance variables
bool initialized_;
CdmSessionId session_id_;
WvCdmEventListener* event_listener_;
scoped_ptr<CdmLicense> license_parser_;
scoped_ptr<CryptoSession> crypto_session_;
scoped_ptr<PolicyEngine> policy_engine_;
@@ -156,18 +158,6 @@ class CdmSession {
// license type release and offline related information
CdmKeySetId key_set_id_;
std::set<WvCdmEventListener*> listeners_;
// For testing only
// Takes ownership of license_parser, crypto_session, policy_engine
// and device_files
CdmSession(CdmLicense* license_parser, CryptoSession* crypto_session,
PolicyEngine* policy_engine, DeviceFiles* file_handle,
const CdmClientPropertySet* cdm_client_property_set);
#if defined(UNIT_TEST)
friend class CdmSessionTest;
#endif
CORE_DISALLOW_COPY_AND_ASSIGN(CdmSession);
};

View File

@@ -7,6 +7,7 @@
#include "license_protocol.pb.h"
#include "max_res_engine.h"
#include "scoped_ptr.h"
#include "wv_cdm_types.h"
namespace wvcdm {
@@ -15,7 +16,6 @@ using video_widevine_server::sdk::LicenseIdentification;
class Clock;
class CryptoSession;
class PolicyEngineTest;
// This acts as an oracle that basically says "Yes(true) you may still decrypt
// or no(false) you may not decrypt this data anymore."
@@ -78,6 +78,8 @@ class PolicyEngine {
bool IsLicenseForFuture() { return license_state_ == kLicenseStatePending; }
private:
friend class PolicyEngineTest;
typedef enum {
kLicenseStateInitial,
kLicenseStatePending, // if license is issued for sometime in the future
@@ -87,8 +89,6 @@ class PolicyEngine {
kLicenseStateExpired
} LicenseState;
void Init(Clock* clock);
int64_t GetLicenseDurationRemaining(int64_t current_time);
int64_t GetPlaybackDurationRemaining(int64_t current_time);
@@ -98,6 +98,9 @@ class PolicyEngine {
void UpdateRenewalRequest(int64_t current_time);
// These setters are for testing only. Takes ownership of the pointers.
void set_clock(Clock* clock);
LicenseState license_state_;
bool can_decrypt_;
@@ -124,11 +127,7 @@ class PolicyEngine {
int64_t policy_max_duration_seconds_;
MaxResEngine max_res_engine_;
Clock* clock_;
// For testing
friend class PolicyEngineTest;
PolicyEngine(CryptoSession* crypto_session, Clock* clock);
scoped_ptr<Clock> clock_;
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyEngine);
};

View File

@@ -8,9 +8,6 @@
namespace wvcdm {
// Listener for events from the Content Decryption Module.
// The caller of the CDM API must provide an implementation for OnEvent
// and signal its intent by using the Attach/DetachEventListener methods
// in the WvContentDecryptionModule class.
class WvCdmEventListener {
public:
WvCdmEventListener() {}