From 833b8165f1222c9e34957c472bd24fbb1aa9a8ea Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Thu, 15 Mar 2018 17:19:01 -0700 Subject: [PATCH] Change Scte35 to use double for time Change-Id: I2588d3c86d48dc2d9f3692aa0aab28b9de63d109 --- packager/media/ad_cue_generator/ad_cue_generator.cc | 4 ++-- packager/media/base/media_handler.h | 4 ++-- packager/media/chunking/chunking_handler.cc | 8 ++------ packager/media/chunking/chunking_handler_unittest.cc | 8 ++++---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packager/media/ad_cue_generator/ad_cue_generator.cc b/packager/media/ad_cue_generator/ad_cue_generator.cc index dbefaa9711..4cea44c952 100644 --- a/packager/media/ad_cue_generator/ad_cue_generator.cc +++ b/packager/media/ad_cue_generator/ad_cue_generator.cc @@ -50,8 +50,8 @@ Status AdCueGenerator::DispatchScte35Events(size_t stream_index, 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; + scte35_event->start_time_in_seconds = cue_point.start_time_in_seconds; + scte35_event->duration_in_seconds = cue_point.duration_in_seconds; status.Update(DispatchScte35Event(stream_index, std::move(scte35_event))); if (!status.ok()) { return status; diff --git a/packager/media/base/media_handler.h b/packager/media/base/media_handler.h index 73a3fe91a4..e4875a006e 100644 --- a/packager/media/base/media_handler.h +++ b/packager/media/base/media_handler.h @@ -35,8 +35,8 @@ struct Scte35Event { std::string id; // Segmentation type id from SCTE35 segmentation descriptor. int type = 0; - int64_t start_time = 0; - int64_t duration = 0; + double start_time_in_seconds = 0; + double duration_in_seconds = 0; std::string cue_data; }; diff --git a/packager/media/chunking/chunking_handler.cc b/packager/media/chunking/chunking_handler.cc index 4facd451ab..bbc08c4674 100644 --- a/packager/media/chunking/chunking_handler.cc +++ b/packager/media/chunking/chunking_handler.cc @@ -16,10 +16,6 @@ namespace shaka { namespace media { namespace { int64_t kThreadIdUnset = -1; - -double TimeInSeconds(const Scte35Event& event, int64_t timescale) { - return static_cast(event.start_time) / timescale; -} } // namespace ChunkingHandler::ChunkingHandler(const ChunkingParams& chunking_params) @@ -200,7 +196,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() && - TimeInSeconds(*scte35_events_.top(), time_scale) <= dts_in_seconds) { + scte35_events_.top()->start_time_in_seconds <= dts_in_seconds) { // For simplicity, don't change |current_segment_index_|. current_subsegment_index_ = 0; new_segment = true; @@ -343,7 +339,7 @@ bool ChunkingHandler::Scte35EventTimestampGreater::operator()( const std::shared_ptr& rhs) const { DCHECK(lhs); DCHECK(rhs); - return lhs->start_time > rhs->start_time; + return lhs->start_time_in_seconds > rhs->start_time_in_seconds; } } // namespace media diff --git a/packager/media/chunking/chunking_handler_unittest.cc b/packager/media/chunking/chunking_handler_unittest.cc index 073f397b5d..d02b02c8e9 100644 --- a/packager/media/chunking/chunking_handler_unittest.cc +++ b/packager/media/chunking/chunking_handler_unittest.cc @@ -282,9 +282,11 @@ TEST_F(ChunkingHandlerTest, Scte35Event) { kStreamIndex0, GetVideoStreamInfo(kTimeScale1)))); const int64_t kVideoStartTimestamp = 12345; + const double kScte35TimeInSeconds = + static_cast(kVideoStartTimestamp + kDuration1) / kTimeScale1; auto scte35_event = std::make_shared(); - scte35_event->start_time = kVideoStartTimestamp + kDuration1; + scte35_event->start_time_in_seconds = kScte35TimeInSeconds; ASSERT_OK(Process(StreamData::FromScte35Event(kStreamIndex0, scte35_event))); for (int i = 0; i < 3; ++i) { @@ -303,9 +305,7 @@ TEST_F(ChunkingHandlerTest, Scte35Event) { // A new segment is created due to the existance of Cue. IsSegmentInfo(kStreamIndex0, kVideoStartTimestamp, kDuration1, !kIsSubsegment, !kEncrypted), - IsCueEvent( - kStreamIndex0, - static_cast(kVideoStartTimestamp + kDuration1) / 1000), + IsCueEvent(kStreamIndex0, kScte35TimeInSeconds), IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 1, kDuration1, !kEncrypted), IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 2,