Skip to content

VPAAMP-163: Latency is fluctuating during normal playback in Linear/SLE assets#1412

Open
psiva01 wants to merge 6 commits into
dev_sprint_25_2from
feature/VPAAMP-143
Open

VPAAMP-163: Latency is fluctuating during normal playback in Linear/SLE assets#1412
psiva01 wants to merge 6 commits into
dev_sprint_25_2from
feature/VPAAMP-143

Conversation

@psiva01
Copy link
Copy Markdown
Contributor

@psiva01 psiva01 commented May 5, 2026

Reason for Change: Current HLS latency is fluctuating because it's based on playlist end position which gets updated by 0/4/8s during every refresh. Change HLS Latency calculation based on PDT which is gradual.

psiva01 added 3 commits April 21, 2026 19:08
Signed-off-by: psiva01 <sivasubramanian.patchaiperumal@ltts.com>
Signed-off-by: psiva01 <sivasubramanian.patchaiperumal@ltts.com>
Signed-off-by: psiva01 <sivasubramanian.patchaiperumal@ltts.com>
@psiva01 psiva01 requested a review from a team as a code owner May 5, 2026 09:39
@psiva01 psiva01 requested a review from Copilot May 5, 2026 09:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses fluctuating HLS live latency reporting by switching the latency calculation from “live edge position delta” (which advances in segment-sized steps per playlist refresh) to a Program Date Time (PDT)-based wall-clock calculation when EXT-X-PROGRAM-DATE-TIME is available.

Changes:

  • Add a PDT-based HLS live latency calculation path using mProgramDateTime and current epoch time.
  • Keep the prior live-edge-based latency calculation as a fallback when PDT is unavailable.
  • Add detailed logging around the new PDT latency computation.

Comment thread priv_aamp.cpp Outdated
Comment on lines +2742 to +2749
// to guard against transient position-behind-start edge cases.
double playbackOffsetFromWindowStartMs = reportFormattedCurrPos - (culledSeconds*1000.0);
if (playbackOffsetFromWindowStartMs < 0.0)
{
playbackOffsetFromWindowStartMs = 0.0;
}
long long pdtAtCurrentPosMs = static_cast<long long>(
(mProgramDateTime * 1000.0) + playbackOffsetFromWindowStartMs);
Copy link
Copy Markdown
Contributor Author

@psiva01 psiva01 May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback and #1412 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cd37ddd. Changed playbackOffsetFromWindowStartMs from reportFormattedCurrPos - (culledSeconds*1000.0) (mixed coordinate spaces) to position - (culledSeconds * 1000.0) — both in the same raw (unadjusted) space. Using position directly (rather than reportFormattedCurrPos - start) also avoids the edge case where start is reset to -1 for TSB-less linear streams. Also updated the block comment and downgraded the log from WARN to INFO.

Comment thread priv_aamp.cpp Outdated
long long pdtAtCurrentPosMs = static_cast<long long>(
(mProgramDateTime * 1000.0) + playbackOffsetFromWindowStartMs);
latency = static_cast<long>(nowMs - pdtAtCurrentPosMs);
AAMPLOG_WARN("HLS PDT latency = %ldms, nowMs = %lldms, mProgramDateTime = %.3fs, "
Comment thread priv_aamp.cpp
latency, nowMs, mProgramDateTime, start, culledSeconds*1000.0, reportFormattedCurrPos, playbackOffsetFromWindowStartMs);
if(latency < 0)
{ // this should never happen!
AAMPLOG_ERR("HLS PDT-based negative live latency = %ldms, nowMs = %lldms, pdtAtCurrentPosMs = %lldms", latency, nowMs, pdtAtCurrentPosMs);
Comment thread priv_aamp.cpp Outdated
Comment on lines +2725 to +2733
{
// For HLS Live, calculate latency based on live edge; round to nearest ms
latency = static_cast<long>(std::lround(end - reportFormattedCurrPos));
if(latency < 0)
{ // this should never happen!
AAMPLOG_ERR("HLS negative live latency = %ldms, end = %lfms, reportFormattedCurrPos = %lfms", latency, end, reportFormattedCurrPos);
if(mProgramDateTime > 0.0)
{
// For HLS Live with EXT-X-PROGRAM-DATE-TIME: calculate latency as the
// difference between the current wall-clock time and the absolute wall-clock
// time at the player's current playback position.
// mProgramDateTime is the current playlist-window start in epoch seconds.
// reportFormattedCurrPos is the player's position in ms, measured from the
// same window start (i.e. relative to culledSeconds). Adding them together
Copilot finished work on behalf of psiva01 May 6, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants