2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-09-12 19:22:39 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/media/base/widevine_pssh_generator.h>
|
2017-09-12 19:22:39 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/macros/compiler.h>
|
|
|
|
#include <packager/macros/logging.h>
|
|
|
|
#include <packager/media/base/protection_system_ids.h>
|
|
|
|
#include <packager/media/base/widevine_pssh_data.pb.h>
|
2017-09-12 19:22:39 +00:00
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
2018-08-07 20:47:53 +00:00
|
|
|
namespace {
|
|
|
|
// Use version 0 for backward compatibility.
|
|
|
|
const uint8_t kWidevinePsshBoxVersion = 0;
|
2018-08-07 21:43:42 +00:00
|
|
|
|
|
|
|
std::vector<uint8_t> StringToBytes(const std::string& string) {
|
|
|
|
return std::vector<uint8_t>(string.begin(), string.end());
|
|
|
|
}
|
2018-08-07 20:47:53 +00:00
|
|
|
} // namespace
|
2017-09-12 19:22:39 +00:00
|
|
|
|
2018-08-07 21:43:42 +00:00
|
|
|
WidevinePsshGenerator::WidevinePsshGenerator(FourCC protection_scheme)
|
2018-08-07 20:47:53 +00:00
|
|
|
: PsshGenerator(std::vector<uint8_t>(std::begin(kWidevineSystemId),
|
|
|
|
std::end(kWidevineSystemId)),
|
2018-08-07 21:43:42 +00:00
|
|
|
kWidevinePsshBoxVersion),
|
|
|
|
protection_scheme_(protection_scheme) {}
|
2017-09-12 19:22:39 +00:00
|
|
|
|
|
|
|
WidevinePsshGenerator::~WidevinePsshGenerator() {}
|
|
|
|
|
|
|
|
bool WidevinePsshGenerator::SupportMultipleKeys() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<std::vector<uint8_t>>
|
2017-09-12 19:22:39 +00:00
|
|
|
WidevinePsshGenerator::GeneratePsshDataFromKeyIds(
|
|
|
|
const std::vector<std::vector<uint8_t>>& key_ids) const {
|
2018-08-07 21:43:42 +00:00
|
|
|
media::WidevinePsshData widevine_pssh_data;
|
|
|
|
for (const std::vector<uint8_t>& key_id : key_ids)
|
|
|
|
widevine_pssh_data.add_key_id(key_id.data(), key_id.size());
|
|
|
|
if (protection_scheme_ != FOURCC_NULL)
|
|
|
|
widevine_pssh_data.set_protection_scheme(protection_scheme_);
|
|
|
|
return StringToBytes(widevine_pssh_data.SerializeAsString());
|
2017-09-12 19:22:39 +00:00
|
|
|
}
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<std::vector<uint8_t>>
|
2017-09-12 19:22:39 +00:00
|
|
|
WidevinePsshGenerator::GeneratePsshDataFromKeyIdAndKey(
|
|
|
|
const std::vector<uint8_t>& key_id,
|
|
|
|
const std::vector<uint8_t>& key) const {
|
2023-12-01 17:32:19 +00:00
|
|
|
UNUSED(key_id);
|
|
|
|
UNUSED(key);
|
2017-09-12 19:22:39 +00:00
|
|
|
NOTIMPLEMENTED();
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2017-09-12 19:22:39 +00:00
|
|
|
}
|
2018-08-07 20:47:53 +00:00
|
|
|
|
2017-09-12 19:22:39 +00:00
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|