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;
41  std::vector<uint8_t> key_id;
43  std::vector<std::vector<uint8_t>> key_ids;
44  std::vector<uint8_t> key;
45  std::vector<uint8_t> iv;
46 };
47 
48 typedef std::map<std::string, std::unique_ptr<EncryptionKey>> EncryptionKeyMap;
49 
51 class KeySource {
52  public:
53  KeySource();
54 
55  virtual ~KeySource();
56 
61  virtual Status FetchKeys(EmeInitDataType init_data_type,
62  const std::vector<uint8_t>& init_data) = 0;
63 
69  virtual Status GetKey(const std::string& stream_label,
70  EncryptionKey* key) = 0;
71 
77  virtual Status GetKey(const std::vector<uint8_t>& key_id,
78  EncryptionKey* key) = 0;
79 
89  virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
90  uint32_t crypto_period_duration_in_seconds,
91  const std::string& stream_label,
92  EncryptionKey* key) = 0;
93 
94  private:
95  DISALLOW_COPY_AND_ASSIGN(KeySource);
96 };
97 
98 } // namespace media
99 } // namespace shaka
100 
101 #endif // PACKAGER_MEDIA_BASE_KEY_SOURCE_H_
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:51
virtual Status FetchKeys(EmeInitDataType init_data_type, const std::vector< uint8_t > &init_data)=0
virtual Status GetKey(const std::vector< uint8_t > &key_id, EncryptionKey *key)=0
virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index, uint32_t crypto_period_duration_in_seconds, const std::string &stream_label, EncryptionKey *key)=0
virtual Status GetKey(const std::string &stream_label, EncryptionKey *key)=0
All the methods that are virtual are virtual for mocking.
std::vector< std::vector< uint8_t > > key_ids
The IDs of the other keys to include in PSSH info.
Definition: key_source.h:43
std::vector< uint8_t > key_id
The ID of this key.
Definition: key_source.h:41