Skip to content
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
8 changes: 8 additions & 0 deletions src/common/AdaptiveTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,17 @@ namespace adaptive

updLck.lock();

// Store the interval before it is cleared, skipping a value that a parser
// lowered as a temporary backoff
if (!m_resetInterval && m_tree->m_updateInterval != NO_VALUE && m_tree->m_updateInterval > 0)
m_tree->m_lastValidUpdateInterval = m_tree->m_updateInterval.load();

// Reset interval value to allow forced update from manifest
if (m_resetInterval)
{
m_tree->m_updateInterval = PLAYLIST::NO_VALUE;
m_resetInterval = false;
}

m_tree->OnUpdateSegments();
}
Expand Down
5 changes: 5 additions & 0 deletions src/common/AdaptiveTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ class ATTR_DLL_LOCAL AdaptiveTree
// Non-zero value: refresh interval starting from the moment mpd download was initiated
// Value 0: refresh each time we need to make new segments
std::atomic<uint64_t> m_updateInterval{PLAYLIST::NO_VALUE};

// Last update interval that came from a manifest, as opposed to one a parser
// applied as a temporary backoff. Since m_updateInterval is set to NO_VALUE
// before each update, a parser that backs off has no other usable base value.
std::atomic<uint64_t> m_lastValidUpdateInterval{0};
TreeUpdateThread m_updThread;
std::atomic<std::chrono::time_point<std::chrono::system_clock>> lastUpdated_{std::chrono::system_clock::now()};

Expand Down
6 changes: 5 additions & 1 deletion src/parser/HLSTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace
// Timescale for ms
constexpr uint64_t TIMESCALE = 1000;

// Lower bound for the update interval backoff, in ms, to keep the halving from
// reaching zero and stopping the update thread
constexpr uint64_t MIN_UPDATE_INTERVAL_MS = 500;

// \brief Parse a tag (e.g. #EXT-X-VERSION:1) to extract name and value
void ParseTagNameValue(const std::string& line, std::string& tagName, std::string& tagValue)
{
Expand Down Expand Up @@ -1157,7 +1161,7 @@ void adaptive::CHLSTree::OnUpdateSegments()
// so avoid requesting updates too quickly but you also need to make sure
// that we have segments to mitigate a buffering problem
// so try halve the interval time in a temporary way
m_updateInterval = m_updateInterval / 2;
m_updateInterval = std::max<uint64_t>(m_lastValidUpdateInterval / 2, MIN_UPDATE_INTERVAL_MS);
// Reset the interval on the next update, to restore the original value
m_updThread.ResetInterval();
}
Expand Down