From 4408718b5bcf66d73cd55dd202291b493dfbc6cf Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Wed, 20 Jun 2018 16:12:09 -0700 Subject: [PATCH] Move ChainHandlers to MediaHandler Made ChainHandlers to MediaHandler::Chain so that it can be used in our test code as well. After all it is a pretty helpful function. Change-Id: I8d83ee184052cd9fa9b37f2741c96f3223d5ab48 --- packager/media/base/media_handler.cc | 23 ++++++++++++++++- packager/media/base/media_handler.h | 3 +++ packager/packager.cc | 38 +++++++--------------------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/packager/media/base/media_handler.cc b/packager/media/base/media_handler.cc index 425b01368f..d394b0c1f7 100644 --- a/packager/media/base/media_handler.cc +++ b/packager/media/base/media_handler.cc @@ -6,6 +6,8 @@ #include "packager/media/base/media_handler.h" +#include "packager/status_macros.h" + namespace shaka { namespace media { @@ -58,6 +60,26 @@ Status MediaHandler::Initialize() { return Status::OK; } +Status MediaHandler::Chain( + std::initializer_list> list) { + std::shared_ptr previous; + + for (auto& next : list) { + // Skip null entries. + if (!next) { + continue; + } + + if (previous) { + RETURN_IF_ERROR(previous->AddHandler(next)); + } + + previous = std::move(next); + } + + return Status::OK; +} + Status MediaHandler::OnFlushRequest(size_t input_stream_index) { // The default implementation treats the output stream index to be identical // to the input stream index, which is true for most handlers. @@ -98,6 +120,5 @@ Status MediaHandler::FlushAllDownstreams() { } return Status::OK; } - } // namespace media } // namespace shaka diff --git a/packager/media/base/media_handler.h b/packager/media/base/media_handler.h index 20d8160939..098a0a12a9 100644 --- a/packager/media/base/media_handler.h +++ b/packager/media/base/media_handler.h @@ -172,6 +172,9 @@ class MediaHandler { /// Validate if the handler is connected to its upstream handler. bool IsConnected() { return num_input_streams_ > 0; } + static Status Chain( + std::initializer_list> list); + protected: /// Internal implementation of initialize. Note that it should only initialize /// the MediaHandler itself. Downstream handlers are handled in Initialize(). diff --git a/packager/packager.cc b/packager/packager.cc index e73687c402..b58585e26e 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -67,26 +67,6 @@ namespace { const char kMediaInfoSuffix[] = ".media_info"; -Status ChainHandlers( - std::initializer_list> list) { - std::shared_ptr previous; - - for (auto& next : list) { - // Skip null entries. - if (!next) { - continue; - } - - if (previous) { - RETURN_IF_ERROR(previous->AddHandler(next)); - } - - previous = std::move(next); - } - - return Status::OK; -} - MuxerOptions CreateMuxerOptions(const StreamDescriptor& stream, const PackagingParams& params) { MuxerOptions options; @@ -497,9 +477,9 @@ Status CreateHlsTextJob(const StreamDescriptor& stream, job_manager->Add("Segmented Text Job", parser); - return ChainHandlers({std::move(parser), std::move(padder), - std::move(cue_aligner), std::move(chunker), - std::move(output)}); + return MediaHandler::Chain({std::move(parser), std::move(padder), + std::move(cue_aligner), std::move(chunker), + std::move(output)}); } Status CreateWebVttToMp4TextJob(const StreamDescriptor& stream, @@ -531,9 +511,9 @@ Status CreateWebVttToMp4TextJob(const StreamDescriptor& stream, *root = parser; - return ChainHandlers({std::move(parser), std::move(padder), - std::move(cue_aligner), std::move(chunker), - std::move(text_to_mp4), std::move(muxer)}); + return MediaHandler::Chain({std::move(parser), std::move(padder), + std::move(cue_aligner), std::move(chunker), + std::move(text_to_mp4), std::move(muxer)}); } Status CreateTextJobs( @@ -710,11 +690,11 @@ Status CreateAudioVideoJobs( // TODO(vaage) : Create a nicer way to connect handlers to demuxers. if (sync_points) { RETURN_IF_ERROR( - ChainHandlers({cue_aligner, chunker, encryptor, replicator})); + MediaHandler::Chain({cue_aligner, chunker, encryptor, replicator})); RETURN_IF_ERROR( demuxer->SetHandler(stream.stream_selector, cue_aligner)); } else { - RETURN_IF_ERROR(ChainHandlers({chunker, encryptor, replicator})); + RETURN_IF_ERROR(MediaHandler::Chain({chunker, encryptor, replicator})); RETURN_IF_ERROR(demuxer->SetHandler(stream.stream_selector, chunker)); } } @@ -738,7 +718,7 @@ Status CreateAudioVideoJobs( ? std::make_shared(stream.trick_play_factor) : nullptr; - RETURN_IF_ERROR(ChainHandlers({replicator, trick_play, muxer})); + RETURN_IF_ERROR(MediaHandler::Chain({replicator, trick_play, muxer})); } return Status::OK;