Skip to content

Fix alternate audio stalling after a pause longer than the live playlist window - #8178

Open
thexeos wants to merge 1 commit into
video-dev:masterfrom
thexeos:fix/adjust-sliding-relative
Open

thexeos wants to merge 1 commit into
video-dev:masterfrom
thexeos:fix/adjust-sliding-relative

Conversation

@thexeos

@thexeos thexeos commented Nov 17, 2026

Copy link
Copy Markdown

This PR will...

Make adjustSliding() shift a playlist relative to where its fragments already start, instead of adding an absolute offset.

Why is this Pull Request needed?

adjustSliding() assumes newDetails is freshly parsed, with its first fragment at 0. On an alternate audio refresh it can run twice, and the second call adds the offset again.

  1. On a live stream with an alternate audio rendition, pause for longer than the playlist window.
  2. The next audio playlist refresh goes through mergeDetails(). No overlapping fragment has startPTS, so it places the new playlist with adjustSliding(oldDetails, newDetails). The position is correct, but alignedSliding stays false.
  3. onAudioTrackLoaded() sees !alignedSliding and calls alignStream(mainDetails, newDetails). Neither discontinuity nor PDT alignment applies, so it reaches adjustSliding(mainDetails, newDetails, false). When delta >= 0, that adds mainDetails.fragments[delta].start to fragments that are already at that start.

Log from a stalled run:

Aligning playlists based on SN 4234 (diff: 76.03)

The audio playlist then starts around 152 s while the playhead is around 86 s, so audio never loads again. Each later refresh repeats it (diff: 78.03, 82.03, ...). The media element stays at readyState 1 with video buffered ahead. No error is raised and no waiting event fires after resume, so nothing recovers.

During normal playback the overlap usually carries PTS, mergeDetails() sets alignedSliding, and step 3 is skipped. That is why it takes a pause or stall longer than the window.

Reproduced on a Cloudflare Stream live channel (2 s segments, 8-segment window, alternate audio) in iPhone Safari with ManagedMediaSource. It depends on which playlist refreshed last, so it is intermittent: 2 of 4 paused runs stalled. With this change 4 of 4 played on, and in the two runs that hit this path the realignment moved audio by 0.02 s instead of 76 s.

Are there any points in the code the reviewer needs to double check?

For freshly parsed details fragments[skippedSegments].start is 0, so existing callers compute the same offset as before. Only details that were already placed change, and they now get a near-zero correction. The last branch (fragmentStart === 0) is unchanged.

Alternatives I considered: set alignedSliding in mergeDetails() when its adjustSliding() call placed the playlist, or skip alignStream(mainDetails, ...) in the audio and subtitle controllers after a merge. Both would also skip discontinuity and PDT alignment against main on that refresh, which seemed riskier than making the helper safe to call twice. Happy to switch if you prefer one of those.

Resolves issues:

None filed.

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable): "does not shift a playlist that is already in place" in tests/unit/controller/level-helper.ts. It fails on master with [10, 15, 20] instead of [5, 10, 15].
  • API or design changes are documented in API.md (no API change)

…ed an offset mergeDetails had already applied
@robwalch

robwalch commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

This appears to duplicate #8170 for which I left the following comment #8170 (comment)

Playlists should not be adjusted twice.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants