diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 006c2801d1..2862cc371b 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -7,6 +7,7 @@ #include #include +#include "packager/app/ad_cue_generator_flags.h" #include "packager/app/crypto_flags.h" #include "packager/app/hls_flags.h" #include "packager/app/mpd_flags.h" @@ -213,9 +214,55 @@ bool GetRawKeyParams(RawKeyParams* raw_key) { return true; } +bool ParseAdCues(const std::string& ad_cues, std::vector* cuepoints) { + // Track if optional field is supplied consistently across all cue points. + size_t duration_count = 0; + + for (const std::string& ad_cue : base::SplitString( + ad_cues, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { + Cuepoint cuepoint; + auto split_ad_cue = base::SplitString(ad_cue, ",", base::TRIM_WHITESPACE, + base::SPLIT_WANT_NONEMPTY); + if (split_ad_cue.size() > 2) { + LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues + << " Each ad cue must contain no more than 2 components."; + } + if (!base::StringToDouble(split_ad_cue.front(), + &cuepoint.start_time_in_seconds)) { + LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues + << " Start time component must be of type double."; + return false; + } + if (split_ad_cue.size() > 1) { + duration_count++; + if (!base::StringToDouble(split_ad_cue[1], + &cuepoint.duration_in_seconds)) { + LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues + << " Duration component must be of type double."; + return false; + } + } + cuepoints->push_back(cuepoint); + } + + if (duration_count > 0 && duration_count != cuepoints->size()) { + LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues + << " Duration component is optional. However if it is supplied," + << " it must be supplied consistently across all cuepoints."; + return false; + } + return true; +} + base::Optional GetPackagingParams() { PackagingParams packaging_params; + AdCueGeneratorParams& ad_cue_generator_params = + packaging_params.ad_cue_generator_params; + if (!ParseAdCues(FLAGS_ad_cues, &ad_cue_generator_params.cue_points)) { + return base::nullopt; + } + 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; diff --git a/packager/packager.h b/packager/packager.h index 5d7a9901b2..bd4799bca6 100644 --- a/packager/packager.h +++ b/packager/packager.h @@ -11,8 +11,9 @@ #include #include -#include "packager/hls/public/hls_params.h" #include "packager/file/public/buffer_callback_params.h" +#include "packager/hls/public/hls_params.h" +#include "packager/media/public/ad_cue_generator_params.h" #include "packager/media/public/chunking_params.h" #include "packager/media/public/crypto_params.h" #include "packager/media/public/mp4_output_params.h" @@ -42,6 +43,9 @@ struct PackagingParams { /// Chunking (segmentation) related parameters. ChunkingParams chunking_params; + /// Out of band cuepoint parameters. + AdCueGeneratorParams ad_cue_generator_params; + /// Create a human readable format of MediaInfo. The output file name will be /// the name specified by output flag, suffixed with `.media_info`. bool output_media_info = false;