Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DASHTree] Limit insert live segs to uncovered interval cases #1353

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions src/parser/DASHTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ void adaptive::CDashTree::ParseTagMPDAttribs(pugi::xml_node nodeMPD)
std::string minimumUpdatePeriodStr;
if (XML::QueryAttrib(nodeMPD, "minimumUpdatePeriod", minimumUpdatePeriodStr))
{
double duration = XML::ParseDuration(minimumUpdatePeriodStr) * 1000;
m_updateInterval = static_cast<uint64_t>(duration);
double duration = XML::ParseDuration(minimumUpdatePeriodStr);
m_minimumUpdatePeriod = static_cast<uint64_t>(duration);
m_allowInsertLiveSegments = m_minimumUpdatePeriod == 0;
m_updateInterval = static_cast<uint64_t>(duration * 1000);
}

if (mediaPresDuration == 0)
Expand Down Expand Up @@ -1005,16 +1007,14 @@ void adaptive::CDashTree::ParseTagRepresentation(pugi::xml_node nodeRepr,

if (segmentsCount < 65536) // SIDX atom is limited to 65535 references (fragments)
{
CSegment segTl;
segTl.m_time = adpSet->GetStartPTS();
segTl.m_number = repr->GetStartNumber();
segTl.startPTS_ = adpSet->GetStartPTS();
uint64_t segStartNumber = repr->GetStartNumber();
uint64_t segStartPts = adpSet->GetStartPTS();

if (m_isLive && !segTemplate->HasVariableTime() &&
segTemplate->GetDuration() > 0)
{
uint64_t sampleTime = period->GetStart() / 1000;
segTl.m_number +=
segStartNumber +=
static_cast<uint64_t>(static_cast<int64_t>(stream_start_ - available_time_ -
reprTotalTimeSecs - sampleTime) *
segTemplate->GetTimescale() / segTemplate->GetDuration() +
Expand All @@ -1032,18 +1032,32 @@ void adaptive::CDashTree::ParseTagRepresentation(pugi::xml_node nodeRepr,
// Reserve memory to speedup
repr->SegmentTimeline().GetData().reserve(segmentsCount);

CSegment seg;
seg.m_number = segStartNumber;
seg.startPTS_ = segStartPts;
seg.m_time = segStartPts;

for (size_t pos{0}; pos < segmentsCount; pos++)
{
repr->SegmentTimeline().GetData().push_back(segTl);

uint32_t* tlDuration = adpSet->SegmentTimelineDuration().Get(pos);
uint32_t duration = tlDuration ? *tlDuration : segTplDuration;
segTl.m_time += duration;
segTl.m_number += 1;
segTl.startPTS_ += duration;
seg.m_duration = duration;
repr->SegmentTimeline().GetData().push_back(seg);

seg.m_number += 1;
seg.startPTS_ += duration;
seg.m_time += duration;
}

repr->nextPts_ = segTl.startPTS_;
const CSegment& lastSeg = repr->SegmentTimeline().GetData().back();
uint64_t totalSegsDuration = lastSeg.startPTS_ + lastSeg.m_duration;

repr->nextPts_ = totalSegsDuration;

// If the duration of segments dont cover the interval duration for the manifest update
// then allow new segments to be inserted until the next manifest update
if (m_isLive && totalSegsDuration < m_minimumUpdatePeriod)
m_allowInsertLiveSegments = true;
}
else
{
Expand Down Expand Up @@ -1727,7 +1741,7 @@ void adaptive::CDashTree::InsertLiveSegment(PLAYLIST::CPeriod* period,
uint64_t fragmentDuration,
uint32_t movieTimescale)
{
if (HasManifestUpdatesSegs())
if (!m_allowInsertLiveSegments || HasManifestUpdatesSegs())
return;

// Check if its the last frame we watch
Expand Down
3 changes: 3 additions & 0 deletions src/parser/DASHTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,8 @@ class ATTR_DLL_LOCAL CDashTree : public adaptive::AdaptiveTree

// Period sequence incremented to every new period added
uint32_t m_periodCurrentSeq{0};

uint64_t m_minimumUpdatePeriod{0}; // in seconds
bool m_allowInsertLiveSegments{false};
};
} // namespace adaptive
Loading