Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Compare sync matrix pts against the first delivered frame's origin

Richie McIlroy8001c19feded
diff --git a/crates/recording/tests/sync_matrix.rs b/crates/recording/tests/sync_matrix.rs
index d7b08a3d1..eddd85d42 100644
--- a/crates/recording/tests/sync_matrix.rs
+++ b/crates/recording/tests/sync_matrix.rs
@@ -29,9 +29,10 @@ use cap_timestamp::{Timestamp, Timestamps};
use serde::Serialize;
const CONTENT_SECS: f64 = 4.0;
-/// Absolute tolerance for a muxed pts vs the sent capture timestamp. Covers
-/// warmup anchoring, emission jitter and encoder rounding, plus scheduler
-/// noise on shared CI runners.
+/// Absolute tolerance for a muxed pts vs the sent capture timestamp,
+/// measured from each side's own origin (first sent frame vs first muxed
+/// pts). Covers warmup anchoring, emission jitter and encoder rounding,
+/// plus scheduler noise on shared CI runners.
const ABS_TOLERANCE_SECS: f64 = 0.25;
/// Tolerance for the relative structure (pts deltas vs sent deltas), which is
/// what actually determines sync drift. The bug class this guards against
@@ -304,9 +305,18 @@ async fn run_video_case(case: VideoCase) -> Result<String, String> {
// floor in frames as well. The bug class this guards produces errors of
// a second or more either way.
let rel_tolerance = REL_TOLERANCE_SECS.max(2.5 / f64::from(case.fps));
+ // The muxed timeline's origin is the first DELIVERED frame: the pipeline
+ // zeroes each track at its first frame and the recorder persists the
+ // track's start_time for cross-track alignment. A random case whose
+ // leading frames were dropped therefore legitimately muxes pts starting
+ // near 0, not at sent[0]; compare against the origin-normalized sent
+ // timeline. The absolute leg can also never be held to a tighter bound
+ // than the relative one, since it contains the same per-frame jitter.
+ let abs_tolerance = ABS_TOLERANCE_SECS.max(rel_tolerance);
+ let sent_origin = sent[0];
for (i, (&p, &s)) in pts.iter().zip(&sent).enumerate() {
- max_abs = max_abs.max((p - s).abs());
- let rel = ((p - pts[0]) - (s - sent[0])).abs();
+ max_abs = max_abs.max((p - (s - sent_origin)).abs());
+ let rel = ((p - pts[0]) - (s - sent_origin)).abs();
max_rel = max_rel.max(rel);
if rel > rel_tolerance {
return Err(format!(
@@ -314,7 +324,7 @@ async fn run_video_case(case: VideoCase) -> Result<String, String> {
));
}
}
- if max_abs > ABS_TOLERANCE_SECS {
+ if max_abs > abs_tolerance {
return Err(format!(
"absolute pts error {max_abs:.3}s exceeds tolerance"
));