Repository navigation
Publish a first-frame-ready signal (#315) - #329
Merged
Merged
Conversation
`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
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.
Reported in #315:
NativeAVPlayerHost.playerLayer.isReadyForDisplayis the only real first-frame signal on the native path, andnativeHostis internal, so a host approximates presentation fromreadyToPlayinstead. 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:AVPlayerLayer.isReadyForDisplayon the session's own layer,AVSampleBufferDisplayLayer.isReadyForDisplay. That property is explicitly not KVO-observable; AVFoundation postsAVSampleBufferDisplayLayerReadyForDisplayDidChangeNotificationfor 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:
replaceCurrentItemcostsisReadyForDisplayabout 40 ms offalseand 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 waySeekEventwas 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 throughload(),reloadAtCurrentPosition()included, resets it with the item.It claims readiness, not visibility. Both layers reach
isReadyForDisplaywhile in no view hierarchy at all. Measured headless withaetherctl, 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,
isReadyForDisplayis unchanged acrossseek). The per-seek answer isseekEvents/SeekEvent.landed(renderedTime:), which terminates each.beganwith 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
@Publishedreplays 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;Issue315FirstFramePresentedTestspins that case and fails without the guard.Verification
swift test: 1560 tests in 233 suites, 0 failuresswift build -Xswiftc -strict-concurrency=complete: cleanxcodebuildtvOS Simulator and iOS Simulator: BUILD SUCCEEDEDaetherctl play(native) andaetherctl play --swon local fixtures: the newFIRSTFRAME ... t+line and the per-tickrfd=y/nshow the edge on both pathsaetherctl playcarries both, so the signal is capturable where the report came from.