Skip to content

Commit

Permalink
Remove validation func from header
Browse files Browse the repository at this point in the history
  • Loading branch information
jedekar committed Jan 15, 2024
1 parent f0b622b commit eaf27c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
6 changes: 2 additions & 4 deletions include/packager/live_packager.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ struct PSSHData {
std::vector<uint8_t> wv_box;
};

enum struct EncryptionSchemeFourCC : uint32_t {
enum struct MP4ProtectionSchemeFourCC : uint32_t {
CBCS = 0x63626373,
CENC = 0x63656e63,
};

struct PSSHGeneratorInput {
EncryptionSchemeFourCC encryption_scheme;
MP4ProtectionSchemeFourCC protection_scheme;

// key of a single adaption set for DRM systems that don't support
// multile keys (i.e PlayReady)
Expand All @@ -147,8 +147,6 @@ struct PSSHGeneratorInput {
// key ids of all adaptation sets for DRM systems that support
// multiple keys (i.e Widevine, Common Encryption)
std::vector<std::vector<uint8_t>> key_ids;

Status Validate() const;
};

Status GeneratePSSHData(const PSSHGeneratorInput& in, PSSHData* out);
Expand Down
22 changes: 11 additions & 11 deletions packager/live_packager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,36 +455,36 @@ void FillPSSHBoxByDRM(const media::ProtectionSystemSpecificInfo& pssh_info,
}
}

Status PSSHGeneratorInput::Validate() const {
Status ValidatePSSHGeneratorInput(const PSSHGeneratorInput& input) {
constexpr int kKeySize = 16;

if (encryption_scheme != EncryptionSchemeFourCC::CBCS &&
encryption_scheme != EncryptionSchemeFourCC::CENC) {
if (input.protection_scheme != MP4ProtectionSchemeFourCC::CBCS &&
input.protection_scheme != MP4ProtectionSchemeFourCC::CENC) {
LOG(WARNING) << "invalid encryption scheme in PSSH generator input";
return Status(error::INVALID_ARGUMENT,
"invalid encryption scheme in PSSH generator input");
}

if (key.size() != kKeySize) {
if (input.key.size() != kKeySize) {
LOG(WARNING) << "invalid key length in PSSH generator input";
return Status(error::INVALID_ARGUMENT,
"invalid key length in PSSH generator input");
}

if (key_id.size() != kKeySize) {
if (input.key_id.size() != kKeySize) {
LOG(WARNING) << "invalid key id length in PSSH generator input";
return Status(error::INVALID_ARGUMENT,
"invalid key id length in PSSH generator input");
}

if (key_ids.empty()) {
if (input.key_ids.empty()) {
LOG(WARNING) << "key ids cannot be empty in PSSH generator input";
return Status(error::INVALID_ARGUMENT,
"key ids cannot be empty in PSSH generator input");
}

for (size_t i = 0; i < key_ids.size(); ++i) {
if (key_ids[i].size() != kKeySize) {
for (size_t i = 0; i < input.key_ids.size(); ++i) {
if (input.key_ids[i].size() != kKeySize) {
LOG(WARNING) << "invalid key id length in key ids array in PSSH "
"generator input, index " +
std::to_string(i);
Expand All @@ -501,7 +501,7 @@ Status PSSHGeneratorInput::Validate() const {
Status GeneratePSSHData(const PSSHGeneratorInput& in, PSSHData* out) {
const char* kNoExtraHeadersForPlayReady = "";

RETURN_IF_ERROR(in.Validate());
RETURN_IF_ERROR(ValidatePSSHGeneratorInput(in));
if (!out) {
return Status(error::INVALID_ARGUMENT, "output data cannot be null");
}
Expand All @@ -510,9 +510,9 @@ Status GeneratePSSHData(const PSSHGeneratorInput& in, PSSHData* out) {
pssh_generators.emplace_back(std::make_unique<media::CommonPsshGenerator>());
pssh_generators.emplace_back(std::make_unique<media::PlayReadyPsshGenerator>(
kNoExtraHeadersForPlayReady,
static_cast<media::FourCC>(in.encryption_scheme)));
static_cast<media::FourCC>(in.protection_scheme)));
pssh_generators.emplace_back(std::make_unique<media::WidevinePsshGenerator>(
static_cast<media::FourCC>(in.encryption_scheme)));
static_cast<media::FourCC>(in.protection_scheme)));

for (const auto& pssh_generator : pssh_generators) {
media::ProtectionSystemSpecificInfo info;
Expand Down
6 changes: 3 additions & 3 deletions packager/live_packager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void CheckSegment(const LiveConfig& config, const FullSegmentBuffer& buffer) {
} // namespace

TEST(GeneratePSSHData, GeneratesPSSHBoxesAndMSPRObject) {
PSSHGeneratorInput in{.encryption_scheme = EncryptionSchemeFourCC::CENC,
PSSHGeneratorInput in{.protection_scheme = MP4ProtectionSchemeFourCC::CENC,
.key_id = unhex("00000000621f2afe7ab2c868d5fd2e2e"),
.key = unhex("1af987fa084ff3c0f4ad35a6bdab98e2"),
.key_ids = {unhex("00000000621f2afe7ab2c868d5fd2e2e"),
Expand Down Expand Up @@ -304,7 +304,7 @@ TEST(GeneratePSSHData, GeneratesPSSHBoxesAndMSPRObject) {

TEST(GeneratePSSHData, FailsOnInvalidInput) {
const PSSHGeneratorInput valid_input{
.encryption_scheme = EncryptionSchemeFourCC::CENC,
.protection_scheme = MP4ProtectionSchemeFourCC::CENC,
.key_id = unhex("00000000621f2afe7ab2c868d5fd2e2e"),
.key = unhex("1af987fa084ff3c0f4ad35a6bdab98e2"),
.key_ids = {unhex("00000000621f2afe7ab2c868d5fd2e2e"),
Expand All @@ -315,7 +315,7 @@ TEST(GeneratePSSHData, FailsOnInvalidInput) {
"invalid encryption scheme in PSSH generator input"),
GeneratePSSHData(in, nullptr));

in.encryption_scheme = valid_input.encryption_scheme;
in.protection_scheme = valid_input.protection_scheme;
ASSERT_EQ(Status(error::INVALID_ARGUMENT,
"invalid key length in PSSH generator input"),
GeneratePSSHData(in, nullptr));
Expand Down

0 comments on commit eaf27c1

Please sign in to comment.