7 #include "packager/packager.h" 11 #include "packager/app/job_manager.h" 12 #include "packager/app/libcrypto_threading.h" 13 #include "packager/app/muxer_factory.h" 14 #include "packager/app/packager_util.h" 15 #include "packager/app/stream_descriptor.h" 16 #include "packager/base/at_exit.h" 17 #include "packager/base/files/file_path.h" 18 #include "packager/base/logging.h" 19 #include "packager/base/optional.h" 20 #include "packager/base/path_service.h" 21 #include "packager/base/strings/string_util.h" 22 #include "packager/base/strings/stringprintf.h" 23 #include "packager/base/threading/simple_thread.h" 24 #include "packager/base/time/clock.h" 25 #include "packager/file/file.h" 26 #include "packager/hls/base/hls_notifier.h" 27 #include "packager/hls/base/simple_hls_notifier.h" 28 #include "packager/media/ad_cue_generator/ad_cue_generator.h" 29 #include "packager/media/base/container_names.h" 30 #include "packager/media/base/fourccs.h" 31 #include "packager/media/base/key_source.h" 32 #include "packager/media/base/language_utils.h" 33 #include "packager/media/base/muxer.h" 34 #include "packager/media/base/muxer_options.h" 35 #include "packager/media/base/muxer_util.h" 36 #include "packager/media/chunking/chunking_handler.h" 37 #include "packager/media/chunking/cue_alignment_handler.h" 38 #include "packager/media/chunking/text_chunker.h" 39 #include "packager/media/crypto/encryption_handler.h" 40 #include "packager/media/demuxer/demuxer.h" 41 #include "packager/media/event/muxer_listener_factory.h" 42 #include "packager/media/event/vod_media_info_dump_muxer_listener.h" 43 #include "packager/media/formats/webvtt/text_padder.h" 44 #include "packager/media/formats/webvtt/text_readers.h" 45 #include "packager/media/formats/webvtt/webvtt_parser.h" 46 #include "packager/media/formats/webvtt/webvtt_text_output_handler.h" 47 #include "packager/media/formats/webvtt/webvtt_to_mp4_handler.h" 48 #include "packager/media/replicator/replicator.h" 49 #include "packager/media/trick_play/trick_play_handler.h" 50 #include "packager/mpd/base/media_info.pb.h" 51 #include "packager/mpd/base/mpd_builder.h" 52 #include "packager/mpd/base/simple_mpd_notifier.h" 53 #include "packager/status_macros.h" 54 #include "packager/version/version.h" 60 using media::JobManager;
61 using media::KeySource;
62 using media::MuxerOptions;
63 using media::SyncPointQueue;
68 const char kMediaInfoSuffix[] =
".media_info";
71 std::initializer_list<std::shared_ptr<MediaHandler>> list) {
72 std::shared_ptr<MediaHandler> previous;
74 for (
auto& next : list) {
81 RETURN_IF_ERROR(previous->AddHandler(next));
84 previous = std::move(next);
90 MuxerOptions CreateMuxerOptions(
const StreamDescriptor& stream,
91 const PackagingParams& params) {
94 options.mp4_params = params.mp4_output_params;
95 options.temp_dir = params.temp_dir;
96 options.bandwidth = stream.bandwidth;
97 options.output_file_name = stream.output;
98 options.segment_template = stream.segment_template;
103 MuxerListenerFactory::StreamData ToMuxerListenerData(
104 const StreamDescriptor& stream) {
105 MuxerListenerFactory::StreamData data;
106 data.media_info_output = stream.output;
107 data.hls_group_id = stream.hls_group_id;
108 data.hls_name = stream.hls_name;
109 data.hls_playlist_name = stream.hls_playlist_name;
110 data.hls_iframe_playlist_name = stream.hls_iframe_playlist_name;
117 bool DetermineTextFileCodec(
const std::string& file, std::string* out) {
122 LOG(ERROR) <<
"Failed to open file " << file
123 <<
" to determine file format.";
127 const uint8_t* content_data =
128 reinterpret_cast<const uint8_t*
>(content.data());
129 MediaContainerName container_name =
130 DetermineContainer(content_data, content.size());
132 if (container_name == CONTAINER_WEBVTT) {
137 if (container_name == CONTAINER_TTML) {
145 MediaContainerName GetOutputFormat(
const StreamDescriptor& descriptor) {
146 if (!descriptor.output_format.empty()) {
147 MediaContainerName format =
148 DetermineContainerFromFormatName(descriptor.output_format);
149 if (format == CONTAINER_UNKNOWN) {
150 LOG(ERROR) <<
"Unable to determine output format from '" 151 << descriptor.output_format <<
"'.";
156 base::Optional<MediaContainerName> format_from_output;
157 base::Optional<MediaContainerName> format_from_segment;
158 if (!descriptor.output.empty()) {
159 format_from_output = DetermineContainerFromFileName(descriptor.output);
160 if (format_from_output.value() == CONTAINER_UNKNOWN) {
161 LOG(ERROR) <<
"Unable to determine output format from '" 162 << descriptor.output <<
"'.";
165 if (!descriptor.segment_template.empty()) {
166 format_from_segment =
167 DetermineContainerFromFileName(descriptor.segment_template);
168 if (format_from_segment.value() == CONTAINER_UNKNOWN) {
169 LOG(ERROR) <<
"Unable to determine output format from '" 170 << descriptor.segment_template <<
"'.";
174 if (format_from_output && format_from_segment) {
175 if (format_from_output.value() != format_from_segment.value()) {
176 LOG(ERROR) <<
"Output format determined from '" << descriptor.output
177 <<
"' differs from output format determined from '" 178 << descriptor.segment_template <<
"'.";
179 return CONTAINER_UNKNOWN;
183 if (format_from_output)
184 return format_from_output.value();
185 if (format_from_segment)
186 return format_from_segment.value();
187 return CONTAINER_UNKNOWN;
190 Status ValidateStreamDescriptor(
bool dump_stream_info,
191 const StreamDescriptor& stream) {
192 if (stream.input.empty()) {
193 return Status(error::INVALID_ARGUMENT,
"Stream input not specified.");
198 if (dump_stream_info && stream.output.empty() &&
199 stream.segment_template.empty()) {
203 if (stream.output.empty() && stream.segment_template.empty()) {
204 return Status(error::INVALID_ARGUMENT,
205 "Streams must specify 'output' or 'segment template'.");
209 if (stream.stream_selector.empty()) {
210 return Status(error::INVALID_ARGUMENT,
211 "Stream stream_selector not specified.");
215 if (stream.segment_template.length()) {
216 RETURN_IF_ERROR(ValidateSegmentTemplate(stream.segment_template));
219 if (stream.output.find(
'$') != std::string::npos) {
223 RETURN_IF_ERROR(ValidateSegmentTemplate(stream.output));
228 const MediaContainerName output_format = GetOutputFormat(stream);
230 if (output_format == CONTAINER_UNKNOWN) {
231 return Status(error::INVALID_ARGUMENT,
"Unsupported output format.");
232 }
else if (output_format == MediaContainerName::CONTAINER_MPEG2TS) {
233 if (stream.segment_template.empty()) {
235 error::INVALID_ARGUMENT,
236 "Please specify 'segment_template'. Single file TS output is " 243 if (stream.output.length()) {
244 return Status(error::INVALID_ARGUMENT,
245 "All TS segments must be self-initializing. Stream " 246 "descriptors 'output' or 'init_segment' are not allowed.");
248 }
else if (output_format == CONTAINER_WEBVTT ||
249 output_format == CONTAINER_AAC || output_format == CONTAINER_AC3 ||
250 output_format == CONTAINER_EAC3) {
253 if (stream.segment_template.length() && stream.output.length()) {
255 error::INVALID_ARGUMENT,
256 "Segmented WebVTT or PackedAudio output cannot have an init segment. " 257 "Do not specify stream descriptors 'output' or 'init_segment' when " 258 "using 'segment_template'.");
263 if (stream.segment_template.length() && stream.output.empty()) {
264 return Status(error::INVALID_ARGUMENT,
265 "Please specify 'init_segment'. All non-TS multi-segment " 266 "content must provide an init segment.");
273 Status ValidateParams(
const PackagingParams& packaging_params,
274 const std::vector<StreamDescriptor>& stream_descriptors) {
275 if (!packaging_params.chunking_params.segment_sap_aligned &&
276 packaging_params.chunking_params.subsegment_sap_aligned) {
277 return Status(error::INVALID_ARGUMENT,
278 "Setting segment_sap_aligned to false but " 279 "subsegment_sap_aligned to true is not allowed.");
282 if (stream_descriptors.empty()) {
283 return Status(error::INVALID_ARGUMENT,
284 "Stream descriptors cannot be empty.");
289 const bool on_demand_dash_profile =
290 stream_descriptors.begin()->segment_template.empty();
291 for (
const auto& descriptor : stream_descriptors) {
292 if (on_demand_dash_profile != descriptor.segment_template.empty()) {
293 return Status(error::INVALID_ARGUMENT,
294 "Inconsistent stream descriptor specification: " 295 "segment_template should be specified for none or all " 296 "stream descriptors.");
299 RETURN_IF_ERROR(ValidateStreamDescriptor(
300 packaging_params.test_params.dump_stream_info, descriptor));
302 if (base::StartsWith(descriptor.input,
"udp://",
303 base::CompareCase::SENSITIVE)) {
304 const HlsParams& hls_params = packaging_params.hls_params;
305 if (!hls_params.master_playlist_output.empty() &&
306 hls_params.playlist_type == HlsPlaylistType::kVod) {
308 <<
"Seeing UDP input with HLS Playlist Type set to VOD. The " 309 "playlists will only be generated when UDP socket is closed. " 310 "If you want to do live packaging, --hls_playlist_type needs to " 318 if (packaging_params.output_media_info && !on_demand_dash_profile) {
320 return Status(error::UNIMPLEMENTED,
321 "--output_media_info is only supported for on-demand profile " 322 "(not using segment_template).");
328 bool StreamDescriptorCompareFn(
const StreamDescriptor& a,
329 const StreamDescriptor& b) {
330 if (a.input == b.input) {
331 if (a.stream_selector == b.stream_selector) {
334 if (a.trick_play_factor == 0 || b.trick_play_factor == 0) {
335 return a.trick_play_factor == 0;
337 return a.trick_play_factor > b.trick_play_factor;
340 return a.stream_selector < b.stream_selector;
344 return a.input < b.input;
349 class FakeClock :
public base::Clock {
351 base::Time Now()
override {
return base::Time(); }
354 bool StreamInfoToTextMediaInfo(
const StreamDescriptor& stream_descriptor,
355 MediaInfo* text_media_info) {
357 if (!DetermineTextFileCodec(stream_descriptor.input, &codec)) {
358 LOG(ERROR) <<
"Failed to determine the text file format for " 359 << stream_descriptor.input;
363 MediaInfo::TextInfo* text_info = text_media_info->mutable_text_info();
364 text_info->set_codec(codec);
366 const std::string& language = stream_descriptor.language;
367 if (!language.empty()) {
368 text_info->set_language(language);
371 text_media_info->set_media_file_name(stream_descriptor.output);
372 text_media_info->set_container_type(MediaInfo::CONTAINER_TEXT);
374 if (stream_descriptor.bandwidth != 0) {
375 text_media_info->set_bandwidth(stream_descriptor.bandwidth);
380 const int kDefaultTextBandwidth = 256;
381 text_media_info->set_bandwidth(kDefaultTextBandwidth);
390 Status CreateDemuxer(
const StreamDescriptor& stream,
391 const PackagingParams& packaging_params,
392 std::shared_ptr<Demuxer>* new_demuxer) {
393 std::shared_ptr<Demuxer> demuxer = std::make_shared<Demuxer>(stream.input);
394 demuxer->set_dump_stream_info(packaging_params.test_params.dump_stream_info);
396 if (packaging_params.decryption_params.key_provider != KeyProvider::kNone) {
397 std::unique_ptr<KeySource> decryption_key_source(
398 CreateDecryptionKeySource(packaging_params.decryption_params));
399 if (!decryption_key_source) {
401 error::INVALID_ARGUMENT,
402 "Must define decryption key source when defining key provider");
404 demuxer->SetKeySource(std::move(decryption_key_source));
407 *new_demuxer = std::move(demuxer);
411 std::shared_ptr<MediaHandler> CreateEncryptionHandler(
412 const PackagingParams& packaging_params,
413 const StreamDescriptor& stream,
414 KeySource* key_source) {
415 if (stream.skip_encryption) {
424 EncryptionParams encryption_params = packaging_params.encryption_params;
429 if (GetOutputFormat(stream) == CONTAINER_MPEG2TS ||
430 GetOutputFormat(stream) == CONTAINER_AAC ||
431 GetOutputFormat(stream) == CONTAINER_AC3 ||
432 GetOutputFormat(stream) == CONTAINER_EAC3) {
433 VLOG(1) <<
"Use Apple Sample AES encryption for MPEG2TS or Packed Audio.";
434 encryption_params.protection_scheme = kAppleSampleAesProtectionScheme;
437 if (!stream.drm_label.empty()) {
438 const std::string& drm_label = stream.drm_label;
439 encryption_params.stream_label_func =
440 [drm_label](
const EncryptionParams::EncryptedStreamAttributes&) {
443 }
else if (!encryption_params.stream_label_func) {
444 const int kDefaultMaxSdPixels = 768 * 576;
445 const int kDefaultMaxHdPixels = 1920 * 1080;
446 const int kDefaultMaxUhd1Pixels = 4096 * 2160;
447 encryption_params.stream_label_func = std::bind(
449 kDefaultMaxHdPixels, kDefaultMaxUhd1Pixels, std::placeholders::_1);
452 return std::make_shared<EncryptionHandler>(encryption_params, key_source);
455 std::unique_ptr<TextChunker> CreateTextChunker(
456 const ChunkingParams& chunking_params) {
457 const float segment_length_in_seconds =
458 chunking_params.segment_duration_in_seconds;
459 const uint64_t segment_length_in_ms =
460 static_cast<uint64_t
>(segment_length_in_seconds * 1000);
462 return std::unique_ptr<TextChunker>(
new TextChunker(segment_length_in_ms));
465 Status CreateHlsTextJob(
const StreamDescriptor& stream,
466 const PackagingParams& packaging_params,
467 std::unique_ptr<MuxerListener> muxer_listener,
468 SyncPointQueue* sync_points,
469 JobManager* job_manager) {
470 DCHECK(muxer_listener);
473 if (stream.segment_template.empty()) {
474 return Status(error::INVALID_ARGUMENT,
475 "Cannot output text (" + stream.input +
476 ") to HLS with no segment template");
482 MuxerOptions muxer_options = CreateMuxerOptions(stream, packaging_params);
483 muxer_options.bandwidth = stream.bandwidth ? stream.bandwidth : 256;
485 auto output = std::make_shared<WebVttTextOutputHandler>(
486 muxer_options, std::move(muxer_listener));
488 std::unique_ptr<FileReader> reader;
491 const int64_t kNoDuration = 0;
493 std::make_shared<WebVttParser>(std::move(reader), stream.language);
494 auto padder = std::make_shared<TextPadder>(kNoDuration);
495 auto cue_aligner = sync_points
496 ? std::make_shared<CueAlignmentHandler>(sync_points)
498 auto chunker = CreateTextChunker(packaging_params.chunking_params);
500 job_manager->Add(
"Segmented Text Job", parser);
502 return ChainHandlers({std::move(parser), std::move(padder),
503 std::move(cue_aligner), std::move(chunker),
507 Status CreateWebVttToMp4TextJob(
const StreamDescriptor& stream,
508 const PackagingParams& packaging_params,
509 std::unique_ptr<MuxerListener> muxer_listener,
510 SyncPointQueue* sync_points,
511 MuxerFactory* muxer_factory,
512 std::shared_ptr<OriginHandler>* root) {
513 std::unique_ptr<FileReader> reader;
516 const int64_t kNoDuration = 0;
518 std::make_shared<WebVttParser>(std::move(reader), stream.language);
519 auto padder = std::make_shared<TextPadder>(kNoDuration);
521 auto text_to_mp4 = std::make_shared<WebVttToMp4Handler>();
522 auto muxer = muxer_factory->CreateMuxer(GetOutputFormat(stream), stream);
523 muxer->SetMuxerListener(std::move(muxer_listener));
526 std::shared_ptr<MediaHandler> cue_aligner;
528 cue_aligner = std::make_shared<CueAlignmentHandler>(sync_points);
531 std::shared_ptr<MediaHandler> chunker =
532 CreateTextChunker(packaging_params.chunking_params);
536 return ChainHandlers({std::move(parser), std::move(padder),
537 std::move(cue_aligner), std::move(chunker),
538 std::move(text_to_mp4), std::move(muxer)});
541 Status CreateTextJobs(
542 const std::vector<std::reference_wrapper<const StreamDescriptor>>& streams,
543 const PackagingParams& packaging_params,
544 SyncPointQueue* sync_points,
545 MuxerListenerFactory* muxer_listener_factory,
546 MuxerFactory* muxer_factory,
547 MpdNotifier* mpd_notifier,
548 JobManager* job_manager) {
549 DCHECK(muxer_listener_factory);
551 for (
const StreamDescriptor& stream : streams) {
557 const auto input_container = DetermineContainerFromFileName(stream.input);
558 const auto output_container = GetOutputFormat(stream);
560 if (input_container != CONTAINER_WEBVTT) {
561 return Status(error::INVALID_ARGUMENT,
562 "Text output format is not support for " + stream.input);
565 if (output_container == CONTAINER_MOV) {
566 std::unique_ptr<MuxerListener> muxer_listener =
567 muxer_listener_factory->CreateListener(ToMuxerListenerData(stream));
569 std::shared_ptr<OriginHandler> root;
570 RETURN_IF_ERROR(CreateWebVttToMp4TextJob(
571 stream, packaging_params, std::move(muxer_listener), sync_points,
572 muxer_factory, &root));
574 job_manager->Add(
"MP4 text job", std::move(root));
576 std::unique_ptr<MuxerListener> hls_listener =
577 muxer_listener_factory->CreateHlsListener(
578 ToMuxerListenerData(stream));
582 if (stream.segment_template.empty() || !stream.output.empty()) {
583 return Status(error::INVALID_ARGUMENT,
584 "segment_template needs to be specified for HLS text " 585 "output. Single file output is not supported yet.");
589 if (mpd_notifier && !stream.segment_template.empty()) {
590 return Status(error::INVALID_ARGUMENT,
591 "Cannot create text output for MPD with segment output.");
597 RETURN_IF_ERROR(CreateHlsTextJob(stream, packaging_params,
598 std::move(hls_listener), sync_points,
602 if (!stream.output.empty()) {
603 if (!
File::Copy(stream.input.c_str(), stream.output.c_str())) {
606 &error,
"Failed to copy the input file (%s) to output file (%s).",
607 stream.input.c_str(), stream.output.c_str());
608 return Status(error::FILE_FAILURE, error);
611 MediaInfo text_media_info;
612 if (!StreamInfoToTextMediaInfo(stream, &text_media_info)) {
613 return Status(error::INVALID_ARGUMENT,
614 "Could not create media info for stream.");
621 if (mpd_notifier->NotifyNewContainer(text_media_info, &unused)) {
622 mpd_notifier->Flush();
624 return Status(error::PARSER_FAILURE,
625 "Failed to process text file " + stream.input);
629 if (packaging_params.output_media_info) {
631 text_media_info, stream.output + kMediaInfoSuffix);
640 Status CreateAudioVideoJobs(
641 const std::vector<std::reference_wrapper<const StreamDescriptor>>& streams,
642 const PackagingParams& packaging_params,
643 KeySource* encryption_key_source,
644 SyncPointQueue* sync_points,
645 MuxerListenerFactory* muxer_listener_factory,
646 MuxerFactory* muxer_factory,
647 JobManager* job_manager) {
648 DCHECK(muxer_listener_factory);
649 DCHECK(muxer_factory);
654 std::map<std::string, std::shared_ptr<Demuxer>> sources;
655 std::map<std::string, std::shared_ptr<MediaHandler>> cue_aligners;
657 for (
const StreamDescriptor& stream : streams) {
658 bool seen_input_before = sources.find(stream.input) != sources.end();
659 if (seen_input_before) {
664 CreateDemuxer(stream, packaging_params, &sources[stream.input]));
665 cue_aligners[stream.input] =
666 sync_points ? std::make_shared<CueAlignmentHandler>(sync_points)
670 for (
auto& source : sources) {
671 job_manager->Add(
"RemuxJob", source.second);
676 std::shared_ptr<MediaHandler> replicator;
678 std::string previous_input;
679 std::string previous_selector;
681 for (
const StreamDescriptor& stream : streams) {
683 auto& demuxer = sources[stream.input];
684 auto& cue_aligner = cue_aligners[stream.input];
686 const bool new_input_file = stream.input != previous_input;
687 const bool new_stream =
688 new_input_file || previous_selector != stream.stream_selector;
689 previous_input = stream.input;
690 previous_selector = stream.stream_selector;
694 if (stream.output.empty() && stream.segment_template.empty()) {
702 if (!stream.language.empty()) {
703 demuxer->SetLanguageOverride(stream.stream_selector, stream.language);
706 replicator = std::make_shared<Replicator>();
708 std::make_shared<ChunkingHandler>(packaging_params.chunking_params);
709 auto encryptor = CreateEncryptionHandler(packaging_params, stream,
710 encryption_key_source);
715 ChainHandlers({cue_aligner, chunker, encryptor, replicator}));
717 demuxer->SetHandler(stream.stream_selector, cue_aligner));
719 RETURN_IF_ERROR(ChainHandlers({chunker, encryptor, replicator}));
720 RETURN_IF_ERROR(demuxer->SetHandler(stream.stream_selector, chunker));
725 std::shared_ptr<Muxer> muxer =
726 muxer_factory->CreateMuxer(GetOutputFormat(stream), stream);
728 return Status(error::INVALID_ARGUMENT,
"Failed to create muxer for " +
730 stream.stream_selector);
733 std::unique_ptr<MuxerListener> muxer_listener =
734 muxer_listener_factory->CreateListener(ToMuxerListenerData(stream));
735 muxer->SetMuxerListener(std::move(muxer_listener));
738 std::shared_ptr<MediaHandler> trick_play =
739 stream.trick_play_factor
740 ? std::make_shared<TrickPlayHandler>(stream.trick_play_factor)
743 RETURN_IF_ERROR(ChainHandlers({replicator, trick_play, muxer}));
749 Status CreateAllJobs(
const std::vector<StreamDescriptor>& stream_descriptors,
750 const PackagingParams& packaging_params,
751 MpdNotifier* mpd_notifier,
752 KeySource* encryption_key_source,
753 SyncPointQueue* sync_points,
754 MuxerListenerFactory* muxer_listener_factory,
755 MuxerFactory* muxer_factory,
756 JobManager* job_manager) {
757 DCHECK(muxer_factory);
758 DCHECK(muxer_listener_factory);
762 std::vector<std::reference_wrapper<const StreamDescriptor>> text_streams;
763 std::vector<std::reference_wrapper<const StreamDescriptor>>
766 for (
const StreamDescriptor& stream : stream_descriptors) {
770 if (stream.stream_selector ==
"text") {
771 text_streams.push_back(stream);
773 audio_video_streams.push_back(stream);
779 std::sort(audio_video_streams.begin(), audio_video_streams.end(),
780 media::StreamDescriptorCompareFn);
782 RETURN_IF_ERROR(CreateTextJobs(text_streams, packaging_params, sync_points,
783 muxer_listener_factory, muxer_factory,
784 mpd_notifier, job_manager));
785 RETURN_IF_ERROR(CreateAudioVideoJobs(
786 audio_video_streams, packaging_params, encryption_key_source, sync_points,
787 muxer_listener_factory, muxer_factory, job_manager));
790 return job_manager->InitializeJobs();
796 struct Packager::PackagerInternal {
797 media::FakeClock fake_clock;
798 std::unique_ptr<KeySource> encryption_key_source;
799 std::unique_ptr<MpdNotifier> mpd_notifier;
800 std::unique_ptr<hls::HlsNotifier> hls_notifier;
801 BufferCallbackParams buffer_callback_params;
802 std::unique_ptr<media::JobManager> job_manager;
805 Packager::Packager() {}
807 Packager::~Packager() {}
811 const std::vector<StreamDescriptor>& stream_descriptors) {
813 static base::AtExitManager exit;
817 return Status(error::INVALID_ARGUMENT,
"Already initialized.");
819 RETURN_IF_ERROR(media::ValidateParams(packaging_params, stream_descriptors));
822 SetPackagerVersionForTesting(
826 std::unique_ptr<PackagerInternal>
internal(
new PackagerInternal);
830 internal->encryption_key_source = CreateEncryptionKeySource(
831 static_cast<media::FourCC>(
834 if (!internal->encryption_key_source)
835 return Status(error::INVALID_ARGUMENT,
"Failed to create key source.");
844 if (internal->buffer_callback_params.write_func) {
846 internal->buffer_callback_params, mpd_params.
mpd_output);
859 const bool on_demand_dash_profile =
860 stream_descriptors.begin()->segment_template.empty();
861 const double target_segment_duration =
863 const MpdOptions mpd_options = media::GetMpdOptions(
864 on_demand_dash_profile, mpd_params, target_segment_duration);
866 if (!internal->mpd_notifier->Init()) {
867 LOG(ERROR) <<
"MpdNotifier failed to initialize.";
868 return Status(error::INVALID_ARGUMENT,
869 "Failed to initialize MpdNotifier.");
877 std::unique_ptr<SyncPointQueue> sync_points;
882 internal->job_manager.reset(
new JobManager(std::move(sync_points)));
884 std::vector<StreamDescriptor> streams_for_jobs;
890 if (internal->buffer_callback_params.read_func) {
895 if (internal->buffer_callback_params.write_func) {
899 internal->buffer_callback_params, descriptor.segment_template);
907 error::INVALID_ARGUMENT,
908 "Unknown/invalid language specified: " + descriptor.language);
912 streams_for_jobs.push_back(copy);
922 internal->hls_notifier.get());
924 RETURN_IF_ERROR(media::CreateAllJobs(
925 streams_for_jobs, packaging_params, internal->mpd_notifier.get(),
926 internal->encryption_key_source.get(),
927 internal->job_manager->sync_points(), &muxer_listener_factory,
928 &muxer_factory,
internal->job_manager.get()));
930 internal_ = std::move(
internal);
936 return Status(error::INVALID_ARGUMENT,
"Not yet initialized.");
938 RETURN_IF_ERROR(internal_->job_manager->RunJobs());
940 if (internal_->hls_notifier) {
941 if (!internal_->hls_notifier->Flush())
942 return Status(error::INVALID_ARGUMENT,
"Failed to flush Hls.");
944 if (internal_->mpd_notifier) {
945 if (!internal_->mpd_notifier->Flush())
946 return Status(error::INVALID_ARGUMENT,
"Failed to flush Mpd.");
953 LOG(INFO) <<
"Not yet initialized. Return directly.";
956 internal_->job_manager->CancelJobs();
960 return GetPackagerVersion();
968 if (stream_attributes.stream_type ==
969 EncryptionParams::EncryptedStreamAttributes::kAudio)
971 if (stream_attributes.stream_type ==
972 EncryptionParams::EncryptedStreamAttributes::kVideo) {
973 const int pixels = stream_attributes.oneof.video.width *
974 stream_attributes.oneof.video.height;
975 if (pixels <= max_sd_pixels)
977 if (pixels <= max_hd_pixels)
979 if (pixels <= max_uhd1_pixels)
BufferCallbackParams buffer_callback_params
Buffer callback params.
std::string master_playlist_output
HLS master playlist output path.
DASH MPD related parameters.
Defines a single input/output stream.
std::string input
Input/source media file path or network stream URL. Required.
HlsParams hls_params
HLS related parameters.
Status Initialize(const PackagingParams &packaging_params, const std::vector< StreamDescriptor > &stream_descriptors)
std::string default_language
static std::string DefaultStreamLabelFunction(int max_sd_pixels, int max_hd_pixels, int max_uhd1_pixels, const EncryptionParams::EncryptedStreamAttributes &stream_attributes)
ChunkingParams chunking_params
Chunking (segmentation) related parameters.
std::vector< Cuepoint > cue_points
List of cuepoints.
std::string LanguageToShortestForm(const std::string &language)
std::string segment_template
Specifies segment template. Can be empty.
static bool Copy(const char *from_file_name, const char *to_file_name)
static bool ReadFileToString(const char *file_name, std::string *contents)
All the methods that are virtual are virtual for mocking.
static std::string GetLibraryVersion()
std::string LanguageToISO_639_2(const std::string &language)
std::string injected_library_version
MpdParams mpd_params
DASH MPD related parameters.
AdCueGeneratorParams ad_cue_generator_params
Out of band cuepoint parameters.
EncryptionParams encryption_params
Encryption and Decryption Parameters.
std::string mpd_output
MPD output file path.
static std::string MakeCallbackFileName(const BufferCallbackParams &callback_params, const std::string &name)
Encrypted stream information that is used to determine stream label.
std::string default_language
double segment_duration_in_seconds
Segment duration in seconds.
void Cancel()
Cancel packaging. Note that it has to be called from another thread.