fix(audio): check capture ring available before read (fixes Opus6k choppy)
Some checks failed
Mirror to GitHub / mirror (push) Failing after 32s
Build Release Binaries / build-amd64 (push) Failing after 3m58s

Partial reads from the capture ring consumed samples that were then
discarded when the send loop retried from buf[0]. For 20ms codecs this
was invisible (single Oboe burst fills 960 samples in one read), but
40ms codecs (Opus6k, 1920 samples) needed 2 bursts — the first partial
read consumed 960 real samples and threw them away.

Result: Opus6k produced ~11 frames/s instead of 25 (~44% of expected).

Fix: expose wzp_native_audio_capture_available() and check it before
reading, matching the desktop capture_ring.available() pattern. Partial
reads no longer occur because we only read when enough samples exist.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-04-13 11:46:15 +04:00
parent d9e7e72978
commit 9ae9441de4
3 changed files with 25 additions and 6 deletions

View File

@@ -570,16 +570,21 @@ impl CallEngine {
if !send_r.load(Ordering::Relaxed) {
break;
}
// wzp-native doesn't expose `available()`, so we just try
// to read a full frame and sleep briefly if the ring is
// short. Oboe's capture callback fills at a steady rate
// so in steady state this spins once per frame.
let read = crate::wzp_native::audio_read_capture(&mut buf[..frame_samples]);
if read < frame_samples {
// Check ring has enough samples before reading to avoid
// partial reads that consume samples and then get
// overwritten on the next attempt (caused 40ms codecs
// like Opus6k to produce ~11 frames/s instead of 25).
if crate::wzp_native::audio_capture_available() < frame_samples {
short_reads += 1;
tokio::time::sleep(std::time::Duration::from_millis(5)).await;
continue;
}
let read = crate::wzp_native::audio_read_capture(&mut buf[..frame_samples]);
if read < frame_samples {
// Shouldn't happen after available() check, but guard anyway.
short_reads += 1;
continue;
}
if !first_full_read_logged {
info!(
t_ms = send_t0.elapsed().as_millis(),