From dd75f369ab404eef86dd4a78d74e024d3ceb9f33 Mon Sep 17 00:00:00 2001 From: sr90 Date: Mon, 27 Apr 2020 19:57:46 -0700 Subject: [PATCH] Changes as per comments - 3 --- packager/mpd/base/representation.cc | 3 +-- packager/mpd/base/xml/xml_node.cc | 20 ++++------------ packager/mpd/base/xml/xml_node.h | 3 +-- packager/mpd/base/xml/xml_node_unittest.cc | 28 +++++++++++----------- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/packager/mpd/base/representation.cc b/packager/mpd/base/representation.cc index c9018ef7bfc..501f5f42c4c 100644 --- a/packager/mpd/base/representation.cc +++ b/packager/mpd/base/representation.cc @@ -270,8 +270,7 @@ xml::scoped_xml_ptr Representation::GetXml() { if (HasLiveOnlyFields(media_info_) && !representation.AddLiveOnlyInfo( - media_info_, segment_infos_, start_number_, - mpd_options_.mpd_params.target_segment_duration)) { + media_info_, segment_infos_, start_number_)) { LOG(ERROR) << "Failed to add Live info."; return xml::scoped_xml_ptr(); } diff --git a/packager/mpd/base/xml/xml_node.cc b/packager/mpd/base/xml/xml_node.cc index 4efaa84d60f..5ea24184e45 100644 --- a/packager/mpd/base/xml/xml_node.cc +++ b/packager/mpd/base/xml/xml_node.cc @@ -47,8 +47,7 @@ std::string RangeToString(const Range& range) { // Check if segments are continuous and all segments except the last one are of // the same duration. bool IsTimelineConstantDuration(const std::list& segment_infos, - uint32_t start_number, - const double target_duration) { + uint32_t start_number) { if (!FLAGS_segment_template_constant_duration) return false; @@ -57,7 +56,6 @@ bool IsTimelineConstantDuration(const std::list& segment_infos, return false; const SegmentInfo& first_segment = segment_infos.front(); - if (first_segment.start_time / first_segment.duration != (start_number - 1)) return false; @@ -407,8 +405,7 @@ bool RepresentationXmlNode::AddVODOnlyInfo(const MediaInfo& media_info) { bool RepresentationXmlNode::AddLiveOnlyInfo( const MediaInfo& media_info, const std::list& segment_infos, - uint32_t start_number, - const double target_duration) { + uint32_t start_number) { XmlNode segment_template("SegmentTemplate"); if (media_info.has_reference_time_scale()) { segment_template.SetIntegerAttribute("timescale", @@ -434,16 +431,9 @@ bool RepresentationXmlNode::AddLiveOnlyInfo( if (!segment_infos.empty()) { // Don't use SegmentTimeline if all segments except the last one are of // the same duration. - if (IsTimelineConstantDuration( - segment_infos, start_number, - target_duration * media_info.reference_time_scale())) { - if (target_duration > 0) { - segment_template.SetIntegerAttribute( - "duration", target_duration * media_info.reference_time_scale()); - } else { - segment_template.SetIntegerAttribute("duration", - segment_infos.front().duration); - } + if (IsTimelineConstantDuration(segment_infos, start_number)) { + segment_template.SetIntegerAttribute("duration", + segment_infos.front().duration); if (FLAGS_dash_add_last_segment_number_when_needed) { uint32_t last_segment_number = start_number - 1; for (const auto& segment_info_element : segment_infos) diff --git a/packager/mpd/base/xml/xml_node.h b/packager/mpd/base/xml/xml_node.h index 858a56fb2e4..976730d4d3f 100644 --- a/packager/mpd/base/xml/xml_node.h +++ b/packager/mpd/base/xml/xml_node.h @@ -186,8 +186,7 @@ class RepresentationXmlNode : public RepresentationBaseXmlNode { /// SegmentInfos are sorted by its start time. bool AddLiveOnlyInfo(const MediaInfo& media_info, const std::list& segment_infos, - uint32_t start_number, - const double target_duration); + uint32_t start_number); private: // Add AudioChannelConfiguration element. Note that it is a required element diff --git a/packager/mpd/base/xml/xml_node_unittest.cc b/packager/mpd/base/xml/xml_node_unittest.cc index fbf50831657..ef5b478f691 100644 --- a/packager/mpd/base/xml/xml_node_unittest.cc +++ b/packager/mpd/base/xml/xml_node_unittest.cc @@ -251,8 +251,8 @@ TEST_F(LiveSegmentTimelineTest, OneSegmentInfo) { {kStartTime, kDuration, kRepeat}, }; RepresentationXmlNode representation; - ASSERT_TRUE(representation.AddLiveOnlyInfo(media_info_, segment_infos, - kStartNumber, 0)); + ASSERT_TRUE( + representation.AddLiveOnlyInfo(media_info_, segment_infos, kStartNumber)); EXPECT_THAT( representation.GetRawPtr(), @@ -272,8 +272,8 @@ TEST_F(LiveSegmentTimelineTest, OneSegmentInfoNonZeroStartTime) { {kNonZeroStartTime, kDuration, kRepeat}, }; RepresentationXmlNode representation; - ASSERT_TRUE(representation.AddLiveOnlyInfo(media_info_, segment_infos, - kStartNumber, 0)); + ASSERT_TRUE( + representation.AddLiveOnlyInfo(media_info_, segment_infos, kStartNumber)); EXPECT_THAT(representation.GetRawPtr(), XmlNodeEqual( @@ -296,8 +296,8 @@ TEST_F(LiveSegmentTimelineTest, OneSegmentInfoMatchingStartTimeAndNumber) { {kNonZeroStartTime, kDuration, kRepeat}, }; RepresentationXmlNode representation; - ASSERT_TRUE(representation.AddLiveOnlyInfo(media_info_, segment_infos, - kStartNumber, 0)); + ASSERT_TRUE( + representation.AddLiveOnlyInfo(media_info_, segment_infos, kStartNumber)); EXPECT_THAT( representation.GetRawPtr(), @@ -323,8 +323,8 @@ TEST_F(LiveSegmentTimelineTest, AllSegmentsSameDurationExpectLastOne) { {kStartTime2, kDuration2, kRepeat2}, }; RepresentationXmlNode representation; - ASSERT_TRUE(representation.AddLiveOnlyInfo(media_info_, segment_infos, - kStartNumber, 0)); + ASSERT_TRUE( + representation.AddLiveOnlyInfo(media_info_, segment_infos, kStartNumber)); EXPECT_THAT( representation.GetRawPtr(), @@ -350,8 +350,8 @@ TEST_F(LiveSegmentTimelineTest, SecondSegmentInfoNonZeroRepeat) { {kStartTime2, kDuration2, kRepeat2}, }; RepresentationXmlNode representation; - ASSERT_TRUE(representation.AddLiveOnlyInfo(media_info_, segment_infos, - kStartNumber, 0)); + ASSERT_TRUE( + representation.AddLiveOnlyInfo(media_info_, segment_infos, kStartNumber)); EXPECT_THAT(representation.GetRawPtr(), XmlNodeEqual( @@ -382,8 +382,8 @@ TEST_F(LiveSegmentTimelineTest, TwoSegmentInfoWithGap) { {kStartTime2, kDuration2, kRepeat2}, }; RepresentationXmlNode representation; - ASSERT_TRUE(representation.AddLiveOnlyInfo(media_info_, segment_infos, - kStartNumber, 0)); + ASSERT_TRUE( + representation.AddLiveOnlyInfo(media_info_, segment_infos, kStartNumber)); EXPECT_THAT(representation.GetRawPtr(), XmlNodeEqual( @@ -409,8 +409,8 @@ TEST_F(LiveSegmentTimelineTest, LastSegmentNumberSupplementalProperty) { RepresentationXmlNode representation; FLAGS_dash_add_last_segment_number_when_needed = true; - ASSERT_TRUE(representation.AddLiveOnlyInfo(media_info_, segment_infos, - kStartNumber, 0)); + ASSERT_TRUE( + representation.AddLiveOnlyInfo(media_info_, segment_infos, kStartNumber)); EXPECT_THAT( representation.GetRawPtr(),