Shaka Packager SDK
key_source.cc
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/media/base/key_source.h"
8 
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"
15 
16 namespace shaka {
17 namespace media {
18 
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());
22  }
23 
24  if (protection_systems_flags & PLAYREADY_PROTECTION_SYSTEM_FLAG) {
25  pssh_generators_.emplace_back(
26  new PlayReadyPsshGenerator(protection_scheme));
27  }
28 
29  if (protection_systems_flags & WIDEVINE_PROTECTION_SYSTEM_FLAG) {
30  pssh_generators_.emplace_back(new WidevinePsshGenerator(protection_scheme));
31  }
32 
33  if (protection_systems_flags & FAIRPLAY_PROTECTION_SYSTEM_FLAG) {
34  no_pssh_systems_.emplace_back(std::begin(kFairPlaySystemId),
35  std::end(kFairPlaySystemId));
36  }
37  // We only support Marlin Adaptive Streaming Specification – Simple Profile
38  // with Implicit Content ID Mapping, which does not need a PSSH. Marlin
39  // specific PSSH with Explicit Content ID Mapping is not generated.
40  if (protection_systems_flags & MARLIN_PROTECTION_SYSTEM_FLAG) {
41  no_pssh_systems_.emplace_back(std::begin(kMarlinSystemId),
42  std::end(kMarlinSystemId));
43  }
44 }
45 
46 KeySource::~KeySource() = default;
47 
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);
57  }
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);
61  }
62  } else {
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);
68  }
69  }
70  }
71 
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);
77  }
78  }
79 
80  return Status::OK;
81 }
82 
83 } // namespace media
84 } // namespace shaka
All the methods that are virtual are virtual for mocking.
Status UpdateProtectionSystemInfo(EncryptionKeyMap *encryption_key_map)
Definition: key_source.cc:48