diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 65466ac144..4ebf183e97 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -166,6 +166,7 @@ base::Optional GetPackagingParams() { widevine.content_id = FLAGS_content_id_bytes; widevine.policy = FLAGS_policy; + widevine.group_id = FLAGS_group_id_bytes; if (!GetWidevineSigner(&widevine.signer)) return base::nullopt; break; diff --git a/packager/app/packager_util.cc b/packager/app/packager_util.cc index 84adb2e6f4..99a54f376c 100644 --- a/packager/app/packager_util.cc +++ b/packager/app/packager_util.cc @@ -88,6 +88,7 @@ std::unique_ptr CreateEncryptionKeySource( return std::unique_ptr(); widevine_key_source->set_signer(std::move(request_signer)); } + widevine_key_source->set_group_id(widevine.group_id); Status status = widevine_key_source->FetchKeys(widevine.content_id, widevine.policy); diff --git a/packager/app/widevine_encryption_flags.cc b/packager/app/widevine_encryption_flags.cc index adc8db327c..f26eb6b578 100644 --- a/packager/app/widevine_encryption_flags.cc +++ b/packager/app/widevine_encryption_flags.cc @@ -63,6 +63,7 @@ DEFINE_int32(crypto_period_duration, 0, "Crypto period duration in seconds. If it is non-zero, key " "rotation is enabled."); +DEFINE_hex_bytes(group_id, "", "Identifier for a group of licenses (hex)."); namespace shaka { namespace { diff --git a/packager/app/widevine_encryption_flags.h b/packager/app/widevine_encryption_flags.h index 7447ceb783..c584bf49b9 100644 --- a/packager/app/widevine_encryption_flags.h +++ b/packager/app/widevine_encryption_flags.h @@ -27,6 +27,7 @@ DECLARE_hex_bytes(aes_signing_key); DECLARE_hex_bytes(aes_signing_iv); DECLARE_string(rsa_signing_key_path); DECLARE_int32(crypto_period_duration); +DECLARE_hex_bytes(group_id); namespace shaka { diff --git a/packager/media/base/widevine_key_source.cc b/packager/media/base/widevine_key_source.cc index 49be200a85..ef6e1ae34d 100644 --- a/packager/media/base/widevine_key_source.cc +++ b/packager/media/base/widevine_key_source.cc @@ -292,6 +292,10 @@ void WidevineKeySource::set_key_fetcher( key_fetcher_ = std::move(key_fetcher); } +void WidevineKeySource::set_group_id(const std::vector& group_id) { + group_id_ = group_id; +} + Status WidevineKeySource::GetKeyInternal(uint32_t crypto_period_index, const std::string& stream_label, EncryptionKey* key) { @@ -434,6 +438,13 @@ void WidevineKeySource::FillRequest(bool enable_key_rotation, request_dict_.SetInteger("crypto_period_count", crypto_period_count_); } + // Set group id if present. + if (!group_id_.empty()) { + std::string group_id_base64; + BytesToBase64String(group_id_, &group_id_base64); + request_dict_.SetString("group_id", group_id_base64); + } + base::JSONWriter::WriteWithOptions( request_dict_, // Write doubles that have no fractional part as a normal integer, i.e. diff --git a/packager/media/base/widevine_key_source.h b/packager/media/base/widevine_key_source.h index 2e57f12bd0..9df4ddcdd3 100644 --- a/packager/media/base/widevine_key_source.h +++ b/packager/media/base/widevine_key_source.h @@ -67,6 +67,10 @@ class WidevineKeySource : public KeySource { /// @param key_fetcher points to the @b KeyFetcher object to be injected. void set_key_fetcher(std::unique_ptr key_fetcher); + // Set the group id for the key source + // @param group_id group identifier + void set_group_id(const std::vector& group_id); + private: typedef std::map> EncryptionKeyMap; @@ -124,6 +128,7 @@ class WidevineKeySource : public KeySource { bool key_production_started_; base::WaitableEvent start_key_production_; uint32_t first_crypto_period_index_; + std::vector group_id_; std::unique_ptr key_pool_; EncryptionKeyMap encryption_key_map_; // For non key rotation request. Status common_encryption_request_status_; diff --git a/packager/packager.h b/packager/packager.h index 5025ea212e..a45dc639f9 100644 --- a/packager/packager.h +++ b/packager/packager.h @@ -164,6 +164,8 @@ struct WidevineEncryptionParams { std::string policy; /// Signer credential for Widevine license / key server. WidevineSigner signer; + /// Group identifier, if present licenses will belong to this group. + std::vector group_id; }; /// Playready encryption parameters.