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
This commit is contained in:
parent
eb2385491c
commit
4408718b5b
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include "packager/media/base/media_handler.h"
|
#include "packager/media/base/media_handler.h"
|
||||||
|
|
||||||
|
#include "packager/status_macros.h"
|
||||||
|
|
||||||
namespace shaka {
|
namespace shaka {
|
||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
|
@ -58,6 +60,26 @@ Status MediaHandler::Initialize() {
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status MediaHandler::Chain(
|
||||||
|
std::initializer_list<std::shared_ptr<MediaHandler>> list) {
|
||||||
|
std::shared_ptr<MediaHandler> 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) {
|
Status MediaHandler::OnFlushRequest(size_t input_stream_index) {
|
||||||
// The default implementation treats the output stream index to be identical
|
// The default implementation treats the output stream index to be identical
|
||||||
// to the input stream index, which is true for most handlers.
|
// to the input stream index, which is true for most handlers.
|
||||||
|
@ -98,6 +120,5 @@ Status MediaHandler::FlushAllDownstreams() {
|
||||||
}
|
}
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace media
|
} // namespace media
|
||||||
} // namespace shaka
|
} // namespace shaka
|
||||||
|
|
|
@ -172,6 +172,9 @@ class MediaHandler {
|
||||||
/// Validate if the handler is connected to its upstream handler.
|
/// Validate if the handler is connected to its upstream handler.
|
||||||
bool IsConnected() { return num_input_streams_ > 0; }
|
bool IsConnected() { return num_input_streams_ > 0; }
|
||||||
|
|
||||||
|
static Status Chain(
|
||||||
|
std::initializer_list<std::shared_ptr<MediaHandler>> list);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Internal implementation of initialize. Note that it should only initialize
|
/// Internal implementation of initialize. Note that it should only initialize
|
||||||
/// the MediaHandler itself. Downstream handlers are handled in Initialize().
|
/// the MediaHandler itself. Downstream handlers are handled in Initialize().
|
||||||
|
|
|
@ -67,26 +67,6 @@ namespace {
|
||||||
|
|
||||||
const char kMediaInfoSuffix[] = ".media_info";
|
const char kMediaInfoSuffix[] = ".media_info";
|
||||||
|
|
||||||
Status ChainHandlers(
|
|
||||||
std::initializer_list<std::shared_ptr<MediaHandler>> list) {
|
|
||||||
std::shared_ptr<MediaHandler> 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,
|
MuxerOptions CreateMuxerOptions(const StreamDescriptor& stream,
|
||||||
const PackagingParams& params) {
|
const PackagingParams& params) {
|
||||||
MuxerOptions options;
|
MuxerOptions options;
|
||||||
|
@ -497,7 +477,7 @@ Status CreateHlsTextJob(const StreamDescriptor& stream,
|
||||||
|
|
||||||
job_manager->Add("Segmented Text Job", parser);
|
job_manager->Add("Segmented Text Job", parser);
|
||||||
|
|
||||||
return ChainHandlers({std::move(parser), std::move(padder),
|
return MediaHandler::Chain({std::move(parser), std::move(padder),
|
||||||
std::move(cue_aligner), std::move(chunker),
|
std::move(cue_aligner), std::move(chunker),
|
||||||
std::move(output)});
|
std::move(output)});
|
||||||
}
|
}
|
||||||
|
@ -531,7 +511,7 @@ Status CreateWebVttToMp4TextJob(const StreamDescriptor& stream,
|
||||||
|
|
||||||
*root = parser;
|
*root = parser;
|
||||||
|
|
||||||
return ChainHandlers({std::move(parser), std::move(padder),
|
return MediaHandler::Chain({std::move(parser), std::move(padder),
|
||||||
std::move(cue_aligner), std::move(chunker),
|
std::move(cue_aligner), std::move(chunker),
|
||||||
std::move(text_to_mp4), std::move(muxer)});
|
std::move(text_to_mp4), std::move(muxer)});
|
||||||
}
|
}
|
||||||
|
@ -710,11 +690,11 @@ Status CreateAudioVideoJobs(
|
||||||
// TODO(vaage) : Create a nicer way to connect handlers to demuxers.
|
// TODO(vaage) : Create a nicer way to connect handlers to demuxers.
|
||||||
if (sync_points) {
|
if (sync_points) {
|
||||||
RETURN_IF_ERROR(
|
RETURN_IF_ERROR(
|
||||||
ChainHandlers({cue_aligner, chunker, encryptor, replicator}));
|
MediaHandler::Chain({cue_aligner, chunker, encryptor, replicator}));
|
||||||
RETURN_IF_ERROR(
|
RETURN_IF_ERROR(
|
||||||
demuxer->SetHandler(stream.stream_selector, cue_aligner));
|
demuxer->SetHandler(stream.stream_selector, cue_aligner));
|
||||||
} else {
|
} 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));
|
RETURN_IF_ERROR(demuxer->SetHandler(stream.stream_selector, chunker));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,7 +718,7 @@ Status CreateAudioVideoJobs(
|
||||||
? std::make_shared<TrickPlayHandler>(stream.trick_play_factor)
|
? std::make_shared<TrickPlayHandler>(stream.trick_play_factor)
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
|
||||||
RETURN_IF_ERROR(ChainHandlers({replicator, trick_play, muxer}));
|
RETURN_IF_ERROR(MediaHandler::Chain({replicator, trick_play, muxer}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
|
|
Loading…
Reference in New Issue