2014-02-14 23:21:05 +00:00
|
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// 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
|
2013-11-12 20:34:58 +00:00
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
|
#include "packager/media/base/key_source.h"
|
2013-11-12 20:34:58 +00:00
|
|
|
|
|
2016-02-19 20:23:37 +00:00
|
|
|
|
#include "packager/base/logging.h"
|
2018-09-17 22:04:38 +00:00
|
|
|
|
#include "packager/media/base/common_pssh_generator.h"
|
2017-09-12 19:22:39 +00:00
|
|
|
|
#include "packager/media/base/playready_pssh_generator.h"
|
2018-09-17 22:39:26 +00:00
|
|
|
|
#include "packager/media/base/protection_system_ids.h"
|
2017-09-12 19:22:39 +00:00
|
|
|
|
#include "packager/media/base/widevine_pssh_generator.h"
|
2018-08-10 01:31:44 +00:00
|
|
|
|
#include "packager/status_macros.h"
|
2014-01-13 19:34:08 +00:00
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
|
namespace shaka {
|
2013-11-12 20:34:58 +00:00
|
|
|
|
namespace media {
|
|
|
|
|
|
2020-05-29 18:45:57 +00:00
|
|
|
|
KeySource::KeySource(ProtectionSystem protection_systems,
|
|
|
|
|
FourCC protection_scheme) {
|
|
|
|
|
if (has_flag(protection_systems, ProtectionSystem::kCommon)) {
|
2018-09-17 22:04:38 +00:00
|
|
|
|
pssh_generators_.emplace_back(new CommonPsshGenerator());
|
2017-09-12 19:22:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 18:45:57 +00:00
|
|
|
|
if (has_flag(protection_systems, ProtectionSystem::kPlayReady)) {
|
2019-11-15 19:48:48 +00:00
|
|
|
|
pssh_generators_.emplace_back(
|
|
|
|
|
new PlayReadyPsshGenerator(protection_scheme));
|
2017-09-12 19:22:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 18:45:57 +00:00
|
|
|
|
if (has_flag(protection_systems, ProtectionSystem::kWidevine)) {
|
2018-08-07 21:43:42 +00:00
|
|
|
|
pssh_generators_.emplace_back(new WidevinePsshGenerator(protection_scheme));
|
2017-09-12 19:22:39 +00:00
|
|
|
|
}
|
2018-08-07 23:01:43 +00:00
|
|
|
|
|
2020-05-29 18:45:57 +00:00
|
|
|
|
if (has_flag(protection_systems, ProtectionSystem::kFairPlay)) {
|
2018-09-17 22:39:26 +00:00
|
|
|
|
no_pssh_systems_.emplace_back(std::begin(kFairPlaySystemId),
|
|
|
|
|
std::end(kFairPlaySystemId));
|
2018-08-07 23:01:43 +00:00
|
|
|
|
}
|
2018-09-18 00:27:02 +00:00
|
|
|
|
// We only support Marlin Adaptive Streaming Specification – Simple Profile
|
|
|
|
|
// with Implicit Content ID Mapping, which does not need a PSSH. Marlin
|
|
|
|
|
// specific PSSH with Explicit Content ID Mapping is not generated.
|
2020-05-29 18:45:57 +00:00
|
|
|
|
if (has_flag(protection_systems, ProtectionSystem::kMarlin)) {
|
2018-09-18 00:27:02 +00:00
|
|
|
|
no_pssh_systems_.emplace_back(std::begin(kMarlinSystemId),
|
|
|
|
|
std::end(kMarlinSystemId));
|
|
|
|
|
}
|
2017-09-12 19:22:39 +00:00
|
|
|
|
}
|
2014-01-13 19:34:08 +00:00
|
|
|
|
|
2018-08-10 01:31:44 +00:00
|
|
|
|
KeySource::~KeySource() = default;
|
2017-06-13 21:54:12 +00:00
|
|
|
|
|
2017-09-12 19:22:39 +00:00
|
|
|
|
Status KeySource::UpdateProtectionSystemInfo(
|
|
|
|
|
EncryptionKeyMap* encryption_key_map) {
|
|
|
|
|
for (const auto& pssh_generator : pssh_generators_) {
|
|
|
|
|
const bool support_multiple_keys = pssh_generator->SupportMultipleKeys();
|
|
|
|
|
if (support_multiple_keys) {
|
|
|
|
|
ProtectionSystemSpecificInfo info;
|
|
|
|
|
std::vector<std::vector<uint8_t>> key_ids;
|
|
|
|
|
for (const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
|
|
|
|
|
key_ids.push_back(pair.second->key_id);
|
|
|
|
|
}
|
2018-08-10 01:31:44 +00:00
|
|
|
|
RETURN_IF_ERROR(pssh_generator->GeneratePsshFromKeyIds(key_ids, &info));
|
2017-09-12 19:22:39 +00:00
|
|
|
|
for (const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
|
|
|
|
|
pair.second->key_system_info.push_back(info);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
|
|
|
|
|
ProtectionSystemSpecificInfo info;
|
2018-08-10 01:31:44 +00:00
|
|
|
|
RETURN_IF_ERROR(pssh_generator->GeneratePsshFromKeyIdAndKey(
|
|
|
|
|
pair.second->key_id, pair.second->key, &info));
|
2017-09-12 19:22:39 +00:00
|
|
|
|
pair.second->key_system_info.push_back(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 22:39:26 +00:00
|
|
|
|
for (const auto& no_pssh_system : no_pssh_systems_) {
|
|
|
|
|
ProtectionSystemSpecificInfo info;
|
|
|
|
|
info.system_id = no_pssh_system;
|
|
|
|
|
for (const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
|
|
|
|
|
pair.second->key_system_info.push_back(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-12 19:22:39 +00:00
|
|
|
|
return Status::OK;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 20:34:58 +00:00
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
|
} // namespace shaka
|