diff --git a/packager/media/chunking/chunking_handler.cc b/packager/media/chunking/chunking_handler.cc index ccf86f5241..f1decb5970 100644 --- a/packager/media/chunking/chunking_handler.cc +++ b/packager/media/chunking/chunking_handler.cc @@ -66,8 +66,19 @@ Status ChunkingHandler::Process(std::unique_ptr stream_data) { time_scales_[stream_data->stream_index] = time_scale; break; } + case StreamDataType::kScte35Event: { + DCHECK_NE(main_stream_index_, kInvalidStreamIndex) + << "kStreamInfo should arrive before kScte35Event"; + const auto stream_index = stream_data->stream_index; + if (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::kSegmentInfo: - VLOG(3) << "Drop existing segment info."; + VLOG(3) << "Droppping existing segment info."; return Status::OK; case StreamDataType::kMediaSample: { const size_t stream_index = stream_data->stream_index; diff --git a/packager/media/chunking/chunking_handler.h b/packager/media/chunking/chunking_handler.h index 9910d01f6e..1d6fad937e 100644 --- a/packager/media/chunking/chunking_handler.h +++ b/packager/media/chunking/chunking_handler.h @@ -8,7 +8,9 @@ #define PACKAGER_MEDIA_CHUNKING_CHUNKING_HANDLER_ #include +#include +#include "packager/base/logging.h" #include "packager/media/base/media_handler.h" #include "packager/media/public/chunking_params.h" @@ -99,6 +101,24 @@ class ChunkingHandler : public MediaHandler { std::vector time_scales_; // The end timestamp of the last dispatched sample. std::vector last_sample_end_timestamps_; + + struct Scte35EventComparator { + bool operator()(const std::shared_ptr& lhs, + const std::shared_ptr& rhs) const { + DCHECK(lhs); + DCHECK(rhs); + DCHECK(lhs->scte35_event); + return lhs->scte35_event->start_time > rhs->scte35_event->start_time; + } + }; + + // 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>, + Scte35EventComparator> + scte35_events_; }; } // namespace media