Skip to content

fix: capture screens with ScreenCaptureKit on macOS - #354

Merged
devopvoid merged 1 commit into
mainfrom
fix/macos-screen-capture-sck
Oct 12, 2026
Merged

devopvoid merged 1 commit into
mainfrom
fix/macos-screen-capture-sck

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

Addresses #344: screen capture on macOS freezing on its first frame while the cursor keeps moving.

Screens are captured with ScreenCaptureKit on macOS 14 and newer

VideoDesktopSource always got ScreenCapturerMac on macOS, because WebRTC tries ScreenCaptureKit only when allow_sck_capturer is set, and it never was. ScreenCapturerMac takes its first frame from a display snapshot and afterwards only copies in what its CGDisplayStream reports as changed. When that stream stops calling back, it keeps delivering the first frame as SUCCESS, and DesktopAndCursorComposer draws a live cursor over it: the symptom in the issue.

VideoTrackDesktopSource::capture() now sets allow_sck_capturer on macOS. On releases before 14, CreateScreenCapturerSck returns null and WebRTC falls back to ScreenCapturerMac as before. The capturer is also given the source's frame rate, since ScreenCaptureKit otherwise captures at the display refresh rate.

What stays as it was:

  • Source lists (ScreenCapturer.getDesktopSources()): without its system picker, ScreenCaptureKit lists no screens, so DesktopCapturer keeps ScreenCapturerMac. Both name a screen by its CGDirectDisplayID, so the listed IDs select the same screen.
  • Window capture: this WebRTC branch has no ScreenCaptureKit window capturer outside the system picker, so WindowCapturerMac is still used.

One behavioural difference, from reading WebRTC rather than testing it: without screen recording permission, ScreenCaptureKit fails with ERROR_PERMANENT and the capture stops, where ScreenCapturerMac delivered the wallpaper and the app's own windows.

Reproduction

Not reproduced. On macOS 14.5 (Apple silicon, screen recording permission granted), the unfixed build followed a window switching between black and white in another process every 400 ms, in three 12 s runs, and window capture followed it too. The reporter's macOS version isn't known yet.

Testing

macOS 14.5 arm64: mvn -pl webrtc test passes (284 tests, 0 failures, 15 skipped), with the desktop capture tests run, not skipped.

With the fix, the WebRTC log shows ScreenCapturerSck capturing the display listed by ScreenCapturerMac. Frames follow the same switching window as before, the first one arriving 120 to 230 ms after start(), at the right size and colours, with a single cursor.

VideoDesktopSourceTests.screenFramesFollowScreen (macOS only) switches a window of its own between black and white while the screen is captured, and fails if the frames don't follow. It passes on this Mac with either capturer, so it guards against a frozen capture rather than reproducing #344.

A VideoDesktopSource capturing a screen on macOS always used
ScreenCapturerMac, since WebRTC tries ScreenCaptureKit only when
allow_sck_capturer is set. That capturer takes its first frame from a
display snapshot and afterwards only copies what its CGDisplayStream
reports as changed, so when the stream stops calling back, it keeps
sending the first frame, with a live cursor composited on top (#344).

Screens are now captured with ScreenCaptureKit on macOS 14 and newer,
and with ScreenCapturerMac as before on older releases. ScreenCaptureKit
is told the source's frame rate, as it otherwise captures at the display
refresh rate. Source lists stay with ScreenCapturerMac: without its
system picker ScreenCaptureKit lists no screens, and both name a screen
by its display ID. Window capture is unchanged.

A new test switches a window of its own between black and white while
the screen is captured, and checks the frames follow.
@devopvoid
devopvoid merged commit abc19d5 into main Oct 12, 2026
22 checks passed
@devopvoid
devopvoid deleted the fix/macos-screen-capture-sck branch October 12, 2026 21:11
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