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 <string>
11 #include <vector>
12 
13 #include "packager/base/memory/scoped_ptr.h"
14 #include "packager/media/base/protection_system_specific_info.h"
15 #include "packager/media/base/status.h"
16 
17 namespace edash_packager {
18 namespace media {
19 
20 const uint8_t kWidevineSystemId[] = {0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6,
21  0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc,
22  0xd5, 0x1d, 0x21, 0xed};
23 
24 struct EncryptionKey {
25  EncryptionKey();
26  ~EncryptionKey();
27 
28  std::vector<ProtectionSystemSpecificInfo> key_system_info;
29  std::vector<uint8_t> key_id;
30  std::vector<uint8_t> key;
31  std::vector<uint8_t> iv;
32 };
33 
35 class KeySource {
36  public:
37  enum TrackType {
38  TRACK_TYPE_UNKNOWN = 0,
39  TRACK_TYPE_SD = 1,
40  TRACK_TYPE_HD = 2,
41  TRACK_TYPE_AUDIO = 3,
42  TRACK_TYPE_UNSPECIFIED = 4,
43  NUM_VALID_TRACK_TYPES = 4
44  };
45 
46  virtual ~KeySource();
47 
52  virtual Status FetchKeys(const std::vector<uint8_t>& content_id,
53  const std::string& policy);
54 
58  virtual Status FetchKeys(const std::vector<uint8_t>& pssh_box);
59 
63  virtual Status FetchKeys(const std::vector<std::vector<uint8_t>>& key_ids);
64 
69  virtual Status FetchKeys(uint32_t asset_id);
70 
76  virtual Status GetKey(TrackType track_type, EncryptionKey* key);
77 
83  virtual Status GetKey(const std::vector<uint8_t>& key_id, EncryptionKey* key);
84 
92  virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
93  TrackType track_type,
94  EncryptionKey* key);
95 
104  static scoped_ptr<KeySource> CreateFromHexStrings(
105  const std::string& key_id_hex,
106  const std::string& key_hex,
107  const std::string& pssh_data_hex,
108  const std::string& iv_hex);
109 
111  static TrackType GetTrackTypeFromString(const std::string& track_type_string);
112 
114  static std::string TrackTypeToString(TrackType track_type);
115 
116  protected:
117  KeySource();
118 
119  private:
120  explicit KeySource(scoped_ptr<EncryptionKey> encryption_key);
121 
122  scoped_ptr<EncryptionKey> encryption_key_;
123 
124  DISALLOW_COPY_AND_ASSIGN(KeySource);
125 };
126 
127 } // namespace media
128 } // namespace edash_packager
129 
130 #endif // MEDIA_BASE_KEY_SOURCE_H_
virtual Status GetKey(TrackType track_type, EncryptionKey *key)
Definition: key_source.cc:42
virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index, TrackType track_type, EncryptionKey *key)
Definition: key_source.cc:62
virtual Status FetchKeys(const std::vector< uint8_t > &content_id, const std::string &policy)
Definition: key_source.cc:21
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:35
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 TrackType GetTrackTypeFromString(const std::string &track_type_string)
Convert string representation of track type to enum representation.
Definition: key_source.cc:142
static std::string TrackTypeToString(TrackType track_type)
Convert TrackType to string.
Definition: key_source.cc:156