Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(recording): start the gated Instant screen track at the arm point
Richie McIlroy072b588459b3
diff --git a/crates/recording/src/instant_recording.rs b/crates/recording/src/instant_recording.rsindex 33d9ef279..bae7bf008 100644--- a/crates/recording/src/instant_recording.rs+++ b/crates/recording/src/instant_recording.rs@@ -710,6 +710,11 @@ async fn create_pipeline(start_time: Timestamps,start_gate: Option<RecordingStartGate>,) -> anyhow::Result<Pipeline> {+ // Instant merges its screen and audio tracks by timestamp, and gated+ // audio starts at the arm point, so the screen must start there too.+ if let Some(gate) = &start_gate {+ gate.set_video_origin_at_arm();+ }let ScreenPipelineInput {source: screen_capture,info: screen_info,diff --git a/crates/recording/src/output_pipeline/core.rs b/crates/recording/src/output_pipeline/core.rsindex dee920e3d..3e856fb6e 100644--- a/crates/recording/src/output_pipeline/core.rs+++ b/crates/recording/src/output_pipeline/core.rs@@ -3553,6 +3553,13 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: Vgate.offset_secs(timestamp).unwrap_or_default() * 1000.0,"Start gate admitted first video frame");+ // The first frame is shown from the arm point;+ // every later frame keeps its own capture time.+ if gate.video_origin_at_arm()+ && let Some(armed) = gate.armed_instant()+ {+ timestamp = Timestamp::Instant(armed);+ }}wall_clock_origin = gate.armed_instant()@@ -3690,11 +3697,16 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: Vmatch tokio::time::timeout_at(drain_deadline, video_rx.next()).await {Ok(Some(frame)) => {- let timestamp = frame.timestamp();+ let mut timestamp = frame.timestamp();if let Some(gate) = &start_gate {if !gate.admits_video(timestamp) {continue;}+ if gate.video_origin_at_arm()+ && let Some(armed) = gate.armed_instant()+ {+ timestamp = Timestamp::Instant(armed);+ }wall_clock_origin = gate.armed_instant().unwrap_or(timestamps.instant());diff --git a/crates/recording/src/output_pipeline/start_gate.rs b/crates/recording/src/output_pipeline/start_gate.rsindex 888a4334e..9e13f3792 100644--- a/crates/recording/src/output_pipeline/start_gate.rs+++ b/crates/recording/src/output_pipeline/start_gate.rs@@ -27,6 +27,7 @@ struct Inner {armed_at: OnceLock<Timestamps>,created: Instant,failsafe_logged: AtomicBool,+ video_origin_at_arm: AtomicBool,}impl Default for RecordingStartGate {@@ -41,9 +42,22 @@ impl RecordingStartGate {armed_at: OnceLock::new(),created: Instant::now(),failsafe_logged: AtomicBool::new(false),+ video_origin_at_arm: AtomicBool::new(false),}))}+ /// Stamps the first admitted video frame at the arm point, so the video+ /// timeline starts where audio anchored at the recording epoch does.+ /// Instant merges its tracks by timestamp; Studio aligns them with each+ /// track's recorded start time instead and leaves this off.+ pub(crate) fn set_video_origin_at_arm(&self) {+ self.0.video_origin_at_arm.store(true, Ordering::Release);+ }++ pub(crate) fn video_origin_at_arm(&self) -> bool {+ self.0.video_origin_at_arm.load(Ordering::Acquire)+ }+pub fn arm(&self) -> bool {self.arm_at(Timestamps::now())}