Skip to content

fix(hls): plan VOD segments on the source's declared boundaries (#268) - #275

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/268-plan-on-declared-boundaries
Aug 2, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/268-plan-on-declared-boundaries

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Round 2 of #268, from the reporter's hardware retest against the original source on 6.4.0: route selection, finite-playlist resolution and a 122 s control seek are confirmed, while a 1055.79 s seek never recovers and dies with CoreMediaErrorDomain -12889.

Root cause

The ingest route resolves the playlist, but the SEGMENT PLAN behind it does not use it. MPEG-TS has no upfront keyframe table, so keyframeIndexIsTrustworthy rejects the sparse index and the plan falls back to the uniform 4 s stride. The reporter's source carries one I-frame per 10 s segment, so only every fifth grid boundary is a random-access point:

  • a restart at any other index makes the producer's scan-forward gate wait for the first IRAP at-or-after the boundary, up to 8 s (two whole plan segments) late;
  • that overshoot rides in videoShiftPts, which the video cutter and the audio index mapping then fold back on two different axes, so they disagree by the overshoot;
  • AVPlayer ends up waiting on a segment that never arrives, which is the engine's own -12889 signature.

The control seek passed because 120 s is a multiple of both 4 and 10, the one alignment in five where a grid boundary is a real IRAP. Producer index 263 (1052 s) is not.

Fix

  • TimeSeekableIOReader publishes its segment starts; the HLS VOD ingest reports the playlist's EXTINF sums.
  • The plan is built on those boundaries whenever a source declares them, so every advertised boundary is one the gate can open. Each boundary is backed off half a segment (0.5 s cap) so manifest-vs-PTS rounding cannot put a boundary past its own IRAP; the reader's restart index snaps with the same tolerance instead of refetching a segment more.
  • VODSegmentCutter compares on the item axis rather than mixing shift-rebased packet timestamps with source-axis boundaries. That mismatch cut a whole PTS origin late on every non-zero-origin source, and against boundaries that ARE the IRAPs it would never have cut at all.
  • The audio index mapping folds back the plan anchor, not videoShiftPts.
  • A restart's first tfdt is the segment's advertised item-axis start.

Verification

New fixture (fetch-fixtures.sh): 20 min, 10 s segments, one I-frame each, served from a static local origin. The existing 2 s-GOP fixture cannot reproduce this, because every plan boundary there still catches a keyframe.

Same five scattered seek targets, including the reporter's 1055.79 s:

gate overshoot per restart
before 0 / 4 / 0 / 2 / 6 s
after 0.5 s on every restart (the plan's own boundary backoff)

Before, the misaligned restarts also produced the reporter's other signature: repeated identical re-anchors at one index plus a stalled consumer. After, seven seeks land in 77-114 ms with no wedge, no re-anchor and no stall.

Regression: full suite green (1387 tests), tvOS Simulator build green, -strict-concurrency=complete clean. Smoke-checked on the keyframe-aligned MP4 path (drift stays 0.000 s), the 2 s-GOP #268 fixture, a plain long-GOP local MPEG-TS on the uniform plan, and the H.264 HLS control that must stay on the native route.

Residual, out of scope here: a plain long-GOP MPEG-TS with no manifest still gets the 4 s uniform grid, so a seek there can still land up to a GOP ahead of the clock. It recovers, unlike the #268 route.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE

A finite HEVC-in-MPEG-TS HLS VOD carries no upfront keyframe index, so the segment
plan fell back to the uniform 4 s stride. The reporter's source carries one I-frame
per 10 s segment, so only every fifth grid boundary was a random-access point. A
restart at any other index made the producer's scan-forward gate open up to 8 s (two
whole plan segments) late, the overshoot then rode in videoShiftPts, skewed the video
cutter against the audio index mapping, and left AVPlayer rebuffering on a segment
that never arrived (CoreMediaErrorDomain -12889). The 122 s control seek passed
because 120 s is a multiple of both 4 and 10, the one alignment in five where a grid
boundary is a real IRAP.

- TimeSeekableIOReader publishes its segment starts; the HLS VOD ingest reports the
  playlist's EXTINF sums.
- The plan is built on those boundaries whenever a source declares them, so every
  advertised boundary is one the gate can open. Each boundary is backed off half a
  segment (0.5 s cap) so manifest-vs-PTS rounding can never put a boundary past its
  own IRAP, and the reader's restart index snaps with the same tolerance instead of
  refetching one segment more.
- VODSegmentCutter compares on the item axis rather than mixing shift-rebased packet
  timestamps with source-axis boundaries. That mismatch cut a whole PTS origin late on
  every non-zero-origin source, and against boundaries that ARE the IRAPs it would
  never have cut at all.
- The audio index mapping folds back the plan anchor, not videoShiftPts, so a
  restart's own gate overshoot cannot route audio into a segment the video cutter
  never opened.
- A restart's first tfdt is the segment's advertised item-axis start, not its
  backed-off source boundary.
- fetch-fixtures.sh grows the fixture that reproduces this: 20 min, 10 s segments, one
  I-frame each. The existing 2 s-GOP fixture cannot, because every plan boundary there
  still catches a keyframe.

Measured on that fixture over a local origin, five scattered seek targets including
the reporter's 1055.79 s: gate overshoot per restart 0/4/0/2/6 s before, 0.5 s on
every restart after. Full suite green, tvOS Simulator build green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
@superuser404notfound
superuser404notfound merged commit 14e4706 into main Aug 2, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/268-plan-on-declared-boundaries branch August 2, 2026 03:16
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.

1 participant