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/playready_pssh_generator.h"
11 #include "packager/media/base/raw_key_pssh_generator.h"
12 #include "packager/media/base/widevine_pssh_generator.h"
13 
14 namespace shaka {
15 namespace media {
16 
17 EncryptionKey::EncryptionKey() {}
18 
19 EncryptionKey::~EncryptionKey() {}
20 
21 KeySource::KeySource(int protection_systems_flags) {
22  if (protection_systems_flags & COMMON_PROTECTION_SYSTEM_FLAG) {
23  pssh_generators_.emplace_back(new RawKeyPsshGenerator());
24  }
25 
26  if (protection_systems_flags & PLAYREADY_PROTECTION_SYSTEM_FLAG) {
27  pssh_generators_.emplace_back(new PlayReadyPsshGenerator());
28  }
29 
30  if (protection_systems_flags & WIDEVINE_PROTECTION_SYSTEM_FLAG) {
31  pssh_generators_.emplace_back(new WidevinePsshGenerator());
32  }
33 }
34 
35 KeySource::~KeySource() {}
36 
38  EncryptionKeyMap* encryption_key_map) {
39  for (const auto& pssh_generator : pssh_generators_) {
40  const bool support_multiple_keys = pssh_generator->SupportMultipleKeys();
41  if (support_multiple_keys) {
43  std::vector<std::vector<uint8_t>> key_ids;
44  for (const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
45  key_ids.push_back(pair.second->key_id);
46  }
47  Status status = pssh_generator->GeneratePsshFromKeyIds(key_ids, &info);
48  if (!status.ok()) {
49  return status;
50  }
51  for (const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
52  pair.second->key_system_info.push_back(info);
53  }
54  } else {
55  for (const EncryptionKeyMap::value_type& pair : *encryption_key_map) {
57  Status status = pssh_generator->GeneratePsshFromKeyIdAndKey(
58  pair.second->key_id, pair.second->key, &info);
59  if (!status.ok()) {
60  return status;
61  }
62  pair.second->key_system_info.push_back(info);
63  }
64  }
65  }
66 
67  return Status::OK;
68 }
69 
70 } // namespace media
71 } // namespace shaka
All the methods that are virtual are virtual for mocking.
Status UpdateProtectionSystemInfo(EncryptionKeyMap *encryption_key_map)
Definition: key_source.cc:37