Conn O'Griofa 95da4b5c85 feat(linux/xdgportal): implement reactive capture with duplicate detection (#4740)
* feat(linux/xdgportal): implement reactive capture with duplicate detection

Replaces polling-based frame capture with event-driven approach using
condition variables for immediate notification when new frames arrive.

Changes:
- on_process: Notify snapshot() via condition variable on new buffer
- fill_img: Extract and pass through PipeWire seq/pts metadata
- snapshot: Block on condition variable with timeout; detect and skip
  duplicate frames using seq/pts metadata to avoid redundant processing
- capture: Simplify catch-up logic to maintain timeline consistency
  by advancing in delay intervals without resetting origin

This eliminates tight polling loops and reduces unnecessary frame
processing when compositor reuses buffers.

* feat(linux/xdgportal): optimize software path and fix modesetting crashes

This patch addresses a performance bottleneck in the software encoding
path and a race condition during PipeWire stream re-initialization.

1. Performance Optimization (Double-Buffering):
   - Implemented a front/back buffer swapping strategy for the software
     (MemPtr) path.
   - Frame data is copied to a `back_buffer` without holding the
     `frame_mutex`, then swapped with the `front_buffer` under a
     short-lived lock.
   - This prevents memory bandwidth contention and allows the encoder
     and PipeWire threads to work in parallel without blocking.

2. Stability Fixes:
   - Implemented `frame_mutex` protection across `on_process`, `fill_img`,
     and `cleanup_stream` to prevent use-after-free and dangling pointers
     during resolution changes.
   - Enhanced `fill_img` to safely bail out if the stream is dead or
     no new frame is ready.
   - Added explicit state resets (`frame_ready = false`, `current_buffer = nullptr`)
     to ensure the encoder thread ignores stale data during re-init.

Fixes intermittent segfaults during resolution changes and restores
performance on systems using software encoding.

* feat(linux/xdgportal): support x-nv-video[0].clientRefreshRateX100 for requesting fractional NTSC framerates

* fix(linux/xdgportal): improve dbus & pipewire teardown logic

* Close dbus proxy connection; fixes orphaned XDG notification icons after
  mode changes or stream pauses via XDG icon interaction.
* Migrate shared pipewire destructor logic into cleanup_stream() to reduce
  duplication.

---------

Co-authored-by: Andy Grundman <andy@hybridized.org>
2026-02-22 12:43:49 -05:00
2025-06-12 20:42:08 -04:00
2024-05-23 21:42:06 -04:00
2020-02-09 22:54:06 +01:00
2025-11-11 23:46:11 -05:00
2022-04-30 10:24:59 +01:00
2022-03-15 22:30:01 -04:00
2023-03-15 16:30:18 -04:00

Sunshine icon

Sunshine

Self-hosted game stream host for Moonlight.

GitHub stars GitHub Releases Docker GHCR Flathub installs Flathub Version Winget Version Gurubase GitHub Workflow Status (CI) GitHub Workflow Status (localize) Read the Docs Codecov

About

Sunshine is a self-hosted game stream host for Moonlight. Offering low-latency, cloud gaming server capabilities with support for AMD, Intel, and Nvidia GPUs for hardware encoding. Software encoding is also available. You can connect to Sunshine from any Moonlight client on a variety of devices. A web UI is provided to allow configuration, and client pairing, from your favorite web browser. Pair from the local server or any mobile device.

LizardByte has the full documentation hosted on Read the Docs

🎮 Feature Compatibility

Platform Feature Support
Feature FreeBSD Linux macOS Windows
Gamepad Emulation
What type of gamepads can be emulated on the host.
Clients may support other gamepads.
DualShock / DS4 (PlayStation 4)
DualSense / DS5 (PlayStation 5)
Nintendo Switch Pro
Xbox 360
Xbox One/Series
GPU Encoding
AMD/AMF (vaapi) (vaapi) (Video Toolbox)
Intel QuickSync (vaapi) (vaapi) (Video Toolbox)
NVIDIA NVENC (vaapi) (vaapi) (Video Toolbox)
Screen Capture
DXGI
KMS
NVIDIA NvFBC 🟡
  ↳ X11 Support
  ↳ Wayland Support
Video Toolbox
Wayland
Windows.Graphics.Capture 🟡
  ↳ Portable
  ↳ Service
X11

Legend: Supported | 🟡 Partial Support | Not Yet Supported | Not Applicable

🖥️ System Requirements

Warning

These tables are a work in progress. Do not purchase hardware based on this information.

Minimum Requirements
Component Requirement
GPU AMD: VCE 1.0 or higher, see: obs-amd hardware support
Intel:
  FreeBSD/Linux: VAAPI-compatible, see: VAAPI hardware support
  Windows: Skylake or newer with QuickSync encoding support
Nvidia: NVENC enabled cards, see: nvenc support matrix
CPU AMD: Ryzen 3 or higher
Intel: Core i3 or higher
RAM 4GB or more
OS FreeBSD: 14.3+
Linux/Debian: 13+ (trixie)
Linux/Fedora: 41+
Linux/Ubuntu: 22.04+ (jammy)
macOS: 14+
Windows: 11+ (Windows Server does not support virtual gamepads)
Network Host: 5GHz, 802.11ac
Client: 5GHz, 802.11ac
4k Suggestions
Component Requirement
GPU AMD: Video Coding Engine 3.1 or higher
Intel:
  FreeBSD/Linux: HD Graphics 510 or higher
  Windows: Skylake or newer with QuickSync encoding support
Nvidia:
  FreeBSD/Linux: GeForce RTX 2000 series or higher
  Windows: Geforce GTX 1080 or higher
CPU AMD: Ryzen 5 or higher
Intel: Core i5 or higher
Network Host: CAT5e ethernet or better
Client: CAT5e ethernet or better
HDR Suggestions
Component Requirement
GPU AMD: Video Coding Engine 3.4 or higher
Intel: HD Graphics 730 or higher
Nvidia: Pascal-based GPU (GTX 10-series) or higher
CPU AMD: Ryzen 5 or higher
Intel: Core i5 or higher
Network Host: CAT5e ethernet or better
Client: CAT5e ethernet or better

Support

Our support methods are listed in our LizardByte Docs.

💲 Sponsors and Supporters

Sponsors

👥 Contributors

Thank you to all the contributors who have helped make Sunshine better!

GitHub

GitHub contributors

CrowdIn

CrowdIn contributors

Previous Next
Getting Started
[TOC]
Description
No description provided
Readme GPL-3.0 42 MiB
Languages
C++ 76.4%
CMake 6%
HTML 4.3%
Vue 2.9%
Objective-C++ 2.8%
Other 7.4%