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  uint32_t crypto_period_duration_in_seconds,
60  const std::string& stream_label,
61  EncryptionKey* key) override;
63  virtual Status FetchKeysWithProgramIdentifier(const std::string& program_identifier);
64 
69  static std::unique_ptr<PlayReadyKeySource> CreateFromKeyAndKeyId(
70  const std::vector<uint8_t>& key_id,
71  const std::vector<uint8_t>& key);
73  void SetCaFile(const std::string& ca_file) {
74  ca_file_ = ca_file;
75  }
76 
77  private:
78  Status GetKeyInternal();
79  Status GetCryptoPeriodKeyInternal();
80 
81  // Indicates whether PlayReady protection system should be generated.
82  bool generate_playready_protection_system_ = true;
83 
84  std::unique_ptr<EncryptionKey> encryption_key_;
85  std::string server_url_;
86  std::string ca_file_;
87  std::string client_cert_file_;
88  std::string client_cert_private_key_file_;
89  std::string client_cert_private_key_password_;
90 
91  DISALLOW_COPY_AND_ASSIGN(PlayReadyKeySource);
92 };
93 
94 } // namespace media
95 } // namespace shaka
96 
97 #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.
Status GetCryptoPeriodKey(uint32_t crypto_period_index, uint32_t crypto_period_duration_in_seconds, const std::string &stream_label, EncryptionKey *key) override
A key source that uses PlayReady for encryption.
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)