Skip to content

fix(video): rebase the timeline across an archive chunk seam on a sequential origin (#368) - #371

Merged
superuser404notfound merged 2 commits into
superuser404notfound:mainfrom
tschuegy:fix/368-sequential-chunk-seam-rebase
Aug 13, 2026
Merged

superuser404notfound merged 2 commits into
superuser404notfound:mainfrom
tschuegy:fix/368-sequential-chunk-seam-rebase

Conversation

@tschuegy

Copy link
Copy Markdown
Contributor

Fixes #368.

What happens today

On a sequential origin (LoadOptions.sequentialOrigin, IPTV timeshift archives), a chunk seam's PTS reset — wrap-corrected by libavformat into a +2^33 leap — reaches VODSegmentCutter as item-axis time and walks its monotonic index to the plan tail in one call. From there the session is structurally dead: the append playlist freezes (folded indices publish duration 0 and get no URI), the backpressure park waits for a fetch of head − 10 that the playlist can never advertise, AVPlayer drains and stalls, and the #65 wedge recovery's reposition is exactly what a sequential origin categorically refuses. Field trace: 4 minutes of clean playback, stall, and a retry session that died the same way ~2 s in (the arithmetic fingerprint: 363524400 + 8226410192 = 2^33 exactly, surfaced by movenc as Application provided duration: 8226410192 in stream 0 is invalid).

The fix

Run the existing live timeline rebase (video and audio, unchanged thresholds and pairing machinery) for sequential-origin VOD as well: rebasesTimelineOnDiscontinuity = isLive || foldsSequentialTimeline, with the engine passing sequentialOriginPinsProducerToZero. The cutter, ledger, and append playlist need no change — they operate on post-shift output time, so after the rebase the cutter keeps walking the same plan boundaries sequentially and EXTINF stays real.

Deliberate choices, spelled out in comments:

  • No new LoadOption. sequentialOrigin is already the client's declaration "this is a forward-only chunked recording"; timeline continuity across its chunk seams is a correctness property of that declaration. SoftwarePlaybackHost.shouldFoldTimeline already folds these seams unconditionally for isLive || !sourceSeekable (its comment cites the same failure at +92726 s), so gating the producer path behind a second flag would make the two hosts behave differently for identical options.
  • No EXT-X-DISCONTINUITY at the seam. The archive is content-continuous and the output timeline stays continuous after the rebase; the discontinuity/force-cut flags stay live-only (they feed only the live segment bookkeeping).
  • onLiveTimelineRebase fires for sequential seams too, on purpose: the A53 caption tap and subtitle mapping need the playlist axis moved the same way, and handleLiveTimelineRebase's deferred-shift contract is exactly right for it.
  • isSourceReplay stays untouched in the shared path: it requires a recent unplanned reconnect, which a sequential origin (single connection, no reconnect) can never have.

Tests

Test plan

  • macOS: swift test (full suite, counts above).
  • Device: Apple TV 4K, tvOS 26.6, Xtream timeshift archives of SRF channels (H.264 720p50; AC-3 field-coded open-GOP on one, AAC on the other) — the two field sessions that die today. Verification runs through the Syravo client after the next release is pinned; both failure signatures (4-minute freeze, instant retry death) are reliably reproducible there today.

Merges cleanly alongside the #369 and #370 PRs; the three-way combination is integration-tested locally (full suite green on the merged tree).

tschuegy and others added 2 commits August 13, 2026 22:25
…uential origin (superuser404notfound#368)

IPTV timeshift archives are chunked recordings whose every chunk restarts
near PTS 0; libavformat's 33-bit wrap correction turns that backward seam
into a +2^33 leap (device: dts delta 8226410192 ticks, 363524400 +
8226410192 = 2^33 exactly). The producer's timeline rebase was live-only,
so on a sequential origin the leap reached the keyframe-gated cutter as
item-axis time and walked its monotonic index to the plan tail: frozen
playlist, a backpressure park waiting on a segment the playlist can never
advertise, and a wedge recovery whose reposition a sequential origin
refuses. The SW host already folds these seams for forward-only VOD
(shouldFoldTimeline); this is the producer-path equivalent.

Both stream rebases (video + audio) now run for sequential-origin VOD
under the same thresholds. Cutter, ledger and append playlist are
untouched: they operate on post-shift output time, so after the rebase
the cutter keeps walking the same plan boundaries sequentially and
EXTINF stays real. No EXT-X-DISCONTINUITY is added at the seam - the
archive is content-continuous and the output timeline stays continuous;
the discontinuity/force-cut flags stay live-only.

Co-Authored-By: Claude Fable 5 <[email protected]>
…user404notfound#368)

rebasedVideoShift is extracted as a pure static so the chunk-seam wrap
can be pinned against the field values: the seam packet lands exactly one
fallback frame past the last output dts, for the 2^33 wrap, a backward
chunk restart, and the live-scale jump (extraction changed nothing for
live). The cutter test pins the superuser404notfound#368 contract from the other side:
rebased continuous dts advances one boundary per cut, while a raw
wrap-scale leap saturates at the tail clamp in a single call.

Co-Authored-By: Claude Fable 5 <[email protected]>
@superuser404notfound
superuser404notfound merged commit 0e3dd02 into superuser404notfound:main Aug 13, 2026
4 checks passed
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged, thanks. The shape is right: the cutter, the ledger and the append playlist all work post-shift, so the rebase is the one place that needed to know about the seam, and reusing the live thresholds keeps one definition of "discontinuity" in the file. Verified here that isSourceReplay really is unreachable on this path, for a second reason beyond the single connection: the sequential reader reports EIO on a stall and never sets lastUnplannedReconnectAt at all.

One gap the rebase opens, fixed in a follow-up on main (20adae8, merge a17a8b4). The published clock folds item + shift - origin against an origin latched once at session start, so moving the shift by the wrap moves the scrubber with it. Driving applyNativeHostClockTick across a seam assembled from the field traces (source start 32070.8 s, seam at item 244 s, wrap to 2^33 ticks) puts the playhead at 63378 s instead of 250 s on an archive whose declared duration is one hour, with bufferedPosition and sourceTime following it.

A sequential archive has no source axis to anchor a display origin on: every chunk restarts near PTS 0 and the wrap correction turns each seam into a fresh fiction, so no single source PTS maps to display-0 for the session. Its item axis does, it starts at 0 because the producer is pinned to byte 0, and it is exactly what declaredDurationSeconds measures. Such a session now publishes that axis; every other source keeps AE#270's latched origin and true source PTS.

Nothing structural depended on it, which is why the traces do not show it: the #65 wedge detector reads the rendered playlist position, not the engine clock. It is worth a look during the device retest though, since a host progress bar and any resume position ride on it.

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

Labels

None yet

Projects

None yet

2 participants