From 418e741f7f46480dc0bfb8dae6c9e6654bf02483 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Thu, 21 Jun 2018 14:26:41 -0700 Subject: [PATCH] [DASH] Fix potential text Segment Timeline not grouped This happens when --allow_approximate_segment_timeline_ is set. Fixes #417. Change-Id: Idf938ad4e0f7788a00c7485b7eeda43358a94178 --- packager/mpd/base/representation.cc | 2 +- packager/mpd/base/representation_unittest.cc | 40 +++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packager/mpd/base/representation.cc b/packager/mpd/base/representation.cc index 44092d30bd..3883fc45d9 100644 --- a/packager/mpd/base/representation.cc +++ b/packager/mpd/base/representation.cc @@ -420,7 +420,7 @@ bool Representation::ApproximiatelyEqual(uint64_t time1, uint64_t time2) const { std::min(frame_duration_, static_cast(kErrorThresholdSeconds * media_info_.reference_time_scale())); - return time1 < time2 + error_threshold && time2 < time1 + error_threshold; + return time1 <= time2 + error_threshold && time2 <= time1 + error_threshold; } uint64_t Representation::AdjustDuration(uint64_t duration) const { diff --git a/packager/mpd/base/representation_unittest.cc b/packager/mpd/base/representation_unittest.cc index 7fb55f4965..f7c24fc3c8 100644 --- a/packager/mpd/base/representation_unittest.cc +++ b/packager/mpd/base/representation_unittest.cc @@ -856,8 +856,8 @@ TEST_P(ApproximateSegmentTimelineTest, SegmentsWithSimilarDurations2) { std::string expected_s_elements; if (allow_approximate_segment_timeline_) { expected_s_elements = - "" - ""; + "" + ""; } else { uint64_t kNumSegments = 3; expected_s_elements = base::StringPrintf(kSElementTemplate, kStartTime, @@ -915,6 +915,42 @@ TEST_P(ApproximateSegmentTimelineTest, FillSmallOverlap) { XmlNodeEqual(ExpectedXml(expected_s_elements))); } +// Check the segments are grouped correctly when sample duration is not +// available, which happens for text streams. +// See https://github.com/google/shaka-packager/issues/417 for the background. +TEST_P(ApproximateSegmentTimelineTest, NoSampleDuration) { + const char kMediaInfo[] = + "text_info {\n" + " codec: 'wvtt'\n" + "}\n" + "reference_time_scale: 1000\n" + "container_type: 1\n" + "init_segment_url: 'init.mp4'\n" + "segment_template_url: '$Number$.mp4'\n"; + representation_ = CreateRepresentation(ConvertToMediaInfo(kMediaInfo), + kAnyRepresentationId, NoListener()); + ASSERT_TRUE(representation_->Init()); + + const uint64_t kStartTime = 0; + const uint64_t kDuration = kScaledTargetSegmentDuration; + const uint64_t kSize = 128; + AddSegments(kStartTime, kDuration, kSize, 0); + AddSegments(kStartTime + kDuration, kDuration, kSize, 0); + AddSegments(kStartTime + 2 * kDuration, kDuration, kSize, 0); + + const char kExpectedXml[] = + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + EXPECT_THAT(representation_->GetXml().get(), XmlNodeEqual(kExpectedXml)); +} + INSTANTIATE_TEST_CASE_P(ApproximateSegmentTimelineTest, ApproximateSegmentTimelineTest, Bool());