Files
shaka-player/lib/hls
Felipe 2e13ea2c41 fix(HLS): Fix LL-HLS stall on live playlist updates after #9998 (#10154)
Fixes https://github.com/shaka-project/shaka-player/issues/10149

PR #9998 (`perf(HLS): skip merging known segments on live playlist
updates`) introduced a regression where low-latency HLS live streams
stall after ~10 seconds of playback. The video and audio simply stop
with no error.

### Root Cause

`createSegments_()` keeps a `mediaSequenceToStartTime` map to track
which segments it has already seen. The optimization only passes **new**
segments (those not yet in the map) to `mergeAndEvict()`:

```js
// line 4838
if (isNewSegment) {
    newReferences.push(reference);
}
```

However, in LL-HLS, a segment's partial references **grow** across
playlist refreshes — e.g., a segment starts with 2 partials, then 4,
then 8, until the segment is complete. The `firstReferenceToCreate`
logic at line 4665 correctly detects segments with active partials and
triggers a **rebuild**, but the rebuilt reference is **not** included in
`newReferences` because its position already exists in
`mediaSequenceToStartTime`. So `mergeAndEvict()` never receives the
updated reference, the segment index retains **stale partial data**, and
the player stalls once it exhausts those stale partials — roughly 10
seconds of content.

### The Fix

**1 line, no behavioral impact on VOD or non-low-latency streams.**

```diff
- if (isNewSegment) {
+ if (isNewSegment || !isNewStream) {
```

During live updates (`isNewStream = false`), **all** rebuilt segments
are now passed to `mergeAndEvict`, not just the truly new ones. This is
correct because rebuilt segments (triggered by partials or EXTINF
changes) have updated content that must replace the stale data in the
segment index.

**No performance regression:** When there are truly no changes (all
segments known, no partials, no EXTINF changes),
`firstReferenceToCreate` stays at `hlsSegments.length`, so all segments
are skipped, `references` is empty, and `mergeAndEvict` is never called
— preserving the optimization.

### Steps to Reproduce

1. Play any LL-HLS live stream (e.g., with `#EXT-X-SERVER-CONTROL` and
partial segments)
2. Observe playback stops after ~8–12 seconds with no error
2026-05-29 14:01:39 +02:00
..