Return Status from CreateRemuxJobs

Inside of CreateRemuxJobs, we would take a status value from another call,
log the message, and return a boolean. The caller of CreateRemuxJobs would
then create status from the boolean.

Now we will pass the status value from the other call directly to the caller
of CreateRemuxJobs. So that failures can be better communicate in our code.

This includes a pass of clang-format over packager/packager.cc.

Change-Id: I071e7bad13f916e963641b9e53699573fe1060ed
This commit is contained in:
Aaron Vaage 2017-08-23 10:30:43 -07:00
parent 591fd5456e
commit 2539920a5d
1 changed files with 40 additions and 35 deletions

View File

@ -231,7 +231,7 @@ class FakeClock : public base::Clock {
class Job : public base::SimpleThread { class Job : public base::SimpleThread {
public: public:
Job(const std::string& name, std::shared_ptr<OriginHandler> work) Job(const std::string& name, std::shared_ptr<OriginHandler> work)
: SimpleThread(name), : SimpleThread(name),
work_(work), work_(work),
wait_(base::WaitableEvent::ResetPolicy::MANUAL, wait_(base::WaitableEvent::ResetPolicy::MANUAL,
@ -319,13 +319,13 @@ std::shared_ptr<Muxer> CreateOutputMuxer(const MuxerOptions& options,
} }
} }
bool 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,
KeySource* encryption_key_source, KeySource* encryption_key_source,
MpdNotifier* mpd_notifier, MpdNotifier* mpd_notifier,
hls::HlsNotifier* hls_notifier, hls::HlsNotifier* hls_notifier,
std::vector<std::unique_ptr<Job>>* jobs) { std::vector<std::unique_ptr<Job>>* jobs) {
// No notifiers OR (mpd_notifier XOR hls_notifier); which is NAND. // No notifiers OR (mpd_notifier XOR hls_notifier); which is NAND.
DCHECK(!(mpd_notifier && hls_notifier)); DCHECK(!(mpd_notifier && hls_notifier));
DCHECK(jobs); DCHECK(jobs);
@ -349,9 +349,9 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
stream_muxer_options.output_file_name = stream_iter->output; stream_muxer_options.output_file_name = stream_iter->output;
if (!stream_iter->segment_template.empty()) { if (!stream_iter->segment_template.empty()) {
if (!ValidateSegmentTemplate(stream_iter->segment_template)) { if (!ValidateSegmentTemplate(stream_iter->segment_template)) {
LOG(ERROR) << "ERROR: segment template with '" return Status(
<< stream_iter->segment_template << "' is invalid."; error::INVALID_ARGUMENT,
return false; "Invalid segment template: " + stream_iter->segment_template);
} }
stream_muxer_options.segment_template = stream_iter->segment_template; stream_muxer_options.segment_template = stream_iter->segment_template;
} }
@ -362,7 +362,8 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
MediaInfo text_media_info; MediaInfo text_media_info;
if (!StreamInfoToTextMediaInfo(*stream_iter, stream_muxer_options, if (!StreamInfoToTextMediaInfo(*stream_iter, stream_muxer_options,
&text_media_info)) { &text_media_info)) {
return false; return Status(error::INVALID_ARGUMENT,
"Could not create media info for stream.");
} }
if (mpd_notifier) { if (mpd_notifier) {
@ -390,8 +391,11 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
KeyProvider::kNone) { KeyProvider::kNone) {
std::unique_ptr<KeySource> decryption_key_source( std::unique_ptr<KeySource> decryption_key_source(
CreateDecryptionKeySource(packaging_params.decryption_params)); CreateDecryptionKeySource(packaging_params.decryption_params));
if (!decryption_key_source) if (!decryption_key_source) {
return false; return Status(
error::INVALID_ARGUMENT,
"Must define decryption key source when defining key provider");
}
demuxer->SetKeySource(std::move(decryption_key_source)); demuxer->SetKeySource(std::move(decryption_key_source));
} }
jobs->emplace_back(new media::Job("RemuxJob", demuxer)); jobs->emplace_back(new media::Job("RemuxJob", demuxer));
@ -484,8 +488,7 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
// will support CENC in TS in the future. // will support CENC in TS in the future.
if (output_format == CONTAINER_MPEG2TS) { if (output_format == CONTAINER_MPEG2TS) {
VLOG(1) << "Use Apple Sample AES encryption for MPEG2TS."; VLOG(1) << "Use Apple Sample AES encryption for MPEG2TS.";
encryption_params.protection_scheme = encryption_params.protection_scheme = kAppleSampleAesProtectionScheme;
kAppleSampleAesProtectionScheme;
} }
if (!encryption_params.stream_label_func) { if (!encryption_params.stream_label_func) {
const int kDefaultMaxSdPixels = 768 * 576; const int kDefaultMaxSdPixels = 768 * 576;
@ -512,22 +515,19 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
status.Update(ConnectHandlers(handlers)); status.Update(ConnectHandlers(handlers));
if (!status.ok()) { if (!status.ok()) {
LOG(ERROR) << "Failed to setup graph: " << status; return status;
return false;
} }
if (!stream_iter->language.empty()) if (!stream_iter->language.empty())
demuxer->SetLanguageOverride(stream_selector, stream_iter->language); demuxer->SetLanguageOverride(stream_selector, stream_iter->language);
} }
// Initialize processing graph. // Initialize processing graph.
Status status;
for (const std::unique_ptr<Job>& job : *jobs) { for (const std::unique_ptr<Job>& job : *jobs) {
job->Initialize(); job->Initialize();
if (!job->status().ok()) { status.Update(job->status());
LOG(ERROR) << "Failed to initialize processing graph " << job->status();
return false;
}
} }
return true; return status;
} }
Status RunJobs(const std::vector<std::unique_ptr<Job>>& jobs) { Status RunJobs(const std::vector<std::unique_ptr<Job>>& jobs) {
@ -553,8 +553,8 @@ Status RunJobs(const std::vector<std::unique_ptr<Job>>& jobs) {
while (status.ok() && active_jobs.size()) { while (status.ok() && active_jobs.size()) {
// Wait for an event to finish and then update our status so that we can // Wait for an event to finish and then update our status so that we can
// quit if something has gone wrong. // quit if something has gone wrong.
const size_t done = base::WaitableEvent::WaitMany(active_waits.data(), const size_t done =
active_waits.size()); base::WaitableEvent::WaitMany(active_waits.data(), active_waits.size());
Job* job = active_jobs[done]; Job* job = active_jobs[done];
job->Join(); job->Join();
@ -657,14 +657,16 @@ Status Packager::Initialize(
media::StreamDescriptorList stream_descriptor_list; media::StreamDescriptorList stream_descriptor_list;
for (const StreamDescriptor& descriptor : stream_descriptors) for (const StreamDescriptor& descriptor : stream_descriptors)
stream_descriptor_list.insert(descriptor); stream_descriptor_list.insert(descriptor);
if (!media::CreateRemuxJobs( Status status = media::CreateRemuxJobs(
stream_descriptor_list, packaging_params, &internal->fake_clock, stream_descriptor_list, packaging_params, &internal->fake_clock,
internal->encryption_key_source.get(), internal->mpd_notifier.get(), internal->encryption_key_source.get(), internal->mpd_notifier.get(),
internal->hls_notifier.get(), &internal->jobs)) { internal->hls_notifier.get(), &internal->jobs);
return Status(error::INVALID_ARGUMENT, "Failed to create remux jobs.");
if (status.ok()) {
internal_ = std::move(internal);
} }
internal_ = std::move(internal);
return Status::OK; return status;
} }
Status Packager::Run() { Status Packager::Run() {
@ -710,9 +712,12 @@ std::string Packager::DefaultStreamLabelFunction(
EncryptionParams::EncryptedStreamAttributes::kVideo) { EncryptionParams::EncryptedStreamAttributes::kVideo) {
const int pixels = stream_attributes.oneof.video.width * const int pixels = stream_attributes.oneof.video.width *
stream_attributes.oneof.video.height; stream_attributes.oneof.video.height;
if (pixels <= max_sd_pixels) return "SD"; if (pixels <= max_sd_pixels)
if (pixels <= max_hd_pixels) return "HD"; return "SD";
if (pixels <= max_uhd1_pixels) return "UHD1"; if (pixels <= max_hd_pixels)
return "HD";
if (pixels <= max_uhd1_pixels)
return "UHD1";
return "UHD2"; return "UHD2";
} }
return ""; return "";