pub(crate) struct PlayQueue {
pub(crate) buf: Mutex<VecDeque<u8>>,
pub(crate) max_bytes: AtomicUsize,
pub(crate) frame_bytes: AtomicUsize,
}Expand description
Bounded, drop-oldest byte queue for the mic-PCM handoff into the virtual “input” sink — the whole of the playback path’s buffering in a single bound.
push runs on the Python side with the GIL released; drain_upto runs on the
playback thread. Overflow discards the OLDEST bytes, keeping the newest window (mic
audio is drift-tolerant and stale samples are worthless).
Fields§
§buf: Mutex<VecDeque<u8>>§max_bytes: AtomicUsizeBounds (re)published by start(); atomics so a restart can reconfigure the
Arc-shared queue in place without swapping it. frame_bytes >= 1 (set at new()).
frame_bytes: AtomicUsizeImplementations§
Source§impl PlayQueue
impl PlayQueue
pub(crate) fn new() -> Self
Sourcepub(crate) fn configure(&self, max_bytes: usize, frame_bytes: usize)
pub(crate) fn configure(&self, max_bytes: usize, frame_bytes: usize)
Apply this run’s byte bound and frame alignment, and drop any stale audio
left from a prior run. frame_bytes is floored to 1; the bound is floored
to a whole-frame multiple (min one frame) so overflow drops can never split
a sample frame.
Sourcepub(crate) fn clear(&self)
pub(crate) fn clear(&self)
Drop everything queued, keeping the bounds. Used when a run starts and whenever the playback session is reopened, since audio buffered across an outage is stale.
Sourcepub(crate) fn push(&self, data: &[u8])
pub(crate) fn push(&self, data: &[u8])
Append client PCM, dropping the OLDEST whole frames once the queue passes the byte bound so the newest audio is always retained. Drops stay frame-aligned: trimming mid-frame would phase-shift every later drain into interleaved garbage.
Sourcepub(crate) fn drain_upto(&self, n: usize, out: &mut Vec<u8>)
pub(crate) fn drain_upto(&self, n: usize, out: &mut Vec<u8>)
Drain up to n bytes into out, clamped to what is queued and floored to a
whole frame, since a PA write must be a multiple of the sample-spec frame size.