From e7540bf303c886f6d3a206ba1819aa459e8ca330 Mon Sep 17 00:00:00 2001 From: Kamesh Devarakonda Date: Thu, 30 Nov 2017 10:58:32 -0500 Subject: [PATCH] Dispatch Scte35Events. This patch also fixes a bug which was introduced in https://widevine-internal-review.googlesource.com/c/packager/+/38040 where it was inconsistently assumed that AdCueGenerator would be MIMO while connecting with other handlers and at the same time it was assumed SISO in the AdCueGenerator class. Now we assume SISO everywhere. Change-Id: Icd8c40b5ccfe0d98f47f09a60ea1635f74dceef9 --- .../ad_cue_generator/ad_cue_generator.cc | 31 ++++++++++++++++--- .../media/ad_cue_generator/ad_cue_generator.h | 3 ++ packager/packager.cc | 13 ++++---- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/packager/media/ad_cue_generator/ad_cue_generator.cc b/packager/media/ad_cue_generator/ad_cue_generator.cc index c46e7328d8..dbefaa9711 100644 --- a/packager/media/ad_cue_generator/ad_cue_generator.cc +++ b/packager/media/ad_cue_generator/ad_cue_generator.cc @@ -23,19 +23,42 @@ AdCueGenerator::AdCueGenerator( AdCueGenerator::~AdCueGenerator() {} Status AdCueGenerator::InitializeInternal() { + if (num_input_streams() != 1 || next_output_stream_index() != 1) { + return Status(error::INVALID_ARGUMENT, + "Expects exactly one input and one output."); + } return Status::OK; } Status AdCueGenerator::Process(std::unique_ptr stream_data) { switch (stream_data->stream_data_type) { - case StreamDataType::kStreamInfo: - // TODO(kdevarakonda): dispatch scte35 events. - return DispatchStreamInfo(kStreamIndex, - std::move(stream_data->stream_info)); + case StreamDataType::kStreamInfo: { + const uint32_t time_scale = stream_data->stream_info->time_scale(); + Status status = Dispatch(std::move(stream_data)); + if (!status.ok()) { + return status; + } + return DispatchScte35Events(kStreamIndex, time_scale); + } default: return Dispatch(std::move(stream_data)); } } +Status AdCueGenerator::DispatchScte35Events(size_t stream_index, + uint32_t time_scale) { + Status status; + for (const auto& cue_point : ad_cue_generator_params_.cue_points) { + std::shared_ptr scte35_event = std::make_shared(); + scte35_event->start_time = cue_point.start_time_in_seconds * time_scale; + scte35_event->duration = cue_point.duration_in_seconds * time_scale; + status.Update(DispatchScte35Event(stream_index, std::move(scte35_event))); + if (!status.ok()) { + return status; + } + } + return Status::OK; +} + } // namespace media } // namespace shaka diff --git a/packager/media/ad_cue_generator/ad_cue_generator.h b/packager/media/ad_cue_generator/ad_cue_generator.h index 59d05c2875..be43bd63db 100644 --- a/packager/media/ad_cue_generator/ad_cue_generator.h +++ b/packager/media/ad_cue_generator/ad_cue_generator.h @@ -26,6 +26,9 @@ class AdCueGenerator : public MediaHandler { Status InitializeInternal() override; Status Process(std::unique_ptr stream_data) override; + // Dispatches SCTE35 events that are built from AdCueGenerator params. + Status DispatchScte35Events(size_t stream_index, uint32_t time_scale); + const AdCueGeneratorParams ad_cue_generator_params_; }; diff --git a/packager/packager.cc b/packager/packager.cc index 8a26b0615e..665bddd3d4 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -496,8 +496,6 @@ Status CreateAudioVideoJobs( // Demuxers are shared among all streams with the same input. std::shared_ptr demuxer; - // AdCueGenerator is shared among all streams. - std::shared_ptr ad_cue_generator; // Replicators are shared among all streams with the same input and stream // selector. std::shared_ptr replicator; @@ -509,11 +507,6 @@ Status CreateAudioVideoJobs( // iteration. int stream_number = first_stream_number - 1; - if (!packaging_params.ad_cue_generator_params.cue_points.empty()) { - ad_cue_generator = std::make_shared( - packaging_params.ad_cue_generator_params); - } - for (const StreamDescriptor& stream : streams) { stream_number += 1; @@ -554,6 +547,12 @@ Status CreateAudioVideoJobs( } if (new_source) { + std::shared_ptr ad_cue_generator; + if (!packaging_params.ad_cue_generator_params.cue_points.empty()) { + ad_cue_generator = std::make_shared( + packaging_params.ad_cue_generator_params); + } + replicator = std::make_shared(); std::shared_ptr chunker =