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>
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
#include "packager/app/crypto_flags.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/app/fixed_key_encryption_flags.h"
|
2016-04-16 22:58:47 +00:00
|
|
|
#include "packager/app/hls_flags.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/app/mpd_flags.h"
|
|
|
|
#include "packager/app/muxer_flags.h"
|
|
|
|
#include "packager/app/packager_util.h"
|
2017-01-05 17:32:17 +00:00
|
|
|
#include "packager/app/playready_key_encryption_flags.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#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-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"
|
2017-05-22 20:31:41 +00:00
|
|
|
#include "packager/base/optional.h"
|
|
|
|
#include "packager/base/strings/string_number_conversions.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/strings/string_split.h"
|
|
|
|
#include "packager/base/strings/stringprintf.h"
|
2015-11-05 01:49:35 +00:00
|
|
|
#include "packager/media/file/file.h"
|
2017-05-22 20:31:41 +00:00
|
|
|
#include "packager/packager.h"
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <codecvt>
|
|
|
|
#include <functional>
|
|
|
|
#include <locale>
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
2017-05-23 02:41:26 +00:00
|
|
|
DEFINE_bool(dump_stream_info, false, "Dump demuxed stream info.");
|
|
|
|
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-07-07 19:34:07 +00:00
|
|
|
DEFINE_bool(override_version,
|
|
|
|
false,
|
|
|
|
"Override packager version in the generated outputs with "
|
|
|
|
"--test_version if it is set to true. Should be used for "
|
|
|
|
"testing only.");
|
|
|
|
DEFINE_string(test_version,
|
|
|
|
"",
|
|
|
|
"Packager version for testing. Ignored if --override_version is "
|
|
|
|
"false. Should be used for testing only.");
|
2015-09-25 22:48:18 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
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[] =
|
2016-12-08 20:07:09 +00:00
|
|
|
"%s [flags] <stream_descriptor> ...\n\n"
|
|
|
|
" stream_descriptor consists of comma separated field_name/value pairs:\n"
|
|
|
|
" field_name=value,[field_name=value,]...\n"
|
2017-04-28 23:29:02 +00:00
|
|
|
" Supported field names are as follows (names in parenthesis are alias):\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"
|
2015-11-23 23:12:04 +00:00
|
|
|
" 'video', 'text', or stream number (zero based).\n"
|
2017-04-28 23:29:02 +00:00
|
|
|
" - output (out,init_segment): Required output file (single file) or\n"
|
|
|
|
" initialization file path (multiple file).\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - 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"
|
2017-06-21 22:50:32 +00:00
|
|
|
" value is propagated to (HLS) EXT-X-STREAM-INF:BANDWIDTH or (DASH)\n"
|
|
|
|
" Representation@bandwidth and the $Bandwidth$ template parameter for\n"
|
|
|
|
" segment names. If not specified, the bandwidth value is estimated\n"
|
|
|
|
" from content bitrate. Note that it only affects the generated\n"
|
|
|
|
" manifests/playlists; it has no effect on the media content itself.\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - language (lang): Optional value which contains a user-specified\n"
|
|
|
|
" language tag. If specified, this value overrides any language\n"
|
2017-05-22 20:31:41 +00:00
|
|
|
" metadata in the input stream.\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - output_format (format): Optional value which specifies the format\n"
|
|
|
|
" of the output files (MP4 or WebM). If not specified, it will be\n"
|
2016-04-16 22:58:47 +00:00
|
|
|
" derived from the file extension of the output file.\n"
|
2017-05-22 20:31:41 +00:00
|
|
|
" - skip_encryption=0|1: Optional. Defaults to 0 if not specified. If\n"
|
|
|
|
" it is set to 1, no encryption of the stream will be made.\n"
|
2017-05-17 22:53:32 +00:00
|
|
|
" - trick_play_factor (tpf): Optional value which specifies the trick\n"
|
|
|
|
" play, a.k.a. trick mode, stream sampling rate among key frames.\n"
|
|
|
|
" If specified, the output is a trick play stream.\n"
|
2016-04-16 22:58:47 +00:00
|
|
|
" - hls_name: Required for audio when outputting HLS.\n"
|
|
|
|
" name of the output stream. This is not (necessarily) the same as\n"
|
|
|
|
" output. This is used as the NAME attribute for EXT-X-MEDIA\n"
|
|
|
|
" - hls_group_id: Required for audio when outputting HLS.\n"
|
2017-05-22 20:31:41 +00:00
|
|
|
" The group ID for the output stream. This is used as the GROUP-ID\n"
|
|
|
|
" attribute for EXT-X-MEDIA.\n"
|
2016-04-16 22:58:47 +00:00
|
|
|
" - playlist_name: Required for HLS output.\n"
|
2017-05-22 20:31:41 +00:00
|
|
|
" Name of the playlist for the stream. Usually ends with '.m3u8'.\n";
|
2015-11-05 01:49:35 +00:00
|
|
|
|
2014-10-13 22:06:48 +00:00
|
|
|
enum ExitStatus {
|
|
|
|
kSuccess = 0,
|
|
|
|
kArgumentValidationFailed,
|
|
|
|
kPackagingFailed,
|
|
|
|
kInternalError,
|
|
|
|
};
|
2015-11-05 01:49:35 +00:00
|
|
|
|
2017-06-14 23:18:16 +00:00
|
|
|
bool GetWidevineSigner(WidevineSigner* signer) {
|
|
|
|
signer->signer_name = FLAGS_signer;
|
|
|
|
if (!FLAGS_aes_signing_key_bytes.empty()) {
|
|
|
|
signer->signing_key_type = WidevineSigner::SigningKeyType::kAes;
|
|
|
|
signer->aes.key = FLAGS_aes_signing_key_bytes;
|
|
|
|
signer->aes.iv = FLAGS_aes_signing_iv_bytes;
|
|
|
|
} else if (!FLAGS_rsa_signing_key_path.empty()) {
|
|
|
|
signer->signing_key_type = WidevineSigner::SigningKeyType::kRsa;
|
|
|
|
if (!media::File::ReadFileToString(FLAGS_rsa_signing_key_path.c_str(),
|
|
|
|
&signer->rsa.key)) {
|
|
|
|
LOG(ERROR) << "Failed to read from '" << FLAGS_rsa_signing_key_path
|
|
|
|
<< "'.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
base::Optional<PackagingParams> GetPackagingParams() {
|
|
|
|
PackagingParams packaging_params;
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
ChunkingParams& chunking_params = packaging_params.chunking_params;
|
|
|
|
chunking_params.segment_duration_in_seconds = FLAGS_segment_duration;
|
|
|
|
chunking_params.subsegment_duration_in_seconds = FLAGS_fragment_duration;
|
|
|
|
chunking_params.segment_sap_aligned = FLAGS_segment_sap_aligned;
|
|
|
|
chunking_params.subsegment_sap_aligned = FLAGS_fragment_sap_aligned;
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
int num_key_providers = 0;
|
|
|
|
EncryptionParams& encryption_params = packaging_params.encryption_params;
|
|
|
|
if (FLAGS_enable_widevine_encryption) {
|
|
|
|
encryption_params.key_provider = KeyProvider::kWidevine;
|
|
|
|
++num_key_providers;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
if (FLAGS_enable_playready_encryption) {
|
|
|
|
encryption_params.key_provider = KeyProvider::kPlayready;
|
|
|
|
++num_key_providers;
|
2015-11-05 01:49:35 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
if (FLAGS_enable_fixed_key_encryption) {
|
|
|
|
encryption_params.key_provider = KeyProvider::kRawKey;
|
|
|
|
++num_key_providers;
|
2015-11-05 01:49:35 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
if (num_key_providers > 1) {
|
|
|
|
LOG(ERROR) << "Only one of --enable_widevine_encryption, "
|
|
|
|
"--enable_playready_encryption, "
|
|
|
|
"--enable_fixed_key_encryption can be enabled.";
|
|
|
|
return base::nullopt;
|
2015-11-05 01:49:35 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
if (encryption_params.key_provider != KeyProvider::kNone) {
|
|
|
|
encryption_params.clear_lead_in_seconds = FLAGS_clear_lead;
|
|
|
|
encryption_params.protection_scheme = FLAGS_protection_scheme;
|
|
|
|
encryption_params.crypto_period_duration_in_seconds =
|
|
|
|
FLAGS_crypto_period_duration;
|
|
|
|
encryption_params.vp9_subsample_encryption = FLAGS_vp9_subsample_encryption;
|
|
|
|
encryption_params.stream_label_func = std::bind(
|
|
|
|
&EncryptionParams::DefaultStreamLabelFunction, FLAGS_max_sd_pixels,
|
|
|
|
FLAGS_max_hd_pixels, FLAGS_max_uhd1_pixels, std::placeholders::_1);
|
2015-10-28 17:23:08 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
switch (encryption_params.key_provider) {
|
|
|
|
case KeyProvider::kWidevine: {
|
|
|
|
WidevineEncryptionParams& widevine = encryption_params.widevine;
|
|
|
|
widevine.key_server_url = FLAGS_key_server_url;
|
|
|
|
widevine.include_common_pssh = FLAGS_include_common_pssh;
|
|
|
|
|
2017-06-14 23:18:16 +00:00
|
|
|
widevine.content_id = FLAGS_content_id_bytes;
|
2017-05-22 20:31:41 +00:00
|
|
|
widevine.policy = FLAGS_policy;
|
2017-06-14 23:18:16 +00:00
|
|
|
if (!GetWidevineSigner(&widevine.signer))
|
2017-05-22 20:31:41 +00:00
|
|
|
return base::nullopt;
|
|
|
|
break;
|
2017-03-21 23:14:46 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kPlayready: {
|
|
|
|
PlayreadyEncryptionParams& playready = encryption_params.playready;
|
|
|
|
playready.key_server_url = FLAGS_playready_server_url;
|
|
|
|
playready.program_identifier = FLAGS_program_identifier;
|
|
|
|
playready.ca_file = FLAGS_ca_file;
|
|
|
|
playready.client_cert_file = FLAGS_client_cert_file;
|
|
|
|
playready.client_cert_private_key_file =
|
|
|
|
FLAGS_client_cert_private_key_file;
|
|
|
|
playready.client_cert_private_key_password =
|
|
|
|
FLAGS_client_cert_private_key_password;
|
2017-06-14 23:18:16 +00:00
|
|
|
playready.key_id = FLAGS_playready_key_id_bytes;
|
|
|
|
playready.key = FLAGS_playready_key_bytes;
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2017-03-11 02:49:55 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kRawKey: {
|
|
|
|
RawKeyEncryptionParams& raw_key = encryption_params.raw_key;
|
2017-06-14 23:18:16 +00:00
|
|
|
raw_key.iv = FLAGS_iv_bytes;
|
|
|
|
raw_key.pssh = FLAGS_pssh_bytes;
|
|
|
|
// An empty StreamLabel specifies the default KeyPair.
|
2017-05-22 20:31:41 +00:00
|
|
|
RawKeyEncryptionParams::KeyPair& key_pair = raw_key.key_map[""];
|
2017-06-14 23:18:16 +00:00
|
|
|
key_pair.key_id = FLAGS_key_id_bytes;
|
|
|
|
key_pair.key = FLAGS_key_bytes;
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kNone:
|
|
|
|
break;
|
2014-06-11 00:20:00 +00:00
|
|
|
}
|
2014-06-26 17:42:12 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
num_key_providers = 0;
|
|
|
|
DecryptionParams& decryption_params = packaging_params.decryption_params;
|
|
|
|
if (FLAGS_enable_widevine_decryption) {
|
|
|
|
decryption_params.key_provider = KeyProvider::kWidevine;
|
|
|
|
++num_key_providers;
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
if (FLAGS_enable_fixed_key_decryption) {
|
|
|
|
decryption_params.key_provider = KeyProvider::kRawKey;
|
|
|
|
++num_key_providers;
|
2017-01-07 02:40:37 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
if (num_key_providers > 1) {
|
|
|
|
LOG(ERROR) << "Only one of --enable_widevine_decryption, "
|
|
|
|
"--enable_fixed_key_decryption can be enabled.";
|
|
|
|
return base::nullopt;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
switch (decryption_params.key_provider) {
|
|
|
|
case KeyProvider::kWidevine: {
|
|
|
|
WidevineDecryptionParams& widevine = decryption_params.widevine;
|
|
|
|
widevine.key_server_url = FLAGS_key_server_url;
|
2017-06-14 23:18:16 +00:00
|
|
|
if (!GetWidevineSigner(&widevine.signer))
|
2017-05-22 20:31:41 +00:00
|
|
|
return base::nullopt;
|
|
|
|
break;
|
2015-08-04 22:26:15 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kRawKey: {
|
|
|
|
RawKeyDecryptionParams& raw_key = decryption_params.raw_key;
|
2017-06-14 23:18:16 +00:00
|
|
|
// An empty StreamLabel specifies the default KeyPair.
|
2017-05-22 20:31:41 +00:00
|
|
|
RawKeyDecryptionParams::KeyPair& key_pair = raw_key.key_map[""];
|
2017-06-14 23:18:16 +00:00
|
|
|
key_pair.key_id = FLAGS_key_id_bytes;
|
|
|
|
key_pair.key = FLAGS_key_bytes;
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2014-05-22 19:39:30 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kPlayready:
|
2017-06-14 23:18:16 +00:00
|
|
|
case KeyProvider::kNone:
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2014-05-22 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
Mp4OutputParams& mp4_params = packaging_params.mp4_output_params;
|
|
|
|
mp4_params.num_subsegments_per_sidx = FLAGS_num_subsegments_per_sidx;
|
|
|
|
if (FLAGS_mp4_use_decoding_timestamp_in_timeline) {
|
|
|
|
LOG(WARNING) << "Flag --mp4_use_decoding_timestamp_in_timeline is set. "
|
|
|
|
"Note that it is a temporary hack to workaround Chromium "
|
|
|
|
"bug https://crbug.com/398130. The flag may be removed "
|
|
|
|
"when the Chromium bug is fixed.";
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
mp4_params.use_decoding_timestamp_in_timeline =
|
|
|
|
FLAGS_mp4_use_decoding_timestamp_in_timeline;
|
|
|
|
mp4_params.include_pssh_in_stream = FLAGS_mp4_include_pssh_in_stream;
|
|
|
|
|
|
|
|
packaging_params.output_media_info = FLAGS_output_media_info;
|
|
|
|
|
|
|
|
MpdParams& mpd_params = packaging_params.mpd_params;
|
|
|
|
mpd_params.generate_static_live_mpd = FLAGS_generate_static_mpd;
|
|
|
|
mpd_params.mpd_output = FLAGS_mpd_output;
|
|
|
|
mpd_params.base_urls = base::SplitString(
|
|
|
|
FLAGS_base_urls, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
|
|
|
mpd_params.generate_dash_if_iop_compliant_mpd =
|
|
|
|
FLAGS_generate_dash_if_iop_compliant_mpd;
|
|
|
|
mpd_params.minimum_update_period = FLAGS_minimum_update_period;
|
|
|
|
mpd_params.min_buffer_time = FLAGS_min_buffer_time;
|
|
|
|
mpd_params.time_shift_buffer_depth = FLAGS_time_shift_buffer_depth;
|
|
|
|
mpd_params.suggested_presentation_delay = FLAGS_suggested_presentation_delay;
|
|
|
|
mpd_params.default_language = FLAGS_default_language;
|
|
|
|
|
|
|
|
HlsParams& hls_params = packaging_params.hls_params;
|
2017-06-03 00:05:47 +00:00
|
|
|
if (FLAGS_hls_playlist_type == "VOD") {
|
|
|
|
hls_params.playlist_type = HlsPlaylistType::kVod;
|
|
|
|
} else if (FLAGS_hls_playlist_type == "LIVE") {
|
|
|
|
hls_params.playlist_type = HlsPlaylistType::kLive;
|
|
|
|
} else if (FLAGS_hls_playlist_type == "EVENT") {
|
|
|
|
hls_params.playlist_type = HlsPlaylistType::kEvent;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unrecognized playlist type " << FLAGS_hls_playlist_type;
|
|
|
|
return base::nullopt;
|
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
hls_params.master_playlist_output = FLAGS_hls_master_playlist_output;
|
|
|
|
hls_params.base_url = FLAGS_hls_base_url;
|
2017-06-03 00:05:47 +00:00
|
|
|
hls_params.time_shift_buffer_depth = FLAGS_time_shift_buffer_depth;
|
2017-05-22 20:31:41 +00:00
|
|
|
|
2017-05-23 02:41:26 +00:00
|
|
|
TestParams& test_params = packaging_params.test_params;
|
|
|
|
test_params.dump_stream_info = FLAGS_dump_stream_info;
|
|
|
|
test_params.inject_fake_clock = FLAGS_use_fake_clock_for_muxer;
|
|
|
|
if (FLAGS_override_version)
|
|
|
|
test_params.injected_library_version = FLAGS_test_version;
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
return packaging_params;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-03 05:17:54 +00:00
|
|
|
int PackagerMain(int argc, char** argv) {
|
2015-10-27 18:52:50 +00:00
|
|
|
// Needed to enable VLOG/DVLOG through --vmodule or --v.
|
|
|
|
base::CommandLine::Init(argc, argv);
|
2016-08-14 22:28:21 +00:00
|
|
|
|
|
|
|
// Set up logging.
|
|
|
|
logging::LoggingSettings log_settings;
|
2016-08-31 21:50:19 +00:00
|
|
|
log_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
2016-08-14 22:28:21 +00:00
|
|
|
CHECK(logging::InitLogging(log_settings));
|
2015-10-27 18:52:50 +00:00
|
|
|
|
2017-06-13 22:16:08 +00:00
|
|
|
google::SetVersionString(shaka::Packager::GetLibraryVersion());
|
2014-05-09 01:23:54 +00:00
|
|
|
google::SetUsageMessage(base::StringPrintf(kUsage, argv[0]));
|
|
|
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
if (argc < 2) {
|
2016-12-08 20:07:09 +00:00
|
|
|
google::ShowUsageWithFlags("Usage");
|
2015-12-21 23:10:17 +00:00
|
|
|
return kSuccess;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
|
2017-01-05 17:32:17 +00:00
|
|
|
if (!ValidateWidevineCryptoFlags() || !ValidateFixedCryptoFlags() ||
|
|
|
|
!ValidatePRCryptoFlags()) {
|
2014-10-13 22:06:48 +00:00
|
|
|
return kArgumentValidationFailed;
|
2017-01-05 17:32:17 +00:00
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
base::Optional<PackagingParams> packaging_params = GetPackagingParams();
|
|
|
|
if (!packaging_params)
|
|
|
|
return kArgumentValidationFailed;
|
|
|
|
|
|
|
|
std::vector<StreamDescriptor> stream_descriptors;
|
2014-06-27 23:07:36 +00:00
|
|
|
for (int i = 1; i < argc; ++i) {
|
2017-05-22 20:31:41 +00:00
|
|
|
base::Optional<StreamDescriptor> stream_descriptor =
|
|
|
|
ParseStreamDescriptor(argv[i]);
|
|
|
|
if (!stream_descriptor)
|
2014-10-13 22:06:48 +00:00
|
|
|
return kArgumentValidationFailed;
|
2017-05-22 20:31:41 +00:00
|
|
|
stream_descriptors.push_back(stream_descriptor.value());
|
|
|
|
}
|
2017-06-13 22:16:08 +00:00
|
|
|
Packager packager;
|
2017-06-29 22:23:53 +00:00
|
|
|
Status status =
|
2017-05-22 20:31:41 +00:00
|
|
|
packager.Initialize(packaging_params.value(), stream_descriptors);
|
|
|
|
if (!status.ok()) {
|
|
|
|
LOG(ERROR) << "Failed to initialize packager: " << status.ToString();
|
|
|
|
return kArgumentValidationFailed;
|
|
|
|
}
|
|
|
|
status = packager.Run();
|
|
|
|
if (!status.ok()) {
|
|
|
|
LOG(ERROR) << "Packaging Error: " << status.ToString();
|
|
|
|
return kPackagingFailed;
|
2014-06-27 23:07:36 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
printf("Packaging completed successfully.\n");
|
|
|
|
return kSuccess;
|
2014-10-03 05:17:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
} // namespace
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-10-03 05:17:54 +00:00
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Windows wmain, which converts wide character arguments to UTF-8.
|
|
|
|
int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) {
|
|
|
|
std::unique_ptr<char* [], std::function<void(char**)>> utf8_argv(
|
|
|
|
new char*[argc], [argc](char** utf8_args) {
|
|
|
|
// TODO(tinskip): This leaks, but if this code is enabled, it crashes.
|
|
|
|
// Figure out why. I suspect gflags does something funny with the
|
|
|
|
// argument array.
|
|
|
|
// for (int idx = 0; idx < argc; ++idx)
|
|
|
|
// delete[] utf8_args[idx];
|
|
|
|
delete[] utf8_args;
|
|
|
|
});
|
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
|
|
|
for (int idx = 0; idx < argc; ++idx) {
|
|
|
|
std::string utf8_arg(converter.to_bytes(argv[idx]));
|
|
|
|
utf8_arg += '\0';
|
|
|
|
utf8_argv[idx] = new char[utf8_arg.size()];
|
|
|
|
memcpy(utf8_argv[idx], &utf8_arg[0], utf8_arg.size());
|
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
return shaka::PackagerMain(argc, utf8_argv.get());
|
2016-08-14 22:28:21 +00:00
|
|
|
}
|
|
|
|
#else
|
2014-10-03 05:17:54 +00:00
|
|
|
int main(int argc, char** argv) {
|
2017-05-22 20:31:41 +00:00
|
|
|
return shaka::PackagerMain(argc, argv);
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2016-08-14 22:28:21 +00:00
|
|
|
#endif // defined(OS_WIN)
|