summaryrefslogtreecommitdiffstats
path: root/media/cdm
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/cdm
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/cdm')
-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
3 files changed, 34 insertions, 26 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(