diff --git a/packager/media/base/playready_key_source.h b/packager/media/base/playready_key_source.h index bfeed139d7..3eceb0c4dc 100644 --- a/packager/media/base/playready_key_source.h +++ b/packager/media/base/playready_key_source.h @@ -24,7 +24,7 @@ class PlayReadyKeySource : public KeySource { /// @param proteciton_systems_flags is the flags indicating which PSSH should /// be included. PlayReadyKeySource(const std::string& server_url, - int protection_scheme_flags); + int protection_systems_flags); /// Creates a new PlayReadyKeySource from the given packaging information. /// @param server_url PlayReady packaging server url. /// @param client_cert_file absolute path to a client certificate. @@ -37,7 +37,7 @@ class PlayReadyKeySource : public KeySource { const std::string& client_cert_file, const std::string& client_cert_private_key_file, const std::string& client_cert_private_key_password, - int protection_scheme_flags); + int protection_systems_flags); ~PlayReadyKeySource() override; /// @name KeySource implementation overrides. diff --git a/packager/media/base/playready_pssh_generator.cc b/packager/media/base/playready_pssh_generator.cc index fe8f21ba36..e319b124c9 100644 --- a/packager/media/base/playready_pssh_generator.cc +++ b/packager/media/base/playready_pssh_generator.cc @@ -17,14 +17,12 @@ #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_util.h" #include "packager/media/base/buffer_writer.h" -#include "packager/media/base/http_key_fetcher.h" -#include "packager/media/base/key_source.h" -#include "packager/media/base/playready_key_source.h" namespace shaka { namespace media { namespace { +const uint8_t kPlayReadyPsshBoxVersion = 1; const std::string kPlayHeaderObject_4_1 = "& key_id, } // namespace PlayReadyPsshGenerator::PlayReadyPsshGenerator() - : system_id_(std::begin(kPlayReadySystemId), std::end(kPlayReadySystemId)) { -} + : PsshGenerator(std::vector(std::begin(kPlayReadySystemId), + std::end(kPlayReadySystemId)), + kPlayReadyPsshBoxVersion) {} PlayReadyPsshGenerator::~PlayReadyPsshGenerator() {} @@ -137,14 +136,6 @@ bool PlayReadyPsshGenerator::SupportMultipleKeys() { return false; } -uint8_t PlayReadyPsshGenerator::PsshBoxVersion() const { - return 1; -} - -const std::vector& PlayReadyPsshGenerator::SystemId() const { - return system_id_; -} - base::Optional> PlayReadyPsshGenerator::GeneratePsshDataFromKeyIdAndKey( const std::vector& key_id, @@ -165,5 +156,6 @@ PlayReadyPsshGenerator::GeneratePsshDataFromKeyIds( NOTIMPLEMENTED(); return base::nullopt; } + } // namespace media } // namespace shaka diff --git a/packager/media/base/playready_pssh_generator.h b/packager/media/base/playready_pssh_generator.h index 1bbeb68e5a..d6e03c7201 100644 --- a/packager/media/base/playready_pssh_generator.h +++ b/packager/media/base/playready_pssh_generator.h @@ -7,10 +7,7 @@ #ifndef MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_ #define MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_ -#include - #include "packager/media/base/pssh_generator.h" -#include "testing/gtest/include/gtest/gtest_prod.h" namespace shaka { namespace media { @@ -35,9 +32,6 @@ class PlayReadyPsshGenerator : public PsshGenerator { PlayReadyPsshGenerator(const PlayReadyPsshGenerator&) = delete; // PsshGenerator implemetation overrides. - uint8_t PsshBoxVersion() const override; - - const std::vector& SystemId() const override; base::Optional> GeneratePsshDataFromKeyIds( const std::vector>& key_ids) const override; @@ -45,10 +39,6 @@ class PlayReadyPsshGenerator : public PsshGenerator { base::Optional> GeneratePsshDataFromKeyIdAndKey( const std::vector& key_id, const std::vector& key) const override; - - std::vector system_id_; - - FRIEND_TEST(PsshGeneratorTest, GeneratePlayReadyPsshDataFromKeyIdAndKey); }; } // namespace media diff --git a/packager/media/base/pssh_generator.cc b/packager/media/base/pssh_generator.cc index 713998dffb..74458319c2 100644 --- a/packager/media/base/pssh_generator.cc +++ b/packager/media/base/pssh_generator.cc @@ -28,9 +28,11 @@ std::vector CreatePsshBox( } // namespace -PsshGenerator::PsshGenerator() {} +PsshGenerator::PsshGenerator(const std::vector& system_id, + uint8_t box_version) + : system_id_(system_id), box_version_(box_version) {} -PsshGenerator::~PsshGenerator() {} +PsshGenerator::~PsshGenerator() = default; Status PsshGenerator::GeneratePsshFromKeyIds( const std::vector>& key_ids, @@ -41,9 +43,9 @@ Status PsshGenerator::GeneratePsshFromKeyIds( return Status(error::ENCRYPTION_FAILURE, "Fail to generate PSSH data from multiple Key IDs."); } - info->system_id = SystemId(); + info->system_id = system_id_; info->psshs = - CreatePsshBox(SystemId(), PsshBoxVersion(), key_ids, pssh_data.value()); + CreatePsshBox(system_id_, box_version_, key_ids, pssh_data.value()); return Status::OK; } @@ -57,9 +59,9 @@ Status PsshGenerator::GeneratePsshFromKeyIdAndKey( return Status(error::ENCRYPTION_FAILURE, "Fail to generate PSSH data from Key ID and Key."); } - info->system_id = SystemId(); + info->system_id = system_id_; info->psshs = - CreatePsshBox(SystemId(), PsshBoxVersion(), {key_id}, pssh_data.value()); + CreatePsshBox(system_id_, box_version_, {key_id}, pssh_data.value()); return Status::OK; } diff --git a/packager/media/base/pssh_generator.h b/packager/media/base/pssh_generator.h index c96aeb89ca..fc8f87cbfe 100644 --- a/packager/media/base/pssh_generator.h +++ b/packager/media/base/pssh_generator.h @@ -17,12 +17,12 @@ namespace shaka { namespace media { -struct EncryptionKey; - class PsshGenerator { public: - PsshGenerator(); - virtual ~PsshGenerator() = 0; + /// @param system_id is the protection system id for the PSSH. + /// @param box_version specifies the version of the new PSSH box. + PsshGenerator(const std::vector& system_id, uint8_t box_version); + virtual ~PsshGenerator(); /// @return whether the PSSH generates the PSSH box based on multiple key /// IDs. @@ -60,11 +60,8 @@ class PsshGenerator { const std::vector& key_id, const std::vector& key) const = 0; - /// Return the PSSH box version. - virtual uint8_t PsshBoxVersion() const = 0; - - /// Return the System ID. - virtual const std::vector& SystemId() const = 0; + std::vector system_id_; + uint8_t box_version_ = 0; }; } // namespace media diff --git a/packager/media/base/pssh_generator_unittest.cc b/packager/media/base/pssh_generator_unittest.cc index 5fba63b7f9..c023edff8e 100644 --- a/packager/media/base/pssh_generator_unittest.cc +++ b/packager/media/base/pssh_generator_unittest.cc @@ -130,7 +130,7 @@ std::vector GetTestKeyId2() { // TODO(hmchen): move each PsshGenerateTest for each specific key system // to each individual files (e.g., playready_pssh_generate_unittest.cc). -TEST(PsshGeneratorTest, GeneratePlayReadyPsshDataFromKeyIds) { +TEST(PsshGeneratorTest, GeneratePlayReadyPsshFromKeyIds) { const std::vector> kTestKeyIds = {GetTestKeyId1(), GetTestKeyId2()}; std::unique_ptr playready_pssh_generator( diff --git a/packager/media/base/raw_key_pssh_generator.cc b/packager/media/base/raw_key_pssh_generator.cc index 05efc87545..6f602f4024 100644 --- a/packager/media/base/raw_key_pssh_generator.cc +++ b/packager/media/base/raw_key_pssh_generator.cc @@ -10,9 +10,14 @@ namespace shaka { namespace media { +namespace { +const uint8_t kCommonSystemPsshBoxVersion = 1; +} // namespace RawKeyPsshGenerator::RawKeyPsshGenerator() - : system_id_(std::begin(kCommonSystemId), std::end(kCommonSystemId)) {} + : PsshGenerator(std::vector(std::begin(kCommonSystemId), + std::end(kCommonSystemId)), + kCommonSystemPsshBoxVersion) {} RawKeyPsshGenerator::~RawKeyPsshGenerator() {} @@ -20,14 +25,6 @@ bool RawKeyPsshGenerator::SupportMultipleKeys() { return true; } -uint8_t RawKeyPsshGenerator::PsshBoxVersion() const { - return 1; -} - -const std::vector& RawKeyPsshGenerator::SystemId() const { - return system_id_; -} - base::Optional> RawKeyPsshGenerator::GeneratePsshDataFromKeyIdAndKey( const std::vector& key_id, diff --git a/packager/media/base/raw_key_pssh_generator.h b/packager/media/base/raw_key_pssh_generator.h index bdf1dd4989..8d169c67e2 100644 --- a/packager/media/base/raw_key_pssh_generator.h +++ b/packager/media/base/raw_key_pssh_generator.h @@ -7,12 +7,7 @@ #ifndef MEDIA_BASE_RAW_KEY_PSSH_GENERATOR_H_ #define MEDIA_BASE_RAW_KEY_PSSH_GENERATOR_H_ -#include - -#include "packager/media/base/key_source.h" -#include "packager/media/base/protection_system_specific_info.h" #include "packager/media/base/pssh_generator.h" -#include "testing/gtest/include/gtest/gtest_prod.h" namespace shaka { namespace media { @@ -39,9 +34,6 @@ class RawKeyPsshGenerator : public PsshGenerator { RawKeyPsshGenerator(const RawKeyPsshGenerator&) = delete; // PsshGenerator implemetation overrides. - uint8_t PsshBoxVersion() const override; - - const std::vector& SystemId() const override; base::Optional> GeneratePsshDataFromKeyIds( const std::vector>& key_ids) const override; @@ -49,8 +41,6 @@ class RawKeyPsshGenerator : public PsshGenerator { base::Optional> GeneratePsshDataFromKeyIdAndKey( const std::vector& key_id, const std::vector& key) const override; - - std::vector system_id_; }; } // namespace media } // namespace shaka diff --git a/packager/media/base/widevine_pssh_generator.cc b/packager/media/base/widevine_pssh_generator.cc index fdc32b7bfe..7b0d827f4b 100644 --- a/packager/media/base/widevine_pssh_generator.cc +++ b/packager/media/base/widevine_pssh_generator.cc @@ -7,13 +7,18 @@ #include "packager/media/base/widevine_pssh_generator.h" #include "packager/media/base/pssh_generator_util.h" -#include "packager/media/base/widevine_key_source.h" namespace shaka { namespace media { +namespace { +// Use version 0 for backward compatibility. +const uint8_t kWidevinePsshBoxVersion = 0; +} // namespace WidevinePsshGenerator::WidevinePsshGenerator() - : system_id_(std::begin(kWidevineSystemId), std::end(kWidevineSystemId)) {} + : PsshGenerator(std::vector(std::begin(kWidevineSystemId), + std::end(kWidevineSystemId)), + kWidevinePsshBoxVersion) {} WidevinePsshGenerator::~WidevinePsshGenerator() {} @@ -21,15 +26,6 @@ bool WidevinePsshGenerator::SupportMultipleKeys() { return true; } -uint8_t WidevinePsshGenerator::PsshBoxVersion() const { - // This is for backward compatibility. - return 0; -} - -const std::vector& WidevinePsshGenerator::SystemId() const { - return system_id_; -} - base::Optional> WidevinePsshGenerator::GeneratePsshDataFromKeyIds( const std::vector>& key_ids) const { @@ -43,5 +39,6 @@ WidevinePsshGenerator::GeneratePsshDataFromKeyIdAndKey( NOTIMPLEMENTED(); return base::nullopt; } + } // namespace media } // namespace shaka diff --git a/packager/media/base/widevine_pssh_generator.h b/packager/media/base/widevine_pssh_generator.h index f6162c163d..a632fad015 100644 --- a/packager/media/base/widevine_pssh_generator.h +++ b/packager/media/base/widevine_pssh_generator.h @@ -7,11 +7,7 @@ #ifndef MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_ #define MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_ -#include - -#include "packager/media/base/key_source.h" -#include "packager/media/base/protection_system_specific_info.h" -#include "testing/gtest/include/gtest/gtest_prod.h" +#include "packager/media/base/pssh_generator.h" namespace shaka { namespace media { @@ -19,7 +15,6 @@ namespace media { const uint8_t kWidevineSystemId[] = {0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6, 0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc, 0xd5, 0x1d, 0x21, 0xed}; -class WidevineKeySource; class WidevinePsshGenerator : public PsshGenerator { public: @@ -36,9 +31,6 @@ class WidevinePsshGenerator : public PsshGenerator { WidevinePsshGenerator(const WidevinePsshGenerator&) = delete; // PsshGenerator implemetation overrides. - uint8_t PsshBoxVersion() const override; - - const std::vector& SystemId() const override; base::Optional> GeneratePsshDataFromKeyIds( const std::vector>& key_ids) const override; @@ -46,8 +38,6 @@ class WidevinePsshGenerator : public PsshGenerator { base::Optional> GeneratePsshDataFromKeyIdAndKey( const std::vector& key_id, const std::vector& key) const override; - - std::vector system_id_; }; } // namespace media