Merge Tweaks Originating in Merge Review Comments

This merges several small changes that were made in response to
comments that arose when LMP changes were merged into the Widevine
repository's master branch.

Change-Id: Ifec968af54dbc3288f24654ec0c6ca9b5962e1aa
This commit is contained in:
John "Juce" Bruce
2015-03-10 15:22:11 -07:00
parent fb6d83398c
commit 1bd405fc40
11 changed files with 32 additions and 52 deletions

View File

@@ -142,7 +142,7 @@ class CdmEngine {
// We assume that the WvCdmEventListener is asynchronous -- i.e. an event // We assume that the WvCdmEventListener is asynchronous -- i.e. an event
// should be dispatched to another thread which actually does the work. In // should be dispatched to another thread which actually does the work. In
// particular, if a syncrhonous listener calls OpenSession or CloseSession, // particular, if a synchronous listener calls OpenSession or CloseSession,
// the thread will dead lock. // the thread will dead lock.
// Returns false if listener already attached. // Returns false if listener already attached.
virtual bool AttachEventListener(const CdmSessionId& session_id, virtual bool AttachEventListener(const CdmSessionId& session_id,

View File

@@ -134,7 +134,7 @@ class CdmSession {
// decryption and usage flags // decryption and usage flags
bool is_initial_decryption_; bool is_initial_decryption_;
bool has_decrypted_recently_; bool has_decrypted_since_last_report_; // ... last report to policy engine.
bool is_initial_usage_update_; bool is_initial_usage_update_;
bool is_usage_update_needed_; bool is_usage_update_needed_;

View File

@@ -13,7 +13,7 @@ class WvCdmEngineTest;
class InitializationData { class InitializationData {
public: public:
InitializationData(const std::string& type, InitializationData(const std::string& type = std::string(),
const CdmInitData& data = CdmInitData()); const CdmInitData& data = CdmInitData());
bool is_supported() const { return is_cenc_ || is_webm_; } bool is_supported() const { return is_cenc_ || is_webm_; }

View File

@@ -74,11 +74,12 @@ class MaxResEngine {
bool can_decrypt_; bool can_decrypt_;
scoped_ptr<CryptoSession::OemCryptoHdcpVersion> default_hdcp_level_; CryptoSession::OemCryptoHdcpVersion default_hdcp_level_;
ConstraintList constraints_; ConstraintList constraints_;
}; };
typedef std::map<wvcdm::KeyId, KeyStatus*>::const_iterator KeyIterator; typedef std::map<wvcdm::KeyId,
wvcdm::MaxResEngine::KeyStatus*>::const_iterator KeyIterator;
void Init(CryptoSession* crypto_session, Clock* clock); void Init(CryptoSession* crypto_session, Clock* clock);

View File

@@ -22,7 +22,7 @@ std::string HexEncode(const uint8_t* bytes, unsigned size);
std::string IntToString(int value); std::string IntToString(int value);
std::string UintToString(unsigned int value); std::string UintToString(unsigned int value);
int64_t htonll64(int64_t x); int64_t htonll64(int64_t x);
int64_t ntohll64(int64_t x); inline int64_t ntohll64(int64_t x) { return htonll64(x); }
} // namespace wvcdm } // namespace wvcdm

View File

@@ -40,9 +40,7 @@ class UsagePropertySet : public CdmClientPropertySet {
virtual const std::string& service_certificate() const { return empty_; } virtual const std::string& service_certificate() const { return empty_; }
virtual bool is_session_sharing_enabled() const { return false; } virtual bool is_session_sharing_enabled() const { return false; }
virtual uint32_t session_sharing_id() const { return 0; } virtual uint32_t session_sharing_id() const { return 0; }
virtual void set_session_sharing_id(uint32_t id) { virtual void set_session_sharing_id(uint32_t /* id */) {}
id; // noop to suppress warning
}
virtual const std::string& app_id() const { return app_id_; } virtual const std::string& app_id() const { return app_id_; }
void set_app_id(const std::string& appId) { app_id_ = appId; } void set_app_id(const std::string& appId) { app_id_ = appId; }

View File

@@ -72,7 +72,7 @@ void CdmSession::Create(CdmLicense* license_parser,
is_initial_usage_update_ = true; is_initial_usage_update_ = true;
is_usage_update_needed_ = false; is_usage_update_needed_ = false;
is_initial_decryption_ = true; is_initial_decryption_ = true;
has_decrypted_recently_ = false; has_decrypted_since_last_report_ = false;
if (cdm_client_property_set) { if (cdm_client_property_set) {
Properties::AddSessionPropertySet(session_id_, cdm_client_property_set); Properties::AddSessionPropertySet(session_id_, cdm_client_property_set);
} }
@@ -340,6 +340,8 @@ CdmResponseType CdmSession::Decrypt(const CdmDecryptionParameters& params) {
if (crypto_session_.get() == NULL || !crypto_session_->IsOpen()) if (crypto_session_.get() == NULL || !crypto_session_->IsOpen())
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
// Playback may not begin until either the start time passes or the license
// is updated, so we treat this Decrypt call as invalid and return KEY_ERROR.
if (params.is_encrypted && !policy_engine_->CanDecrypt(*params.key_id)) { if (params.is_encrypted && !policy_engine_->CanDecrypt(*params.key_id)) {
return policy_engine_->IsLicenseForFuture() ? KEY_ERROR : NEED_KEY; return policy_engine_->IsLicenseForFuture() ? KEY_ERROR : NEED_KEY;
} }
@@ -352,7 +354,7 @@ CdmResponseType CdmSession::Decrypt(const CdmDecryptionParameters& params) {
policy_engine_->BeginDecryption(); policy_engine_->BeginDecryption();
is_initial_decryption_ = false; is_initial_decryption_ = false;
} }
has_decrypted_recently_ = true; has_decrypted_since_last_report_ = true;
if (!is_usage_update_needed_) { if (!is_usage_update_needed_) {
is_usage_update_needed_ = is_usage_update_needed_ =
!license_parser_->provider_session_token().empty(); !license_parser_->provider_session_token().empty();
@@ -368,9 +370,6 @@ CdmResponseType CdmSession::Decrypt(const CdmDecryptionParameters& params) {
} }
break; break;
} }
default: { //Ignore
break;
}
} }
return status; return status;
@@ -557,9 +556,9 @@ void CdmSession::OnTimerEvent(bool update_usage) {
bool event_occurred = false; bool event_occurred = false;
CdmEventType event; CdmEventType event;
if (update_usage && has_decrypted_recently_) { if (update_usage && has_decrypted_since_last_report_) {
policy_engine_->DecryptionEvent(); policy_engine_->DecryptionEvent();
has_decrypted_recently_ = false; has_decrypted_since_last_report_ = false;
if (is_offline_ && !is_release_) { if (is_offline_ && !is_release_) {
StoreLicense(DeviceFiles::kLicenseStateActive); StoreLicense(DeviceFiles::kLicenseStateActive);
} }

View File

@@ -14,12 +14,11 @@ const uint32_t kNoResolution = 0;
namespace wvcdm { namespace wvcdm {
MaxResEngine::MaxResEngine(CryptoSession* crypto_session) : status_lock_() { MaxResEngine::MaxResEngine(CryptoSession* crypto_session) {
Init(crypto_session, new Clock()); Init(crypto_session, new Clock());
} }
MaxResEngine::MaxResEngine(CryptoSession* crypto_session, Clock* clock) MaxResEngine::MaxResEngine(CryptoSession* crypto_session, Clock* clock) {
: status_lock_() {
Init(crypto_session, clock); Init(crypto_session, clock);
} }
@@ -51,8 +50,8 @@ void MaxResEngine::SetLicense(
const video_widevine_server::sdk::License& license) { const video_widevine_server::sdk::License& license) {
AutoLock lock(status_lock_); AutoLock lock(status_lock_);
DeleteAllKeys(); DeleteAllKeys();
for (int32_t key_iter = 0; key_iter < license.key_size(); ++key_iter) { for (int32_t key_index = 0; key_index < license.key_size(); ++key_index) {
const KeyContainer& key = license.key(key_iter); const KeyContainer& key = license.key(key_index);
if (key.type() == KeyContainer::CONTENT && key.has_id() && if (key.type() == KeyContainer::CONTENT && key.has_id() &&
key.video_resolution_constraints_size() > 0) { key.video_resolution_constraints_size() > 0) {
const ConstraintList& constraints = key.video_resolution_constraints(); const ConstraintList& constraints = key.video_resolution_constraints();
@@ -96,15 +95,14 @@ void MaxResEngine::DeleteAllKeys() {
} }
MaxResEngine::KeyStatus::KeyStatus(const ConstraintList& constraints) MaxResEngine::KeyStatus::KeyStatus(const ConstraintList& constraints)
: default_hdcp_level_(NULL) { : default_hdcp_level_(CryptoSession::kOemCryptoHdcpNotSupported) {
Init(constraints); Init(constraints);
} }
MaxResEngine::KeyStatus::KeyStatus( MaxResEngine::KeyStatus::KeyStatus(
const ConstraintList& constraints, const ConstraintList& constraints,
const OutputProtection::HDCP& default_hdcp_level) { const OutputProtection::HDCP& default_hdcp_level)
default_hdcp_level_.reset(new CryptoSession::OemCryptoHdcpVersion( : default_hdcp_level_(ProtobufHdcpToOemCryptoHdcp(default_hdcp_level)) {
ProtobufHdcpToOemCryptoHdcp(default_hdcp_level)));
Init(constraints); Init(constraints);
} }
@@ -127,14 +125,9 @@ void MaxResEngine::KeyStatus::Update(
if (current_constraint->has_required_protection()) { if (current_constraint->has_required_protection()) {
desired_hdcp_level = ProtobufHdcpToOemCryptoHdcp( desired_hdcp_level = ProtobufHdcpToOemCryptoHdcp(
current_constraint->required_protection().hdcp()); current_constraint->required_protection().hdcp());
} else if (default_hdcp_level_.get() != NULL) {
desired_hdcp_level = *default_hdcp_level_;
} else { } else {
// No constraint value and no default means there's nothing to enforce. desired_hdcp_level = default_hdcp_level_;
can_decrypt_ = true;
return;
} }
can_decrypt_ = (current_hdcp_level >= desired_hdcp_level); can_decrypt_ = (current_hdcp_level >= desired_hdcp_level);
} }

View File

@@ -185,21 +185,4 @@ int64_t htonll64(int64_t x) { // Convert to big endian (network-byte-order)
} }
} }
int64_t ntohll64(int64_t x) { // Convert from big endian (network-byte-order)
union {
uint32_t array[2];
int64_t number;
} mixed;
mixed.number = 1;
if (mixed.array[0] == 1) { // Little Endian.
mixed.number = x;
uint32_t temp = mixed.array[0];
mixed.array[0] = ntohl(mixed.array[1]);
mixed.array[1] = ntohl(temp);
return mixed.number;
} else { // Big Endian.
return x;
}
}
} // namespace wvcdm } // namespace wvcdm

View File

@@ -1098,8 +1098,7 @@ TEST_P(WvCdmStreamingUsageReportTest, UsageTest) {
uint32_t num_usage_info = 0; uint32_t num_usage_info = 0;
CdmUsageInfo usage_info; CdmUsageInfo usage_info;
CdmUsageInfoReleaseMessage release_msg; CdmUsageInfoReleaseMessage release_msg;
std::string app_id; CdmResponseType status = decryptor_.GetUsageInfo("", &usage_info);
CdmResponseType status = decryptor_.GetUsageInfo(app_id, &usage_info);
EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status); EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status);
while (usage_info.size() > 0) { while (usage_info.size() > 0) {
for (size_t i = 0; i < usage_info.size(); ++i) { for (size_t i = 0; i < usage_info.size(); ++i) {
@@ -1111,7 +1110,7 @@ TEST_P(WvCdmStreamingUsageReportTest, UsageTest) {
GetUsageInfoResponse(g_license_server, g_client_auth, usage_info[i]); GetUsageInfoResponse(g_license_server, g_client_auth, usage_info[i]);
EXPECT_EQ(NO_ERROR, decryptor_.ReleaseUsageInfo(release_msg)); EXPECT_EQ(NO_ERROR, decryptor_.ReleaseUsageInfo(release_msg));
} }
status = decryptor_.GetUsageInfo(app_id, &usage_info); status = decryptor_.GetUsageInfo("", &usage_info);
switch (status) { switch (status) {
case KEY_MESSAGE: case KEY_MESSAGE:
EXPECT_FALSE(usage_info.empty()); EXPECT_FALSE(usage_info.empty());

View File

@@ -1559,9 +1559,16 @@ TEST_F(WvCdmRequestLicenseTest, SecurityLevelPathBackwardCompatibility) {
TestWvCdmClientPropertySet property_set; TestWvCdmClientPropertySet property_set;
property_set.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3); property_set.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3);
EXPECT_EQ(wvcdm::NEED_PROVISIONING, EXPECT_EQ(NO_ERROR,
decryptor_.OpenSession(g_key_system, &property_set, &session_id_)); decryptor_.OpenSession(g_key_system, &property_set, &session_id_));
wvcdm::CdmAppParameterMap app_parameters;
std::string server_url;
EXPECT_EQ(wvcdm::NEED_PROVISIONING,
decryptor_.GenerateKeyRequest(session_id_, key_set_id, "video/mp4",
key_id, kLicenseTypeStreaming,
app_parameters, NULL, &key_msg_,
&server_url));
EXPECT_EQ(NO_ERROR, decryptor_.GetProvisioningRequest( EXPECT_EQ(NO_ERROR, decryptor_.GetProvisioningRequest(
cert_type, cert_authority, &key_msg_, cert_type, cert_authority, &key_msg_,
&provisioning_server_url)); &provisioning_server_url));