Skip to main content

FakeStream

Struct FakeStream 

Source
pub struct FakeStream { /* private fields */ }
Expand description

Fake callbacks execute inline after releasing locks, unlike real DAC callbacks. USB timing, feedback, volume safety and bit-perfect verification require the real implementation; this fake tests application decisions.

Implementations§

Source§

impl FakeStream

Source

pub fn advance(&self, frames: u64) -> Result<u64>

Complete up to frames queued frames. Paused audio is not consumed.

Examples found in repository?
examples/sdk_host_boundary.rs (line 41)
33fn fake() {
34    use std::sync::Arc;
35    use usbdac_core::{fake::FakeDac, DeviceInfo, PlaybackDevice, PlaybackStream, StreamRequest};
36    let request = StreamRequest::pcm(48_000, 2, 16);
37    let dac = FakeDac::new(DeviceInfo::new(1, 2, "test"), vec![request], 128).unwrap();
38    let format = dac.negotiate(&request).unwrap();
39    let stream = dac.open_stream(&format, Arc::new(|_| {})).unwrap();
40    assert_eq!(stream.write(&[0; 16]).unwrap(), 16);
41    assert_eq!(stream.advance(4).unwrap(), 4);
42    assert_eq!(stream.played_frames(), 4);
43    dac.detach();
44    assert!(stream.write(&[0; 4]).is_err());
45}
Source

pub fn lose_frames(&self, frames: u64) -> Result<u64>

Lose queued audio without incrementing played frames.

Source

pub fn lost_frames(&self) -> u64

Source

pub fn state(&self) -> StreamState

Trait Implementations§

Source§

impl Drop for FakeStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl PlaybackStream for FakeStream

Source§

fn write(&self, bytes: &[u8]) -> Result<usize>

Source§

fn writable_bytes(&self) -> usize

Source§

fn played_frames(&self) -> u64

Source§

fn latency_frames(&self) -> u64

Source§

fn play(&self) -> Result<()>

Source§

fn pause(&self) -> Result<()>

Source§

fn flush(&self) -> Result<()>

Source§

fn drain(&self) -> Result<()>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.