Repository navigation
Description
What happened?
Summary
On iOS, when an HEVC source plays on the software path (SoftwarePlaybackHost + HardwareVideoDecoder) and the screen is locked and woken, the system invalidates the VTDecompressionSession. VTDecompressionSessionDecodeFrame then returns kVTInvalidSessionErr (-12903) for every remaining packet. HardwareVideoDecoder only logs the error and keeps feeding the dead session, so video never comes back.
For a source with no audio track it is worse. The background audio-only mode drops every video packet with nothing pacing the demux loop, so the demuxer reads to EOF within moments. The host then parks the clock as end of media. After wake the session looks finished and the screen stays black.
Environment
- AetherEngine:
7.34.0 - Device / iOS:
backgroundPlaybackEnabled = true(default), PiP not active
Steps to reproduce
Case A: HEVC source with audio
- Play a 4K HEVC MKV that routes to the software path (
dispatch: codec=173 → software,selected HardwareVideoDecoder (VT HEVC)). The test file was 3840x1610 with DTS, E-AC-3 and AAC tracks. - Lock the screen during playback, then wake it.
Case B: HEVC source without audio (video-only MP4)
- Play a 30 s 4K HEVC MP4 with no audio stream (
audio delivery = noAudioInSource). - Lock the screen a few seconds in, then wake it.
Expected
Video resumes at (or near) the playhead after wake. Audio, if any, stays in place.
Actual
Case A: every video decode after the lock fails:
[SWDiag] clk=1.60 dclk=1.00 rate=1.00 aLead=4.02 ... status=rendering
<<<< DecompressionSessionRemote >>>> signalled err=-12903 at <>:2002
[HardwareVideoDecoder] decode error -12903 at pts=2017
[HardwareVideoDecoder] decode error -12903 at pts=2050
...
Case B: the decode errors run to the end of the file, then end of media is declared where the picture froze. In the first run, the clip was 30 s long and the clock parked at 4.97 s. The screen is black after wake (isReadyForDisplay=false):
[HardwareVideoDecoder] decode error -12903 at pts=6096000
... (one line per packet until EOF) ...
[AudioOutput] pause at t=4.967
[SWHost] end of media: clock parked at 4.967s
[SWHost] layer.isReadyForDisplay=false after 255 frames
Even with the session rebuilt (local experiment, see below), Case B still ends early, because the packets were already dropped in the background:
[HardwareVideoDecoder] recovered at keyframe pts=18000000 after dropping 132 packet(s)
[SWHost] end of media: clock parked at 12.244s
Root cause
There are three independent problems.
-
HardwareVideoDecoderignores session invalidation. Indecode(packet:epoch:), a non-noErrstatus fromVTDecompressionSessionDecodeFrameis only logged.kVTInvalidSessionErris permanent for that session; every later call fails the same way. Nothing tells the host, and nothing rebuilds the session. -
The foreground return reuses the stale session.
SoftwarePlaybackHost.exitBackgroundAudioOnly()flushes the decoder and renderer and resumes feeding video into the sameVTDecompressionSession. In audio-only mode no video is decoded in the background, so nothing notices that the lock invalidated the session until the first packet after wake fails. -
Background audio-only on a source with no audio.
AetherEngine.backgroundAction(...)returns.enterSoftwareAudioOnlywhenever a software host is kept alive without PiP. In the demux loop's video branch,backgroundAudioOnly()frees every video packet and returns immediately. Only the audio branch paces onaOut.isReadyForMoreMediaData. With no audio stream, nothing paces the loop at all, so it hits EOF andparkClockAtEndOfMedia()runs while the app is in the background.
The lifecycle also left no trace in the log, because enterBackgroundAudioOnly() and exitBackgroundAudioOnly() emit nothing. That made these reports hard to tie to the lock and wake.
Proposed fix
1. Decoder reports, host recovers
HardwareVideoDecoder: onkVTInvalidSessionErr, mark the session lost, log once, and fire a newonSessionLostcallback. Drop every later packet instead of calling VT.- Add
HardwareVideoDecoder.rebuildSession() -> Bool. It invalidates the old session and creates a new one from the stored format description and pixel buffer attributes, reusing the existing refCon box so all callbacks and settings carry over. It bumps the feed epoch and drops packets until the next keyframe. Factor session creation into one helper shared withopen()so the two cannot drift apart. SoftwarePlaybackHost, ononSessionLost(hopped to the main actor):- In the foreground:
rebuildSession(), thenseek(to: currentTime). The demuxer repositions to the keyframe before the playhead and the existing skip threshold hides the pre-roll. The picture returns on the right frame, with no freeze until the next keyframe, and audio keeps its place. Live sources without a rewind ring only rebuild and pick up at the next keyframe. - In the background, or when VT refuses the rebuild: record the recovery as owed and do it on the foreground return.
- In the foreground:
2. Rebuild the session on every foreground return
In exitBackgroundAudioOnly(), rebuild the hardware session unconditionally before clearing backgroundAudioOnly. It costs a few milliseconds and covers the invalidation that nothing observed while video was dropped.
3. Do not enter audio-only when there is no audio
Pass the software host's audio state into backgroundAction, for example softwareHostHasAudio: softwareHost?.audioDelivery == .decoded. When it is false and PiP is not active, return .teardownVideo instead of .enterSoftwareAudioOnly. The session is then torn down like a paused one (state = .paused) and the host's existing foreground reload (reloadAtCurrentPosition()) restores it at the frame it left. An alternative is to make the video branch pace on the clock while backgroundAudioOnly() is set and the source has no audio.
4. Log the lifecycle
Log entering and leaving audio-only, and log session loss, rebuild and reposition, so field logs show what triggered a recovery.
Alternative considered
Rebuilding inside HardwareVideoDecoder on the first -12903 and resuming at the next keyframe works and is self-contained. But it leaves the picture frozen for up to one GOP, it cannot recover packets the host already dropped (Case B above), and the decoder cannot tell whether the app is in the foreground. Recovery at the host level avoids all three problems.
Steps to reproduce
none
AetherEngine version or commit SHA
7.34.0
Host app
Custom / my own integration
Platform
iOS
OS version
macOS26.6.2
Device / chip
Mac mini m4
Playback path
Not sure / not a playback bug
Source media (for playback bugs)
No response
Error codes / log lines
Anything else
No response
Activity
superuser404notfound commentedon Oct 12, 2026
Thanks for the thorough write-up. The root-cause analysis was right on all three counts, and the fix in #750 follows the proposal closely:
HardwareVideoDecodermarks the session lost onkVTInvalidSessionErr, stops feeding VT, and firesonSessionLostonce.rebuildSession()goes through one session factory shared withopen().currentTime. In the background, or if VT refuses, the recovery is owed to the foreground return.exitBackgroundAudioOnly()now rebuilds unconditionally.backgroundActiontakessoftwareHostHasAudio, so a SW host without decoded audio is released like a paused session instead of entering audio-only (your Case B).To reproduce it without a device, I added
aetherctl bgaudio --lose-session. It invalidates the session in place, which yields the same -12903, and video stayed at +0 frames before the fix. I haven't run an actual iOS screen lock yet. If you can try the branch (fix/739-vt-session-loss) on your Case A and Case B files before it is released, that would be the real confirmation.ijuniorfu commentedon Oct 12, 2026
Tested; the issue has been resolved.
superuser404notfound commentedon Oct 12, 2026
Merged into
main(3149b39), so the fix branch is gone. Please test againstmaininstead. It will be in the next release.fix(sw): recover the VideoToolbox session a screen lock invalidates (s…
chore(release): prep 7.36.0 - DTS:X keeps its heights, a repeated liv…