Skip to main content

PlayQueue

Struct PlayQueue 

Source
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: AtomicUsize

Bounds (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: AtomicUsize

Implementations§

Source§

impl PlayQueue

Source

pub(crate) fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,