virtio_drivers::device::sound

Struct VirtIOSound

Source
pub struct VirtIOSound<H: Hal, T: Transport> { /* private fields */ }
Expand description

Audio driver based on virtio v1.2.

Supports synchronous blocking and asynchronous non-blocking audio playback.

Currently, only audio playback functionality has been implemented.

Implementations§

Source§

impl<H: Hal, T: Transport> VirtIOSound<H, T>

Source

pub fn new(transport: T) -> Result<Self>

Create a new VirtIO-Sound driver.

Source

pub fn jacks(&self) -> u32

Total jack num.

Source

pub fn streams(&self) -> u32

Total stream num.

Source

pub fn chmaps(&self) -> u32

Total chmap num.

Source

pub fn ack_interrupt(&mut self) -> bool

Acknowledge interrupt.

Source

pub fn enable_interrupts(&mut self, enable: bool)

Enables interrupts from the device.

Source

pub fn jack_remap( &mut self, jack_id: u32, association: u32, sequence: u32, ) -> Result

If the VIRTIO_SND_JACK_F_REMAP feature bit is set in the jack information, then the driver can send a control request to change the association and/or sequence number for the specified jack ID.

§Arguments
  • jack_id - A u32 int which is in the range of [0, jacks)
Source

pub fn pcm_set_params( &mut self, stream_id: u32, buffer_bytes: u32, period_bytes: u32, features: PcmFeatures, channels: u8, format: PcmFormat, rate: PcmRate, ) -> Result

Set selected stream parameters for the specified stream ID.

Source

pub fn pcm_prepare(&mut self, stream_id: u32) -> Result

Prepare a stream with specified stream ID.

Source

pub fn pcm_release(&mut self, stream_id: u32) -> Result

Release a stream with specified stream ID.

Source

pub fn pcm_start(&mut self, stream_id: u32) -> Result

Start a stream with specified stream ID.

Source

pub fn pcm_stop(&mut self, stream_id: u32) -> Result

Stop a stream with specified stream ID.

Source

pub fn pcm_xfer(&mut self, stream_id: u32, frames: &[u8]) -> Result

Transfer PCM frame to device, based on the stream type(OUTPUT/INPUT).

Currently supports only output stream.

This is a blocking method that will not return until the audio playback is complete.

Source

pub fn pcm_xfer_nb(&mut self, stream_id: u32, frames: &[u8]) -> Result<u16>

Transfer PCM frame to device, based on the stream type(OUTPUT/INPUT).

Currently supports only output stream.

This is a non-blocking method that returns a token.

The length of the frames must be equal to the buffer size set for the stream corresponding to the stream_id.

Source

pub fn pcm_xfer_ok(&mut self, token: u16) -> Result

The PCM frame transmission corresponding to the given token has been completed.

Source

pub fn output_streams(&mut self) -> Result<Vec<u32>>

Get all output streams.

Source

pub fn input_streams(&mut self) -> Result<Vec<u32>>

Get all input streams.

Source

pub fn rates_supported(&mut self, stream_id: u32) -> Result<PcmRates>

Get the rates that a stream supports.

Source

pub fn formats_supported(&mut self, stream_id: u32) -> Result<PcmFormats>

Get the formats that a stream supports.

Source

pub fn channel_range_supported( &mut self, stream_id: u32, ) -> Result<RangeInclusive<u8>>

Get channel range that a stream supports.

Source

pub fn features_supported(&mut self, stream_id: u32) -> Result<PcmFeatures>

Get features that a stream supports.

Source

pub fn latest_notification(&mut self) -> Result<Option<Notification>>

Get the latest notification.

Auto Trait Implementations§

§

impl<H, T> Freeze for VirtIOSound<H, T>
where T: Freeze,

§

impl<H, T> RefUnwindSafe for VirtIOSound<H, T>
where T: RefUnwindSafe, H: RefUnwindSafe,

§

impl<H, T> Send for VirtIOSound<H, T>
where T: Send,

§

impl<H, T> Sync for VirtIOSound<H, T>
where T: Sync,

§

impl<H, T> Unpin for VirtIOSound<H, T>
where T: Unpin, H: Unpin,

§

impl<H, T> UnwindSafe for VirtIOSound<H, T>
where T: UnwindSafe, H: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.