2014-05-09 01:23:54 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2015-09-25 22:48:18 +00:00
|
|
|
#include <gflags/gflags.h>
|
2014-05-09 01:23:54 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/app/fixed_key_encryption_flags.h"
|
|
|
|
#include "packager/app/libcrypto_threading.h"
|
|
|
|
#include "packager/app/mpd_flags.h"
|
|
|
|
#include "packager/app/muxer_flags.h"
|
|
|
|
#include "packager/app/packager_util.h"
|
|
|
|
#include "packager/app/stream_descriptor.h"
|
2015-10-27 18:52:50 +00:00
|
|
|
#include "packager/app/vlog_flags.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/app/widevine_encryption_flags.h"
|
2015-12-30 01:09:12 +00:00
|
|
|
#include "packager/base/at_exit.h"
|
2015-10-27 18:52:50 +00:00
|
|
|
#include "packager/base/command_line.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/logging.h"
|
|
|
|
#include "packager/base/stl_util.h"
|
|
|
|
#include "packager/base/strings/string_split.h"
|
|
|
|
#include "packager/base/strings/stringprintf.h"
|
|
|
|
#include "packager/base/threading/simple_thread.h"
|
2015-09-25 22:48:18 +00:00
|
|
|
#include "packager/base/time/clock.h"
|
2015-11-05 01:49:35 +00:00
|
|
|
#include "packager/media/base/container_names.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/demuxer.h"
|
2016-04-08 18:41:17 +00:00
|
|
|
#include "packager/media/base/fourccs.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/key_source.h"
|
|
|
|
#include "packager/media/base/muxer_options.h"
|
|
|
|
#include "packager/media/base/muxer_util.h"
|
|
|
|
#include "packager/media/event/mpd_notify_muxer_listener.h"
|
|
|
|
#include "packager/media/event/vod_media_info_dump_muxer_listener.h"
|
2015-11-05 01:49:35 +00:00
|
|
|
#include "packager/media/file/file.h"
|
2016-04-06 08:26:48 +00:00
|
|
|
#include "packager/media/formats/mp2t/ts_muxer.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/formats/mp4/mp4_muxer.h"
|
2015-10-28 17:23:08 +00:00
|
|
|
#include "packager/media/formats/webm/webm_muxer.h"
|
2015-08-04 22:26:15 +00:00
|
|
|
#include "packager/mpd/base/dash_iop_mpd_notifier.h"
|
2015-11-05 01:49:35 +00:00
|
|
|
#include "packager/mpd/base/media_info.pb.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/mpd_builder.h"
|
|
|
|
#include "packager/mpd/base/simple_mpd_notifier.h"
|
2015-12-21 23:10:17 +00:00
|
|
|
#include "packager/version/version.h"
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2015-09-25 22:48:18 +00:00
|
|
|
DEFINE_bool(use_fake_clock_for_muxer,
|
|
|
|
false,
|
|
|
|
"Set to true to use a fake clock for muxer. With this flag set, "
|
|
|
|
"creation time and modification time in outputs are set to 0. "
|
|
|
|
"Should only be used for testing.");
|
|
|
|
|
2016-05-19 21:38:15 +00:00
|
|
|
namespace edash_packager {
|
|
|
|
namespace media {
|
2014-05-09 01:23:54 +00:00
|
|
|
namespace {
|
2016-05-19 21:38:15 +00:00
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
const char kUsage[] =
|
2015-12-21 23:10:17 +00:00
|
|
|
"Packager driver program. Usage:\n\n"
|
2014-05-09 01:23:54 +00:00
|
|
|
"%s [flags] <stream_descriptor> ...\n"
|
2014-06-27 23:07:36 +00:00
|
|
|
"stream_descriptor consists of comma separated field_name/value pairs:\n"
|
|
|
|
"field_name=value,[field_name=value,]...\n"
|
|
|
|
"Supported field names are as follows:\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - input (in): Required input/source media file path or network stream\n"
|
|
|
|
" URL.\n"
|
|
|
|
" - stream_selector (stream): Required field with value 'audio',\n"
|
|
|
|
" 'video', or stream number (zero based).\n"
|
|
|
|
" - output (out): Required output file (single file) or initialization\n"
|
|
|
|
" file path (multiple file).\n"
|
|
|
|
" - segment_template (segment): Optional value which specifies the\n"
|
|
|
|
" naming pattern for the segment files, and that the stream should be\n"
|
|
|
|
" split into multiple files. Its presence should be consistent across\n"
|
|
|
|
" streams.\n"
|
|
|
|
" - bandwidth (bw): Optional value which contains a user-specified\n"
|
|
|
|
" content bit rate for the stream, in bits/sec. If specified, this\n"
|
|
|
|
" value is propagated to the $Bandwidth$ template parameter for\n"
|
|
|
|
" segment names. If not specified, its value may be estimated.\n"
|
|
|
|
" - language (lang): Optional value which contains a user-specified\n"
|
|
|
|
" language tag. If specified, this value overrides any language\n"
|
|
|
|
" metadata in the input track.\n"
|
|
|
|
" - output_format (format): Optional value which specifies the format\n"
|
|
|
|
" of the output files (MP4 or WebM). If not specified, it will be\n"
|
|
|
|
" derived from the file extension of the output file.\n";
|
2014-10-13 22:06:48 +00:00
|
|
|
|
2015-11-05 01:49:35 +00:00
|
|
|
const char kMediaInfoSuffix[] = ".media_info";
|
|
|
|
|
2014-10-13 22:06:48 +00:00
|
|
|
enum ExitStatus {
|
|
|
|
kSuccess = 0,
|
|
|
|
kArgumentValidationFailed,
|
|
|
|
kPackagingFailed,
|
|
|
|
kInternalError,
|
|
|
|
};
|
2015-11-05 01:49:35 +00:00
|
|
|
|
|
|
|
// TODO(rkuroiwa): Write TTML and WebVTT parser (demuxing) for a better check
|
|
|
|
// and for supporting live/segmenting (muxing). With a demuxer and a muxer,
|
|
|
|
// CreateRemuxJobs() shouldn't treat text as a special case.
|
|
|
|
std::string DetermineTextFileFormat(const std::string& file) {
|
|
|
|
std::string content;
|
2016-05-19 21:38:15 +00:00
|
|
|
if (!File::ReadFileToString(file.c_str(), &content)) {
|
2015-11-05 01:49:35 +00:00
|
|
|
LOG(ERROR) << "Failed to open file " << file
|
|
|
|
<< " to determine file format.";
|
|
|
|
return "";
|
|
|
|
}
|
2016-05-19 21:38:15 +00:00
|
|
|
MediaContainerName container_name = DetermineContainer(
|
|
|
|
reinterpret_cast<const uint8_t*>(content.data()), content.size());
|
|
|
|
if (container_name == CONTAINER_WEBVTT) {
|
2015-11-05 01:49:35 +00:00
|
|
|
return "vtt";
|
2016-05-19 21:38:15 +00:00
|
|
|
} else if (container_name == CONTAINER_TTML) {
|
2015-11-05 01:49:35 +00:00
|
|
|
return "ttml";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-05-19 21:38:15 +00:00
|
|
|
FourCC GetProtectionScheme(const std::string& protection_scheme) {
|
2016-03-17 17:03:19 +00:00
|
|
|
if (protection_scheme == "cenc") {
|
2016-05-19 21:38:15 +00:00
|
|
|
return FOURCC_cenc;
|
2016-04-08 18:41:17 +00:00
|
|
|
} else if (protection_scheme == "cens") {
|
2016-05-19 21:38:15 +00:00
|
|
|
return FOURCC_cens;
|
2016-03-17 17:03:19 +00:00
|
|
|
} else if (protection_scheme == "cbc1") {
|
2016-05-19 21:38:15 +00:00
|
|
|
return FOURCC_cbc1;
|
2016-04-08 18:41:17 +00:00
|
|
|
} else if (protection_scheme == "cbcs") {
|
2016-05-19 21:38:15 +00:00
|
|
|
return FOURCC_cbcs;
|
2016-03-17 17:03:19 +00:00
|
|
|
} else {
|
2016-03-25 18:02:43 +00:00
|
|
|
LOG(ERROR) << "Unknown protection scheme: " << protection_scheme;
|
2016-05-19 21:38:15 +00:00
|
|
|
return FOURCC_NULL;
|
2016-03-17 17:03:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-09-25 22:48:18 +00:00
|
|
|
// A fake clock that always return time 0 (epoch). Should only be used for
|
|
|
|
// testing.
|
|
|
|
class FakeClock : public base::Clock {
|
|
|
|
public:
|
2015-07-22 23:40:45 +00:00
|
|
|
base::Time Now() override { return base::Time(); }
|
2015-09-25 22:48:18 +00:00
|
|
|
};
|
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
// Demux, Mux(es) and worker thread used to remux a source file/stream.
|
|
|
|
class RemuxJob : public base::SimpleThread {
|
|
|
|
public:
|
|
|
|
RemuxJob(scoped_ptr<Demuxer> demuxer)
|
|
|
|
: SimpleThread("RemuxJob"),
|
|
|
|
demuxer_(demuxer.Pass()) {}
|
|
|
|
|
2015-07-22 23:40:45 +00:00
|
|
|
~RemuxJob() override {
|
2014-05-09 01:23:54 +00:00
|
|
|
STLDeleteElements(&muxers_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddMuxer(scoped_ptr<Muxer> mux) {
|
|
|
|
muxers_.push_back(mux.release());
|
|
|
|
}
|
|
|
|
|
|
|
|
Demuxer* demuxer() { return demuxer_.get(); }
|
|
|
|
Status status() { return status_; }
|
|
|
|
|
|
|
|
private:
|
2015-07-22 23:40:45 +00:00
|
|
|
void Run() override {
|
2014-05-09 01:23:54 +00:00
|
|
|
DCHECK(demuxer_);
|
|
|
|
status_ = demuxer_->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_ptr<Demuxer> demuxer_;
|
|
|
|
std::vector<Muxer*> muxers_;
|
|
|
|
Status status_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RemuxJob);
|
|
|
|
};
|
|
|
|
|
2015-11-05 01:49:35 +00:00
|
|
|
bool StreamInfoToTextMediaInfo(const StreamDescriptor& stream_descriptor,
|
|
|
|
const MuxerOptions& stream_muxer_options,
|
|
|
|
MediaInfo* text_media_info) {
|
|
|
|
const std::string& language = stream_descriptor.language;
|
|
|
|
std::string format = DetermineTextFileFormat(stream_descriptor.input);
|
|
|
|
if (format.empty()) {
|
|
|
|
LOG(ERROR) << "Failed to determine the text file format for "
|
|
|
|
<< stream_descriptor.input;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!File::Copy(stream_descriptor.input.c_str(),
|
|
|
|
stream_muxer_options.output_file_name.c_str())) {
|
|
|
|
LOG(ERROR) << "Failed to copy the input file (" << stream_descriptor.input
|
|
|
|
<< ") to output file (" << stream_muxer_options.output_file_name
|
|
|
|
<< ").";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_media_info->set_media_file_name(stream_muxer_options.output_file_name);
|
|
|
|
text_media_info->set_container_type(MediaInfo::CONTAINER_TEXT);
|
|
|
|
|
|
|
|
if (stream_muxer_options.bandwidth != 0) {
|
|
|
|
text_media_info->set_bandwidth(stream_muxer_options.bandwidth);
|
|
|
|
} else {
|
|
|
|
// Text files are usually small and since the input is one file; there's no
|
|
|
|
// way for the player to do ranged requests. So set this value to something
|
|
|
|
// reasonable.
|
|
|
|
text_media_info->set_bandwidth(256);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaInfo::TextInfo* text_info = text_media_info->mutable_text_info();
|
|
|
|
text_info->set_format(format);
|
|
|
|
if (!language.empty())
|
|
|
|
text_info->set_language(language);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-16 18:20:13 +00:00
|
|
|
scoped_ptr<Muxer> CreateOutputMuxer(const MuxerOptions& options,
|
|
|
|
MediaContainerName container) {
|
|
|
|
if (container == CONTAINER_WEBM) {
|
2015-10-28 17:23:08 +00:00
|
|
|
return scoped_ptr<Muxer>(new webm::WebMMuxer(options));
|
2016-04-06 08:26:48 +00:00
|
|
|
} else if (container == CONTAINER_MPEG2TS) {
|
|
|
|
return scoped_ptr<Muxer>(new mp2t::TsMuxer(options));
|
2015-10-28 17:23:08 +00:00
|
|
|
} else {
|
2015-12-16 18:20:13 +00:00
|
|
|
DCHECK_EQ(container, CONTAINER_MOV);
|
|
|
|
return scoped_ptr<Muxer>(new mp4::MP4Muxer(options));
|
2015-10-28 17:23:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 23:07:36 +00:00
|
|
|
bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
|
2014-05-09 01:23:54 +00:00
|
|
|
const MuxerOptions& muxer_options,
|
2015-09-25 22:48:18 +00:00
|
|
|
FakeClock* fake_clock,
|
2014-08-20 23:51:15 +00:00
|
|
|
KeySource* key_source,
|
2014-05-22 19:39:30 +00:00
|
|
|
MpdNotifier* mpd_notifier,
|
2014-05-09 01:23:54 +00:00
|
|
|
std::vector<RemuxJob*>* remux_jobs) {
|
|
|
|
DCHECK(remux_jobs);
|
|
|
|
|
2014-06-27 23:07:36 +00:00
|
|
|
std::string previous_input;
|
|
|
|
for (StreamDescriptorList::const_iterator stream_iter =
|
|
|
|
stream_descriptors.begin();
|
|
|
|
stream_iter != stream_descriptors.end();
|
2014-05-09 01:23:54 +00:00
|
|
|
++stream_iter) {
|
|
|
|
// Process stream descriptor.
|
|
|
|
MuxerOptions stream_muxer_options(muxer_options);
|
2014-06-27 23:07:36 +00:00
|
|
|
stream_muxer_options.output_file_name = stream_iter->output;
|
|
|
|
if (!stream_iter->segment_template.empty()) {
|
|
|
|
if (!ValidateSegmentTemplate(stream_iter->segment_template)) {
|
2014-05-14 23:19:35 +00:00
|
|
|
LOG(ERROR) << "ERROR: segment template with '"
|
2014-06-27 23:07:36 +00:00
|
|
|
<< stream_iter->segment_template << "' is invalid.";
|
2014-05-14 23:19:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-06-27 23:07:36 +00:00
|
|
|
stream_muxer_options.segment_template = stream_iter->segment_template;
|
2014-05-14 23:19:35 +00:00
|
|
|
}
|
2014-06-27 23:07:36 +00:00
|
|
|
stream_muxer_options.bandwidth = stream_iter->bandwidth;
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2015-11-05 01:49:35 +00:00
|
|
|
// Handle text input.
|
|
|
|
if (stream_iter->stream_selector == "text") {
|
|
|
|
MediaInfo text_media_info;
|
|
|
|
if (!StreamInfoToTextMediaInfo(*stream_iter, stream_muxer_options,
|
|
|
|
&text_media_info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mpd_notifier) {
|
|
|
|
uint32 unused;
|
|
|
|
if (!mpd_notifier->NotifyNewContainer(text_media_info, &unused)) {
|
|
|
|
LOG(ERROR) << "Failed to process text file " << stream_iter->input;
|
|
|
|
} else {
|
|
|
|
mpd_notifier->Flush();
|
|
|
|
}
|
|
|
|
} else if (FLAGS_output_media_info) {
|
|
|
|
VodMediaInfoDumpMuxerListener::WriteMediaInfoToFile(
|
|
|
|
text_media_info,
|
|
|
|
stream_muxer_options.output_file_name + kMediaInfoSuffix);
|
|
|
|
} else {
|
|
|
|
NOTIMPLEMENTED()
|
|
|
|
<< "--mpd_output or --output_media_info flags are "
|
|
|
|
"required for text output. Skipping manifest related output for "
|
|
|
|
<< stream_iter->input;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-27 23:07:36 +00:00
|
|
|
if (stream_iter->input != previous_input) {
|
2014-05-09 01:23:54 +00:00
|
|
|
// New remux job needed. Create demux and job thread.
|
2014-08-25 22:51:19 +00:00
|
|
|
scoped_ptr<Demuxer> demuxer(new Demuxer(stream_iter->input));
|
2014-10-15 00:47:25 +00:00
|
|
|
if (FLAGS_enable_widevine_decryption ||
|
|
|
|
FLAGS_enable_fixed_key_decryption) {
|
|
|
|
scoped_ptr<KeySource> key_source(CreateDecryptionKeySource());
|
|
|
|
if (!key_source)
|
|
|
|
return false;
|
|
|
|
demuxer->SetKeySource(key_source.Pass());
|
|
|
|
}
|
2014-08-25 22:51:19 +00:00
|
|
|
Status status = demuxer->Initialize();
|
2014-05-09 01:23:54 +00:00
|
|
|
if (!status.ok()) {
|
|
|
|
LOG(ERROR) << "Demuxer failed to initialize: " << status.ToString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (FLAGS_dump_stream_info) {
|
2014-06-27 23:07:36 +00:00
|
|
|
printf("\nFile \"%s\":\n", stream_iter->input.c_str());
|
2014-08-25 22:51:19 +00:00
|
|
|
DumpStreamInfo(demuxer->streams());
|
2014-06-27 23:07:36 +00:00
|
|
|
if (stream_iter->output.empty())
|
|
|
|
continue; // just need stream info.
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2014-08-25 22:51:19 +00:00
|
|
|
remux_jobs->push_back(new RemuxJob(demuxer.Pass()));
|
2014-06-27 23:07:36 +00:00
|
|
|
previous_input = stream_iter->input;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
|
|
|
DCHECK(!remux_jobs->empty());
|
|
|
|
|
2015-12-16 18:20:13 +00:00
|
|
|
MediaContainerName output_format = stream_iter->output_format;
|
|
|
|
if (output_format == CONTAINER_UNKNOWN) {
|
|
|
|
output_format =
|
|
|
|
DetermineContainerFromFileName(stream_muxer_options.output_file_name);
|
|
|
|
|
|
|
|
if (output_format == CONTAINER_UNKNOWN) {
|
|
|
|
LOG(ERROR) << "Unable to determine output format for file "
|
|
|
|
<< stream_muxer_options.output_file_name;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_ptr<Muxer> muxer(
|
|
|
|
CreateOutputMuxer(stream_muxer_options, output_format));
|
2015-09-25 22:48:18 +00:00
|
|
|
if (FLAGS_use_fake_clock_for_muxer) muxer->set_clock(fake_clock);
|
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
if (key_source) {
|
2014-08-20 23:51:15 +00:00
|
|
|
muxer->SetKeySource(key_source,
|
|
|
|
FLAGS_max_sd_pixels,
|
|
|
|
FLAGS_clear_lead,
|
2016-03-17 17:03:19 +00:00
|
|
|
FLAGS_crypto_period_duration,
|
2016-04-08 18:41:17 +00:00
|
|
|
GetProtectionScheme(FLAGS_protection_scheme));
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-11 00:20:00 +00:00
|
|
|
scoped_ptr<MuxerListener> muxer_listener;
|
|
|
|
DCHECK(!(FLAGS_output_media_info && mpd_notifier));
|
|
|
|
if (FLAGS_output_media_info) {
|
2015-02-02 19:27:32 +00:00
|
|
|
const std::string output_media_info_file_name =
|
2015-11-05 01:49:35 +00:00
|
|
|
stream_muxer_options.output_file_name + kMediaInfoSuffix;
|
2014-06-11 00:20:00 +00:00
|
|
|
scoped_ptr<VodMediaInfoDumpMuxerListener>
|
|
|
|
vod_media_info_dump_muxer_listener(
|
2015-02-02 19:27:32 +00:00
|
|
|
new VodMediaInfoDumpMuxerListener(output_media_info_file_name));
|
2014-06-11 00:20:00 +00:00
|
|
|
muxer_listener = vod_media_info_dump_muxer_listener.Pass();
|
|
|
|
}
|
2014-05-22 19:39:30 +00:00
|
|
|
if (mpd_notifier) {
|
|
|
|
scoped_ptr<MpdNotifyMuxerListener> mpd_notify_muxer_listener(
|
|
|
|
new MpdNotifyMuxerListener(mpd_notifier));
|
2014-06-11 00:20:00 +00:00
|
|
|
muxer_listener = mpd_notify_muxer_listener.Pass();
|
|
|
|
}
|
|
|
|
|
2015-05-05 23:30:14 +00:00
|
|
|
if (muxer_listener)
|
|
|
|
muxer->SetMuxerListener(muxer_listener.Pass());
|
2014-05-22 19:39:30 +00:00
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
if (!AddStreamToMuxer(remux_jobs->back()->demuxer()->streams(),
|
2014-06-27 23:07:36 +00:00
|
|
|
stream_iter->stream_selector,
|
2015-02-02 19:27:32 +00:00
|
|
|
stream_iter->language,
|
2014-05-09 01:23:54 +00:00
|
|
|
muxer.get()))
|
|
|
|
return false;
|
|
|
|
remux_jobs->back()->AddMuxer(muxer.Pass());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status RunRemuxJobs(const std::vector<RemuxJob*>& remux_jobs) {
|
|
|
|
// Start the job threads.
|
|
|
|
for (std::vector<RemuxJob*>::const_iterator job_iter = remux_jobs.begin();
|
|
|
|
job_iter != remux_jobs.end();
|
|
|
|
++job_iter) {
|
|
|
|
(*job_iter)->Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for all jobs to complete or an error occurs.
|
|
|
|
Status status;
|
|
|
|
bool all_joined;
|
|
|
|
do {
|
|
|
|
all_joined = true;
|
|
|
|
for (std::vector<RemuxJob*>::const_iterator job_iter = remux_jobs.begin();
|
|
|
|
job_iter != remux_jobs.end();
|
|
|
|
++job_iter) {
|
|
|
|
if ((*job_iter)->HasBeenJoined()) {
|
|
|
|
status = (*job_iter)->status();
|
|
|
|
if (!status.ok())
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
all_joined = false;
|
|
|
|
(*job_iter)->Join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!all_joined && status.ok());
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-06-27 23:07:36 +00:00
|
|
|
bool RunPackager(const StreamDescriptorList& stream_descriptors) {
|
2016-04-08 18:41:17 +00:00
|
|
|
const FourCC protection_scheme = GetProtectionScheme(FLAGS_protection_scheme);
|
|
|
|
if (protection_scheme == FOURCC_NULL)
|
2016-03-17 17:03:19 +00:00
|
|
|
return false;
|
|
|
|
|
2014-06-11 00:20:00 +00:00
|
|
|
if (!AssignFlagsFromProfile())
|
2014-05-22 19:39:30 +00:00
|
|
|
return false;
|
|
|
|
|
2014-06-11 00:20:00 +00:00
|
|
|
if (FLAGS_output_media_info && !FLAGS_mpd_output.empty()) {
|
|
|
|
NOTIMPLEMENTED() << "ERROR: --output_media_info and --mpd_output do not "
|
|
|
|
"work together.";
|
2014-06-26 17:42:12 +00:00
|
|
|
return false;
|
2014-06-11 00:20:00 +00:00
|
|
|
}
|
|
|
|
if (FLAGS_output_media_info && !FLAGS_single_segment) {
|
|
|
|
// TODO(rkuroiwa, kqyang): Support partial media info dump for live.
|
|
|
|
NOTIMPLEMENTED() << "ERROR: --output_media_info is only supported if "
|
|
|
|
"--single_segment is true.";
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-26 17:42:12 +00:00
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
// Get basic muxer options.
|
|
|
|
MuxerOptions muxer_options;
|
|
|
|
if (!GetMuxerOptions(&muxer_options))
|
|
|
|
return false;
|
|
|
|
|
2014-06-26 01:33:09 +00:00
|
|
|
MpdOptions mpd_options;
|
|
|
|
if (!GetMpdOptions(&mpd_options))
|
|
|
|
return false;
|
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
// Create encryption key source if needed.
|
2014-08-20 23:51:15 +00:00
|
|
|
scoped_ptr<KeySource> encryption_key_source;
|
2014-05-09 01:23:54 +00:00
|
|
|
if (FLAGS_enable_widevine_encryption || FLAGS_enable_fixed_key_encryption) {
|
|
|
|
encryption_key_source = CreateEncryptionKeySource();
|
|
|
|
if (!encryption_key_source)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-22 19:39:30 +00:00
|
|
|
scoped_ptr<MpdNotifier> mpd_notifier;
|
|
|
|
if (!FLAGS_mpd_output.empty()) {
|
|
|
|
DashProfile profile =
|
|
|
|
FLAGS_single_segment ? kOnDemandProfile : kLiveProfile;
|
|
|
|
std::vector<std::string> base_urls;
|
|
|
|
base::SplitString(FLAGS_base_urls, ',', &base_urls);
|
2015-08-04 22:26:15 +00:00
|
|
|
if (FLAGS_generate_dash_if_iop_compliant_mpd) {
|
|
|
|
mpd_notifier.reset(new DashIopMpdNotifier(profile, mpd_options, base_urls,
|
|
|
|
FLAGS_mpd_output));
|
|
|
|
} else {
|
|
|
|
mpd_notifier.reset(new SimpleMpdNotifier(profile, mpd_options, base_urls,
|
|
|
|
FLAGS_mpd_output));
|
|
|
|
}
|
2014-05-22 19:39:30 +00:00
|
|
|
if (!mpd_notifier->Init()) {
|
|
|
|
LOG(ERROR) << "MpdNotifier failed to initialize.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
std::vector<RemuxJob*> remux_jobs;
|
|
|
|
STLElementDeleter<std::vector<RemuxJob*> > scoped_jobs_deleter(&remux_jobs);
|
2015-09-25 22:48:18 +00:00
|
|
|
FakeClock fake_clock;
|
|
|
|
if (!CreateRemuxJobs(stream_descriptors, muxer_options, &fake_clock,
|
|
|
|
encryption_key_source.get(), mpd_notifier.get(),
|
2014-05-22 19:39:30 +00:00
|
|
|
&remux_jobs)) {
|
2014-05-09 01:23:54 +00:00
|
|
|
return false;
|
2014-05-22 19:39:30 +00:00
|
|
|
}
|
2014-05-09 01:23:54 +00:00
|
|
|
|
|
|
|
Status status = RunRemuxJobs(remux_jobs);
|
|
|
|
if (!status.ok()) {
|
|
|
|
LOG(ERROR) << "Packaging Error: " << status.ToString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Packaging completed successfully.\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-03 05:17:54 +00:00
|
|
|
int PackagerMain(int argc, char** argv) {
|
2015-12-30 01:09:12 +00:00
|
|
|
base::AtExitManager exit;
|
2015-10-27 18:52:50 +00:00
|
|
|
// Needed to enable VLOG/DVLOG through --vmodule or --v.
|
|
|
|
base::CommandLine::Init(argc, argv);
|
|
|
|
CHECK(logging::InitLogging(logging::LoggingSettings()));
|
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
google::SetUsageMessage(base::StringPrintf(kUsage, argv[0]));
|
|
|
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
if (argc < 2) {
|
2015-12-21 23:10:17 +00:00
|
|
|
std::string version_string =
|
2016-05-20 21:28:13 +00:00
|
|
|
base::StringPrintf("shaka-packager version %s", kPackagerVersion);
|
2015-12-21 23:10:17 +00:00
|
|
|
google::ShowUsageWithFlags(version_string.c_str());
|
|
|
|
return kSuccess;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
|
|
|
|
if (!ValidateWidevineCryptoFlags() || !ValidateFixedCryptoFlags())
|
|
|
|
return kArgumentValidationFailed;
|
|
|
|
|
2016-05-19 21:38:15 +00:00
|
|
|
LibcryptoThreading libcrypto_threading;
|
2014-06-27 23:07:36 +00:00
|
|
|
// TODO(tinskip): Make InsertStreamDescriptor a member of
|
|
|
|
// StreamDescriptorList.
|
2014-10-03 05:17:54 +00:00
|
|
|
StreamDescriptorList stream_descriptors;
|
2014-06-27 23:07:36 +00:00
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (!InsertStreamDescriptor(argv[i], &stream_descriptors))
|
2014-10-13 22:06:48 +00:00
|
|
|
return kArgumentValidationFailed;
|
2014-06-27 23:07:36 +00:00
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
return RunPackager(stream_descriptors) ? kSuccess : kPackagingFailed;
|
2014-10-03 05:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace edash_packager
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
return edash_packager::media::PackagerMain(argc, argv);
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|