Clean up PsshGenerators

Change-Id: I0940bd5a2a0a5af175088a15890ddd82602d0c7f
This commit is contained in:
KongQun Yang 2018-08-07 13:47:53 -07:00
parent 2fee1e673b
commit 2a80c6773a
10 changed files with 37 additions and 82 deletions

View File

@ -24,7 +24,7 @@ class PlayReadyKeySource : public KeySource {
/// @param proteciton_systems_flags is the flags indicating which PSSH should /// @param proteciton_systems_flags is the flags indicating which PSSH should
/// be included. /// be included.
PlayReadyKeySource(const std::string& server_url, PlayReadyKeySource(const std::string& server_url,
int protection_scheme_flags); int protection_systems_flags);
/// Creates a new PlayReadyKeySource from the given packaging information. /// Creates a new PlayReadyKeySource from the given packaging information.
/// @param server_url PlayReady packaging server url. /// @param server_url PlayReady packaging server url.
/// @param client_cert_file absolute path to a client certificate. /// @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_file,
const std::string& client_cert_private_key_file, const std::string& client_cert_private_key_file,
const std::string& client_cert_private_key_password, const std::string& client_cert_private_key_password,
int protection_scheme_flags); int protection_systems_flags);
~PlayReadyKeySource() override; ~PlayReadyKeySource() override;
/// @name KeySource implementation overrides. /// @name KeySource implementation overrides.

View File

@ -17,14 +17,12 @@
#include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_number_conversions.h"
#include "packager/base/strings/string_util.h" #include "packager/base/strings/string_util.h"
#include "packager/media/base/buffer_writer.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 shaka {
namespace media { namespace media {
namespace { namespace {
const uint8_t kPlayReadyPsshBoxVersion = 1;
const std::string kPlayHeaderObject_4_1 = const std::string kPlayHeaderObject_4_1 =
"<WRMHEADER " "<WRMHEADER "
"xmlns=\"http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader\" " "xmlns=\"http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader\" "
@ -128,8 +126,9 @@ Status GeneratePlayReadyPsshData(const std::vector<uint8_t>& key_id,
} // namespace } // namespace
PlayReadyPsshGenerator::PlayReadyPsshGenerator() PlayReadyPsshGenerator::PlayReadyPsshGenerator()
: system_id_(std::begin(kPlayReadySystemId), std::end(kPlayReadySystemId)) { : PsshGenerator(std::vector<uint8_t>(std::begin(kPlayReadySystemId),
} std::end(kPlayReadySystemId)),
kPlayReadyPsshBoxVersion) {}
PlayReadyPsshGenerator::~PlayReadyPsshGenerator() {} PlayReadyPsshGenerator::~PlayReadyPsshGenerator() {}
@ -137,14 +136,6 @@ bool PlayReadyPsshGenerator::SupportMultipleKeys() {
return false; return false;
} }
uint8_t PlayReadyPsshGenerator::PsshBoxVersion() const {
return 1;
}
const std::vector<uint8_t>& PlayReadyPsshGenerator::SystemId() const {
return system_id_;
}
base::Optional<std::vector<uint8_t>> base::Optional<std::vector<uint8_t>>
PlayReadyPsshGenerator::GeneratePsshDataFromKeyIdAndKey( PlayReadyPsshGenerator::GeneratePsshDataFromKeyIdAndKey(
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,
@ -165,5 +156,6 @@ PlayReadyPsshGenerator::GeneratePsshDataFromKeyIds(
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return base::nullopt; return base::nullopt;
} }
} // namespace media } // namespace media
} // namespace shaka } // namespace shaka

View File

@ -7,10 +7,7 @@
#ifndef MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_ #ifndef MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_
#define MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_ #define MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_
#include <vector>
#include "packager/media/base/pssh_generator.h" #include "packager/media/base/pssh_generator.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -35,9 +32,6 @@ class PlayReadyPsshGenerator : public PsshGenerator {
PlayReadyPsshGenerator(const PlayReadyPsshGenerator&) = delete; PlayReadyPsshGenerator(const PlayReadyPsshGenerator&) = delete;
// PsshGenerator implemetation overrides. // PsshGenerator implemetation overrides.
uint8_t PsshBoxVersion() const override;
const std::vector<uint8_t>& SystemId() const override;
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds( base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds(
const std::vector<std::vector<uint8_t>>& key_ids) const override; const std::vector<std::vector<uint8_t>>& key_ids) const override;
@ -45,10 +39,6 @@ class PlayReadyPsshGenerator : public PsshGenerator {
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIdAndKey( base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIdAndKey(
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& key) const override; const std::vector<uint8_t>& key) const override;
std::vector<uint8_t> system_id_;
FRIEND_TEST(PsshGeneratorTest, GeneratePlayReadyPsshDataFromKeyIdAndKey);
}; };
} // namespace media } // namespace media

