Shaka Packager SDK
playready_key_source.h
1 // Copyright 2017 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_PLAYREADY_SOURCE_H_
8 #define PACKAGER_MEDIA_BASE_PLAYREADY_SOURCE_H_
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include "packager/media/base/key_source.h"
15 
16 namespace shaka {
17 namespace media {
18 
20 class PlayReadyKeySource : public KeySource {
21  public:
29  PlayReadyKeySource(const std::string& server_url,
30  int protection_systems_flags,
31  FourCC protection_scheme);
43  PlayReadyKeySource(const std::string& server_url,
44  const std::string& client_cert_file,
45  const std::string& client_cert_private_key_file,
46  const std::string& client_cert_private_key_password,
47  int protection_systems_flags,
48  FourCC protection_scheme);
49  ~PlayReadyKeySource() override;
50 
53  Status FetchKeys(EmeInitDataType init_data_type,
54  const std::vector<uint8_t>& init_data) override;
55  Status GetKey(const std::string& stream_label, EncryptionKey* key) override;
56  Status GetKey(const std::vector<uint8_t>& key_id,
57  EncryptionKey* key) override;
58  Status GetCryptoPeriodKey(uint32_t crypto_period_index,
59  const std::string& stream_label,
60  EncryptionKey* key) override;
62  virtual Status FetchKeysWithProgramIdentifier(const std::string& program_identifier);
63 
68  static std::unique_ptr<PlayReadyKeySource> CreateFromKeyAndKeyId(
69  const std::vector<uint8_t>& key_id,
70  const std::vector<uint8_t>& key);
72  void SetCaFile(const std::string& ca_file) {
73  ca_file_ = ca_file;
74  }
75 
76  private:
77  Status GetKeyInternal();
78  Status GetCryptoPeriodKeyInternal();
79 
80  // Indicates whether PlayReady protection system should be generated.
81  bool generate_playready_protection_system_ = true;
82 
83  std::unique_ptr<EncryptionKey> encryption_key_;
84  std::string server_url_;
85  std::string ca_file_;
86  std::string client_cert_file_;
87  std::string client_cert_private_key_file_;
88  std::string client_cert_private_key_password_;
89 
90  DISALLOW_COPY_AND_ASSIGN(PlayReadyKeySource);
91 };
92 
93 } // namespace media
94 } // namespace shaka
95 
96 #endif // PACKAGER_MEDIA_BASE_PLAYREADY_SOURCE_H_
Status GetKey(const std::string &stream_label, EncryptionKey *key) override
static std::unique_ptr< PlayReadyKeySource > CreateFromKeyAndKeyId(const std::vector< uint8_t > &key_id, const std::vector< uint8_t > &key)
All the methods that are virtual are virtual for mocking.
A key source that uses PlayReady for encryption.
Status GetCryptoPeriodKey(uint32_t crypto_period_index, const std::string &stream_label, EncryptionKey *key) override
void SetCaFile(const std::string &ca_file)
Sets the Certificate Authority file for validating self-signed certificates.
Status FetchKeys(EmeInitDataType init_data_type, const std::vector< uint8_t > &init_data) override
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:48
PlayReadyKeySource(const std::string &server_url, int protection_systems_flags, FourCC protection_scheme)