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