mac-capture: Auto-restart ScreenCaptureKit streams after sleep/wake#13252
Closed
AlanHuang99 wants to merge 4 commits intoobsproject:masterfrom
Closed
mac-capture: Auto-restart ScreenCaptureKit streams after sleep/wake#13252AlanHuang99 wants to merge 4 commits intoobsproject:masterfrom
AlanHuang99 wants to merge 4 commits intoobsproject:masterfrom
Conversation
ScreenCaptureKit streams silently freeze or error out (error -3821) when macOS sleeps and wakes. OBS had no mechanism to detect or recover from this, leaving users with a frozen capture until manual restart. Register for NSWorkspaceWillSleepNotification, DidWakeNotification, and ScreensDidWakeNotification on the ScreenCaptureDelegate. On sleep, suppress capture_failed to avoid showing the restart button for an expected transition. On wake, set a flag that the video_tick callback checks after a 2-second delay (allowing GPU/display subsystem to reinitialize), then tears down and rebuilds the SCStream with a refreshed content list. Applies to both video and audio ScreenCaptureKit captures. Fixes: obsproject#8928 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Temporary workflow to verify the mac-capture plugin compiles on macOS with the sleep/wake auto-restart changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add #include <util/platform.h> for os_gettime_ns() declaration. Declare sleep/wake notification handler methods in the ScreenCaptureDelegate @interface to fix undeclared selector warnings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update workflow to build the complete OBS Studio application and upload OBS.app as a downloadable artifact for testing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
We do not accept AI generated submissions. In the future, please take at least a moment to read a project's contribution guidelines instead of blowing away our PR template and submitting AI code we do not want. |
|
@Fenrirthviti even if its AI generated, this bug is around now for 2+ years and counting. Great that finally someone/thing went ahead and tried doing something about it 😑.... For anybody coming by, the only built-in solution to continue seeing your screen after your monitor turned off, is to use the depreciated Display Capture:
This one survives a turning displays on and off. |
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.
Summary
ScreenCaptureDelegateforNSWorkspaceWillSleepNotification,NSWorkspaceDidWakeNotification, andNSWorkspaceScreensDidWakeNotificationcapture_failedto avoid showing the restart button for an expected transitionvideo_tickafter a 2-second delay (allowing GPU/display subsystem to reinitialize), then tears down and rebuilds theSCStreamwith a refreshed content listMotivation
ScreenCaptureKit streams silently freeze or error out (error -3821) when macOS sleeps and wakes. OBS had no mechanism to detect or recover from this, leaving users with a frozen capture until manual restart via the "Restart Capture" button.
This addresses the root cause: OBS's ScreenCaptureKit integration had zero sleep/wake awareness. Two failure modes exist:
SCStreamstops delivering frames but never callsdidStopWithError:— OBS shows a frozen imagedidStopWithError:fires withSCStreamErrorNoCaptureSourceor error -3821 — OBS markscapture_failedbut never auto-recoversDesign decisions
video_tick(not notification handler) — avoids thread safety issues since tick runs on OBS's video threadWillSleep(marks expected shutdown),DidWake(system wake),ScreensDidWake(lid-open without full system sleep)Test plan
"Restarting screen capture after wake from sleep"messageFixes #8928
Related: #10858, #11435, #9056, #9540
🤖 Generated with Claude Code