Moved Encryption Handler Create to Own Method
Moved all the code used to create the encryption handler for a stream to its own function. Change-Id: I8801a194b470d899aa9fb26b4664e36e61d5d164
This commit is contained in:
parent
ec83d8a73a
commit
f2cbe8f9c1
|
@ -300,6 +300,41 @@ std::shared_ptr<Muxer> CreateOutputMuxer(const MuxerOptions& options,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<MediaHandler> CreateCryptoHandler(
|
||||||
|
const PackagingParams& packaging_params,
|
||||||
|
const StreamDescriptor& stream,
|
||||||
|
KeySource* key_source) {
|
||||||
|
if (stream.skip_encryption) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!key_source) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a copy so that we can modify it for this specific stream.
|
||||||
|
EncryptionParams encryption_params = packaging_params.encryption_params;
|
||||||
|
|
||||||
|
// Use Sample AES in MPEG2TS.
|
||||||
|
// TODO(kqyang): Consider adding a new flag to enable Sample AES as we
|
||||||
|
// will support CENC in TS in the future.
|
||||||
|
if (GetOutputFormat(stream) == CONTAINER_MPEG2TS) {
|
||||||
|
VLOG(1) << "Use Apple Sample AES encryption for MPEG2TS.";
|
||||||
|
encryption_params.protection_scheme = kAppleSampleAesProtectionScheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!encryption_params.stream_label_func) {
|
||||||
|
const int kDefaultMaxSdPixels = 768 * 576;
|
||||||
|
const int kDefaultMaxHdPixels = 1920 * 1080;
|
||||||
|
const int kDefaultMaxUhd1Pixels = 4096 * 2160;
|
||||||
|
encryption_params.stream_label_func = std::bind(
|
||||||
|
&Packager::DefaultStreamLabelFunction, kDefaultMaxSdPixels,
|
||||||
|
kDefaultMaxHdPixels, kDefaultMaxUhd1Pixels, std::placeholders::_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_shared<EncryptionHandler>(encryption_params, key_source);
|
||||||
|
}
|
||||||
|
|
||||||
Status CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
|
Status CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
|
||||||
const PackagingParams& packaging_params,
|
const PackagingParams& packaging_params,
|
||||||
FakeClock* fake_clock,
|
FakeClock* fake_clock,
|
||||||
|
@ -428,9 +463,8 @@ Status CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
|
||||||
if (hls_playlist_name.empty())
|
if (hls_playlist_name.empty())
|
||||||
hls_playlist_name = base::StringPrintf("stream_%d.m3u8", stream_number);
|
hls_playlist_name = base::StringPrintf("stream_%d.m3u8", stream_number);
|
||||||
|
|
||||||
muxer_listeners.emplace_back(
|
muxer_listeners.emplace_back(new HlsNotifyMuxerListener(
|
||||||
new HlsNotifyMuxerListener(hls_playlist_name, name,
|
hls_playlist_name, name, group_id, hls_notifier));
|
||||||
group_id, hls_notifier));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!muxer_listeners.empty()) {
|
if (!muxer_listeners.empty()) {
|
||||||
|
@ -462,26 +496,10 @@ Status CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
|
||||||
std::make_shared<ChunkingHandler>(packaging_params.chunking_params);
|
std::make_shared<ChunkingHandler>(packaging_params.chunking_params);
|
||||||
handlers.push_back(chunking_handler);
|
handlers.push_back(chunking_handler);
|
||||||
|
|
||||||
Status status;
|
std::shared_ptr<MediaHandler> crypto_handler = CreateCryptoHandler(
|
||||||
if (encryption_key_source && !stream_iter->skip_encryption) {
|
packaging_params, *stream_iter, encryption_key_source);
|
||||||
auto encryption_params = packaging_params.encryption_params;
|
if (crypto_handler) {
|
||||||
// Use Sample AES in MPEG2TS.
|
handlers.push_back(crypto_handler);
|
||||||
// TODO(kqyang): Consider adding a new flag to enable Sample AES as we
|
|
||||||
// will support CENC in TS in the future.
|
|
||||||
if (output_format == CONTAINER_MPEG2TS) {
|
|
||||||
VLOG(1) << "Use Apple Sample AES encryption for MPEG2TS.";
|
|
||||||
encryption_params.protection_scheme = kAppleSampleAesProtectionScheme;
|
|
||||||
}
|
|
||||||
if (!encryption_params.stream_label_func) {
|
|
||||||
const int kDefaultMaxSdPixels = 768 * 576;
|
|
||||||
const int kDefaultMaxHdPixels = 1920 * 1080;
|
|
||||||
const int kDefaultMaxUhd1Pixels = 4096 * 2160;
|
|
||||||
encryption_params.stream_label_func = std::bind(
|
|
||||||
&Packager::DefaultStreamLabelFunction, kDefaultMaxSdPixels,
|
|
||||||
kDefaultMaxHdPixels, kDefaultMaxUhd1Pixels, std::placeholders::_1);
|
|
||||||
}
|
|
||||||
handlers.emplace_back(
|
|
||||||
new EncryptionHandler(encryption_params, encryption_key_source));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If trick_play_handler is available, muxer should already be connected to
|
// If trick_play_handler is available, muxer should already be connected to
|
||||||
|
@ -492,15 +510,17 @@ Status CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
|
||||||
handlers.push_back(std::move(muxer));
|
handlers.push_back(std::move(muxer));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& stream_selector = stream_iter->stream_selector;
|
Status status;
|
||||||
status.Update(demuxer->SetHandler(stream_selector, chunking_handler));
|
status.Update(
|
||||||
|
demuxer->SetHandler(stream_iter->stream_selector, chunking_handler));
|
||||||
status.Update(ConnectHandlers(handlers));
|
status.Update(ConnectHandlers(handlers));
|
||||||
|
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
if (!stream_iter->language.empty())
|
if (!stream_iter->language.empty())
|
||||||
demuxer->SetLanguageOverride(stream_selector, stream_iter->language);
|
demuxer->SetLanguageOverride(stream_iter->stream_selector,
|
||||||
|
stream_iter->language);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize processing graph.
|
// Initialize processing graph.
|
||||||
|
|
Loading…
Reference in New Issue