7 #include <packager/app/packager_util.h>
9 #include <absl/log/log.h>
11 #include <packager/file.h>
12 #include <packager/media/base/media_handler.h>
13 #include <packager/media/base/muxer_options.h>
14 #include <packager/media/base/playready_key_source.h>
15 #include <packager/media/base/raw_key_source.h>
16 #include <packager/media/base/request_signer.h>
17 #include <packager/media/base/widevine_key_source.h>
18 #include <packager/mpd/base/mpd_options.h>
24 std::unique_ptr<RequestSigner> CreateSigner(
const WidevineSigner& signer) {
25 std::unique_ptr<RequestSigner> request_signer;
26 switch (signer.signing_key_type) {
27 case WidevineSigner::SigningKeyType::kAes:
29 signer.signer_name, signer.aes.key, signer.aes.iv));
31 case WidevineSigner::SigningKeyType::kRsa:
35 case WidevineSigner::SigningKeyType::kNone:
39 LOG(ERROR) <<
"Failed to create the signer object.";
40 return request_signer;
45 std::unique_ptr<KeySource> CreateEncryptionKeySource(
46 FourCC protection_scheme,
47 const EncryptionParams& encryption_params) {
48 std::unique_ptr<KeySource> encryption_key_source;
49 switch (encryption_params.key_provider) {
50 case KeyProvider::kWidevine: {
51 const WidevineEncryptionParams& widevine = encryption_params.widevine;
52 if (widevine.key_server_url.empty()) {
53 LOG(ERROR) <<
"'key_server_url' should not be empty.";
56 if (widevine.content_id.empty()) {
57 LOG(ERROR) <<
"'content_id' should not be empty.";
60 std::unique_ptr<WidevineKeySource> widevine_key_source(
61 new WidevineKeySource(widevine.key_server_url,
62 encryption_params.protection_systems,
64 if (!widevine.signer.signer_name.empty()) {
65 std::unique_ptr<RequestSigner> request_signer(
66 CreateSigner(widevine.signer));
69 widevine_key_source->set_signer(std::move(request_signer));
71 widevine_key_source->set_group_id(widevine.group_id);
72 widevine_key_source->set_enable_entitlement_license(
73 widevine.enable_entitlement_license);
76 widevine_key_source->FetchKeys(widevine.content_id, widevine.policy);
78 LOG(ERROR) <<
"Widevine encryption key source failed to fetch keys: "
82 encryption_key_source = std::move(widevine_key_source);
85 case KeyProvider::kRawKey: {
89 case KeyProvider::kPlayReady: {
90 const PlayReadyEncryptionParams& playready = encryption_params.playready;
91 if (!playready.key_server_url.empty() ||
92 !playready.program_identifier.empty()) {
93 if (playready.key_server_url.empty() ||
94 playready.program_identifier.empty()) {
95 LOG(ERROR) <<
"Either PlayReady key_server_url or program_identifier "
99 std::unique_ptr<PlayReadyKeySource> playready_key_source;
101 playready_key_source.reset(
new PlayReadyKeySource(
102 playready.key_server_url, encryption_params.protection_systems));
103 Status status = playready_key_source->FetchKeysWithProgramIdentifier(
104 playready.program_identifier);
106 LOG(ERROR) <<
"PlayReady encryption key source failed to fetch keys: "
107 << status.ToString();
110 encryption_key_source = std::move(playready_key_source);
112 LOG(ERROR) <<
"Error creating PlayReady key source.";
120 return encryption_key_source;
123 std::unique_ptr<KeySource> CreateDecryptionKeySource(
124 const DecryptionParams& decryption_params) {
125 std::unique_ptr<KeySource> decryption_key_source;
126 switch (decryption_params.key_provider) {
127 case KeyProvider::kWidevine: {
128 const WidevineDecryptionParams& widevine = decryption_params.widevine;
129 if (widevine.key_server_url.empty()) {
130 LOG(ERROR) <<
"'key_server_url' should not be empty.";
131 return std::unique_ptr<KeySource>();
133 std::unique_ptr<WidevineKeySource> widevine_key_source(
134 new WidevineKeySource(
135 widevine.key_server_url,
136 ProtectionSystem::kWidevine ,
138 if (!widevine.signer.signer_name.empty()) {
139 std::unique_ptr<RequestSigner> request_signer(
140 CreateSigner(widevine.signer));
142 return std::unique_ptr<KeySource>();
143 widevine_key_source->set_signer(std::move(request_signer));
146 decryption_key_source = std::move(widevine_key_source);
149 case KeyProvider::kRawKey: {
156 return decryption_key_source;
159 MpdOptions GetMpdOptions(
bool on_demand_profile,
const MpdParams& mpd_params) {
160 MpdOptions mpd_options;
161 mpd_options.dash_profile =
162 on_demand_profile ? DashProfile::kOnDemand : DashProfile::kLive;
163 mpd_options.mpd_type =
164 (on_demand_profile || mpd_params.generate_static_live_mpd)
167 mpd_options.mpd_params = mpd_params;
All the methods that are virtual are virtual for mocking.