Skip to content

Publish a first-frame-ready signal (#315) - #329

Merged
superuser404notfound merged 1 commit into
mainfrom
feat/issue-315-first-frame-signal
Aug 7, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
feat/issue-315-first-frame-signal

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Reported in #315: NativeAVPlayerHost.playerLayer.isReadyForDisplay is the only real first-frame signal on the native path, and nativeHost is internal, so a host approximates presentation from readyToPlay instead. That is one edge too early on a load and no edge at all across a seek.

What is published

AetherEngine.hasFirstFrameReadyForDisplay (@Published, load-scoped), folded from:

  • native: AVPlayerLayer.isReadyForDisplay on the session's own layer,
  • software: AVSampleBufferDisplayLayer.isReadyForDisplay. That property is explicitly not KVO-observable; AVFoundation posts AVSampleBufferDisplayLayerReadyForDisplayDidChangeNotification for it. It arrived in tvOS/iOS 17.4 and macOS 14.4, below the package floor, so older systems fall back to the first frame handed to the renderer, which is one hop earlier than presentation and is documented as such.

Audio-only sessions have nothing to display and leave it false.

The two shape decisions

Latched for the load, not mirrored as a level. Measured on an unattached layer: replaceCurrentItem costs isReadyForDisplay about 40 ms of false and then raises it again, and that holds for the in-place handover too, the swap that exists precisely so a viewer sees nothing. Publishing the level would make every host re-cover seams they are deliberately not meant to react to, and a falling edge would be ambiguous in the way SeekEvent was introduced to fix. So the seams that reuse a running host (media fallback, wired-HDMI AirPlay master swap, the #93 recovery, the AE#158 handover) keep the latch; a rebuild that goes back through load(), reloadAtCurrentPosition() included, resets it with the item.

It claims readiness, not visibility. Both layers reach isReadyForDisplay while in no view hierarchy at all. Measured headless with aetherctl, native reports it at t+0.05 s and software after 6 enqueued frames, on the same run where the #298 "no host bound a render surface" warning fires. Calling it "presented" would have been a lie for exactly the hosts #298 is about, so the name and the docs say ready-for-display.

Seeks

Not this flag: a seek keeps the previous frame on screen, so the layer never stops being ready for display (measured, isReadyForDisplay is unchanged across seek). The per-seek answer is seekEvents / SeekEvent.landed(renderedTime:), which terminates each .began with landed / stalled / superseded under the seek's own id.

The subtle part of the fold

Every call site wires its host sinks before it loads the host, so the value @Published replays on subscribe is, on a reused native host, still the outgoing item's picture. Taking it would latch this load's flag on the previous load's frame. dropFirst() discards it; Issue315FirstFramePresentedTests pins that case and fails without the guard.

Verification

  • swift test: 1560 tests in 233 suites, 0 failures
  • swift build -Xswiftc -strict-concurrency=complete: clean
  • xcodebuild tvOS Simulator and iOS Simulator: BUILD SUCCEEDED
  • aetherctl play (native) and aetherctl play --sw on local fixtures: the new FIRSTFRAME ... t+ line and the per-tick rfd=y/n show the edge on both paths

aetherctl play carries both, so the signal is capturable where the report came from.

`isSessionReady` is `AVPlayerItem.readyToPlay`, which AVFoundation reaches
before the layer holds a picture and which stays true across a seek. A host
approximating presentation from it lifts its black cover onto black, and the
only signal that can answer the question was internal: `nativeHost` is not
public and the software path had no equivalent at all.

`AetherEngine.hasFirstFrameReadyForDisplay` is that signal, folded from
`AVPlayerLayer.isReadyForDisplay` on the native path and
`AVSampleBufferDisplayLayer.isReadyForDisplay` on the software one (the
property is not KVO-observable there, AVFoundation posts a notification for it;
below tvOS/iOS 17.4 and macOS 14.4 it does not exist and the fallback is the
first frame handed to the renderer, one hop earlier). Audio-only sessions never
arm it.

Two decisions the property's documentation carries, both measured rather than
assumed:

- It is latched for the load, not mirrored as a level. An item swap costs the
  layer its picture for ~40 ms even when the swap is the in-place handover that
  exists to be invisible, so the seams that reuse a running host (media
  fallback, AirPlay master swap, #93 recovery, AE#158 handover) hold the latch.
  A rebuild that goes back through `load()` resets it with the item.
- It says the pipeline has a frame ready, not that a viewer sees one. Both
  layers reach `isReadyForDisplay` while in no view hierarchy at all (measured
  headless: native t+0.05 s, software after 6 enqueued frames, on the same run
  where the #298 unbound-surface warning fires).

The fold discards the value the host replays on subscribe: every call site
wires its sinks before it loads the host, so on a reused native host that
replay is still the outgoing item's picture. `Issue315FirstFramePresentedTests`
pins that case, and fails without the guard.

`aetherctl play` prints the edge (`FIRSTFRAME ... t+`) and carries `rfd=y/n` per
telemetry tick, so the signal is capturable where the report came from.

Verified: 1560 tests green, `-strict-concurrency=complete` clean, tvOS and iOS
Simulator BUILD SUCCEEDED, `play` and `play --sw` on local fixtures.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
@superuser404notfound
superuser404notfound merged commit daf1897 into main Aug 7, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the feat/issue-315-first-frame-signal branch August 7, 2026 15:29
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