Skip to content

fix(swplayback): name a software session that decodes into nothing (#298) - #300

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/298-sw-surface-visibility
Aug 4, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/298-sw-surface-visibility

Conversation

@superuser404notfound

@superuser404notfound superuser404notfound commented Aug 4, 2026 •

Copy link
Copy Markdown
Owner

What #298 reported

A packed-bitstream XviD AVI: audio plays to completion, the picture never appears, and the session log reads

[Renderer] enqueue #1:   status=rendering ready=true  error=nil
[Renderer] enqueue #30:  status=rendering ready=false error=nil   (t+1.37s)
[Renderer] enqueue #100: status=rendering ready=false error=nil   (t+4.74s)

which was read as "the renderer stopped accepting frames".

What the measurement says

isReadyForMoreMediaData is the demux loop's back-pressure gate (SoftwarePlaybackHost parks on it before feeding a video packet), so a full queue immediately after an enqueue is the gate working. The counter reaching #100 at t+4.74s on a 23.976 fps source is real-time pacing, and a queue that had genuinely stopped draining would have parked the one loop that also feeds audio within a queue depth, taking the audio with it.

Reproduced locally on ffmpeg -f lavfi -i testsrc -c:v mpeg4 -vtag XVID -bf 2 ... .avi through aetherctl play --sw: the same three lines, the same pts=0.042s first frame, VERDICT: OK, clock advancing. aetherctl binds no view at all, so it also shows nothing.

That is the actual gap. A software session renders into SampleBufferRenderer.displayLayer, which reaches the screen only once the host binds a surface (AetherEngine.bind(view:) / AetherPlayerSurface). A host presenting AVPlayerViewController instead gets audio, a completely healthy engine log, and no picture, because this path has no AVPlayerItem for AVKit to show (the reporter's log has playerItem.status=0, loading=YES and _becomeNowPlaying denied: no player item throughout). Nothing named that condition.

Changes

1. Surface visibility, SoftwarePlaybackHost. Once per session, 8 ticks (~2 s) after frames start flowing, on the main actor:

[SWHost] 50 frames decoded into a display layer that is in no view hierarchy: the host never
bound a render surface (AetherEngine.bind(view:) / AetherPlayerSurface). The software path
renders into that layer, not through AVPlayerViewController, so audio plays and no picture
can appear

and the sibling case, a layer bound to a view that never got a layout:

[SWHost] display layer is bound but sized 0x0 after 50 frames: the bound view has no layout,
so no frame can be visible

The delay covers a host that binds during load plus the first layout pass. assessSurface(hasSuperlayer:size:) is a pure function so both verdicts are pinned without a live layer.

2. Unschedulable frames, SampleBufferRenderer. AV_NOPTS_VALUE reaches the decoder callback as CMTime.invalid and CoreMedia builds a sample buffer from it without complaint (measured: CMSampleBufferCreateReadyWithImageBuffer returns noErr and the sample's PTS reads back as NaN seconds), so the display queue was the first place it could do damage. The deinterlace path already drops its untimestamped output for that reason; this is the same rule one layer lower, before the reorder buffer, where a NaN also silently breaks ordering for its neighbours (every comparison against NaN is false). Drops are counted and named.

This is hardening, not the cause: the demuxer runs fflags +genpts, so AVI's missing anchor-frame timestamps are regenerated (pktdump on the fixture: NOPTS_pts=0, presentation order I(1) B(2) B(3) P(4)). It closes the mechanism the report hypothesised and makes a source that genuinely produces untimed frames say so.

Not changed

No stall watchdog / .error transition. Nothing is stalled here, and a watchdog on "ready has been false for a while" would fire on healthy back-pressure, which is the exact reading this issue is about. Engine logging already goes through os_log (subsystem de.superuser404.AetherEngine, category sw.playback), which is how the reporter captured these lines.

Verification

  • 1491 tests green (8 new in Issue298SoftwareSurfaceTests), swift build -Xswiftc -strict-concurrency=complete clean, tvOS Simulator BUILD SUCCEEDED.
  • aetherctl play --sw on the AVI fixture emits the new line at t≈1.9s, in the same position the reporter's log would have shown it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE

)

A packed-bitstream XviD AVI reported as "the renderer stops accepting
frames": audio played to completion, no picture, and
`[Renderer] enqueue #30 ... ready=false` read as the stall.

That line is what a healthy session prints. `isReadyForMoreMediaData` is
the demux loop's back-pressure gate, so a full queue right after an
enqueue is the gate working, and the counter reaching #100 at t+4.7s on
a 23.976 fps source is real-time pacing. A queue that had genuinely
stopped draining would have parked the one demux loop that also feeds
audio within a queue depth, and the audio would have stopped with it.
The same three lines, with the same pts=0.042s first frame, reproduce on
an `-c:v mpeg4 -bf 2` AVI through `aetherctl play --sw`, which binds no
view at all and therefore shows nothing either.

That is the gap this closes. A software session renders into
`SampleBufferRenderer.displayLayer`, which reaches the screen only once
the host binds a surface; a host presenting AVPlayerViewController gets
audio, a clean log and no picture, because this path has no
AVPlayerItem for AVKit to show. The same holds for a layer bound to a
view that never got a layout. Both are now named once per session, ~2 s
after frames start flowing, with the frame count that went nowhere.

Second, the renderer refuses a frame whose PTS is not numeric.
AV_NOPTS_VALUE arrives as `CMTime.invalid`, CoreMedia builds a sample
buffer from it without complaint (measured: noErr, PTS reads back as NaN
seconds), and the render synchronizer cannot pace it; the deinterlace
path already drops its untimestamped output for that reason. The gate
sits before the reorder buffer, where a NaN also breaks ordering for its
neighbours (every comparison against NaN is false). Nothing on this
source needs it: the demuxer runs +genpts, so AVI's missing anchor-frame
timestamps are regenerated (NOPTS_pts=0 on the fixture). It closes the
mechanism the report hypothesised and counts what it drops, so a source
that does produce untimed frames says so.

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