Skip to content

fix(macos): retry ScreenCaptureKit after a stream start failure - #6159

Open
dave-atx wants to merge 1 commit into
SunshineStream:masterfrom
dave-atx:fix/macos-sckit-retry-after-start-failure
Open

dave-atx wants to merge 1 commit into
SunshineStream:masterfrom
dave-atx:fix/macos-sckit-retry-after-start-failure

Conversation

@dave-atx

Copy link
Copy Markdown

Description

When an SCStream fails to start, backend_policy_t flips to AVFoundation for the rest of the process (sc_capture_loop.cpp#L14-L24). The failures I've hit were transient: starting a stream while the Mac was on the lock screen failed once. AVFoundation couldn't capture that display either, so every later session stayed black until Sunshine was restarted, long after the Mac was unlocked.

This makes the failure expire after 30 s (backend_policy_t::failure_backoff). Within that window the display is still rebuilt on AVFoundation exactly as today, so a persistent failure (no Screen Recording permission, etc) still falls back. Afterwards the next display creation tries ScreenCaptureKit again. The clock can be passed in so the expiry is testable.

Screenshot

N/A

Issues Fixed or Closed

Roadmap Issues

Testing

  • New SCCaptureLoop.BackendPolicyStreamStartFailureExpiresAfterBackoff: a failure is reported until failure_backoff has passed, then not; a later failure restarts it. The existing policy and capture loop tests pass unchanged.
  • Built test_sunshine on macOS 27.2.1 / M3 Pro with -DBUILD_WERROR=ON: 812 passed, 9 skipped. I excluded *AudioTest*, which waits on a microphone permission prompt for the test binary here and hangs (unrelated).
  • Manual: the same change has run in a downstream build (srikanthamsa/sunshine-macos-gamepads) across a day of streams without regressions. I haven't reproduced the lock-screen start failure on demand, so the recovery itself is covered by the unit test only.
  • Linking the tests needed -DCMAKE_EXE_LINKER_FLAGS=-L$(brew --prefix icu4c)/lib here (keg-only ICU, unrelated to this change).

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

A stream start failure switched capture to AVFoundation for the rest of the process. The failures seen in practice were transient (starting a stream on the lock screen), and AVFoundation couldn't capture that display either, so later sessions stayed black until Sunshine restarted. Let the failure expire after 30 s, so the next display creation tries ScreenCaptureKit again.
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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