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
/// 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.

View File

@ -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 =
"<WRMHEADER "
"xmlns=\"http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader\" "
@ -128,8 +126,9 @@ Status GeneratePlayReadyPsshData(const std::vector<uint8_t>& key_id,
} // namespace
PlayReadyPsshGenerator::PlayReadyPsshGenerator()
: system_id_(std::begin(kPlayReadySystemId), std::end(kPlayReadySystemId)) {
}
: PsshGenerator(std::vector<uint8_t>(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<uint8_t>& PlayReadyPsshGenerator::SystemId() const {
return system_id_;
}
base::Optional<std::vector<uint8_t>>
PlayReadyPsshGenerator::GeneratePsshDataFromKeyIdAndKey(
const std::vector<uint8_t>& key_id,
@ -165,5 +156,6 @@ PlayReadyPsshGenerator::GeneratePsshDataFromKeyIds(
NOTIMPLEMENTED();
return base::nullopt;
}
} // namespace media
} // namespace shaka

View File

@ -7,10 +7,7 @@
#ifndef MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_
#define MEDIA_BASE_PLAYREADY_PSSH_GENERATOR_H_
#include <vector>
#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<uint8_t>& SystemId() const override;
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds(
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(
const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& key) const override;
std::vector<uint8_t> system_id_;
FRIEND_TEST(PsshGeneratorTest, GeneratePlayReadyPsshDataFromKeyIdAndKey);
};
} // namespace media

View File

@ -28,9 +28,11 @@ std::vector<uint8_t> CreatePsshBox(
} // 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(
const std::vector<std::vector<uint8_t>>& 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;
}

View File

@ -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<uint8_t>& 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<uint8_t>& key_id,
const std::vector<uint8_t>& key) const = 0;
/// Return the PSSH box version.
virtual uint8_t PsshBoxVersion() const = 0;
/// Return the System ID.
virtual const std::vector<uint8_t>& SystemId() const = 0;
std::vector<uint8_t> system_id_;
uint8_t box_version_ = 0;
};
} // namespace media

View File

@ -130,7 +130,7 @@ std::vector<uint8_t> 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<std::vector<uint8_t>> kTestKeyIds = {GetTestKeyId1(),
GetTestKeyId2()};
std::unique_ptr<PlayReadyPsshGenerator> playready_pssh_generator(

View File

@ -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<uint8_t>(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<uint8_t>& RawKeyPsshGenerator::SystemId() const {
return system_id_;
}
base::Optional<std::vector<uint8_t>>
RawKeyPsshGenerator::GeneratePsshDataFromKeyIdAndKey(
const std::vector<uint8_t>& key_id,

View File

@ -7,12 +7,7 @@
#ifndef 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 "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<uint8_t>& SystemId() const override;
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds(
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(
const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& key) const override;
std::vector<uint8_t> system_id_;
};
} // namespace media
} // namespace shaka

View File

@ -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<uint8_t>(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<uint8_t>& WidevinePsshGenerator::SystemId() const {
return system_id_;
}
base::Optional<std::vector<uint8_t>>
WidevinePsshGenerator::GeneratePsshDataFromKeyIds(
const std::vector<std::vector<uint8_t>>& key_ids) const {
@ -43,5 +39,6 @@ WidevinePsshGenerator::GeneratePsshDataFromKeyIdAndKey(
NOTIMPLEMENTED();
return base::nullopt;
}
} // namespace media
} // namespace shaka

View File

@ -7,11 +7,7 @@
#ifndef MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_
#define MEDIA_BASE_WIDEVINE_PSSH_GENERATOR_H_
#include <vector>
#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<uint8_t>& SystemId() const override;
base::Optional<std::vector<uint8_t>> GeneratePsshDataFromKeyIds(
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(
const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& key) const override;
std::vector<uint8_t> system_id_;
};
} // namespace media