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
test(capture-linux): cover the encoder-preferred content_rect branch
Benjamin Freeman8de31a445a45
diff --git a/electron/native-bridge/cursor/recording/pipeWireCursorAccumulator.ts b/electron/native-bridge/cursor/recording/pipeWireCursorAccumulator.tsindex ff8f33254..4fe7d1d8f 100644--- a/electron/native-bridge/cursor/recording/pipeWireCursorAccumulator.ts+++ b/electron/native-bridge/cursor/recording/pipeWireCursorAccumulator.ts@@ -155,7 +155,7 @@ export class PipeWireCursorAccumulator {addSample(payload: Extract<PipeWireHelperEvent, { event: "cursor-sample" }>) {this.rememberAsset(payload.asset);- // Normalised against the RECORDED RECTANGLE, which the helper repeats on+ // ponytail: normalised against the RECORDED RECTANGLE, which the helper repeats on// every sample: the crop for a window stream, the whole stream for a// screen. It reports its own because only it knows — for a window,// mutter pins the stream to the monitor and carves the window outdiff --git a/electron/native/pipewire-capture/src/main.rs b/electron/native/pipewire-capture/src/main.rsindex abdd235a7..cfaac2492 100644--- a/electron/native/pipewire-capture/src/main.rs+++ b/electron/native/pipewire-capture/src/main.rs@@ -1554,11 +1554,50 @@ mod cursor_sample_tests {/// stream; once pixels are flowing the encoder's rectangle wins.#[test]fn the_content_rect_prefers_the_encoder_once_it_has_started() {+ // No encoder yet (cursor-only, or before the first frame): the whole+ // negotiated stream, or nothing when the format is still unknown.assert_eq!(content_rect(&None, Some((1920, 1080))),Some(shim::CropRect { x: 0, y: 0, width: 1920, height: 1080 }));assert_eq!(content_rect(&None, None), None);++ // Once a window frame has been staged, the encoder's content rect — the+ // window carved out of the monitor-sized stream — wins over the stream+ // size. This is the branch the fix turns on, so it is the one that has+ // to be pinned.+ let output = std::env::temp_dir().join("openscreen-content-rect-encoder.mp4");+ let (mut capture, _) = Capture::start(+ &output,+ 320,+ 240,+ 30,+ Some(1_000_000),+ Some(encoder::Backend::Software),+ Vec::new(),+ None,+ )+ .expect("start");+ let stride = 1920usize * 4;+ capture+ .stage(&shim::Frame {+ pixels: vec![0x30; stride * 1080],+ stride,+ width: 1920,+ height: 1080,+ video_format: shim::constants().video_format_bgrx,+ pts_ns: -1,+ crop: shim::CropRect { x: 100, y: 50, width: 320, height: 240 },+ has_crop: true,+ dmabuf: None,+ })+ .expect("stage");+ assert_eq!(+ content_rect(&Some(capture), Some((1920, 1080))),+ Some(shim::CropRect { x: 100, y: 50, width: 320, height: 240 }),+ "a started encoder reports the window it read, not the monitor stream"+ );+ let _ = std::fs::remove_file(&output);}}