Skip to content

Commit

Permalink
Appease linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jedekar committed Jan 10, 2024
1 parent 438c520 commit 21896f8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 38 deletions.
2 changes: 1 addition & 1 deletion include/packager/live_packager.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct PSSHData {
std::vector<uint8_t> wv_box;
};

enum struct EncryptionSchemeFourCC: uint32_t {
enum struct EncryptionSchemeFourCC : uint32_t {
CBCS = 0x63626373,
CENC = 0x63656e63,
};
Expand Down
18 changes: 12 additions & 6 deletions packager/live_packager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,16 @@ void FillPSSHBoxByDRM(const media::ProtectionSystemSpecificInfo& pssh_info,
pssh_info.system_id.begin())) {
data->mspr_box = pssh_info.psshs;

std::unique_ptr<media::PsshBoxBuilder> box_builder = media::PsshBoxBuilder::ParseFromBox(pssh_info.psshs.data(), pssh_info.psshs.size());
std::unique_ptr<media::PsshBoxBuilder> box_builder =
media::PsshBoxBuilder::ParseFromBox(pssh_info.psshs.data(),
pssh_info.psshs.size());
data->mspr_pro = box_builder->pssh_data();
}
}

Status PSSHGeneratorInput::Validate() const {
if (encryption_scheme != EncryptionSchemeFourCC::CBCS && encryption_scheme != EncryptionSchemeFourCC::CENC) {
if (encryption_scheme != EncryptionSchemeFourCC::CBCS &&
encryption_scheme != EncryptionSchemeFourCC::CENC) {
LOG(WARNING) << "invalid encryption scheme in PSSH generator input";
return Status(error::INVALID_ARGUMENT,
"invalid encryption scheme in PSSH generator input");
Expand All @@ -482,9 +485,13 @@ Status PSSHGeneratorInput::Validate() const {

for (size_t i = 0; i < key_ids.size(); ++i) {
if (key_ids[i].size() != 16) {
LOG(WARNING) << "invalid key id lenght in key ids array in PSSH generator input, index " + std::to_string(i);
LOG(WARNING) << "invalid key id lenght in key ids array in PSSH "
"generator input, index " +
std::to_string(i);
return Status(error::INVALID_ARGUMENT,
"invalid key id lenght in key ids array in PSSH generator input, index " + std::to_string(i));
"invalid key id lenght in key ids array in PSSH generator "
"input, index " +
std::to_string(i));
}
}

Expand All @@ -496,8 +503,7 @@ Status GeneratePSSHData(const PSSHGeneratorInput& in, PSSHData* out) {

RETURN_IF_ERROR(in.Validate());
if (!out) {
return Status(error::INVALID_ARGUMENT,
"output data cannot be null");
return Status(error::INVALID_ARGUMENT, "output data cannot be null");
}

std::vector<std::unique_ptr<media::PsshGenerator>> pssh_generators;
Expand Down
94 changes: 63 additions & 31 deletions packager/live_packager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ uint8_t hex_char_to_int(const char& c) {

std::vector<uint8_t> unhex(const std::string& in) {
std::vector<uint8_t> out;
for (std::size_t i = 1; i < in.size(); i+=2) {
out.push_back(16 * hex_char_to_int(in[i-1]) +hex_char_to_int(in[i]));
for (std::size_t i = 1; i < in.size(); i += 2) {
out.push_back(16 * hex_char_to_int(in[i - 1]) + hex_char_to_int(in[i]));
}

return out;
Expand Down Expand Up @@ -273,23 +273,46 @@ void CheckSegment(const LiveConfig& config, const FullSegmentBuffer& buffer) {
} // namespace

TEST(GeneratePSSHData, GeneratesPSSHBoxesAndMSPRObject) {
PSSHGeneratorInput in{
.encryption_scheme = EncryptionSchemeFourCC::CENC,
.key_id = unhex("00000000621f2afe7ab2c868d5fd2e2e"),
.key = unhex("1af987fa084ff3c0f4ad35a6bdab98e2"),
.key_ids = {
unhex("00000000621f2afe7ab2c868d5fd2e2e"),
unhex("00000000621f2afe7ab2c868d5fd2e2f")
}
};
PSSHGeneratorInput in{.encryption_scheme = EncryptionSchemeFourCC::CENC,
.key_id = unhex("00000000621f2afe7ab2c868d5fd2e2e"),
.key = unhex("1af987fa084ff3c0f4ad35a6bdab98e2"),
.key_ids = {unhex("00000000621f2afe7ab2c868d5fd2e2e"),
unhex("00000000621f2afe7ab2c868d5fd2e2f")}};

PSSHData expected{
.cenc_box = unbase64("AAAARHBzc2gBAAAAEHfv7MC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APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4AQQBBAEEAQQBBAEIAOQBpAC8AaQBwADYAcwBzAGgAbwAxAGYAMAB1AEwAZwA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgA0AGYAdQBCAHQARABVACsASwBrAEUAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA="),
.wv_box = unbase64("AAAASnBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAACoSEAAAAABiHyr+erLIaNX9Li4SEAAAAABiHyr+erLIaNX9Li9I49yVmwY=")
};
PSSHData actual {};
.cenc_box = unbase64("AAAARHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAIAAAAAYh8"
"q/nqyyGjV/S4uAAAAAGIfKv56ssho1f0uLwAAAAA="),
.mspr_box = unbase64(
"AAACJnBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAgYGAgAAAQABAPwBPABXAFIATQBI"
"AEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0A"
"YQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAv"
"ADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkA"
"bwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBD"
"AFQASQBOAEYATwA+"
"ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwAR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box =
unbase64("AAAASnBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAACoSEAAAAABiHyr+"
"erLIaNX9Li4SEAAAAABiHyr+erLIaNX9Li9I49yVmwY=")};
PSSHData actual{};

ASSERT_EQ(Status::OK, GeneratePSSHData(in, &actual));
ASSERT_EQ(expected.cenc_box, actual.cenc_box);
Expand All @@ -300,33 +323,42 @@ TEST(GeneratePSSHData, GeneratesPSSHBoxesAndMSPRObject) {

TEST(GeneratePSSHData, FailsOnInvalidInput) {
const PSSHGeneratorInput valid_input{
.encryption_scheme = EncryptionSchemeFourCC::CENC,
.key_id = unhex("00000000621f2afe7ab2c868d5fd2e2e"),
.key = unhex("1af987fa084ff3c0f4ad35a6bdab98e2"),
.key_ids = {
unhex("00000000621f2afe7ab2c868d5fd2e2e"),
unhex("00000000621f2afe7ab2c868d5fd2e2f")
}
};
.encryption_scheme = EncryptionSchemeFourCC::CENC,
.key_id = unhex("00000000621f2afe7ab2c868d5fd2e2e"),
.key = unhex("1af987fa084ff3c0f4ad35a6bdab98e2"),
.key_ids = {unhex("00000000621f2afe7ab2c868d5fd2e2e"),
unhex("00000000621f2afe7ab2c868d5fd2e2f")}};

PSSHGeneratorInput in;
ASSERT_EQ(Status(error::INVALID_ARGUMENT, "invalid encryption scheme in PSSH generator input"), GeneratePSSHData(in, nullptr));
ASSERT_EQ(Status(error::INVALID_ARGUMENT,
"invalid encryption scheme in PSSH generator input"),
GeneratePSSHData(in, nullptr));

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

in.key = valid_input.key;
ASSERT_EQ(Status(error::INVALID_ARGUMENT, "invalid key id lenght in PSSH generator input"), GeneratePSSHData(in, nullptr));
ASSERT_EQ(Status(error::INVALID_ARGUMENT,
"invalid key id lenght in PSSH generator input"),
GeneratePSSHData(in, nullptr));

in.key_id = valid_input.key_id;
ASSERT_EQ(Status(error::INVALID_ARGUMENT, "key ids cannot be empty in PSSH generator input"), GeneratePSSHData(in, nullptr));
ASSERT_EQ(Status(error::INVALID_ARGUMENT,
"key ids cannot be empty in PSSH generator input"),
GeneratePSSHData(in, nullptr));

in.key_ids = valid_input.key_ids;
in.key_ids[1] = {};
ASSERT_EQ(Status(error::INVALID_ARGUMENT, "invalid key id lenght in key ids array in PSSH generator input, index 1"), GeneratePSSHData(in, nullptr));
ASSERT_EQ(Status(error::INVALID_ARGUMENT,
"invalid key id lenght in key ids array in PSSH generator "
"input, index 1"),
GeneratePSSHData(in, nullptr));

in.key_ids = valid_input.key_ids;
ASSERT_EQ(Status(error::INVALID_ARGUMENT, "output data cannot be null"), GeneratePSSHData(in, nullptr));
ASSERT_EQ(Status(error::INVALID_ARGUMENT, "output data cannot be null"),
GeneratePSSHData(in, nullptr));
}

class LivePackagerBaseTest : public ::testing::Test {
Expand Down

0 comments on commit 21896f8

Please sign in to comment.