Skip to content

Commit 152dab1

Browse files
committed
test: stress repeated one-sample watermark splits
1 parent 63a7219 commit 152dab1

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎.github/workflows/fix-instant-mixer-regression.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
start = candidate.index(" struct PcmProbe {")
5151
end = candidate.index(" #[tokio::test]\n async fn mix_sources()", start)
5252
tests = candidate[start:end]
53-
for name in ["pcm_first_input_after_grace_drops_and_counts_only_committed_samples", "pcm_watermark_limits_commitment_to_the_shortest_input"]:
53+
for name in ["pcm_first_input_after_grace_drops_and_counts_only_committed_samples", "pcm_watermark_limits_commitment_to_the_shortest_input", "pcm_watermark_splits_do_not_accumulate_timestamp_rounding"]:
5454
begin = tests.index(" #[test]\n fn " + name)
5555
finish = tests.index(" #[test]", begin + 1)
5656
tests = tests[:begin] + tests[finish:]

‎crates/recording/src/sources/audio_mixer.rs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,11 @@ impl AudioMixer {
711711
.context("Audio mixer watermark split failed")?;
712712
source.buffer.push_front(AudioFrame::new(
713713
remaining,
714-
buffer.timestamp + samples_duration(samples, source.info.sample_rate),
714+
start_timestamp
715+
+ samples_duration(
716+
source.samples_supplied + samples,
717+
source.info.sample_rate,
718+
),
715719
));
716720
buffer.inner.set_samples(samples);
717721
}
@@ -1288,6 +1292,23 @@ mod test {
12881292
assert_eq!(probe.deliveries[0].1, 20);
12891293
}
12901294

1295+
#[test]
1296+
fn pcm_watermark_splits_do_not_accumulate_timestamp_rounding() {
1297+
let mut probe = PcmProbe::new(2);
1298+
probe.send(0, 0, 50_001, Some(49_999));
1299+
for sample in 0..50_001 {
1300+
let timestamp = Timestamp::Instant(
1301+
probe.mixer.timestamps.instant()
1302+
+ Duration::from_nanos(sample * 1_000_000_000 / 48_000),
1303+
);
1304+
probe.send_at(1, timestamp, 1, None);
1305+
probe.tick(sample / 48);
1306+
}
1307+
assert_eq!(probe.peaks(0), [49_999]);
1308+
assert_eq!(probe.mixer.sources[0].late_samples_dropped, 0);
1309+
assert_eq!(probe.pcm.len(), 50_001);
1310+
}
1311+
12911312
#[test]
12921313
fn pcm_sub_timeout_gap_is_not_smoothed_away() {
12931314
let mut probe = PcmProbe::new(2);

0 commit comments

Comments
 (0)