Connect voice-host RTP audio to speaker playback (#43248)

## Why

The voice host drained incoming RTP packets without playing them. Route received audio through decoding and speaker output while preserving speaker suppression boundaries.

## What changed

- Add a GStreamer pipeline with RTP jitter buffering, Opus decoding, conversion, and resampling into the native speaker sink.
- Rebuild playout when the speaker is re-enabled, reject packets received before the new pipeline started, and discard queued audio and echo references on speaker transitions while preserving capture history.
- Limit each receive pass to 64 packets so incoming media cannot indefinitely delay audio controls.
- Prevent retired sink failures from failing a new speaker generation, and retain the last coherent playback delay estimate during callback contention.

## Testing

Add tests for real Opus playback and stale packet rejection, combined microphone mute and speaker suppression, retired sink failures, delay contention, and echo-reference reset without losing capture history.

GitOrigin-RevId: c91c94a2ba2347ac98af4e7fd1dc331ae766cc45
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-06 16:40:33 +00:00
1 parent 9daf7d22ca
commit a9896da3fe
17 files changed
+713 -39

No files matched your search

+14
View File
@@ -3,6 +3,8 @@
//! Generation changes, rejected capture buffers and capture gaps discard incomplete frames.
//! Capture/render capacity covers the worker deadline; playback and callback limits stay fixed.
use std::sync::Mutex;
use std::sync::PoisonError;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicU16;
use std::sync::atomic::AtomicU32;
@@ -93,6 +95,7 @@ pub(super) struct Buffers {
pub(super) playback: ArrayQueue<Frame>,
pub(super) microphone: AtomicU64,
pub(super) speaker: AtomicU64,
pub(super) speaker_failure_gate: Mutex<()>,
pub(super) serviced: AtomicBool,
pub(super) failed: AtomicBool,
pub(super) microphone_peak: AtomicU16,
@@ -100,6 +103,7 @@ pub(super) struct Buffers {
pub(super) queued: AtomicU32,
pub(super) last_dac_ns: AtomicU64,
pub(super) clock: Instant,
pub(super) callback_sequence: AtomicU64,
}
impl Buffers {
@@ -129,6 +133,7 @@ impl Buffers {
playback: ArrayQueue::new(QUEUE_CAPACITY),
microphone: AtomicU64::new(/*v*/ 1),
speaker: AtomicU64::new(/*v*/ 1),
speaker_failure_gate: Mutex::new(()),
serviced: AtomicBool::new(false),
failed: AtomicBool::new(false),
microphone_peak: AtomicU16::new(/*v*/ 0),
@@ -136,6 +141,7 @@ impl Buffers {
queued: AtomicU32::new(/*v*/ 0),
last_dac_ns: AtomicU64::new(/*v*/ 0),
clock: Instant::now(),
callback_sequence: AtomicU64::new(/*v*/ 0),
}
}
@@ -147,6 +153,14 @@ impl Buffers {
})
}
pub(super) fn set_speaker_disabled(&self, disabled: bool) -> std::io::Result<()> {
let _transition = self
.speaker_failure_gate
.lock()
.unwrap_or_else(PoisonError::into_inner);
Self::set_disabled(&self.speaker, disabled)
}
// One control worker writes each epoch. Odd epochs are disabled; every
// transition advances the epoch so disable/re-enable cannot replay old audio.
pub(super) fn set_disabled(epoch: &AtomicU64, disabled: bool) -> std::io::Result<()> {