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
refactor(capture): give a paused frame its own StageOutcome::Frozen
Benjamin Freemanecc4b2e58fec
diff --git a/electron/native/pipewire-capture/src/capture.rs b/electron/native/pipewire-capture/src/capture.rsindex 821d6b239..80d63758e 100644--- a/electron/native/pipewire-capture/src/capture.rs+++ b/electron/native/pipewire-capture/src/capture.rs@@ -244,6 +244,13 @@ pub struct Capture {pub enum StageOutcome {/// A new frame was staged; `advance` will encode it.Staged,+ /// The recording is paused, so the incoming frame was deliberately ignored and+ /// the held picture kept frozen at the pause instant (pause is app-side, but the+ /// compositor keeps streaming). A distinct outcome on purpose: it is NOT+ /// `Staged` — nothing new was staged, so a caller counting encoded frames must+ /// not tally it — and NOT `Dropped` — nothing failed, so it must not count+ /// toward the import-failure budget that ends a recording.+ Frozen,/// A recoverable per-frame failure — one dmabuf the GPU could not map, or a/// transient EAGAIN. The frame is skipped and `advance` holds the previously/// staged one forward, so a single bad frame costs one frame, not the whole@@ -395,10 +402,22 @@ impl Capture {// A paused recording must not ingest new pixels. The compositor keeps// streaming while the app is paused — pause is app-side — so frames still// arrive here; staging one would move the held picture to POST-pause- // content, which `finish`'s tail write would then encode into the file if- // a stop follows a pause with no resume. Freeze the staged picture at the- // pause instant instead — reported as `Frozen` so it is not counted as a- // dropped frame.+ // content, which the tail write in `finish` would then encode into the+ // file if a stop follows a pause with no resume. The user expects pause+ // to hold that privacy boundary, so the staged picture is frozen at the+ // pause instant instead.+ //+ // Its own `Frozen`, not `Dropped` and not `Staged`. Not `Dropped`: that is+ // the GPU-import failure signal, which warns per frame and ends the+ // recording past MAX_CONSECUTIVE_IMPORT_FAILURES, so a pause longer than+ // that many frames would abort the file — nothing failed here. Not `Staged`+ // either: nothing was staged, so anything downstream that counts encoded+ // frames or reasons about import health must be able to tell a freeze from+ // a real frame rather than have it hidden behind `Staged`.+ //+ // Ahead of the dmabuf path so the freeze covers the zero-copy route as+ // well, and so `mark_started` stays untouched: a pause that arrives+ // before the first frame must leave the capture unstarted.if self.paused_at.is_some() {return Ok(StageOutcome::Frozen);}@@ -1212,7 +1231,11 @@ mod tests {// Pause BEFORE any frame is staged, then a frame arrives during the pause.capture.pause();let staged = capture.stage(&frame(320, 240, shim::constants().video_format_bgrx));- assert!(staged.is_ok(), "staging while paused is a no-op, not an error: {staged:?}");+ assert_eq!(+ staged.expect("staging while paused is a no-op, not an error"),+ StageOutcome::Frozen,+ "a frame arriving while paused is Frozen — not Staged (nothing staged) nor Dropped (nothing failed)",+ );assert!(!capture.started(), "a frame received while paused must not start the timeline");let summary = capture.finish().expect("finish");diff --git a/electron/native/pipewire-capture/src/main.rs b/electron/native/pipewire-capture/src/main.rsindex 90093b26c..07d4b673e 100644--- a/electron/native/pipewire-capture/src/main.rs+++ b/electron/native/pipewire-capture/src/main.rs@@ -858,7 +858,10 @@ fn run<W: Write>(let (width, height) = (frame.crop.width, frame.crop.height);mailbox.recycle(frame.pixels);match staged {- Ok(capture::StageOutcome::Staged) => {+ // A real frame, or a pause-freeze — neither is an import+ // failure, so end any run of them. (A freeze holds the last+ // picture; `advance` is a no-op while paused.)+ Ok(capture::StageOutcome::Staged | capture::StageOutcome::Frozen) => {consecutive_drops = 0;}// Recoverable: one frame the GPU could not import. Warn so it