Repository navigation
fix(sw): recover the VideoToolbox session a screen lock invalidates (#739) - #750
Merged
Merged
Conversation
…739) On iOS a screen lock invalidates the SW host's VTDecompressionSession. HardwareVideoDecoder only logged the resulting kVTInvalidSessionErr (-12903) and kept feeding the dead session, so video never came back; a source without audio was worse, since background audio-only mode has nothing to pace the demux loop on and it raced to EOF in the background. - HardwareVideoDecoder marks the session lost on kVTInvalidSessionErr, drops packets instead of calling VT, and fires onSessionLost once. rebuildSession() recreates it from the stored format description and attributes through the same factory open() uses, bumps the feed epoch and resumes at the next keyframe. - The host rebuilds and repositions to the playhead on a loss seen in the foreground (picture returns on the audio's frame), owes it to the foreground return in the background or when VT refuses, and rebuilds unconditionally on every foreground return out of audio-only mode. - backgroundAction takes softwareHostHasAudio: a SW host that renders no audio is released like a paused session instead of entering audio-only. - The audio-only lifecycle and the loss/rebuild/reposition are logged. - aetherctl bgaudio --lose-session invalidates the session mid-foreground and on entering background; +0 video frames after both before the fix, frames resume after both with it. Reported and analysed by @ijuniorfu. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
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.
Addresses #739. Implements the fix the report proposes, all three parts.
What was wrong
HardwareVideoDecoderloggedkVTInvalidSessionErr(-12903) per packet and kept feeding the dead session.exitBackgroundAudioOnly()flushed but reused the same session, which a screen lock had invalidated while nothing decoded video.backgroundActionsent a SW host without audio into audio-only mode. Only the audio branch paces the demux loop there, so the loop dropped the rest of the file and parked the clock at end of media in the background.Changes
kVTInvalidSessionErrit marks the session lost (under the same hold oflockthat fed it), logs once, drops further packets and firesonSessionLost.rebuildSession()recreates the session from the stored format description and attributes through onemakeSessionfactory shared withopen(), keeps the refCon box, bumps the feed epoch and gates on the next keyframe.seek(to: currentTime)), so the picture returns on the audio's frame. Live without a rewind ring only rebuilds. In the background, or when VT refuses, the recovery is owed and paid on the next foreground return. Every return out of audio-only mode rebuilds the session unconditionally.backgroundAction(... softwareHostHasAudio: ...). A SW host whoseaudioDeliveryis not.decodedand has no PiP window gets.teardownVideo, as a paused session would.Verification
aetherctl bgaudio --lose-session(new) invalidates the VT session in place mid-foreground and on entering background. That produces exactly the field error (-12903). On a 1080p HEVC+AAC clip it went from +0 / +0 video frames after the loss and after the foreground return (recovery disabled) to +72 / +166 with the fix:BackgroundKeepaliveTests: a SW host without audio tears down whether playing or paused, and keeps the PiP case unchanged.swift test: both runners green (4325 swift-testing tests, XCTest suite passed). Builds for generic iOS and tvOS.Not covered here: an on-device screen lock on iOS. The harness reproduces the invalidation, not the lock itself.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS