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 struct EncryptionKey {
19  EncryptionKey();
20  ~EncryptionKey();
21 
22  std::vector<uint8_t> key_id;
23  std::vector<uint8_t> key;
24  std::vector<uint8_t> pssh;
25  std::vector<uint8_t> iv;
26 };
27 
29 class KeySource {
30  public:
31  enum TrackType {
32  TRACK_TYPE_UNKNOWN = 0,
33  TRACK_TYPE_SD = 1,
34  TRACK_TYPE_HD = 2,
35  TRACK_TYPE_AUDIO = 3,
36  TRACK_TYPE_UNSPECIFIED = 4,
37  NUM_VALID_TRACK_TYPES = 4
38  };
39 
40  virtual ~KeySource();
41 
46  virtual Status FetchKeys(const std::vector<uint8_t>& content_id,
47  const std::string& policy);
48 
53  virtual Status FetchKeys(const std::vector<uint8_t>& pssh_data);
54 
59  virtual Status FetchKeys(uint32_t asset_id);
60 
66  virtual Status GetKey(TrackType track_type, EncryptionKey* key);
67 
73  virtual Status GetKey(const std::vector<uint8_t>& key_id, EncryptionKey* key);
74 
82  virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
83  TrackType track_type,
84  EncryptionKey* key);
85 
90  virtual std::string UUID();
91 
97  virtual std::string SystemName();
98 
107  static scoped_ptr<KeySource> CreateFromHexStrings(
108  const std::string& key_id_hex,
109  const std::string& key_hex,
110  const std::string& pssh_data_hex,
111  const std::string& iv_hex);
112 
114  static TrackType GetTrackTypeFromString(const std::string& track_type_string);
115 
117  static std::string TrackTypeToString(TrackType track_type);
118 
119  protected:
120  KeySource();
121 
124  static std::vector<uint8_t> PsshBoxFromPsshData(
125  const std::vector<uint8_t>& pssh_data);
126 
127  private:
128  explicit KeySource(scoped_ptr<EncryptionKey> encryption_key);
129 
130  scoped_ptr<EncryptionKey> encryption_key_;
131 
132  DISALLOW_COPY_AND_ASSIGN(KeySource);
133 };
134 
135 } // namespace media
136 } // namespace edash_packager
137 
138 #endif // MEDIA_BASE_KEY_SOURCE_H_
virtual Status GetKey(TrackType track_type, EncryptionKey *key)
Definition: key_source.cc:46
virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index, TrackType track_type, EncryptionKey *key)
Definition: key_source.cc:66
virtual Status FetchKeys(const std::vector< uint8_t > &content_id, const std::string &policy)
Definition: key_source.cc:30
virtual std::string UUID()
Definition: key_source.cc:92
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:29
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:100
static std::vector< uint8_t > PsshBoxFromPsshData(const std::vector< uint8_t > &pssh_data)
Definition: key_source.cc:164
virtual std::string SystemName()
Definition: key_source.cc:96
static TrackType GetTrackTypeFromString(const std::string &track_type_string)
Convert string representation of track type to enum representation.
Definition: key_source.cc:136
static std::string TrackTypeToString(TrackType track_type)
Convert TrackType to string.
Definition: key_source.cc:150