-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(recording): prevent double-count of VideoStartGate trim in mic_start_time #1966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
richiemcilroy
merged 1 commit into
CapSoftware:main
from
ManthanNimodiya:fix/mic-av-sync-double-count
Jul 2, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -187,7 +187,15 @@ pub(crate) async fn apply_video_start_gate( | |||||||||
| offset_ns = offset_ns as i64, | ||||||||||
| "Trimmed leading audio samples for encoder-pair alignment" | ||||||||||
| ); | ||||||||||
| VideoStartGateAction::UseFrame(AudioFrame::new(trimmed, frame.timestamp)) | ||||||||||
| // Advance the timestamp to the first *committed* sample so that | ||||||||||
| // first_timestamp (and therefore mic_start_time in metadata) reflects | ||||||||||
| // the actual capture time after the trim, not the pre-trim buffer start. | ||||||||||
| // Without this, the editor's mic_offset = display_start - mic_start equals | ||||||||||
| // trim_duration and causes it to skip that same duration a second time. | ||||||||||
| let trim_duration = Duration::from_nanos( | ||||||||||
| trim_samples as u64 * 1_000_000_000 / sample_rate as u64, | ||||||||||
| ); | ||||||||||
| VideoStartGateAction::UseFrame(AudioFrame::new(trimmed, frame.timestamp + trim_duration)) | ||||||||||
| } | ||||||||||
| None => { | ||||||||||
| warn!( | ||||||||||
|
|
@@ -4492,6 +4500,21 @@ mod tests { | |||||||||
| let expected_trim = | ||||||||||
| ns_to_sample_count(video_start_ns, info.sample_rate) as usize; | ||||||||||
| assert_eq!(new_frame.inner.samples(), 2048 - expected_trim); | ||||||||||
| // Timestamp must be advanced by the trim so that mic_start_time in | ||||||||||
| // metadata reflects the first committed sample, preventing the editor | ||||||||||
| // from double-counting the same gap as a skip offset. | ||||||||||
| let trim_duration = Duration::from_nanos( | ||||||||||
| expected_trim as u64 * 1_000_000_000 / info.sample_rate as u64, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thought in the test: using
Suggested change
|
||||||||||
| ); | ||||||||||
| let expected_ts = Timestamp::Instant(start + trim_duration); | ||||||||||
| assert_eq!( | ||||||||||
| new_frame | ||||||||||
| .timestamp | ||||||||||
| .signed_duration_since_secs(master_clock.timestamps()), | ||||||||||
| expected_ts | ||||||||||
| .signed_duration_since_secs(master_clock.timestamps()), | ||||||||||
| "gate UseFrame timestamp must be advanced past the trimmed samples" | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| other => panic!("expected UseFrame when audio leads, got {other:?}"), | ||||||||||
| } | ||||||||||
|
|
||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice fix. Minor tweak: consider reusing the existing
samples_to_nanos()helper here to avoid a potential divide-by-zero and to keep overflow/rounding behavior consistent.