Skip to content

Commit

Permalink
Omit SegmentTimeline completely, with allow_approximate_segment_timel…
Browse files Browse the repository at this point in the history
…ine option
  • Loading branch information
sr1990 committed Apr 8, 2020
1 parent 069dbc8 commit 4c92d47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packager/mpd/base/representation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ void Representation::AddSegmentInfo(int64_t start_time, int64_t duration) {
const uint64_t kNoRepeat = 0;
const int64_t adjusted_duration = AdjustDuration(duration);

if (segment_infos_.empty()) {
start_number_ = start_time / duration;
}

if (!segment_infos_.empty()) {
// Contiguous segment.
const SegmentInfo& previous = segment_infos_.back();
Expand Down
26 changes: 17 additions & 9 deletions packager/mpd/base/xml/xml_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ std::string RangeToString(const Range& range) {
base::Uint64ToString(range.end());
}

bool ApproximiatelyEqual(int64_t time1, int64_t time2) {
const double kErrorThresholdSeconds = 0.05;

const uint32_t error_threshold =
static_cast<uint32_t>(kErrorThresholdSeconds * time1);
return std::abs(time1 - time2) <= error_threshold;
}

// 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,
Expand All @@ -56,14 +64,15 @@ 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))
if (!ApproximiatelyEqual(first_segment.start_time,
first_segment.duration * start_number))
return false;

if (segment_infos.size() == 1)
return true;

const SegmentInfo& last_segment = segment_infos.back();
if (last_segment.repeat != 0)
if (!(last_segment.repeat == 0 || first_segment.repeat == 0))
return false;

const int64_t expected_last_segment_start_time =
Expand Down Expand Up @@ -179,9 +188,8 @@ void XmlNode::SetStringAttribute(const char* attribute_name,
void XmlNode::SetIntegerAttribute(const char* attribute_name, uint64_t number) {
DCHECK(node_);
DCHECK(attribute_name);
xmlSetProp(node_.get(),
BAD_CAST attribute_name,
BAD_CAST (base::Uint64ToString(number).c_str()));
xmlSetProp(node_.get(), BAD_CAST attribute_name,
BAD_CAST(base::Uint64ToString(number).c_str()));
}

void XmlNode::SetFloatingPointAttribute(const char* attribute_name,
Expand Down Expand Up @@ -437,12 +445,12 @@ bool RepresentationXmlNode::AddLiveOnlyInfo(
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)
for (const auto& segment_info_element : segment_infos)
last_segment_number += segment_info_element.repeat + 1;

AddSupplementalProperty(
"http://dashif.org/guidelines/last-segment-number",
std::to_string(last_segment_number));
"http://dashif.org/guidelines/last-segment-number",
std::to_string(last_segment_number));
}
} else {
XmlNode segment_timeline("SegmentTimeline");
Expand Down

0 comments on commit 4c92d47

Please sign in to comment.