7 #include "packager/app/packager_util.h"
9 #include "packager/base/logging.h"
10 #include "packager/base/strings/string_number_conversions.h"
11 #include "packager/base/strings/string_split.h"
12 #include "packager/file/file.h"
13 #include "packager/media/base/media_handler.h"
14 #include "packager/media/base/muxer_options.h"
15 #include "packager/media/base/playready_key_source.h"
16 #include "packager/media/base/raw_key_source.h"
17 #include "packager/media/base/request_signer.h"
18 #include "packager/media/base/widevine_key_source.h"
19 #include "packager/mpd/base/mpd_options.h"
20 #include "packager/status.h"
26 std::unique_ptr<RequestSigner> CreateSigner(
const WidevineSigner& signer) {
27 std::unique_ptr<RequestSigner> request_signer;
28 switch (signer.signing_key_type) {
29 case WidevineSigner::SigningKeyType::kAes:
31 signer.signer_name, signer.aes.key, signer.aes.iv));
33 case WidevineSigner::SigningKeyType::kRsa:
37 case WidevineSigner::SigningKeyType::kNone:
41 LOG(ERROR) <<
"Failed to create the signer object.";
42 return request_signer;
47 std::unique_ptr<KeySource> CreateEncryptionKeySource(
48 FourCC protection_scheme,
49 const EncryptionParams& encryption_params) {
50 std::unique_ptr<KeySource> encryption_key_source;
51 switch (encryption_params.key_provider) {
52 case KeyProvider::kWidevine: {
53 const WidevineEncryptionParams& widevine = encryption_params.widevine;
54 if (widevine.key_server_url.empty()) {
55 LOG(ERROR) <<
"'key_server_url' should not be empty.";
58 if (widevine.content_id.empty()) {
59 LOG(ERROR) <<
"'content_id' should not be empty.";
62 std::unique_ptr<WidevineKeySource> widevine_key_source(
63 new WidevineKeySource(widevine.key_server_url,
64 encryption_params.protection_systems,
66 if (!widevine.signer.signer_name.empty()) {
67 std::unique_ptr<RequestSigner> request_signer(
68 CreateSigner(widevine.signer));
71 widevine_key_source->set_signer(std::move(request_signer));
73 widevine_key_source->set_group_id(widevine.group_id);
74 widevine_key_source->set_enable_entitlement_license(
75 widevine.enable_entitlement_license);
78 widevine_key_source->FetchKeys(widevine.content_id, widevine.policy);
80 LOG(ERROR) <<
"Widevine encryption key source failed to fetch keys: "
84 encryption_key_source = std::move(widevine_key_source);
87 case KeyProvider::kRawKey: {
91 case KeyProvider::kPlayReady: {
92 const PlayReadyEncryptionParams& playready = encryption_params.playready;
93 if (!playready.key_server_url.empty() ||
94 !playready.program_identifier.empty()) {
95 if (playready.key_server_url.empty() ||
96 playready.program_identifier.empty()) {
97 LOG(ERROR) <<
"Either PlayReady key_server_url or program_identifier "
101 std::unique_ptr<PlayReadyKeySource> playready_key_source;
103 playready_key_source.reset(
new PlayReadyKeySource(
104 playready.key_server_url, encryption_params.protection_systems));
105 Status status = playready_key_source->FetchKeysWithProgramIdentifier(
106 playready.program_identifier);
108 LOG(ERROR) <<
"PlayReady encryption key source failed to fetch keys: "
112 encryption_key_source = std::move(playready_key_source);
114 LOG(ERROR) <<
"Error creating PlayReady key source.";
122 return encryption_key_source;
125 std::unique_ptr<KeySource> CreateDecryptionKeySource(
126 const DecryptionParams& decryption_params) {
127 std::unique_ptr<KeySource> decryption_key_source;
128 switch (decryption_params.key_provider) {
129 case KeyProvider::kWidevine: {
130 const WidevineDecryptionParams& widevine = decryption_params.widevine;
131 if (widevine.key_server_url.empty()) {
132 LOG(ERROR) <<
"'key_server_url' should not be empty.";
133 return std::unique_ptr<KeySource>();
135 std::unique_ptr<WidevineKeySource> widevine_key_source(
136 new WidevineKeySource(
137 widevine.key_server_url,
138 ProtectionSystem::kWidevine ,
140 if (!widevine.signer.signer_name.empty()) {
141 std::unique_ptr<RequestSigner> request_signer(
142 CreateSigner(widevine.signer));
144 return std::unique_ptr<KeySource>();
145 widevine_key_source->set_signer(std::move(request_signer));
148 decryption_key_source = std::move(widevine_key_source);
151 case KeyProvider::kRawKey: {
158 return decryption_key_source;
161 MpdOptions GetMpdOptions(
bool on_demand_profile,
const MpdParams& mpd_params) {
162 MpdOptions mpd_options;
163 mpd_options.dash_profile =
164 on_demand_profile ? DashProfile::kOnDemand : DashProfile::kLive;
165 mpd_options.mpd_type =
166 (on_demand_profile || mpd_params.generate_static_live_mpd)
169 mpd_options.mpd_params = mpd_params;