Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: anchor Instant audio at the recording start only behind a start gate

Richie McIlroya5f1277533de
diff --git a/crates/recording/src/instant_recording.rs b/crates/recording/src/instant_recording.rs
index 3c8314ead..33d9ef279 100644
--- a/crates/recording/src/instant_recording.rs
+++ b/crates/recording/src/instant_recording.rs
@@ -789,11 +789,17 @@ async fn create_pipeline(
let audio_dir = content_dir.join("audio");
let mut builder = output_pipeline::OutputPipeline::builder(audio_dir.clone())
.with_timestamps(start_time)
- .with_start_gate(start_gate.clone())
- // Zero is the recording start, not the first audio sample: a mic
- // that becomes ready late, or loopback system audio that delivers
- // only while sound plays, would otherwise move all audio early.
- .with_audio_anchor(output_pipeline::AudioAnchor::PipelineEpoch);
+ .with_start_gate(start_gate.clone());
+ // Behind a start gate, zero is the gate's arm time, which the screen
+ // track also starts at (within a frame), not the first audio sample:
+ // a mic that becomes ready late, or loopback system audio that
+ // delivers only while sound plays, would otherwise move all audio
+ // early. Without a gate the screen starts at its first encoded frame,
+ // after capture setup, so the epoch would put audio late instead;
+ // only Linux, whose video also starts at the epoch, anchors there.
+ if start_gate.is_some() || cfg!(target_os = "linux") {
+ builder = builder.with_audio_anchor(output_pipeline::AudioAnchor::PipelineEpoch);
+ }
if let Some(sys_audio) = system_audio_source {
builder = builder
diff --git a/crates/verify/expectations.toml b/crates/verify/expectations.toml
index c915bae1c..c3b37bf8d 100644
--- a/crates/verify/expectations.toml
+++ b/crates/verify/expectations.toml
@@ -122,6 +122,24 @@ link = "https://github.com/CapSoftware/Cap/pull/2636"
# finalize_instant_output). Each audio source is its own class, so a known
# loss or offset of one source cannot hide the other's.
+[[xfail]]
+case = "export/instant-ungated-mic-late/output/mp4/native"
+class = "sync-mic"
+platforms = ["macos", "windows"]
+bound = { count = 1, offset-ms = [-210, -190] }
+reason = "NEW: the Instant audio track is anchored at its first sample (AudioAnchor::FirstFrame) and nothing aligns it to the screen afterwards: a mic that becomes ready 0.2 s after the screen plays 200 ms early in output.mp4 (-198.7 to -201.1 ms measured). Bound: early by the mic's start delay"
+link = ""
+
+
+[[xfail]]
+case = "export/instant-ungated-system-loopback/output/mp4/native"
+class = "sync-system"
+platforms = ["macos", "windows"]
+bound = { count = 1, offset-ms = [-270, -250] }
+reason = "NEW: same anchor, loopback-style system audio (WASAPI delivers packets only while sound plays): the first sound becomes audio zero, so all audio is early by the time to first sound (260 ms here; -253.7 to -260.2 ms measured)"
+link = ""
+
+
[[xfail]]
case = "export/instant-gated-*mic*/output/mp4/native"
class = "sync-mic"
@@ -303,9 +321,8 @@ link = ""
case = "recording/instant/late-mic"
class = "sync-screen-mic"
platforms = ["macos"]
-flaky = true
-bound = { count = 1, offset-ms = [-200, -10] }
-reason = "NEW: same encoder start delay as recording/instant/screen-mic-system with a microphone that starts 1.0 s late, which the recording-start audio anchor keeps in place: -30.2 and -50.4 ms on runners; flaky for the same reason"
+bound = { count = 1, offset-ms = [900, 1100] }
+reason = "NEW: a microphone whose first sample arrives 1.0 s after the recording starts becomes audio zero, so all audio plays early by its start-up delay minus the screen's (screen late against the mic by 962 to 1040 ms on runners, every run). Bound: the mic's 1.0 s delay within 100 ms"
link = ""
[[xfail]]
diff --git a/crates/verify/src/pipeline.rs b/crates/verify/src/pipeline.rs
index b30fa11bf..3e4e091c0 100644
--- a/crates/verify/src/pipeline.rs
+++ b/crates/verify/src/pipeline.rs
@@ -669,9 +669,11 @@ pub async fn record_instant(spec: &InstantSpec, dir: &Path) -> anyhow::Result<()
if let Some(gate) = &gate {
builder = builder.with_start_gate(Some(gate.clone()));
}
- // Mirrors the product's Instant audio pipeline, anchored at the recording
- // epoch.
- builder = builder.with_audio_anchor(cap_recording::AudioAnchor::PipelineEpoch);
+ // Mirrors the product's Instant audio pipeline: anchored at the recording
+ // epoch behind a start gate, and on Linux.
+ if gate.is_some() || cfg!(target_os = "linux") {
+ builder = builder.with_audio_anchor(cap_recording::AudioAnchor::PipelineEpoch);
+ }
let has_audio = spec.mic_delay.is_some() || spec.system_audio;
if spec.system_audio {
let track = marker_track(AudioSource::System, spec.duration);