7 #include "packager/media/base/key_source.h" 9 #include "packager/base/logging.h" 10 #include "packager/media/base/common_pssh_generator.h" 11 #include "packager/media/base/playready_pssh_generator.h" 12 #include "packager/media/base/protection_system_ids.h" 13 #include "packager/media/base/widevine_pssh_generator.h" 14 #include "packager/status_macros.h" 19 KeySource::KeySource(
int protection_systems_flags, FourCC protection_scheme) {
20 if (protection_systems_flags & COMMON_PROTECTION_SYSTEM_FLAG) {
21 pssh_generators_.emplace_back(
new CommonPsshGenerator());
24 if (protection_systems_flags & PLAYREADY_PROTECTION_SYSTEM_FLAG) {
25 pssh_generators_.emplace_back(
26 new PlayReadyPsshGenerator(protection_scheme));
29 if (protection_systems_flags & WIDEVINE_PROTECTION_SYSTEM_FLAG) {
30 pssh_generators_.emplace_back(
new WidevinePsshGenerator(protection_scheme));
33 if (protection_systems_flags & FAIRPLAY_PROTECTION_SYSTEM_FLAG) {
34 no_pssh_systems_.emplace_back(std::begin(kFairPlaySystemId),
35 std::end(kFairPlaySystemId));
40 if (protection_systems_flags & MARLIN_PROTECTION_SYSTEM_FLAG) {
41 no_pssh_systems_.emplace_back(std::begin(kMarlinSystemId),
42 std::end(kMarlinSystemId));
46 KeySource::~KeySource() =
default;
49 EncryptionKeyMap* encryption_key_map) {
50 for (
const auto& pssh_generator : pssh_generators_) {
51 const bool support_multiple_keys = pssh_generator->SupportMultipleKeys();
52 if (support_multiple_keys) {
54 std::vector<std::vector<uint8_t>> key_ids;
55 for (
const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
56 key_ids.push_back(pair.second->key_id);
58 RETURN_IF_ERROR(pssh_generator->GeneratePsshFromKeyIds(key_ids, &info));
59 for (
const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
60 pair.second->key_system_info.push_back(info);
63 for (
const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
65 RETURN_IF_ERROR(pssh_generator->GeneratePsshFromKeyIdAndKey(
66 pair.second->key_id, pair.second->key, &info));
67 pair.second->key_system_info.push_back(info);
72 for (
const auto& no_pssh_system : no_pssh_systems_) {
74 info.system_id = no_pssh_system;
75 for (
const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
76 pair.second->key_system_info.push_back(info);
All the methods that are virtual are virtual for mocking.