Implement multi DRM support. (Part 2)
- Allow including Widevine and Playready PSSH boxes for RawKeySource. Partially addresses issue #245 Change-Id: I8a48d6dbbbc21c76cf2c44384dd70286ccf80363
This commit is contained in:
parent
56caecd073
commit
fac16cbf0a
|
@ -93,8 +93,8 @@ std::unique_ptr<KeySource> CreateEncryptionKeySource(
|
|||
break;
|
||||
}
|
||||
case KeyProvider::kRawKey: {
|
||||
// TODO(hmchen): add multiple DRM support for raw key source.
|
||||
encryption_key_source = RawKeySource::Create(encryption_params.raw_key);
|
||||
encryption_key_source = RawKeySource::Create(encryption_params.raw_key,
|
||||
protection_systems_flags);
|
||||
break;
|
||||
}
|
||||
case KeyProvider::kPlayready: {
|
||||
|
@ -176,7 +176,9 @@ std::unique_ptr<KeySource> CreateDecryptionKeySource(
|
|||
break;
|
||||
}
|
||||
case KeyProvider::kRawKey: {
|
||||
decryption_key_source = RawKeySource::Create(decryption_params.raw_key);
|
||||
decryption_key_source = RawKeySource::Create(
|
||||
decryption_params.raw_key,
|
||||
COMMON_PROTECTION_SYSTEM_FLAG /* value does not matter here*/);
|
||||
break;
|
||||
}
|
||||
case KeyProvider::kNone:
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "packager/base/logging.h"
|
||||
#include "packager/media/base/buffer_reader.h"
|
||||
|
||||
#define NO_PROTECTION_SYSTEM_FLAG 0x00
|
||||
#define COMMON_PROTECTION_SYSTEM_FLAG 0x01
|
||||
#define PLAYREADY_PROTECTION_SYSTEM_FLAG 0x02
|
||||
#define WIDEVINE_PROTECTION_SYSTEM_FLAG 0x04
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <algorithm>
|
||||
#include "packager/base/logging.h"
|
||||
#include "packager/base/strings/string_number_conversions.h"
|
||||
#include "packager/media/base/key_source.h"
|
||||
#include "packager/media/base/raw_key_pssh_generator.h"
|
||||
|
||||
namespace {
|
||||
|
@ -78,6 +79,12 @@ Status RawKeySource::GetCryptoPeriodKey(uint32_t crypto_period_index,
|
|||
key->key.end());
|
||||
|
||||
for (auto& key_system : key->key_system_info) {
|
||||
if (key_system.system_id() !=
|
||||
std::vector<uint8_t>(std::begin(kCommonSystemId),
|
||||
std::end(kCommonSystemId))) {
|
||||
LOG(WARNING) << "For key rotation with raw key source, only common key "
|
||||
"system is supported.";
|
||||
}
|
||||
std::vector<uint8_t> pssh_data = key_system.pssh_data();
|
||||
if (!pssh_data.empty()) {
|
||||
std::rotate(pssh_data.begin(),
|
||||
|
@ -103,25 +110,17 @@ Status RawKeySource::GetCryptoPeriodKey(uint32_t crypto_period_index,
|
|||
}
|
||||
|
||||
std::unique_ptr<RawKeySource> RawKeySource::Create(
|
||||
const RawKeyParams& raw_key) {
|
||||
const RawKeyParams& raw_key,
|
||||
int protection_systems_flags) {
|
||||
std::vector<ProtectionSystemSpecificInfo> key_system_info;
|
||||
bool pssh_provided = false;
|
||||
if (!raw_key.pssh.empty()) {
|
||||
pssh_provided = true;
|
||||
if (!ProtectionSystemSpecificInfo::ParseBoxes(
|
||||
raw_key.pssh.data(), raw_key.pssh.size(), &key_system_info)) {
|
||||
LOG(ERROR) << "--pssh argument should be full PSSH boxes.";
|
||||
return std::unique_ptr<RawKeySource>();
|
||||
}
|
||||
} else {
|
||||
// If there aren't any PSSH boxes given, create one with the common system
|
||||
// ID.
|
||||
key_system_info.resize(1);
|
||||
for (const auto& entry : raw_key.key_map) {
|
||||
const RawKeyParams::KeyInfo& key_pair = entry.second;
|
||||
key_system_info.back().add_key_id(key_pair.key_id);
|
||||
}
|
||||
key_system_info.back().set_system_id(kCommonSystemId,
|
||||
arraysize(kCommonSystemId));
|
||||
key_system_info.back().set_pssh_box_version(1);
|
||||
}
|
||||
|
||||
EncryptionKeyMap encryption_key_map;
|
||||
|
@ -149,14 +148,23 @@ std::unique_ptr<RawKeySource> RawKeySource::Create(
|
|||
encryption_key_map[drm_label] = std::move(encryption_key);
|
||||
}
|
||||
|
||||
return std::unique_ptr<RawKeySource>(
|
||||
new RawKeySource(std::move(encryption_key_map)));
|
||||
// Generate common protection system if no other protection system is
|
||||
// specified.
|
||||
if (!pssh_provided && protection_systems_flags == NO_PROTECTION_SYSTEM_FLAG) {
|
||||
protection_systems_flags = COMMON_PROTECTION_SYSTEM_FLAG;
|
||||
}
|
||||
|
||||
RawKeySource::RawKeySource() : KeySource(COMMON_PROTECTION_SYSTEM_FLAG) {}
|
||||
RawKeySource::RawKeySource(EncryptionKeyMap&& encryption_key_map)
|
||||
: KeySource(COMMON_PROTECTION_SYSTEM_FLAG),
|
||||
encryption_key_map_(std::move(encryption_key_map)) {}
|
||||
return std::unique_ptr<RawKeySource>(new RawKeySource(
|
||||
std::move(encryption_key_map), protection_systems_flags));
|
||||
}
|
||||
|
||||
RawKeySource::RawKeySource() : KeySource(NO_PROTECTION_SYSTEM_FLAG) {}
|
||||
RawKeySource::RawKeySource(EncryptionKeyMap&& encryption_key_map,
|
||||
int protection_systems_flags)
|
||||
: KeySource(protection_systems_flags),
|
||||
encryption_key_map_(std::move(encryption_key_map)) {
|
||||
UpdateProtectionSystemInfo(&encryption_key_map_);
|
||||
}
|
||||
|
||||
} // namespace media
|
||||
} // namespace shaka
|
||||
|
|
|
@ -43,16 +43,16 @@ class RawKeySource : public KeySource {
|
|||
/// Creates a new RawKeySource from the given data. Returns null
|
||||
/// if the parameter is malformed.
|
||||
/// @param raw_key contains parameters to setup the key source.
|
||||
static std::unique_ptr<RawKeySource> Create(const RawKeyParams& raw_key);
|
||||
static std::unique_ptr<RawKeySource> Create(const RawKeyParams& raw_key,
|
||||
int protection_system_flags);
|
||||
|
||||
protected:
|
||||
// Allow default constructor for mock key sources.
|
||||
RawKeySource();
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, std::unique_ptr<EncryptionKey>>
|
||||
EncryptionKeyMap;
|
||||
explicit RawKeySource(EncryptionKeyMap&& encryption_key_map);
|
||||
explicit RawKeySource(EncryptionKeyMap&& encryption_key_map,
|
||||
int protection_systems_flags);
|
||||
RawKeySource(const RawKeySource&) = delete;
|
||||
RawKeySource& operator=(const RawKeySource&) = delete;
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ const char kDrmLabel[] = "SomeDrmLabel";
|
|||
const char kAnotherDrmLabel[] = "AnotherDrmLabel";
|
||||
const char kEmptyDrmLabel[] = "";
|
||||
|
||||
const int kNoProtectionSystemFlag = NO_PROTECTION_SYSTEM_FLAG;
|
||||
|
||||
std::vector<uint8_t> HexStringToVector(const std::string& str) {
|
||||
std::vector<uint8_t> vec;
|
||||
CHECK(base::HexStringToBytes(str, &vec));
|
||||
|
@ -69,7 +71,7 @@ TEST(RawKeySourceTest, Success) {
|
|||
raw_key_params.pssh =
|
||||
HexStringToVector(std::string(kPsshBox1Hex) + kPsshBox2Hex);
|
||||
std::unique_ptr<RawKeySource> key_source =
|
||||
RawKeySource::Create(raw_key_params);
|
||||
RawKeySource::Create(raw_key_params, kNoProtectionSystemFlag);
|
||||
ASSERT_NE(nullptr, key_source);
|
||||
|
||||
EncryptionKey key_from_drm_label;
|
||||
|
@ -111,7 +113,7 @@ TEST(RawKeySourceTest, EmptyPssh) {
|
|||
raw_key_params.key_map[kAnotherDrmLabel].key = HexStringToVector(kKey2Hex);
|
||||
raw_key_params.iv = HexStringToVector(kIvHex);
|
||||
std::unique_ptr<RawKeySource> key_source =
|
||||
RawKeySource::Create(raw_key_params);
|
||||
RawKeySource::Create(raw_key_params, kNoProtectionSystemFlag);
|
||||
ASSERT_NE(nullptr, key_source);
|
||||
|
||||
EncryptionKey key;
|
||||
|
@ -132,13 +134,13 @@ TEST(RawKeySourceTest, Failure) {
|
|||
raw_key_params.pssh = HexStringToVector(kPsshBox1Hex);
|
||||
raw_key_params.iv = HexStringToVector(kIvHex);
|
||||
std::unique_ptr<RawKeySource> key_source =
|
||||
RawKeySource::Create(raw_key_params);
|
||||
RawKeySource::Create(raw_key_params, kNoProtectionSystemFlag);
|
||||
EXPECT_EQ(nullptr, key_source);
|
||||
|
||||
// Invalid pssh box.
|
||||
raw_key_params.key_map[kEmptyDrmLabel].key_id = HexStringToVector(kKeyIdHex);
|
||||
raw_key_params.pssh = HexStringToVector("000102030405");
|
||||
key_source = RawKeySource::Create(raw_key_params);
|
||||
key_source = RawKeySource::Create(raw_key_params, kNoProtectionSystemFlag);
|
||||
EXPECT_EQ(nullptr, key_source);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue