Repository navigation
fix(hls): plan VOD segments on the source's declared boundaries (#268) - #275
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
keyframeIndexIsTrustworthyrejects 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:videoShiftPts, which the video cutter and the audio index mapping then fold back on two different axes, so they disagree by the overshoot;-12889signature.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
TimeSeekableIOReaderpublishes its segment starts; the HLS VOD ingest reports the playlist's EXTINF sums.VODSegmentCuttercompares 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.videoShiftPts.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:
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=completeclean. 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