Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop): clamp primed input timing to the pipeline epoch
Richie McIlroy9f6398a28163
diff --git a/apps/desktop-gpui/src/session.rs b/apps/desktop-gpui/src/session.rsindex 7fbc1855c..6bd270b6a 100644--- a/apps/desktop-gpui/src/session.rs+++ b/apps/desktop-gpui/src/session.rs@@ -805,8 +805,12 @@ impl RecordingSession {let start = recording::start(config);let discarding = self.discarding.take();let task = gpui_tokio::Tokio::spawn(cx, async move {- if let Some(discarding) = discarding {- let _ = discarding.await;+ if let Some(discarding) = discarding+ && tokio::time::timeout(Duration::from_secs(5), discarding)+ .await+ .is_err()+ {+ tracing::warn!("previous recording start is still tearing down; starting anyway");}start.await});diff --git a/crates/recording/src/cursor.rs b/crates/recording/src/cursor.rsindex c0cd93f18..8dba97665 100644--- a/crates/recording/src/cursor.rs+++ b/crates/recording/src/cursor.rs@@ -298,7 +298,9 @@ fn keycode_to_string(key: &device_query::Keycode) -> (String, String) {/// epoch. `None` while a primed recording is still waiting for its cue.fn input_epoch(start_gate: Option<&RecordingStartGate>, start_time: Timestamps) -> Option<Instant> {match start_gate {- Some(gate) => gate.armed_at().map(|armed| armed.instant()),+ Some(gate) => gate+ .armed_instant()+ .map(|armed| armed.max(start_time.instant())),None => Some(start_time.instant()),}}@@ -392,6 +394,9 @@ pub fn spawn_cursor_recorder(}let Some(epoch) = input_epoch(start_gate.as_ref(), start_time) else {+ last_position = cap_cursor_capture::RawCursorPosition::get();+ last_mouse_state = device_state.get_mouse();+ last_keys = device_state.get_keys();continue;};let elapsed = epoch.elapsed().as_secs_f64() * 1000.0;@@ -1090,4 +1095,15 @@ mod input_epoch_tests {gate.arm_at(armed);assert_eq!(input_epoch(Some(&gate), start_time), Some(armed.instant()));}++ #[test]+ fn an_arm_point_before_the_pipeline_epoch_is_clamped_to_it() {+ let gate = RecordingStartGate::new();+ gate.arm();+ let start_time = Timestamps::now() + std::time::Duration::from_millis(250);+ assert_eq!(+ input_epoch(Some(&gate), start_time),+ Some(start_time.instant())+ );+ }}diff --git a/crates/recording/src/output_pipeline/core.rs b/crates/recording/src/output_pipeline/core.rsindex 5982f6fbc..97f507977 100644--- a/crates/recording/src/output_pipeline/core.rs+++ b/crates/recording/src/output_pipeline/core.rs@@ -2952,8 +2952,8 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: VNone => break,},_ = tokio::time::sleep(STATIC_SOURCE_RELEASE_POLL) => {- let static_since_arm = gate.armed_at().is_some_and(|armed| {- armed.instant().elapsed() >= STATIC_SOURCE_RELEASE_DELAY+ let static_since_arm = gate.armed_instant().is_some_and(|armed| {+ armed.elapsed() >= STATIC_SOURCE_RELEASE_DELAY});if !static_since_arm {continue;@@ -2978,8 +2978,8 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: Vif let Some(gate) = &start_gate {if released_at_arm {- let armed = gate.armed_at().expect("released only once armed");- timestamp = Timestamp::Instant(armed.instant());+ let armed = gate.armed_instant().expect("released only once armed");+ timestamp = Timestamp::Instant(armed);info!(held_frames = held_before_start,"Start gate released the frame on screen at the arm point"@@ -2997,8 +2997,8 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: V);}wall_clock_origin = gate- .armed_at()- .map_or(timestamps.instant(), |armed| armed.instant());+ .armed_instant()+ .unwrap_or(timestamps.instant());start_gate = None;held_frame = None;}@@ -3136,8 +3136,8 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: Vcontinue;}wall_clock_origin = gate- .armed_at()- .map_or(timestamps.instant(), |armed| armed.instant());+ .armed_instant()+ .unwrap_or(timestamps.instant());start_gate = None;}frame_count += 1;diff --git a/crates/recording/src/output_pipeline/start_gate.rs b/crates/recording/src/output_pipeline/start_gate.rsindex a70b3cde2..888a4334e 100644--- a/crates/recording/src/output_pipeline/start_gate.rs+++ b/crates/recording/src/output_pipeline/start_gate.rs@@ -88,6 +88,11 @@ impl RecordingStartGate {self.0.armed_at.get().copied()}+ /// The arm instant, once the gate is armed or its failsafe has expired.+ pub(crate) fn armed_instant(&self) -> Option<Instant> {+ self.armed_at_or_failsafe().map(|armed| armed.instant())+ }+/// Seconds from the arm point to `timestamp`, negative for media captured/// before it. `None` while the gate is still closed.pub(crate) fn offset_secs(&self, timestamp: Timestamp) -> Option<f64> {