Clean-up Connecting Handlers
Created "Chain" function to connect a series of handlers together so that the connection is easier to read. Changed other calls to use RETURN_IF_ERROR to help make it easier to read as we no longer need to track the status variable anymore. Change-Id: Iffb76ca395b6d62f8feb054c09470c77718e8feb
This commit is contained in:
parent
e5fe2a76d2
commit
e1df680392
|
@ -66,6 +66,26 @@ 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;
|
||||||
|
@ -401,10 +421,8 @@ Status CreateMp4ToMp4TextJob(const StreamDescriptor& stream,
|
||||||
// specifically for text.
|
// specifically for text.
|
||||||
// TODO(kqyang): Support Cue Alignment if |sync_points| is not null.
|
// TODO(kqyang): Support Cue Alignment if |sync_points| is not null.
|
||||||
|
|
||||||
Status status;
|
|
||||||
std::shared_ptr<Demuxer> demuxer;
|
std::shared_ptr<Demuxer> demuxer;
|
||||||
|
RETURN_IF_ERROR(CreateDemuxer(stream, packaging_params, &demuxer));
|
||||||
status.Update(CreateDemuxer(stream, packaging_params, &demuxer));
|
|
||||||
if (!stream.language.empty()) {
|
if (!stream.language.empty()) {
|
||||||
demuxer->SetLanguageOverride(stream.stream_selector, stream.language);
|
demuxer->SetLanguageOverride(stream.stream_selector, stream.language);
|
||||||
}
|
}
|
||||||
|
@ -415,11 +433,11 @@ Status CreateMp4ToMp4TextJob(const StreamDescriptor& stream,
|
||||||
muxer_factory->CreateMuxer(GetOutputFormat(stream), stream);
|
muxer_factory->CreateMuxer(GetOutputFormat(stream), stream);
|
||||||
muxer->SetMuxerListener(std::move(muxer_listener));
|
muxer->SetMuxerListener(std::move(muxer_listener));
|
||||||
|
|
||||||
status.Update(chunker->AddHandler(std::move(muxer)));
|
RETURN_IF_ERROR(chunker->AddHandler(std::move(muxer)));
|
||||||
status.Update(
|
RETURN_IF_ERROR(
|
||||||
demuxer->SetHandler(stream.stream_selector, std::move(chunker)));
|
demuxer->SetHandler(stream.stream_selector, std::move(chunker)));
|
||||||
|
|
||||||
return status;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status CreateHlsTextJob(const StreamDescriptor& stream,
|
Status CreateHlsTextJob(const StreamDescriptor& stream,
|
||||||
|
@ -457,20 +475,14 @@ Status CreateHlsTextJob(const StreamDescriptor& stream,
|
||||||
auto parser =
|
auto parser =
|
||||||
std::make_shared<WebVttParser>(std::move(reader), stream.language);
|
std::make_shared<WebVttParser>(std::move(reader), stream.language);
|
||||||
auto padder = std::make_shared<TextPadder>(kNoDuration);
|
auto padder = std::make_shared<TextPadder>(kNoDuration);
|
||||||
|
auto cue_aligner = sync_points
|
||||||
|
? std::make_shared<CueAlignmentHandler>(sync_points)
|
||||||
|
: nullptr;
|
||||||
auto chunker = std::make_shared<TextChunker>(segment_length_in_ms);
|
auto chunker = std::make_shared<TextChunker>(segment_length_in_ms);
|
||||||
|
|
||||||
// Build in reverse to allow us to move the pointers.
|
RETURN_IF_ERROR(
|
||||||
if (sync_points) {
|
ChainHandlers({parser, std::move(padder), std::move(cue_aligner),
|
||||||
auto cue_aligner = std::make_shared<CueAlignmentHandler>(sync_points);
|
std::move(chunker), std::move(output)}));
|
||||||
RETURN_IF_ERROR(chunker->AddHandler(std::move(output)));
|
|
||||||
RETURN_IF_ERROR(cue_aligner->AddHandler(std::move(chunker)));
|
|
||||||
RETURN_IF_ERROR(padder->AddHandler(std::move(cue_aligner)));
|
|
||||||
RETURN_IF_ERROR(parser->AddHandler(std::move(padder)));
|
|
||||||
} else {
|
|
||||||
RETURN_IF_ERROR(chunker->AddHandler(std::move(output)));
|
|
||||||
RETURN_IF_ERROR(padder->AddHandler(std::move(chunker)));
|
|
||||||
RETURN_IF_ERROR(parser->AddHandler(std::move(padder)));
|
|
||||||
}
|
|
||||||
|
|
||||||
job_manager->Add("Segmented Text Job", std::move(parser));
|
job_manager->Add("Segmented Text Job", std::move(parser));
|
||||||
|
|
||||||
|
@ -498,11 +510,9 @@ Status CreateWebVttToMp4TextJob(const StreamDescriptor& stream,
|
||||||
auto muxer = muxer_factory->CreateMuxer(GetOutputFormat(stream), stream);
|
auto muxer = muxer_factory->CreateMuxer(GetOutputFormat(stream), stream);
|
||||||
muxer->SetMuxerListener(std::move(muxer_listener));
|
muxer->SetMuxerListener(std::move(muxer_listener));
|
||||||
|
|
||||||
RETURN_IF_ERROR(chunker->AddHandler(std::move(muxer)));
|
RETURN_IF_ERROR(
|
||||||
RETURN_IF_ERROR(text_to_mp4->AddHandler(std::move(chunker)));
|
ChainHandlers({parser, std::move(padder), std::move(text_to_mp4),
|
||||||
RETURN_IF_ERROR(padder->AddHandler(std::move(text_to_mp4)));
|
std::move(chunker), std::move(muxer)}));
|
||||||
RETURN_IF_ERROR(parser->AddHandler(std::move(padder)));
|
|
||||||
|
|
||||||
*root = std::move(parser);
|
*root = std::move(parser);
|
||||||
|
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
|
@ -684,22 +694,18 @@ Status CreateAudioVideoJobs(
|
||||||
|
|
||||||
replicator = std::make_shared<Replicator>();
|
replicator = std::make_shared<Replicator>();
|
||||||
|
|
||||||
Status status;
|
|
||||||
if (cue_aligner) {
|
if (cue_aligner) {
|
||||||
status.Update(demuxer->SetHandler(stream.stream_selector, cue_aligner));
|
RETURN_IF_ERROR(
|
||||||
status.Update(cue_aligner->AddHandler(chunker));
|
demuxer->SetHandler(stream.stream_selector, cue_aligner));
|
||||||
|
RETURN_IF_ERROR(cue_aligner->AddHandler(chunker));
|
||||||
} else {
|
} else {
|
||||||
status.Update(demuxer->SetHandler(stream.stream_selector, chunker));
|
RETURN_IF_ERROR(demuxer->SetHandler(stream.stream_selector, chunker));
|
||||||
}
|
}
|
||||||
if (encryptor) {
|
if (encryptor) {
|
||||||
status.Update(chunker->AddHandler(encryptor));
|
RETURN_IF_ERROR(chunker->AddHandler(encryptor));
|
||||||
status.Update(encryptor->AddHandler(replicator));
|
RETURN_IF_ERROR(encryptor->AddHandler(replicator));
|
||||||
} else {
|
} else {
|
||||||
status.Update(chunker->AddHandler(replicator));
|
RETURN_IF_ERROR(chunker->AddHandler(replicator));
|
||||||
}
|
|
||||||
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stream.language.empty()) {
|
if (!stream.language.empty()) {
|
||||||
|
@ -725,16 +731,11 @@ Status CreateAudioVideoJobs(
|
||||||
trick_play = std::make_shared<TrickPlayHandler>(stream.trick_play_factor);
|
trick_play = std::make_shared<TrickPlayHandler>(stream.trick_play_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status status;
|
|
||||||
if (trick_play) {
|
if (trick_play) {
|
||||||
status.Update(replicator->AddHandler(trick_play));
|
RETURN_IF_ERROR(replicator->AddHandler(trick_play));
|
||||||
status.Update(trick_play->AddHandler(muxer));
|
RETURN_IF_ERROR(trick_play->AddHandler(muxer));
|
||||||
} else {
|
} else {
|
||||||
status.Update(replicator->AddHandler(muxer));
|
RETURN_IF_ERROR(replicator->AddHandler(muxer));
|
||||||
}
|
|
||||||
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,22 +775,15 @@ Status CreateAllJobs(const std::vector<StreamDescriptor>& stream_descriptors,
|
||||||
std::sort(audio_video_streams.begin(), audio_video_streams.end(),
|
std::sort(audio_video_streams.begin(), audio_video_streams.end(),
|
||||||
media::StreamDescriptorCompareFn);
|
media::StreamDescriptorCompareFn);
|
||||||
|
|
||||||
Status status;
|
RETURN_IF_ERROR(CreateTextJobs(text_streams, packaging_params, sync_points,
|
||||||
status.Update(CreateTextJobs(text_streams, packaging_params, sync_points,
|
muxer_listener_factory, muxer_factory,
|
||||||
muxer_listener_factory, muxer_factory,
|
mpd_notifier, job_manager));
|
||||||
mpd_notifier, job_manager));
|
RETURN_IF_ERROR(CreateAudioVideoJobs(
|
||||||
status.Update(CreateAudioVideoJobs(
|
|
||||||
audio_video_streams, packaging_params, encryption_key_source, sync_points,
|
audio_video_streams, packaging_params, encryption_key_source, sync_points,
|
||||||
muxer_listener_factory, muxer_factory, job_manager));
|
muxer_listener_factory, muxer_factory, job_manager));
|
||||||
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize processing graph.
|
// Initialize processing graph.
|
||||||
status.Update(job_manager->InitializeJobs());
|
return job_manager->InitializeJobs();
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue