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-08-07 23:01:43 +00:00
|
|
|
#include "packager/media/base/fairplay_pssh_generator.h"
|
2017-09-12 19:22:39 +00:00
|
|
|
#include "packager/media/base/playready_pssh_generator.h"
|
|
|
|
#include "packager/media/base/raw_key_pssh_generator.h"
|
|
|
|
#include "packager/media/base/widevine_pssh_generator.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 {
|
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
EncryptionKey::EncryptionKey() {}
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2017-06-13 21:54:12 +00:00
|
|
|
EncryptionKey::~EncryptionKey() {}
|
2014-04-15 22:18:26 +00:00
|
|
|
|
2018-08-07 21:43:42 +00:00
|
|
|
KeySource::KeySource(int protection_systems_flags, FourCC protection_scheme) {
|
2017-09-12 19:22:39 +00:00
|
|
|
if (protection_systems_flags & COMMON_PROTECTION_SYSTEM_FLAG) {
|
|
|
|
pssh_generators_.emplace_back(new RawKeyPsshGenerator());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (protection_systems_flags & PLAYREADY_PROTECTION_SYSTEM_FLAG) {
|
|
|
|
pssh_generators_.emplace_back(new PlayReadyPsshGenerator());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (protection_systems_flags & WIDEVINE_PROTECTION_SYSTEM_FLAG) {
|
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
|
|
|
|
|
|
|
if (protection_systems_flags & FAIRPLAY_PROTECTION_SYSTEM_FLAG) {
|
|
|
|
pssh_generators_.emplace_back(new FairPlayPsshGenerator());
|
|
|
|
}
|
2017-09-12 19:22:39 +00:00
|
|
|
}
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2017-06-13 21:54:12 +00:00
|
|
|
KeySource::~KeySource() {}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
Status status = pssh_generator->GeneratePsshFromKeyIds(key_ids, &info);
|
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
Status status = pssh_generator->GeneratePsshFromKeyIdAndKey(
|
|
|
|
pair.second->key_id, pair.second->key, &info);
|
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
pair.second->key_system_info.push_back(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
|
2013-11-12 20:34:58 +00:00
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|