dailz fed8c2dcfd
CI / Build + Clippy + Test (pull_request) Failing after 30s
CI / Security audit (RUSTSEC) (pull_request) Failing after 30s
docs(avhw): fix misleading Send soundness reasoning
Oracle audit of all 5 `unsafe impl Send` in src/avhw/ found soundness
intact but reasoning wrong in 3 of 5:

- AvHwDevCtx: claimed '&mut self ensures exclusive access' — false,
  ref_clone() hands raw pointers to other threads / FFmpeg-internal
  codec workers. Real basis is AVBufferRef atomic_uint refcount +
  libva VADisplay thread safety.
- AvHwFrameCtx: claimed 'send/receive pattern is thread-safe' —
  misdirection. Real basis is AVBufferPool atomic get/put.
- EncState: claimed 'raw pointers not shared across threads' — false
  when FFmpeg frame/slice threading is enabled. Real basis is the
  hw device/frames contexts being designed for such sharing.

SwEncState and SwEncEncode comments were acceptable; improved for
clarity (note that contained FFmpeg handles are non-thread-safe but
Send-sound under exclusive access, and that crossbeam/Arc fields are
already Send by design).

Added module-level convention doc to src/avhw/mod.rs centralizing
the C-API-level justification rule and explicitly calling out the
'&mut self as Send basis' anti-pattern so future contributors don't
repeat the category error.

Fixed AGENTS.md:
- Stale claim that Cargo.toml 'only warns' on undocumented_unsafe_blocks
  (it's been 'deny' for a while)
- Stale path src/avhw.rs → src/avhw/ (split in d53e881)
- Stale 'avoid moving wrappers across threads' guidance — Send is sound,
  the audit just confirmed why

No code behavior change. Verified: cargo build --release,
cargo clippy --release --all-targets (0 warnings),
cargo test --release (79 unit + 3 integration, 1 ignored).
2026-07-09 15:20:16 +08:00

wl-webrtc

Wayland screen capture and encoding tool.

Prerequisites

  • Rust toolchain (1.87+; MSRV pinned to match u32::is_multiple_of / Option::is_none_or usage): rustup default stable
  • FFmpeg 6.0+ dev libraries with VAAPI support:
    • Arch: pacman -S ffmpeg
    • Ubuntu/Debian: apt install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libva-dev
    • Fedora: dnf install ffmpeg-devel libva-devel
  • Wayland dev libraries:
    • Arch: pacman -S wayland-protocols
    • Ubuntu/Debian: apt install libwayland-dev wayland-protocols
    • Fedora: dnf install wayland-devel wayland-protocols-devel
  • DRM dev libraries:
    • Arch: pacman -S libdrm
    • Ubuntu/Debian: apt install libdrm-dev
    • Fedora: dnf install libdrm-devel

Build

cargo build --release

Run

# Basic capture to file
wl-webrtc --output output.mp4

# With custom FPS and bitrate
wl-webrtc --output output.mp4 --fps 60 --bitrate 8000000

# Specify DRM device for hardware encoding
wl-webrtc --output output.mp4 --drm-device /dev/dri/renderD128

# Verbose mode
wl-webrtc --output output.mp4 -v

# WebRTC streaming mode (HTTP signaling server)
wl-webrtc --port 8080 -v

# Force a fresh portal authorization dialog (ignore saved restore token)
wl-webrtc --output output.mp4 --no-persist

# Pin the capture backend instead of auto-detecting
wl-webrtc --output output.mp4 --backend portal    # or: --backend screencopy

CLI Arguments

src/args.rs is the authoritative source. Run wl-webrtc --help for the live list.

Argument Default Description
-o, --output (optional) Output file path (e.g. output.mp4). Optional when using --port for WebRTC mode.
--output-name auto Wayland output name to capture
--fps 30 Target frames per second
--codec h264 Video codec (h264 only for MVP)
--hw-accel vaapi Hardware acceleration method
--drm-device auto DRM render device path
--bitrate auto Target bitrate in bps
--max-bitrate 8000000 Max bitrate cap for WebRTC mode (caps BWE escalation; no effect in MP4 mode)
--gop-size auto Group of Pictures size
-v, --verbose false Enable verbose logging
--backend auto Capture backend: screencopy (wlroots) or portal (KWin/KDE). Auto-detected if omitted.
--port 0 WebRTC HTTP signaling server port. 0 keeps MP4 file output mode.
--no-persist false Force re-authorization (ignore saved portal restore token)
--stats false Print per-second pipeline statistics for stutter diagnosis

Capture backends

The tool supports two Wayland capture backends, auto-detected by default:

  • wlr-screencopy (preferred when zwlr_screencopy_manager_v1 is advertised): works on wlroots-based compositors (Sway, Hyprland, etc.).
  • XDG Portal / PipeWire (fallback when D-Bus ScreenCast is available): works on KWin/KDE and any compositor that implements the XDG Desktop Portal screen-cast protocol. The first run shows an authorization dialog; a restore token is cached under wl-webrtc/portal-restore-token so subsequent runs don't re-prompt (use --no-persist to force a fresh authorization).
S
Description
No description provided
Readme
2.2 MiB
Languages
Rust 98.7%
Shell 1.2%