Skip to main content

FakeDac

Struct FakeDac 

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

Independent fake devices do not occupy the process’s real USB session. Profiles must be nonzero PCM at 16, 24 or 32 bits; negotiation is exact.

Implementations§

Source§

impl FakeDac

Source

pub fn new( info: DeviceInfo, profiles: Vec<StreamRequest>, capacity_frames: usize, ) -> Result<Self>

Examples found in repository?
examples/sdk_host_boundary.rs (line 37)
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 info(&self) -> &DeviceInfo

Source

pub fn detach(&self)

Inject unplug. Existing streams fail with DeviceLost; a replug is a new FakeDac, so old handles cannot operate on the replacement attachment.

Examples found in repository?
examples/sdk_host_boundary.rs (line 43)
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 close(self)

Trait Implementations§

Source§

impl Drop for FakeDac

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 PlaybackDevice for FakeDac

Auto Trait Implementations§

§

impl !RefUnwindSafe for FakeDac

§

impl !UnwindSafe for FakeDac

§

impl Forget for FakeDac

§

impl Freeze for FakeDac
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<StreamRequest>: Freeze, *const ArcInner<Mutex<RawMutex, DeviceState>> is !null: Freeze, PhantomData<ArcInner<Mutex<RawMutex, DeviceState>>>: Freeze,

§

impl Move for FakeDac

§

impl Send for FakeDac
where RawVecInner: Send, Arc<Mutex<RawMutex, DeviceState>>: Send,

§

impl Sync for FakeDac
where RawVecInner: Sync, Arc<Mutex<RawMutex, DeviceState>>: Sync,

§

impl Unpin for FakeDac
where *const u8 is !null: Unpin, Arc<Mutex<RawMutex, DeviceState>>: Unpin,

§

impl UnsafeUnpin for FakeDac
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<StreamRequest>: UnsafeUnpin, *const ArcInner<Mutex<RawMutex, DeviceState>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<RawMutex, DeviceState>>>: UnsafeUnpin,

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.