From f125a4e91a6fb79ebdddb5b3a9e8533c615f4303 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Mon, 12 Feb 2018 12:38:47 -0800 Subject: [PATCH] Isolate OnScte35Event in ChunkerHandler Change-Id: I9b34f959c22df498a338eb49c87b67003617ead2 --- packager/media/chunking/chunking_handler.cc | 35 ++++++++++++--------- packager/media/chunking/chunking_handler.h | 10 +++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/packager/media/chunking/chunking_handler.cc b/packager/media/chunking/chunking_handler.cc index 5e1dfe73a2..9850252d88 100644 --- a/packager/media/chunking/chunking_handler.cc +++ b/packager/media/chunking/chunking_handler.cc @@ -42,14 +42,9 @@ Status ChunkingHandler::Process(std::unique_ptr stream_data) { switch (stream_data->stream_data_type) { case StreamDataType::kStreamInfo: return OnStreamInfo(stream_data->stream_index, stream_data->stream_info); - case StreamDataType::kScte35Event: { - if (stream_data->stream_index != main_stream_index_) { - VLOG(3) << "Dropping scte35 event from non main stream."; - return Status::OK; - } - scte35_events_.push(std::move(stream_data)); - return Status::OK; - } + case StreamDataType::kScte35Event: + return OnScte35Event(stream_data->stream_index, + stream_data->scte35_event); case StreamDataType::kSegmentInfo: VLOG(3) << "Droppping existing segment info."; return Status::OK; @@ -165,6 +160,18 @@ Status ChunkingHandler::OnStreamInfo(uint64_t stream_index, return DispatchStreamInfo(stream_index, std::move(info)); } +Status ChunkingHandler::OnScte35Event( + uint64_t stream_index, + std::shared_ptr event) { + if (stream_index == main_stream_index_) { + scte35_events_.push(std::move(event)); + } else { + VLOG(3) << "Dropping scte35 event from non main stream."; + } + + return Status::OK; +} + Status ChunkingHandler::ProcessMainMediaSample(const MediaSample* sample) { const bool is_key_frame = sample->is_key_frame(); const int64_t timestamp = sample->dts(); @@ -183,7 +190,7 @@ Status ChunkingHandler::ProcessMainMediaSample(const MediaSample* sample) { // We use 'while' instead of 'if' to make sure to pop off multiple SCTE35 // events that may be very close to each other. while (!scte35_events_.empty() && - (scte35_events_.top()->scte35_event->start_time <= timestamp)) { + (scte35_events_.top()->start_time <= timestamp)) { // For simplicity, don't change |current_segment_index_|. current_subsegment_index_ = 0; new_segment = true; @@ -191,7 +198,7 @@ Status ChunkingHandler::ProcessMainMediaSample(const MediaSample* sample) { cue_event = std::make_shared(); // Use PTS instead of DTS for cue event timestamp. cue_event->timestamp = sample->pts(); - cue_event->cue_data = scte35_events_.top()->scte35_event->cue_data; + cue_event->cue_data = scte35_events_.top()->cue_data; LOG(INFO) << "Chunked at " << timestamp << " for Ad Cue."; scte35_events_.pop(); @@ -325,13 +332,11 @@ double ChunkingHandler::MediaSampleTimestampGreater::GetSampleTimeInSeconds( } bool ChunkingHandler::Scte35EventTimestampGreater::operator()( - const std::unique_ptr& lhs, - const std::unique_ptr& rhs) const { + const std::shared_ptr& lhs, + const std::shared_ptr& rhs) const { DCHECK(lhs); DCHECK(rhs); - DCHECK(lhs->scte35_event); - DCHECK(rhs->scte35_event); - return lhs->scte35_event->start_time > rhs->scte35_event->start_time; + return lhs->start_time > rhs->start_time; } } // namespace media diff --git a/packager/media/chunking/chunking_handler.h b/packager/media/chunking/chunking_handler.h index 6a1ed895f3..9c6bac60fa 100644 --- a/packager/media/chunking/chunking_handler.h +++ b/packager/media/chunking/chunking_handler.h @@ -64,6 +64,8 @@ class ChunkingHandler : public MediaHandler { Status OnStreamInfo(uint64_t stream_index, std::shared_ptr info); + Status OnScte35Event(uint64_t stream_index, + std::shared_ptr event); // Processes main media sample and apply chunking if needed. Status ProcessMainMediaSample(const MediaSample* sample); @@ -126,14 +128,14 @@ class ChunkingHandler : public MediaHandler { std::vector last_sample_end_timestamps_; struct Scte35EventTimestampGreater { - bool operator()(const std::unique_ptr& lhs, - const std::unique_ptr& rhs) const; + bool operator()(const std::shared_ptr& lhs, + const std::shared_ptr& rhs) const; }; // Captures all incoming SCTE35 events to identify chunking points. Events // will be removed from this queue one at a time as soon as the correct // chunking point is identified in the incoming samples. - std::priority_queue, - std::vector>, + std::priority_queue, + std::vector>, Scte35EventTimestampGreater> scte35_events_; };