View File

@ -28,9 +28,11 @@ std::vector<uint8_t> CreatePsshBox(
} // namespace } // namespace
PsshGenerator::PsshGenerator() {} PsshGenerator::PsshGenerator(const std::vector<uint8_t>& system_id,
uint8_t box_version)
: system_id_(system_id), box_version_(box_version) {}
PsshGenerator::~PsshGenerator() {} PsshGenerator::~PsshGenerator() = default;
Status PsshGenerator::GeneratePsshFromKeyIds( Status PsshGenerator::GeneratePsshFromKeyIds(
const std::vector<std::vector<uint8_t>>& key_ids, const std::vector<std::vector<uint8_t>>& key_ids,
@ -41,9 +43,9 @@ Status PsshGenerator::GeneratePsshFromKeyIds(
return Status(error::ENCRYPTION_FAILURE, return Status(error::ENCRYPTION_FAILURE,
"Fail to generate PSSH data from multiple Key IDs."); "Fail to generate PSSH data from multiple Key IDs.");
} }
info->system_id = SystemId(); info->system_id = system_id_;
info->psshs = info->psshs =
CreatePsshBox(SystemId(), PsshBoxVersion(), key_ids, pssh_data.value()); CreatePsshBox(system_id_, box_version_, key_ids, pssh_data.value());
return Status::OK; return Status::OK;
} }
@ -57,9 +59,9 @@ Status PsshGenerator::GeneratePsshFromKeyIdAndKey(
return Status(error::ENCRYPTION_FAILURE, return Status(error::ENCRYPTION_FAILURE,
"Fail to generate PSSH data from Key ID and Key."); "Fail to generate PSSH data from Key ID and Key.");
} }
info->system_id = SystemId(); info->system_id = system_id_;
info->psshs = info->psshs =
CreatePsshBox(SystemId(), PsshBoxVersion(), {key_id}, pssh_data.value()); CreatePsshBox(system_id_, box_version_, {key_id}, pssh_data.value());
return Status::OK; return Status::OK;
} }

View File

