Screen share 4: Linux screen capture backend (#151) #201
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "screenshare-4-capture-linux"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on: screenshare-3-capture-crate
What
fluxer_capture::DesktopScreenCapturer(newsrc/desktop.rs, Linux): screen and window capture through libwebrtc'sDesktopCapturer(spec §7.1).DisplaySession::detect): Wayland whenXDG_SESSION_TYPE=waylandandWAYLAND_DISPLAYare set, else X11 whenDISPLAYis set, elseCaptureError::Unsupported. CI containers get the error, not a panic.in_app_picker == false, empty source list,SourceChoice::SystemPicker→Genericcapturer → ScreenCast portal picker.startreturns at once;Startedcomes with the first frame after the person picks. Picker closed →Ended(Cancelled), session stopped later →Ended(SessionEnded). The GLib loop comes from libwebrtc'sglib-main-loopfeature.screen:<n>) and windows (window:<xid>) with 480×270 thumbnails. A closed window →Ended(SourceClosed).capture_frame()at the target rate (Pacer), converts BGRA → I420 with libyuv (yuv_helper::argb_to_i420), scales to fit (I420Buffer::scale, even size, no upscaling),Stalled/Resumed(StallDetector, armed only after the first frame so an open picker is not a stall), handlesswitch/update/stopthrough a command channel.Startedis sent again when the frame size changes (README contract updated).default_backends()returns it on Linux, orUnsupported(reason)without a session.libwebrtc = "0.4.0"(the version livekit pins), Linux-only influxer-capture, with featureglib-main-loop.Tests
pacing_holds_target_fps,bgra_frames_become_i420_at_target_size(libyuv matchesfluxer_video::convertwithin ±1), plus odd-size/malformed buffers, fit, update rate, failure →Endedonce, Cancelled vs SessionEnded, no stall while the picker is open,Startedagain on resize, session detection, id round trip.tests/linux_real.rs::new_without_session_is_an_error_not_a_panic(also run here underenv -u DISPLAY -u WAYLAND_DISPLAY).FLUXER_CAPTURE_TESTS=1), on KDE Plasma 6 Wayland (kwin_wayland + XWayland), Ryzen 9 9950X, two 4K outputs:x11_lists_screens_and_windows_with_thumbnails: passed, run through XWayland (env -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11). 2 screens + 3 windows with thumbnails in 55-75 ms; 91 frames in 3.0 s at 30 fps; 4K→1080p30 costs 15-18 % of one core; window frames have real content; the switch keeps the session.wayland_portal_capture_delivers_non_black_frames: not completed. The portal is reached (D-Bus monitor: CreateSession → SelectSources → Start, KDE dialog shown), but nobody was there to click, so it timed out at the picker after 120 s. Same forportal_close_reports_ended, which also needs a person. Follow-up #200 is to run both by hand.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally.Findings are in spikes §2 (
docs/superpowers/research/2026-11-11-screenshare-spikes.md, new file with only §2 on this branch; it will conflict with the §1/§4 branches only by section).Deviations / notes for the reviewer
tests/fake.rs::unsupported_backends_return_errorsnow tests theUnsupportedstub directly: on a Linux desktopdefault_backends()now returns the real capturer, andstart(SystemPicker)would open the portal.deny.toml: license exception fortarget-lexicon(Apache-2.0 WITH LLVM-exception, build-time only, viasystem-depsforglib-sys/gio-sys).glib-main-loopmakes binaries that linkfluxer-captureneedlibgio-2.0,libgobject-2.0andlibglib-2.0(readelf -d).desktopiscfg(target_os = "linux")for now. Screen share 5 widens it to Windows; the loop, conversion and grabber are OS-independent.app_name/pidareNoneon X11 because libwebrtc does not provide them.window_audioisfalse.Closes #151
🤖 Generated with Claude Code
Independent review: Screen share 4 (Linux screen capture), diff d821f19..5f276b8
Verdict: APPROVE. No blocking findings. Local
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciis green in a clean review worktree (all steps pass; 12desktop::testsunit tests pass, andlinux_realruns its CI test with the real-device tests ignored).What I checked
pacing_holds_target_fps(50 fps, 40 to 52 frames/s, no bursts) andbgra_frames_become_i420_at_target_size(padded 1080p BGRA becomes I420 at 1280x720, colours within ±1 of fluxer-video's BT.601) are there. So are the CI testnew_without_session_is_an_error_not_a_panicand the real testswayland_portal_capture_delivers_non_black_frames,x11_lists_screens_and_windows_with_thumbnails(thumbnails at most 480x270 viaTHUMBNAIL_*) andportal_close_reports_ended, which are#[ignore]and gated onFLUXER_CAPTURE_TESTS=1. Extra tests: stall suppressed while the picker is open,Endedreported once, cancel before the first frame vs. session ended after it, size change, session detection.DesktopScreenCapturer: ScreenCapturer. On Wayland:in_app_picker == false, an empty list, andSystemPickermaps toGeneric. On X11: screen and window lists with thumbnails. One thread per session pulls attarget.fps(Pacer), converts BGRA to I420 with libyuv and fits it to the target.Stalledcomes after 3 s (StallDetector). The portal session ending isEnded.default_backends()returns the capturer on Linux and falls back toUnsupportedwithout a session.src/desktop.rs. The public API (new,with_env,session,DisplaySession) has no libwebrtc or LiveKit types. fluxer-capture does not depend on fluxer-core or livekit.Cargo.lockhas a singlelibwebrtc0.4.0, shared with livekit. The FFI callback cannot panic: it handles a poisoned mutex, checks sizes withtry_from, and rejects short buffers or a bad stride without panicking (tested). No secrets.deny.tomlexception fortarget-lexicon(Apache-2.0 WITH LLVM-exception, used only at build time through system-deps) is justified.Findings (all minor, none blocking)
Cancelled/SessionEndedmapping is inferred fromBaseCapturerPipeWire(a permanent error) and tested only with a scripted grabber. Follow-up #200 tracks it. It should be run before Screen share 21 relies on it, because if it fails, the spec'sashpd+pipewirefallback is needed.startreturnsOk, thenEnded(Cancelled)). The README contract line "a closed system picker isCancelled" (in the start-error bullet) and the Wayland paragraph now describe two different behaviours. Screen share 10/21 must treatEnded(Cancelled)beforeStartedas "picker cancelled", not as "stream ended". Suggest rewording that contract bullet so it says both forms are allowed.switch(SystemPicker)on Wayland reuses the old session's state.sizeis stillSome, so cancelling the re-opened picker reportsEnded(SessionEnded)instead ofCancelled. The armedStallDetectorwill reportStalledif the person takes more than 3 s in the new picker. Resettingsize/stallon a successfulSwitchwould fix both.pacing_holds_target_fps40 to 52 frames/s,update_changes_the_rate_on_the_fly25 to 40) could flake on a heavily loaded runner. Watch for it, no change needed now.glib-main-loopaddslibgio-2.0,libgobject-2.0andlibglib-2.0asNEEDEDlibraries for every binary that links fluxer-capture. The README and spikes §2.4 record this correctly. Cargo feature unification also turns the feature on for fluxer-voice's libwebrtc. That is harmless, since the GLib loop starts only fromDesktopCapturer::startunder Wayland.🤖 Generated with Claude Code