DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
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 MEDIA_BASE_KEY_SOURCE_H_
8 #define MEDIA_BASE_KEY_SOURCE_H_
9 
10 #include <vector>
11 
12 #include "packager/base/memory/scoped_ptr.h"
13 #include "packager/media/base/status.h"
14 
15 namespace edash_packager {
16 namespace media {
17 
18 const uint8_t kWidevineSystemId[] = {0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6,
19  0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc,
20  0xd5, 0x1d, 0x21, 0xed};
21 
22 struct EncryptionKey {
23  EncryptionKey();
24  ~EncryptionKey();
25 
26  std::vector<uint8_t> key_id;
27  std::vector<uint8_t> key;
28  std::vector<uint8_t> pssh;
29  std::vector<uint8_t> iv;
30 };
31 
33 class KeySource {
34  public:
35  enum TrackType {
36  TRACK_TYPE_UNKNOWN = 0,
37  TRACK_TYPE_SD = 1,
38  TRACK_TYPE_HD = 2,
39  TRACK_TYPE_AUDIO = 3,
40  TRACK_TYPE_UNSPECIFIED = 4,
41  NUM_VALID_TRACK_TYPES = 4
42  };
43 
44  virtual ~KeySource();
45 
50  virtual Status FetchKeys(const std::vector<uint8_t>& content_id,
51  const std::string& policy);
52 
56  virtual Status FetchKeys(const std::vector<uint8_t>& pssh_box);
57 
61  virtual Status FetchKeys(const std::vector<std::vector<uint8_t>>& key_ids);
62 
67  virtual Status FetchKeys(uint32_t asset_id);
68 
74  virtual Status GetKey(TrackType track_type, EncryptionKey* key);
75 
81  virtual Status GetKey(const std::vector<uint8_t>& key_id, EncryptionKey* key);
82 
90  virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
91  TrackType track_type,
92  EncryptionKey* key);
93 
98  virtual std::string UUID();
99 
105  virtual std::string SystemName();
106 
115  static scoped_ptr<KeySource> CreateFromHexStrings(
116  const std::string& key_id_hex,
117  const std::string& key_hex,
118  const std::string& pssh_data_hex,
119  const std::string& iv_hex);
120 
122  static TrackType GetTrackTypeFromString(const std::string& track_type_string);
123 
125  static std::string TrackTypeToString(TrackType track_type);
126 
127  protected:
128  KeySource();
129 
132  static std::vector<uint8_t> PsshBoxFromPsshData(
133  const std::vector<uint8_t>& pssh_data);
134 
135  private:
136  explicit KeySource(scoped_ptr<EncryptionKey> encryption_key);
137 
138  scoped_ptr<EncryptionKey> encryption_key_;
139 
140  DISALLOW_COPY_AND_ASSIGN(KeySource);
141 };
142 
143 } // namespace media
144 } // namespace edash_packager
145 
146 #endif // MEDIA_BASE_KEY_SOURCE_H_
virtual Status GetKey(TrackType track_type, EncryptionKey *key)
Definition: key_source.cc:48
virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index, TrackType track_type, EncryptionKey *key)
Definition: key_source.cc:68
virtual Status FetchKeys(const std::vector< uint8_t > &content_id, const std::string &policy)
Definition: key_source.cc:27
virtual std::string UUID()
Definition: key_source.cc:94
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:33
static scoped_ptr< KeySource > CreateFromHexStrings(const std::string &key_id_hex, const std::string &key_hex, const std::string &pssh_data_hex, const std::string &iv_hex)
Definition: key_source.cc:102
static std::vector< uint8_t > PsshBoxFromPsshData(const std::vector< uint8_t > &pssh_data)
Definition: key_source.cc:166
virtual std::string SystemName()
Definition: key_source.cc:98
static TrackType GetTrackTypeFromString(const std::string &track_type_string)
Convert string representation of track type to enum representation.
Definition: key_source.cc:138
static std::string TrackTypeToString(TrackType track_type)
Convert TrackType to string.
Definition: key_source.cc:152