mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-11-24 22:58:07 +00:00
* fix(linux): capture Wayland portals that offer only DMA-BUF (niri) niri's screencast stream offers BGRx only as DMA-BUF (linear and tiled modifiers), with no system-memory format. The appsink accepts only system-memory BGRx/RGBx, so the PipeWire link fails with "no more input formats" and the capturer fails with "Element failed to change its state". When the system-memory pipeline cannot start, retry with a pipeline that accepts linear DMA-BUF (XR24/XB24). Linear buffers are CPU readable, so the frame is read by mmap of the dmabuf fd using the VideoMeta stride and offset, inside DMA_BUF_IOCTL_SYNC. A normal map cannot be used: for DMA-BUF the PipeWire chunk size is a placeholder (1 byte on niri), and always-copy copies only that chunk, so it is not set on this pipeline. Desktops where the current pipeline works do not change. Refs #15911 * scrap/wayland: address review of the DMA-BUF fallback - Leave the existing system-memory setup in PipeWireRecorder::new as it was. Only a fallback hook replaces its set_state(Playing)?, and the DMA-BUF pipeline is built by a separate build_dmabuf_pipeline(). - Check every result in read_linear_dmabuf: DMA_BUF_IOCTL_SYNC start and end (restarted on EINTR/EAGAIN, as the kernel requires), lseek, mmap. Log munmap and pipeline-stop failures. - Map the whole dmabuf (size from lseek) and bounds-check the frame against it in pack_rows, so a bad or negative stride is an error. - Unit tests for row packing, the bounds check, and the XR24/XB24 format mapping. * scrap/wayland: throttle the per-frame DMA-BUF unmap warning read_linear_dmabuf runs once per frame, so a persistent munmap failure would log a line per frame. Use hbb_common::throttled_log! (one line per minute with a repeat count). * scrap/wayland: use checked arithmetic for the DMA-BUF frame end The stride and offset come from the compositor. On 32-bit targets, start + stride * (h - 1) + row_len can wrap to a small value that passes the bounds check, and the row copy then panics. Compute the end with checked_mul/checked_add and return an error on overflow. The existing test gets one case for it. * scrap/wayland: keep the system-memory capture path unchanged capture() is back to master's body. A DMA-BUF sample now branches off at the top into capture_dmabuf(), which has its own drm-format mapping, read, duplicate check and crop, so GNOME and KDE run the same code as before. A DMA-BUF frame that does not fit its buffer is now dropped with a trace log, like the system-memory size mismatch (pipewire#985), instead of ending the capture. mmap and sync failures are still errors. * scrap/wayland: drop a DMA-BUF frame whose crop does not fit The crop rectangle comes from the compositor's VideoCropMeta. One left from an old allocation could slice past the packed frame and panic, so capture_dmabuf now drops such a frame with a trace log before reading it. * scrap/wayland: keep only the tests that pin the reported behavior Drop the crop_fits test and the usize overflow assertion, which covered corner cases raised in review. The crop_fits check itself stays.