summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorjrummell <jrummell@chromium.org>2015-06-19 17:47:34 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-20 00:48:18 +0000
commit3b08f4973d951753a94c51ec934e01ff3a214a04 (patch)
tree07c7b665242a6d6a14535adc8a8bfc4150bf208f /media
parent4e2ecb71332584b846862653ac1b8ea2490b29b7 (diff)
downloadchromium_src-3b08f4973d951753a94c51ec934e01ff3a214a04.zip
chromium_src-3b08f4973d951753a94c51ec934e01ff3a214a04.tar.gz
chromium_src-3b08f4973d951753a94c51ec934e01ff3a214a04.tar.bz2
Use 'pssh' data to determine key_id properly
Required regenerating the test files to use Common System format for the relevant 'pssh' box. BUG=460308 TEST=modified tests pass Review URL: https://codereview.chromium.org/1163713007 Cr-Commit-Position: refs/heads/master@{#335405}
Diffstat (limited to 'media')
-rw-r--r--media/cdm/cenc_utils.cc6
-rw-r--r--media/cdm/cenc_utils.h4
-rw-r--r--media/cdm/cenc_utils_unittest.cc50
-rw-r--r--media/test/data/bear-1280x720-a_frag-cenc-key_rotation.mp4bin27968 -> 80032 bytes
-rw-r--r--media/test/data/bear-1280x720-a_frag-cenc.mp4bin39179 -> 74428 bytes
-rw-r--r--media/test/data/bear-1280x720-a_frag-cenc_clear-all.mp4bin38277 -> 73304 bytes
-rw-r--r--media/test/data/bear-1280x720-v_frag-cenc-key_rotation.mp4bin739639 -> 882629 bytes
-rw-r--r--media/test/data/bear-1280x720-v_frag-cenc.mp4bin759524 -> 877947 bytes
-rw-r--r--media/test/data/bear-1280x720-v_frag-cenc_clear-all.mp4bin758226 -> 876484 bytes
-rw-r--r--media/test/data/bear-640x360-a_frag-cenc-key_rotation.mp4bin27968 -> 80372 bytes
-rw-r--r--media/test/data/bear-640x360-a_frag-cenc.mp4bin39179 -> 74768 bytes
-rw-r--r--media/test/data/bear-640x360-v_frag-cenc-key_rotation.mp4bin176963 -> 280361 bytes
-rw-r--r--media/test/data/bear-640x360-v_frag-cenc.mp4bin279399 -> 275679 bytes
-rw-r--r--media/test/pipeline_integration_test.cc183
14 files changed, 112 insertions, 131 deletions
diff --git a/media/cdm/cenc_utils.cc b/media/cdm/cenc_utils.cc
index 495a6f2..1e33cca 100644
--- a/media/cdm/cenc_utils.cc
+++ b/media/cdm/cenc_utils.cc
@@ -89,12 +89,8 @@ bool GetKeyIdsForCommonSystemId(const std::vector<uint8_t>& input,
}
}
- // No matching 'pssh' box found.
- // TODO(jrummell): This should return true only if there was at least one
- // key ID present. However, numerous test files don't contain the 'pssh' box
- // for Common Format, so no keys are found. http://crbug.com/460308
key_ids->swap(result);
- return true;
+ return key_ids->size() > 0;
}
bool GetPsshData(const std::vector<uint8_t>& input,
diff --git a/media/cdm/cenc_utils.h b/media/cdm/cenc_utils.h
index 7dd82a1..8938fb9 100644
--- a/media/cdm/cenc_utils.h
+++ b/media/cdm/cenc_utils.h
@@ -21,10 +21,6 @@ MEDIA_EXPORT bool ValidatePsshInput(const std::vector<uint8_t>& input);
// more concatenated 'pssh' boxes. If |input| looks valid, then true is
// returned and |key_ids| is updated to contain the values found. Otherwise
// return false.
-// TODO(jrummell): This returns true if no Common SystemID 'pssh' boxes are
-// found, or are included but don't contain any key IDs. This should be
-// fixed once the test files are updated to include correct 'pssh' boxes.
-// http://crbug.com/460308
MEDIA_EXPORT bool GetKeyIdsForCommonSystemId(const std::vector<uint8_t>& input,
KeyIdList* key_ids);
diff --git a/media/cdm/cenc_utils_unittest.cc b/media/cdm/cenc_utils_unittest.cc
index 3bc55cc..af6066a 100644
--- a/media/cdm/cenc_utils_unittest.cc
+++ b/media/cdm/cenc_utils_unittest.cc
@@ -180,24 +180,21 @@ class CencUtilsTest : public testing::Test {
TEST_F(CencUtilsTest, EmptyPSSH) {
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>()));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion0) {
std::vector<uint8_t> box = MakePSSHBox(0);
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) {
std::vector<uint8_t> box = MakePSSHBox(1);
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) {
@@ -258,6 +255,9 @@ TEST_F(CencUtilsTest, MultiplePSSHVersion1) {
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
+ // TODO(jrummell): GetKeyIdsForCommonSystemId() returns the key IDs out of
+ // all matching boxes. It should only return the key IDs from the first
+ // matching box.
EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
EXPECT_EQ(4u, key_ids.size());
EXPECT_EQ(key_ids[0], Key1());
@@ -266,31 +266,45 @@ TEST_F(CencUtilsTest, MultiplePSSHVersion1) {
EXPECT_EQ(key_ids[3], Key4());
}
-TEST_F(CencUtilsTest, InvalidPSSH) {
+TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) {
std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
KeyIdList key_ids;
+
+ // Tries every buffer size less than the indicated 'pssh' box size.
for (size_t i = 1; i < box.size(); ++i) {
- // Modify size of data passed to be less than real size.
+ // Truncate the box to be less than the specified box size.
std::vector<uint8_t> truncated(&box[0], &box[0] + i);
EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
- // Modify starting point.
- std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i);
- EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset "
- << i;
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids));
}
}
-TEST_F(CencUtilsTest, InvalidSystemID) {
+TEST_F(CencUtilsTest, PsshBoxLargerThanSize) {
+ std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
+ KeyIdList key_ids;
+
+ // Add 20 additional bytes to |box|.
+ size_t original_size = box.size();
+ for (size_t i = 0; i < 20; ++i)
+ box.push_back(i);
+
+ // Tries every size greater than |original_size|.
+ for (size_t i = original_size + 1; i < box.size(); ++i) {
+ // Modify size of box passed to be less than current size.
+ std::vector<uint8_t> truncated(&box[0], &box[0] + i);
+ EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
+ }
+}
+
+TEST_F(CencUtilsTest, UnrecognizedSystemID) {
std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
// Modify the System ID.
++box[20];
KeyIdList key_ids;
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
}
TEST_F(CencUtilsTest, InvalidFlags) {
@@ -328,7 +342,7 @@ TEST_F(CencUtilsTest, LongSize) {
EXPECT_EQ(2u, key_ids.size());
}
-TEST_F(CencUtilsTest, NoSize) {
+TEST_F(CencUtilsTest, SizeIsZero) {
const uint8_t data[] = {
0x00, 0x00, 0x00, 0x00, // size = 0
0x70, 0x73, 0x73, 0x68, // 'pssh'
@@ -370,6 +384,8 @@ TEST_F(CencUtilsTest, HugeSize) {
};
KeyIdList key_ids;
+ // These calls fail as the box size is huge (0xffffffffffffffff) and there
+ // is not enough bytes in |data|.
EXPECT_FALSE(
ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
EXPECT_FALSE(GetKeyIdsForCommonSystemId(
diff --git a/media/test/data/bear-1280x720-a_frag-cenc-key_rotation.mp4 b/media/test/data/bear-1280x720-a_frag-cenc-key_rotation.mp4
index c3af8d6..078ce0f 100644
--- a/media/test/data/bear-1280x720-a_frag-cenc-key_rotation.mp4
+++ b/media/test/data/bear-1280x720-a_frag-cenc-key_rotation.mp4
Binary files differ
diff --git a/media/test/data/bear-1280x720-a_frag-cenc.mp4 b/media/test/data/bear-1280x720-a_frag-cenc.mp4
index 8feea53..69f44a9 100644
--- a/media/test/data/bear-1280x720-a_frag-cenc.mp4
+++ b/media/test/data/bear-1280x720-a_frag-cenc.mp4
Binary files differ
diff --git a/media/test/data/bear-1280x720-a_frag-cenc_clear-all.mp4 b/media/test/data/bear-1280x720-a_frag-cenc_clear-all.mp4
index 81cdd58..7599dfe 100644
--- a/media/test/data/bear-1280x720-a_frag-cenc_clear-all.mp4
+++ b/media/test/data/bear-1280x720-a_frag-cenc_clear-all.mp4
Binary files differ
diff --git a/media/test/data/bear-1280x720-v_frag-cenc-key_rotation.mp4 b/media/test/data/bear-1280x720-v_frag-cenc-key_rotation.mp4
index a4deb82..5c3d26f 100644
--- a/media/test/data/bear-1280x720-v_frag-cenc-key_rotation.mp4
+++ b/media/test/data/bear-1280x720-v_frag-cenc-key_rotation.mp4
Binary files differ
diff --git a/media/test/data/bear-1280x720-v_frag-cenc.mp4 b/media/test/data/bear-1280x720-v_frag-cenc.mp4
index c4a6ae7..11e65c0 100644
--- a/media/test/data/bear-1280x720-v_frag-cenc.mp4
+++ b/media/test/data/bear-1280x720-v_frag-cenc.mp4
Binary files differ
diff --git a/media/test/data/bear-1280x720-v_frag-cenc_clear-all.mp4 b/media/test/data/bear-1280x720-v_frag-cenc_clear-all.mp4
index 47c83c4..c9f2f6b 100644
--- a/media/test/data/bear-1280x720-v_frag-cenc_clear-all.mp4
+++ b/media/test/data/bear-1280x720-v_frag-cenc_clear-all.mp4
Binary files differ
diff --git a/media/test/data/bear-640x360-a_frag-cenc-key_rotation.mp4 b/media/test/data/bear-640x360-a_frag-cenc-key_rotation.mp4
index 859b98b..dc4f197 100644
--- a/media/test/data/bear-640x360-a_frag-cenc-key_rotation.mp4
+++ b/media/test/data/bear-640x360-a_frag-cenc-key_rotation.mp4
Binary files differ
diff --git a/media/test/data/bear-640x360-a_frag-cenc.mp4 b/media/test/data/bear-640x360-a_frag-cenc.mp4
index 3bd6988..0e249c4 100644
--- a/media/test/data/bear-640x360-a_frag-cenc.mp4
+++ b/media/test/data/bear-640x360-a_frag-cenc.mp4
Binary files differ
diff --git a/media/test/data/bear-640x360-v_frag-cenc-key_rotation.mp4 b/media/test/data/bear-640x360-v_frag-cenc-key_rotation.mp4
index 157cf51..916c64e 100644
--- a/media/test/data/bear-640x360-v_frag-cenc-key_rotation.mp4
+++ b/media/test/data/bear-640x360-v_frag-cenc-key_rotation.mp4
Binary files differ
diff --git a/media/test/data/bear-640x360-v_frag-cenc.mp4 b/media/test/data/bear-640x360-v_frag-cenc.mp4
index eaf1684..1b63dd4 100644
--- a/media/test/data/bear-640x360-v_frag-cenc.mp4
+++ b/media/test/data/bear-640x360-v_frag-cenc.mp4
Binary files differ
diff --git a/media/test/pipeline_integration_test.cc b/media/test/pipeline_integration_test.cc
index 30543e1..71d0f3c 100644
--- a/media/test/pipeline_integration_test.cc
+++ b/media/test/pipeline_integration_test.cc
@@ -77,13 +77,13 @@ const char kMP3[] = "audio/mpeg";
#endif // defined(USE_PROPRIETARY_CODECS)
// Key used to encrypt test files.
-const uint8 kSecretKey[] = {
+const uint8_t kSecretKey[] = {
0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c
};
// The key ID for all encrypted files.
-const uint8 kKeyId[] = {
+const uint8_t kKeyId[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35
};
@@ -153,8 +153,9 @@ class FakeEncryptedMedia {
virtual void OnSessionMessage(const std::string& session_id,
MediaKeys::MessageType message_type,
- const std::vector<uint8>& message,
- const GURL& legacy_destination_url) = 0;
+ const std::vector<uint8_t>& message,
+ const GURL& legacy_destination_url,
+ AesDecryptor* decryptor) = 0;
virtual void OnSessionClosed(const std::string& session_id) = 0;
@@ -165,13 +166,13 @@ class FakeEncryptedMedia {
// Errors are not expected unless overridden.
virtual void OnLegacySessionError(const std::string& session_id,
const std::string& error_name,
- uint32 system_code,
+ uint32_t system_code,
const std::string& error_message) {
FAIL() << "Unexpected Key Error";
}
virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
- const std::vector<uint8>& init_data,
+ const std::vector<uint8_t>& init_data,
AesDecryptor* decryptor) = 0;
};
@@ -191,10 +192,10 @@ class FakeEncryptedMedia {
// Callbacks for firing session events. Delegate to |app_|.
void OnSessionMessage(const std::string& session_id,
MediaKeys::MessageType message_type,
- const std::vector<uint8>& message,
+ const std::vector<uint8_t>& message,
const GURL& legacy_destination_url) {
app_->OnSessionMessage(session_id, message_type, message,
- legacy_destination_url);
+ legacy_destination_url, &decryptor_);
}
void OnSessionClosed(const std::string& session_id) {
@@ -210,14 +211,14 @@ class FakeEncryptedMedia {
void OnLegacySessionError(const std::string& session_id,
const std::string& error_name,
- uint32 system_code,
+ uint32_t system_code,
const std::string& error_message) {
app_->OnLegacySessionError(session_id, error_name, system_code,
error_message);
}
void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
- const std::vector<uint8>& init_data) {
+ const std::vector<uint8_t>& init_data) {
app_->OnEncryptedMediaInitData(init_data_type, init_data, &decryptor_);
}
@@ -258,7 +259,7 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
void OnReject(PromiseResult expected,
media::MediaKeys::Exception exception_code,
- uint32 system_code,
+ uint32_t system_code,
const std::string& error_message) {
EXPECT_EQ(expected, REJECTED) << error_message;
}
@@ -286,11 +287,35 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
void OnSessionMessage(const std::string& session_id,
MediaKeys::MessageType message_type,
- const std::vector<uint8>& message,
- const GURL& legacy_destination_url) override {
+ const std::vector<uint8_t>& message,
+ const GURL& legacy_destination_url,
+ AesDecryptor* decryptor) override {
EXPECT_FALSE(session_id.empty());
EXPECT_FALSE(message.empty());
EXPECT_EQ(current_session_id_, session_id);
+ EXPECT_EQ(MediaKeys::MessageType::LICENSE_REQUEST, message_type);
+
+ // Extract the key ID from |message|. For Clear Key this is a JSON object
+ // containing a set of "kids". There should only be 1 key ID in |message|.
+ std::string message_string(message.begin(), message.end());
+ KeyIdList key_ids;
+ std::string error_message;
+ EXPECT_TRUE(ExtractKeyIdsFromKeyIdsInitData(message_string, &key_ids,
+ &error_message))
+ << error_message;
+ EXPECT_EQ(1u, key_ids.size());
+
+ // Determine the key that matches the key ID |key_ids[0]|.
+ std::vector<uint8_t> key;
+ EXPECT_TRUE(LookupKey(key_ids[0], &key));
+
+ // Update the session with the key ID and key.
+ std::string jwk =
+ GenerateJWKSet(vector_as_array(&key), key.size(),
+ vector_as_array(&key_ids[0]), key_ids[0].size());
+ decryptor->UpdateSession(session_id,
+ std::vector<uint8_t>(jwk.begin(), jwk.end()),
+ CreatePromise(RESOLVED));
}
void OnSessionClosed(const std::string& session_id) override {
@@ -305,7 +330,7 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
}
void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
- const std::vector<uint8>& init_data,
+ const std::vector<uint8_t>& init_data,
AesDecryptor* decryptor) override {
// Since only 1 session is created, skip the request if the |init_data|
// has been seen before (no need to add the same key again).
@@ -314,114 +339,62 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
prev_init_data_ = init_data;
if (current_session_id_.empty()) {
- if (init_data_type == EmeInitDataType::CENC) {
- // Since the 'cenc' files are not created with proper 'pssh' boxes,
- // simply pretend that this is a webm file and pass the expected
- // key ID as the init_data.
- // http://crbug.com/460308
- decryptor->CreateSessionAndGenerateRequest(
- MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
- std::vector<uint8>(kKeyId, kKeyId + arraysize(kKeyId)),
- CreateSessionPromise(RESOLVED));
- } else {
- decryptor->CreateSessionAndGenerateRequest(
- MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
- CreateSessionPromise(RESOLVED));
- }
+ decryptor->CreateSessionAndGenerateRequest(
+ MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
+ CreateSessionPromise(RESOLVED));
EXPECT_FALSE(current_session_id_.empty());
}
+ }
- // Clear Key really needs the key ID from |init_data|. For WebM, they are
- // the same, but this is not the case for ISO CENC (key ID embedded in a
- // 'pssh' box). Therefore, provide the correct key ID.
- const uint8* key_id = vector_as_array(&init_data);
- size_t key_id_length = init_data.size();
- if (init_data_type == EmeInitDataType::CENC) {
- key_id = kKeyId;
- key_id_length = arraysize(kKeyId);
- }
-
- // Convert key into a JSON structure and then add it.
- std::string jwk = GenerateJWKSet(
- kSecretKey, arraysize(kSecretKey), key_id, key_id_length);
- decryptor->UpdateSession(current_session_id_,
- std::vector<uint8>(jwk.begin(), jwk.end()),
- CreatePromise(RESOLVED));
+ virtual bool LookupKey(const std::vector<uint8_t>& key_id,
+ std::vector<uint8_t>* key) {
+ // As there is no key rotation, the key ID provided should be |kKeyId|
+ // which uses |kSecretKey| as the key.
+ EXPECT_EQ(std::vector<uint8_t>(kKeyId, kKeyId + arraysize(kKeyId)), key_id);
+ key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
+ return true;
}
std::string current_session_id_;
- std::vector<uint8> prev_init_data_;
+ std::vector<uint8_t> prev_init_data_;
};
class RotatingKeyProvidingApp : public KeyProvidingApp {
public:
- RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {}
+ RotatingKeyProvidingApp() : num_distinct_need_key_calls_(0) {}
~RotatingKeyProvidingApp() override {
// Expect that OnEncryptedMediaInitData is fired multiple times with
// different |init_data|.
- EXPECT_GT(num_distint_need_key_calls_, 1u);
+ EXPECT_GT(num_distinct_need_key_calls_, 1u);
}
void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
- const std::vector<uint8>& init_data,
+ const std::vector<uint8_t>& init_data,
AesDecryptor* decryptor) override {
// Skip the request if the |init_data| has been seen.
if (init_data == prev_init_data_)
return;
prev_init_data_ = init_data;
- ++num_distint_need_key_calls_;
-
- std::vector<uint8> key_id;
- std::vector<uint8> key;
- EXPECT_TRUE(GetKeyAndKeyId(init_data, &key, &key_id));
+ ++num_distinct_need_key_calls_;
- if (init_data_type == EmeInitDataType::CENC) {
- // Since the 'cenc' files are not created with proper 'pssh' boxes,
- // simply pretend that this is a webm file and pass the expected
- // key ID as the init_data.
- // http://crbug.com/460308
- decryptor->CreateSessionAndGenerateRequest(
- MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, key_id,
- CreateSessionPromise(RESOLVED));
- } else {
- decryptor->CreateSessionAndGenerateRequest(
- MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
- CreateSessionPromise(RESOLVED));
- }
-
- // Convert key into a JSON structure and then add it.
- std::string jwk = GenerateJWKSet(vector_as_array(&key),
- key.size(),
- vector_as_array(&key_id),
- key_id.size());
- decryptor->UpdateSession(current_session_id_,
- std::vector<uint8>(jwk.begin(), jwk.end()),
- CreatePromise(RESOLVED));
+ decryptor->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
+ init_data_type, init_data,
+ CreateSessionPromise(RESOLVED));
}
- private:
- bool GetKeyAndKeyId(std::vector<uint8> init_data,
- std::vector<uint8>* key,
- std::vector<uint8>* key_id) {
- // For WebM, init_data is key_id; for ISO CENC, init_data should contain
- // the key_id. We assume key_id is in the end of init_data here (that is
- // only a reasonable assumption for WebM and clear key ISO CENC).
- DCHECK_GE(init_data.size(), arraysize(kKeyId));
- std::vector<uint8> key_id_from_init_data(
- init_data.end() - arraysize(kKeyId), init_data.end());
-
- key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
- key_id->assign(kKeyId, kKeyId + arraysize(kKeyId));
-
+ bool LookupKey(const std::vector<uint8_t>& key_id,
+ std::vector<uint8_t>* key) override {
// The Key and KeyId for this testing key provider are created by left
- // rotating kSecretKey and kKeyId. Note that this implementation is only
- // intended for testing purpose. The actual key rotation algorithm can be
- // much more complicated.
- // Find out the rotating position from |key_id_from_init_data| and apply on
- // |key|.
- for (size_t pos = 0; pos < arraysize(kKeyId); ++pos) {
- std::rotate(key_id->begin(), key_id->begin() + pos, key_id->end());
- if (*key_id == key_id_from_init_data) {
+ // rotating |kSecretKey| and |kKeyId|. Note that this implementation is
+ // only intended for testing purpose. The actual key rotation algorithm
+ // can be much more complicated.
+ // Find out the rotating position from |starting_key_id| and apply on |key|.
+ std::vector<uint8_t> starting_key_id(kKeyId, kKeyId + arraysize(kKeyId));
+ for (size_t pos = 0; pos < starting_key_id.size(); ++pos) {
+ std::rotate(starting_key_id.begin(), starting_key_id.begin() + pos,
+ starting_key_id.end());
+ if (key_id == starting_key_id) {
+ key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
std::rotate(key->begin(), key->begin() + pos, key->end());
return true;
}
@@ -429,8 +402,7 @@ class RotatingKeyProvidingApp : public KeyProvidingApp {
return false;
}
- std::vector<uint8> prev_init_data_;
- uint32 num_distint_need_key_calls_;
+ uint32_t num_distinct_need_key_calls_;
};
// Ignores needkey and does not perform a license request
@@ -438,8 +410,9 @@ class NoResponseApp : public FakeEncryptedMedia::AppBase {
public:
void OnSessionMessage(const std::string& session_id,
MediaKeys::MessageType message_type,
- const std::vector<uint8>& message,
- const GURL& legacy_destination_url) override {
+ const std::vector<uint8_t>& message,
+ const GURL& legacy_destination_url,
+ AesDecryptor* decryptor) override {
EXPECT_FALSE(session_id.empty());
EXPECT_FALSE(message.empty());
FAIL() << "Unexpected Message";
@@ -458,7 +431,7 @@ class NoResponseApp : public FakeEncryptedMedia::AppBase {
}
void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
- const std::vector<uint8>& init_data,
+ const std::vector<uint8_t>& init_data,
AesDecryptor* decryptor) override {}
};
@@ -526,7 +499,7 @@ class MockMediaSource {
}
void AppendAtTime(base::TimeDelta timestamp_offset,
- const uint8* pData,
+ const uint8_t* pData,
int size) {
CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
chunk_demuxer_->AppendData(kSourceId, pData, size,
@@ -540,7 +513,7 @@ class MockMediaSource {
void AppendAtTimeWithWindow(base::TimeDelta timestamp_offset,
base::TimeDelta append_window_start,
base::TimeDelta append_window_end,
- const uint8* pData,
+ const uint8_t* pData,
int size) {
CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
chunk_demuxer_->AppendData(kSourceId,
@@ -602,7 +575,7 @@ class MockMediaSource {
}
void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
- const std::vector<uint8>& init_data) {
+ const std::vector<uint8_t>& init_data) {
DCHECK(!init_data.empty());
CHECK(!encrypted_media_init_data_cb_.is_null());
encrypted_media_init_data_cb_.Run(init_data_type, init_data);