Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(capture): gate the dmabuf offer on the forced encoder, and allow a render-node override
Benjamin Freeman2060d3738595
diff --git a/electron/native/pipewire-capture/src/capture.rs b/electron/native/pipewire-capture/src/capture.rsindex f6fe75dc3..22b1b8b53 100644--- a/electron/native/pipewire-capture/src/capture.rs+++ b/electron/native/pipewire-capture/src/capture.rs@@ -244,10 +244,10 @@ impl Capture {) -> Result<(Self, Selection), String> {let bitrate = bitrate.unwrap_or_else(|| default_bitrate(width, height, fps));let mut rejected = Vec::new();- // The dmabuf import can only feed VAAPI, so a user forcing `software` or- // `vulkan` must skip it — otherwise the documented `forced` workaround- // (VideoEncoder::open) would be silently ignored on the dmabuf path.- let use_dmabuf = matches!(forced, None | Some(Backend::Vaapi));+ // Shared with the negotiation offer (`prefer_dmabuf` in main) so the two+ // never disagree: offering dmabuf that this then refuses to import is what+ // makes a forced-software recording fail on its first frame.+ let use_dmabuf = crate::encoder::forced_allows_dmabuf(forced);let (encoder, importer) = match dmabuf.filter(|_| use_dmabuf) {Some(desc) => {// The importer maps the full stream (`desc`) and its VPP crops todiff --git a/electron/native/pipewire-capture/src/dmabuf_import.rs b/electron/native/pipewire-capture/src/dmabuf_import.rsindex 71b8d9a6f..26815cdd9 100644--- a/electron/native/pipewire-capture/src/dmabuf_import.rs+++ b/electron/native/pipewire-capture/src/dmabuf_import.rs@@ -134,7 +134,15 @@ impl DmabufImporter {// ENOSYS on radeonsi — VAAPI knows how to open on a DRM fd, but not the// other way round. The DRM device backs the DRM_PRIME source frames;// the derived VAAPI device backs the mapped surface and the encoder.- let node = c"/dev/dri/renderD128";+ // /dev/dri/renderD128 is the default, but on hybrid graphics the+ // compositor may render on a different node — mapping a dmabuf from the+ // wrong GPU then fails on every frame, with `available()` still passing.+ // Honour an override so such a machine can point at the right node+ // without a rebuild; the single-GPU default is unchanged.+ let node_path = std::env::var("OPENSCREEN_LINUX_RENDER_NODE")+ .unwrap_or_else(|_| "/dev/dri/renderD128".to_owned());+ let node = std::ffi::CString::new(node_path)+ .map_err(|_| "OPENSCREEN_LINUX_RENDER_NODE has an interior NUL byte".to_owned())?;let created = ff::av_hwdevice_ctx_create(&mut me.drm_device,ff::AV_HWDEVICE_TYPE_DRM,diff --git a/electron/native/pipewire-capture/src/encoder.rs b/electron/native/pipewire-capture/src/encoder.rsindex 680b27dde..3b06ab4a8 100644--- a/electron/native/pipewire-capture/src/encoder.rs+++ b/electron/native/pipewire-capture/src/encoder.rs@@ -33,6 +33,18 @@ pub enum Backend {Software,}+/// Whether the dmabuf → VAAPI zero-copy import may be used for a `forced` encoder+/// choice. The import can only feed VAAPI, so `software`/`vulkan` must skip it —+/// otherwise the documented `OPENSCREEN_LINUX_ENCODER` override is silently+/// ignored on the dmabuf path.+///+/// The SINGLE source of truth for this: the negotiation offer (`prefer_dmabuf` in+/// main) and the importer build (`Capture::start`) both call it, so they cannot+/// drift into offering dmabuf that no importer will consume.+pub fn forced_allows_dmabuf(forced: Option<Backend>) -> bool {+ matches!(forced, None | Some(Backend::Vaapi))+}+impl Backend {/// The name the app reports and the tests match on. Kept in the same/// vocabulary as the Windows helper's `encoder-selection` event.diff --git a/electron/native/pipewire-capture/src/main.rs b/electron/native/pipewire-capture/src/main.rsindex 2d547ac7a..6d07bd0a4 100644--- a/electron/native/pipewire-capture/src/main.rs+++ b/electron/native/pipewire-capture/src/main.rs@@ -579,12 +579,15 @@ fn run<W: Write>(.output_path.as_ref().map(|_| Arc::new(FrameMailbox::default()));- // Offer dmabuf ahead of shm (issue #507) only for a video session AND only- // when the VAAPI import pipeline actually builds on this GPU. Probed once- // here — it constructs a VAAPI device and filtergraph — so a machine that- // cannot import (no VAAPI, or a driver that will not map) simply keeps the- // shm path with no per-recording cost.- let prefer_dmabuf = frames.is_some() && crate::dmabuf_import::available();+ // Offer dmabuf ahead of shm (issue #507) only for a video session, only when+ // the VAAPI import pipeline actually builds on this GPU, AND only when the+ // forced-encoder choice can consume it — `software`/`vulkan` cannot, and+ // offering dmabuf they can't import makes the first frame fail. The available()+ // probe constructs a VAAPI device and filtergraph once here, so a machine that+ // cannot import keeps the shm path with no per-recording cost.+ let prefer_dmabuf = frames.is_some()+ && crate::dmabuf_import::available()+ && encoder::forced_allows_dmabuf(config.forced_encoder);if frames.is_some() {let _ = emitter.emit(&Event::Debug {code: "dmabuf-import".to_owned(),