Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Handle timestamp anomalies in pause tracking logic

Richie McIlroy909907e1a674
diff --git a/crates/recording/src/output_pipeline/core.rs b/crates/recording/src/output_pipeline/core.rs
index d4f5f6204..f2cf4331b 100644
--- a/crates/recording/src/output_pipeline/core.rs
+++ b/crates/recording/src/output_pipeline/core.rs
@@ -61,26 +61,42 @@ impl SharedPauseState {
}
if let Some(start) = inner.paused_at.take() {
- let delta = timestamp.checked_sub(start).ok_or_else(|| {
- anyhow!(
- "Frame timestamp went backward during unpause (resume={start:?}, current={timestamp:?})"
- )
- })?;
-
- inner.offset = inner.offset.checked_add(delta).ok_or_else(|| {
- anyhow!(
- "Pause offset overflow (offset={:?}, delta={delta:?})",
- inner.offset
- )
- })?;
+ let delta = match timestamp.checked_sub(start) {
+ Some(d) => d,
+ None => {
+ warn!(
+ resume_at = ?start,
+ current = ?timestamp,
+ "Timestamp anomaly: frame timestamp went backward during unpause (clock skew?), treating as zero delta"
+ );
+ Duration::ZERO
+ }
+ };
+
+ inner.offset = match inner.offset.checked_add(delta) {
+ Some(o) => o,
+ None => {
+ warn!(
+ offset = ?inner.offset,
+ delta = ?delta,
+ "Timestamp anomaly: pause offset overflow, clamping to MAX"
+ );
+ Duration::MAX
+ }
+ };
}
- let adjusted = timestamp.checked_sub(inner.offset).ok_or_else(|| {
- anyhow!(
- "Adjusted timestamp underflow (timestamp={timestamp:?}, offset={:?})",
- inner.offset
- )
- })?;
+ let adjusted = match timestamp.checked_sub(inner.offset) {
+ Some(t) => t,
+ None => {
+ warn!(
+ timestamp = ?timestamp,
+ offset = ?inner.offset,
+ "Timestamp anomaly: adjusted timestamp underflow (clock skew?), using zero"
+ );
+ Duration::ZERO
+ }
+ };
Ok(Some(adjusted))
}
diff --git a/crates/recording/src/output_pipeline/win.rs b/crates/recording/src/output_pipeline/win.rs
index 18d710790..2f4b1a8d6 100644
--- a/crates/recording/src/output_pipeline/win.rs
+++ b/crates/recording/src/output_pipeline/win.rs
@@ -47,26 +47,42 @@ impl PauseTracker {
}
if let Some(start) = self.paused_at.take() {
- let delta = timestamp.checked_sub(start).ok_or_else(|| {
- anyhow!(
- "Frame timestamp went backward during unpause (resume={start:?}, current={timestamp:?})"
- )
- })?;
-
- self.offset = self.offset.checked_add(delta).ok_or_else(|| {
- anyhow!(
- "Pause offset overflow (offset={:?}, delta={delta:?})",
- self.offset
- )
- })?;
+ let delta = match timestamp.checked_sub(start) {
+ Some(d) => d,
+ None => {
+ warn!(
+ resume_at = ?start,
+ current = ?timestamp,
+ "Timestamp anomaly: frame timestamp went backward during unpause (clock skew?), treating as zero delta"
+ );
+ Duration::ZERO
+ }
+ };
+
+ self.offset = match self.offset.checked_add(delta) {
+ Some(o) => o,
+ None => {
+ warn!(
+ offset = ?self.offset,
+ delta = ?delta,
+ "Timestamp anomaly: pause offset overflow, clamping to MAX"
+ );
+ Duration::MAX
+ }
+ };
}
- let adjusted = timestamp.checked_sub(self.offset).ok_or_else(|| {
- anyhow!(
- "Adjusted timestamp underflow (timestamp={timestamp:?}, offset={:?})",
- self.offset
- )
- })?;
+ let adjusted = match timestamp.checked_sub(self.offset) {
+ Some(t) => t,
+ None => {
+ warn!(
+ timestamp = ?timestamp,
+ offset = ?self.offset,
+ "Timestamp anomaly: adjusted timestamp underflow (clock skew?), using zero"
+ );
+ Duration::ZERO
+ }
+ };
Ok(Some(adjusted))
}
diff --git a/crates/recording/src/output_pipeline/win_segmented.rs b/crates/recording/src/output_pipeline/win_segmented.rs
index 5c98f790a..ab8e29a14 100644
--- a/crates/recording/src/output_pipeline/win_segmented.rs
+++ b/crates/recording/src/output_pipeline/win_segmented.rs
@@ -111,26 +111,42 @@ impl PauseTracker {
}
if let Some(start) = self.paused_at.take() {
- let delta = timestamp.checked_sub(start).ok_or_else(|| {
- anyhow!(
- "Frame timestamp went backward during unpause (resume={start:?}, current={timestamp:?})"
- )
- })?;
-
- self.offset = self.offset.checked_add(delta).ok_or_else(|| {
- anyhow!(
- "Pause offset overflow (offset={:?}, delta={delta:?})",
- self.offset
- )
- })?;
+ let delta = match timestamp.checked_sub(start) {
+ Some(d) => d,
+ None => {
+ warn!(
+ resume_at = ?start,
+ current = ?timestamp,
+ "Timestamp anomaly: frame timestamp went backward during unpause (clock skew?), treating as zero delta"
+ );
+ Duration::ZERO
+ }
+ };
+
+ self.offset = match self.offset.checked_add(delta) {
+ Some(o) => o,
+ None => {
+ warn!(
+ offset = ?self.offset,
+ delta = ?delta,
+ "Timestamp anomaly: pause offset overflow, clamping to MAX"
+ );
+ Duration::MAX
+ }
+ };
}
- let adjusted = timestamp.checked_sub(self.offset).ok_or_else(|| {
- anyhow!(
- "Adjusted timestamp underflow (timestamp={timestamp:?}, offset={:?})",
- self.offset
- )
- })?;
+ let adjusted = match timestamp.checked_sub(self.offset) {
+ Some(t) => t,
+ None => {
+ warn!(
+ timestamp = ?timestamp,
+ offset = ?self.offset,
+ "Timestamp anomaly: adjusted timestamp underflow (clock skew?), using zero"
+ );
+ Duration::ZERO
+ }
+ };
Ok(Some(adjusted))
}
diff --git a/crates/recording/src/output_pipeline/win_segmented_camera.rs b/crates/recording/src/output_pipeline/win_segmented_camera.rs
index 71fbf6fcd..c6081da7b 100644
--- a/crates/recording/src/output_pipeline/win_segmented_camera.rs
+++ b/crates/recording/src/output_pipeline/win_segmented_camera.rs
@@ -111,26 +111,42 @@ impl PauseTracker {
}
if let Some(start) = self.paused_at.take() {
- let delta = timestamp.checked_sub(start).ok_or_else(|| {
- anyhow!(
- "Frame timestamp went backward during unpause (resume={start:?}, current={timestamp:?})"
- )
- })?;
-
- self.offset = self.offset.checked_add(delta).ok_or_else(|| {
- anyhow!(
- "Pause offset overflow (offset={:?}, delta={delta:?})",
- self.offset
- )
- })?;
+ let delta = match timestamp.checked_sub(start) {
+ Some(d) => d,
+ None => {
+ warn!(
+ resume_at = ?start,
+ current = ?timestamp,
+ "Timestamp anomaly: frame timestamp went backward during unpause (clock skew?), treating as zero delta"
+ );
+ Duration::ZERO
+ }
+ };
+
+ self.offset = match self.offset.checked_add(delta) {
+ Some(o) => o,
+ None => {
+ warn!(
+ offset = ?self.offset,
+ delta = ?delta,
+ "Timestamp anomaly: pause offset overflow, clamping to MAX"
+ );
+ Duration::MAX
+ }
+ };
}
- let adjusted = timestamp.checked_sub(self.offset).ok_or_else(|| {
- anyhow!(
- "Adjusted timestamp underflow (timestamp={timestamp:?}, offset={:?})",
- self.offset
- )
- })?;
+ let adjusted = match timestamp.checked_sub(self.offset) {
+ Some(t) => t,
+ None => {
+ warn!(
+ timestamp = ?timestamp,
+ offset = ?self.offset,
+ "Timestamp anomaly: adjusted timestamp underflow (clock skew?), using zero"
+ );
+ Duration::ZERO
+ }
+ };
Ok(Some(adjusted))
}