Skip to content

Commit

Permalink
Changes as per comments - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
sr1990 committed May 12, 2020
1 parent 65d35a5 commit dd75f36
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
3 changes: 1 addition & 2 deletions packager/mpd/base/representation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ xml::scoped_xml_ptr<xmlNode> 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<xmlNode>();
}
Expand Down
20 changes: 5 additions & 15 deletions packager/mpd/base/xml/xml_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SegmentInfo>& segment_infos,
uint32_t start_number,
const double target_duration) {
uint32_t start_number) {
if (!FLAGS_segment_template_constant_duration)
return false;

Expand All @@ -57,7 +56,6 @@ bool IsTimelineConstantDuration(const std::list<SegmentInfo>& segment_infos,
return false;

const SegmentInfo& first_segment = segment_infos.front();

if (first_segment.start_time / first_segment.duration != (start_number - 1))
return false;

Expand Down Expand Up @@ -407,8 +405,7 @@ bool RepresentationXmlNode::AddVODOnlyInfo(const MediaInfo& media_info) {
bool RepresentationXmlNode::AddLiveOnlyInfo(
const MediaInfo& media_info,
const std::list<SegmentInfo>& 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",
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions packager/mpd/base/xml/xml_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ class RepresentationXmlNode : public RepresentationBaseXmlNode {
/// SegmentInfos are sorted by its start time.
bool AddLiveOnlyInfo(const MediaInfo& media_info,
const std::list<SegmentInfo>& 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
Expand Down
28 changes: 14 additions & 14 deletions packager/mpd/base/xml/xml_node_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(),
Expand Down

0 comments on commit dd75f36

Please sign in to comment.