Shaka Packager SDK
key_source.h
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 #ifndef PACKAGER_MEDIA_BASE_KEY_SOURCE_H_
8 #define PACKAGER_MEDIA_BASE_KEY_SOURCE_H_
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "packager/media/base/fourccs.h"
16 #include "packager/media/base/protection_system_specific_info.h"
17 #include "packager/media/base/pssh_generator.h"
18 #include "packager/status.h"
19 
20 namespace shaka {
21 namespace media {
22 
25 enum class EmeInitDataType {
26  UNKNOWN,
28  CENC,
30  WEBM,
32  KEYIDS,
34  WIDEVINE_CLASSIC,
35  MAX = WIDEVINE_CLASSIC
36 };
37 
38 struct EncryptionKey {
39  std::vector<ProtectionSystemSpecificInfo> key_system_info;
40  std::vector<uint8_t> key_id;
41  std::vector<uint8_t> key;
42  std::vector<uint8_t> iv;
43 };
44 
45 typedef std::map<std::string, std::unique_ptr<EncryptionKey>> EncryptionKeyMap;
46 
48 class KeySource {
49  public:
50  KeySource(int protection_systems_flags, FourCC protection_scheme);
51 
52  virtual ~KeySource();
53 
58  virtual Status FetchKeys(EmeInitDataType init_data_type,
59  const std::vector<uint8_t>& init_data) = 0;
60 
66  virtual Status GetKey(const std::string& stream_label,
67  EncryptionKey* key) = 0;
68 
74  virtual Status GetKey(const std::vector<uint8_t>& key_id,
75  EncryptionKey* key) = 0;
76 
84  virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
85  const std::string& stream_label,
86  EncryptionKey* key) = 0;
87 
88  protected:
91  Status UpdateProtectionSystemInfo(EncryptionKeyMap* encryption_key_map);
92 
93  private:
94  std::vector<std::unique_ptr<PsshGenerator>> pssh_generators_;
95 
96  DISALLOW_COPY_AND_ASSIGN(KeySource);
97 };
98 
99 } // namespace media
100 } // namespace shaka
101 
102 #endif // PACKAGER_MEDIA_BASE_KEY_SOURCE_H_
All the methods that are virtual are virtual for mocking.
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:48