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/protection_system_specific_info.h"
16 #include "packager/media/base/pssh_generator.h"
17 #include "packager/status.h"
18 
19 namespace shaka {
20 namespace media {
21 
24 enum class EmeInitDataType {
25  UNKNOWN,
27  CENC,
29  WEBM,
31  KEYIDS,
33  WIDEVINE_CLASSIC,
34  MAX = WIDEVINE_CLASSIC
35 };
36 
37 struct EncryptionKey {
38  EncryptionKey();
39  ~EncryptionKey();
40 
41  std::vector<ProtectionSystemSpecificInfo> key_system_info;
42  std::vector<uint8_t> key_id;
43  std::vector<uint8_t> key;
44  std::vector<uint8_t> iv;
45 };
46 
47 typedef std::map<std::string, std::unique_ptr<EncryptionKey>> EncryptionKeyMap;
48 
50 class KeySource {
51  public:
52  explicit KeySource(int protection_systems_flags);
53 
54  virtual ~KeySource();
55 
60  virtual Status FetchKeys(EmeInitDataType init_data_type,
61  const std::vector<uint8_t>& init_data) = 0;
62 
68  virtual Status GetKey(const std::string& stream_label,
69  EncryptionKey* key) = 0;
70 
76  virtual Status GetKey(const std::vector<uint8_t>& key_id,
77  EncryptionKey* key) = 0;
78 
86  virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
87  const std::string& stream_label,
88  EncryptionKey* key) = 0;
89 
90  protected:
93  Status UpdateProtectionSystemInfo(EncryptionKeyMap* encryption_key_map);
94 
95  private:
96  std::vector<std::unique_ptr<PsshGenerator>> pssh_generators_;
97 
98  DISALLOW_COPY_AND_ASSIGN(KeySource);
99 };
100 
101 } // namespace media
102 } // namespace shaka
103 
104 #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:50