@ -17,12 +17,12 @@
namespace shaka { namespace shaka {
namespace media { namespace media {
struct EncryptionKey;
class PsshGenerator { class PsshGenerator {
public: public:
PsshGenerator(); /// @param system_id is the protection system id for the PSSH.
virtual ~PsshGenerator() = 0; /// @param box_version specifies the version of the new PSSH box.
PsshGenerator(const std::vector<uint8_t>& system_id, uint8_t box_version);
virtual ~PsshGenerator();
/// @return whether the PSSH generates the PSSH box based on multiple key /// @return whether the PSSH generates the PSSH box based on multiple key
/// IDs. /// IDs.
@ -60,11 +60,8 @@ class PsshGenerator {
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& key) const = 0; const std::vector<uint8_t>& key) const = 0;
/// Return the PSSH box version. std::vector<uint8_t> system_id_;
virtual uint8_t PsshBoxVersion() const = 0; uint8_t box_version_ = 0;
/// Return the System ID.
virtual const std::vector<uint8_t>& SystemId() const = 0;
}; };
} // namespace media } // namespace media

View File

@ -130,7 +130,7 @@ std::vector<uint8_t> GetTestKeyId2() {
// TODO(hmchen): move each PsshGenerateTest for each specific key system // TODO(hmchen): move each PsshGenerateTest for each specific key system
// to each individual files (e.g., playready_pssh_generate_unittest.cc). // to each individual files (e.g., playready_pssh_generate_unittest.cc).
TEST(PsshGeneratorTest, GeneratePlayReadyPsshDataFromKeyIds) { TEST(PsshGeneratorTest, GeneratePlayReadyPsshFromKeyIds) {
const std::vector<std::vector<uint8_t>> kTestKeyIds = {GetTestKeyId1(), const std::vector<std::vector<uint8_t>> kTestKeyIds = {GetTestKeyId1(),
GetTestKeyId2()}; GetTestKeyId2()};
std::unique_ptr<PlayReadyPsshGenerator> playready_pssh_generator( std::unique_ptr<PlayReadyPsshGenerator> playready_pssh_generator(

View File

@ -10,9 +10,14 @@
namespace shaka { namespace shaka {
namespace media { namespace media {
namespace {
const uint8_t kCommonSystemPsshBoxVersion = 1;
} // namespace
RawKeyPsshGenerator::RawKeyPsshGenerator() RawKeyPsshGenerator::RawKeyPsshGenerator()
: system_id_(std::begin(kCommonSystemId), std::end(kCommonSystemId)) {} : PsshGenerator(std::vector<uint8_t>(std::begin(kCommonSystemId),
std::end(kCommonSystemId)),
kCommonSystemPsshBoxVersion) {}
RawKeyPsshGenerator::~RawKeyPsshGenerator() {} RawKeyPsshGenerator::~RawKeyPsshGenerator() {}
@ -20,14 +25,6 @@ bool RawKeyPsshGenerator::SupportMultipleKeys() {
return true; return true;
} }
uint8_t RawKeyPsshGenerator::PsshBoxVersion() const {
return 1;
}
const std::vector<uint8_t>& RawKeyPsshGenerator::SystemId() const {
return system_id_;
}
base::Optional<std::vector<uint8_t>> base::Optional<std::vector<uint8_t>>
RawKeyPsshGenerator::GeneratePsshDataFromKeyIdAndKey( RawKeyPsshGenerator::GeneratePsshDataFromKeyIdAndKey(
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,

View File

@ -7,12 +7,7 @@
#ifndef MEDIA_BASE_RAW_KEY_PSSH_GENERATOR_H_ #ifndef MEDIA_BASE_RAW_KEY_PSSH_GENERATOR_H_
#define MEDIA_BASE_RAW_KEY_PSSH_GENERATOR_H_ #define MEDIA_BASE_RAW_KEY_PSSH_GENERATOR_H_
#include <vector>
#include "packager/media/base/key_source.h"
#include "packager/media/base/protection_system_specific_info.h"
#include "packager/media/base/pssh_generator.h" #include "packager/media/base/pssh_generator.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -39,9 +34,6 @@ class RawKeyPsshGenerator : public PsshGenerator {
RawKeyPsshGenerator(const RawKeyPsshGenerator&) = delete; RawKeyPsshGenerator(const RawKeyPsshGenerator&) = delete;
// PsshGenerator implemetation overrides. // PsshGenerator implemetation overrides.
uint8_t PsshBoxVersion() const override;
const std::vector<uint8_t>& SystemId() const override;
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds( base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds(
const std::vector<std::vector<uint8_t>>& key_ids) const override; const std::vector<std::vector<uint8_t>>& key_ids) const override;
@ -49,8 +41,6 @@ class RawKeyPsshGenerator : public PsshGenerator {
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIdAndKey( base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIdAndKey(
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& key) const override; const std::vector<uint8_t>& key) const override;
std::vector<uint8_t> system_id_;
}; };
} // namespace media } // namespace media
} // namespace shaka } // namespace shaka

View File

@ -7,13 +7,18 @@
#include "packager/media/base/widevine_pssh_generator.h" #include "packager/media/base/widevine_pssh_generator.h"
#include "packager/media/base/pssh_generator_util.h" #include "packager/media/base/pssh_generator_util.h"
#include "packager/media/base/widevine_key_source.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
namespace {
// Use version 0 for backward compatibility.
const uint8_t kWidevinePsshBoxVersion = 0;
} // namespace
WidevinePsshGenerator::WidevinePsshGenerator() WidevinePsshGenerator::WidevinePsshGenerator()
: system_id_(std::begin(kWidevineSystemId), std::end(kWidevineSystemId)) {} : PsshGenerator(std::vector<uint8_t>(std::begin(kWidevineSystemId),
std::end(kWidevineSystemId)),
kWidevinePsshBoxVersion) {}
WidevinePsshGenerator::~WidevinePsshGenerator() {} WidevinePsshGenerator::~WidevinePsshGenerator() {}
@ -21,15 +26,6 @@ bool WidevinePsshGenerator::SupportMultipleKeys() {
return true; return true;
} }
uint8_t WidevinePsshGenerator::PsshBoxVersion() const {
// This is for backward compatibility.
return 0;
}
const std::vector<uint8_t>& WidevinePsshGenerator::SystemId() const {
return system_id_;
}
base::Optional<std::vector<uint8_t>> base::Optional<std::vector<uint8_t>>
WidevinePsshGenerator::GeneratePsshDataFromKeyIds( WidevinePsshGenerator::GeneratePsshDataFromKeyIds(
const std::vector<std::vector<uint8_t>>& key_ids) const { const std::vector<std::vector<uint8_t>>& key_ids) const {
@ -43,5 +39,6 @@ WidevinePsshGenerator::GeneratePsshDataFromKeyIdAndKey(
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return base::nullopt; return base::nullopt;
} }
} // namespace media } // namespace media
} // namespace shaka } // namespace shaka

View File

@ -7,11 +7,7 @@
#ifndef MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_ #ifndef MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_
#define MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_ #define MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_
#include <vector> #include "packager/media/base/pssh_generator.h"
#include "packager/media/base/key_source.h"
#include "packager/media/base/protection_system_specific_info.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -19,7 +15,6 @@ namespace media {
const uint8_t kWidevineSystemId[] = {0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6, const uint8_t kWidevineSystemId[] = {0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6,
0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc, 0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc,
0xd5, 0x1d, 0x21, 0xed}; 0xd5, 0x1d, 0x21, 0xed};
class WidevineKeySource;
class WidevinePsshGenerator : public PsshGenerator { class WidevinePsshGenerator : public PsshGenerator {
public: public:
@ -36,9 +31,6 @@ class WidevinePsshGenerator : public PsshGenerator {
WidevinePsshGenerator(const WidevinePsshGenerator&) = delete; WidevinePsshGenerator(const WidevinePsshGenerator&) = delete;
// PsshGenerator implemetation overrides. // PsshGenerator implemetation overrides.
uint8_t PsshBoxVersion() const override;
const std::vector<uint8_t>& SystemId() const override;
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds( base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds(
const std::vector<std::vector<uint8_t>>& key_ids) const override; const std::vector<std::vector<uint8_t>>& key_ids) const override;
@ -46,8 +38,6 @@ class WidevinePsshGenerator : public PsshGenerator {
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIdAndKey( base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIdAndKey(
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& key) const override; const std::vector<uint8_t>& key) const override;
std::vector<uint8_t> system_id_;
}; };
} // namespace media } // namespace media