Skip to content

fix(playback): carry a seek target onto the source axis (#107) - #573

Merged
superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
tschuegy:fix/vod-seek-session-axis
Sep 20, 2026
Merged

superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
tschuegy:fix/vod-seek-session-axis

Conversation

@tschuegy

Copy link
Copy Markdown
Contributor

A seek on a source whose first packet is not at zero rewinds to the start of the file, and then the reader starves with nothing reported.

What happens

SoftwarePlaybackHost.seek(to:) takes the session axis — the axis the host publishes currentTime on — and hands it unchanged to four things that speak the source's own timestamps:

  • Demuxer.seekBounded(to:)
  • the packet store's beginSeek / prepareSeek / endSeek(sourceClock:)
  • videoDecoder.skipUntilPTS and renderer.setSkipThreshold
  • AudioOutput.seekClock(to:)

For a zero-based source the two axes coincide, so nothing was ever wrong. For a mid-stream-joined one — the case #107 introduced sessionZeroSeconds for — they differ by however far into the broadcast the source was opened, and two things break at once:

  1. The demuxer is asked for a timestamp that lies before the file's first packet and clamps to the beginning, so the seek rewinds.
  2. reservoirSecondsLocked() measures storedVideoSeconds - sourceClock. With the store on the source axis and sourceClock on the session axis, the reservoir reads as the entire offset. The producer concludes it has hours of buffer, relaxes, and stops reading; the consumer then starves. Nothing fails, so nothing is logged and no recovery path can fire — the picture simply stands while the clock runs on past the end of the file.

The change

One conversion at the top of seek(to:), applied to everything that speaks the source axis. currentTime stays on the session axis.

SWClockAnchorPolicy.sourceSeconds(forSession:sessionZeroSeconds:) is the inverse of the mapping the host already applies when publishing the position, and the identity when the offset is zero. liveScrubStill in the same file already makes exactly this conversion with sessionStartPts, and says so in its doc comment — the VOD path was simply missing it.

Test plan

  • swift test — 3147 tests green, including four new cases on the conversion: identity without an offset, the carry itself, a round trip against the position the host publishes, and passing a target through rather than making it worse when it cannot be expressed.
  • Device: Apple TV 4K (3rd generation), tvOS 26. A 64.5 s MPEG-TS capture on an SMB share whose first PTS is 24549.835 s, played through AetherEngineSMB.
before after
packet cache result=miss resident_bytes=0 result=hit resident_bytes=44565599
audio lead aLead=24549.8 aLead=1.96 … -0.04
frames after the seek enq=+0 disp=+0 on every tick plays on from the new position

Seeking forwards and backwards repeatedly, and resuming at a stored position, both behave.

How it was reached

Syravo now records live television to an SMB share and plays it back through AetherEngineSMB, which is what produced a source with a non-zero timestamp origin in the first place. Happy to adjust the shape of the fix if you would rather the conversion sat somewhere else.

…notfound#107)

`SoftwarePlaybackHost.seek(to:)` takes the session axis — the axis the
host publishes positions on — and handed it unchanged to four things
that speak the source's own timestamps: `Demuxer.seekBounded`, the
packet store's `beginSeek`/`prepareSeek`/`endSeek`, the decoder's skip
threshold, and `AudioOutput.seekClock`.

For a zero-based source the two axes coincide and nothing was ever
wrong. For a mid-stream-joined one — the case superuser404notfound#107 added
`sessionZeroSeconds` for — they differ by hours, and two things broke at
once. The demuxer was asked for a timestamp before the file's first
packet and clamped to its start, so a seek rewound. And the packet
store's reservoir, measured as `storedVideoSeconds - sourceClock`, read
as the whole offset: the producer saw hours of buffer, stopped reading,
and the consumer starved with nothing to report — no error, no stall,
just a standing picture and a clock running past the end of the file.

The conversion is `SWClockAnchorPolicy.sourceSeconds(forSession:
sessionZeroSeconds:)`, the inverse of the mapping the host already
applies when publishing `currentTime`, and the identity when the offset
is zero. `currentTime` stays on the session axis.

Test plan
- `swift test`: 3132 tests, all green, including four new cases on the
  conversion (identity, the carry, a round trip against the published
  position, and refusing a target that cannot be expressed).
- Device: Apple TV 4K (3rd gen), tvOS 26, a 64.5 s MPEG-TS capture on an
  SMB share whose first PTS is 24549.835 s, played through
  AetherEngineSMB. Before: `packet cache seek result=miss
  resident_bytes=0`, `aLead=24549.8`, `enq=+0 disp=+0` on every
  diagnostic tick until the session was torn down. After: `target_s`
  lands on the source axis, `result=hit resident_bytes=44565599`,
  `aLead` back to 1.96 … -0.04, and seeking forwards and backwards
  repeatedly plays on from the new position.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@superuser404notfound
superuser404notfound merged commit 8b04315 into superuser404notfound:main Sep 20, 2026
7 checks passed
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged, thank you. The diagnosis is exactly right, and the write-up made it possible to check rather than take on trust.

Three things were worth verifying before this went in, and all three hold:

  • Demuxer.seekBounded(to:) wants an absolute source timestamp. It hands seconds * AV_TIME_BASE straight to avformat_seek_file, and the time-seekable path subtracts sourcePTSOriginSeconds itself, so the carry does not double-apply.
  • SoftwarePacketReadAhead really is on the source axis on both sides: updatePlayhead is fed the raw synchronizer clock, and prepareSeek matches against keyframes stored in source PTS. That is the cache miss and the reservoir reading as the whole offset, as described.
  • clockSessionZero is the right variable to carry with, and this is the subtle part: it is firstSample - initialSeconds, not firstSample. So the mapping stays correct after a resume as well, where the session axis has its zero point before the file's first packet.

Two changes were made on merge, neither of them to the logic: the CHANGELOG entry was rebased onto the two that landed ahead of it, and three em-dashes were replaced, since the house style does not use them.

One thing the review turned up that this PR does not cover, mentioned here because it is the same root cause. AetherEngine.swift states the subtitle pump's harvest anchor at the session-axis target while subtitleDrainTick reports that reader's progress from sourceTime. On a mid-stream-joined source the anchor lands the whole offset below every note that follows it, and noteReach has no unannounced-advance guard, so one run stretches over ground nobody read and the #416 landing gate stops refusing anything. That is #575.

This will go out in the next release; there is no need to run anything further on it in the meantime.

ijuniorfu pushed a commit to ijuniorfu/AetherEngine that referenced this pull request Sep 21, 2026
superuser404notfound#107, superuser404notfound#416)

A software VOD seek opened the pump's coverage run at the session-axis target
while `subtitleDrainTick` reports that reader's progress from `sourceTime`.
On a zero-based source the two coincide, so nothing was ever wrong. On a
mid-stream-joined one the anchor sits the whole offset below every note that
follows it, and `noteReach` has no unannounced-advance guard (only
`noteProgress` does), so the first note stretches one run across ground nobody
read. `SubtitleHarvestCoverage.covers` then answers yes to anything, and
`subtitleLandingGroundIsRead` admits exactly the stale PGS arrival superuser404notfound#416 exists
to refuse.

`SoftwarePlaybackHost.sourceSeconds(forSession:)` exposes the conversion
`seek(to:)` already makes for everything inside the host, so the anchor and
the notes name the same axis.

Found while reviewing superuser404notfound#573, which fixes the same axis confusion inside the
host. swift test: 3163 swift-testing tests and the XCTest half green, exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F
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.

2 participants