pub struct Dac { /* private fields */ }Expand description
An open USB DAC.
v0.1 supports one open Dac per process; a second Dac::open returns
Error::Busy until the first is closed or dropped. The host keeps its
UsbDeviceConnection open until then.
Implementations§
Source§impl Dac
impl Dac
Sourcepub fn await_usb_retirement(timeout: Duration) -> bool
pub fn await_usb_retirement(timeout: Duration) -> bool
Wait until USB activity has retired before releasing the host’s claimed interfaces and FD.
After Dac::close returns a transfer timeout, retain all host ownership
and call this until it returns true. This does not require a live Dac handle.
Sourcepub fn feedback_preflight(fd: RawFd, info: &DeviceInfo) -> Result<(u8, Vec<u8>)>
pub fn feedback_preflight(fd: RawFd, info: &DeviceInfo) -> Result<(u8, Vec<u8>)>
Identify optional capture interfaces after the host claims the base audio interfaces. Returns the active configuration ID and source interface numbers without starting audio.
Sourcepub fn open(fd: RawFd, info: DeviceInfo, config: DacConfig) -> Result<Dac>
pub fn open(fd: RawFd, info: DeviceInfo, config: DacConfig) -> Result<Dac>
Opens the DAC behind fd.
fd is the usbfs file descriptor of the device (on Android
UsbDeviceConnection.getFileDescriptor()); the library duplicates it, so
the host keeps ownership of its own. info.claimed_interfaces must be
the AudioControl and playback AudioStreaming interfaces plus any
optional capture sources identified by Dac::feedback_preflight.
Opening scans the descriptors, finds the hardware volume control, records
the DAC’s current level and, with the default
StartupVolume::Attenuate, lowers every
channel to at most -40 dB and verifies it, so that no stream can start
at the DAC’s own (often full-scale) level. It does not touch the clock or
start any audio. VolumeControl::startup
says what it did.
Sourcepub fn info(&self) -> &DeviceInfo
pub fn info(&self) -> &DeviceInfo
The identity the host gave at open.
Sourcepub fn feedback_trace(&self) -> Option<FeedbackTrace>
pub fn feedback_trace(&self) -> Option<FeedbackTrace>
Export the last stream’s opt-in support capture, even after the stream has closed. A new successfully opened stream replaces it.
Sourcepub fn capabilities(&self) -> Result<Capabilities>
pub fn capabilities(&self) -> Result<Capabilities>
What the DAC offers, from the descriptors scanned at open.
Sourcepub fn negotiate(&self, request: &StreamRequest) -> Result<StreamFormat>
pub fn negotiate(&self, request: &StreamRequest) -> Result<StreamFormat>
Settles the wire format for request.
This programs the DAC’s sampling frequency and reads it back (it is the
step that can fail with Error::ClockUnverified later), so it takes
100 ms or more. It fails with Error::InvalidState while a stream is
open. Nothing is resampled: with RatePolicy::Exact a rate the DAC
cannot run is Error::Unsupported; with NearestSupported the
returned format carries the rate the DAC will run.
Sourcepub fn open_stream(
&self,
format: &StreamFormat,
listener: Arc<dyn DacListener>,
) -> Result<DacStream>
pub fn open_stream( &self, format: &StreamFormat, listener: Arc<dyn DacListener>, ) -> Result<DacStream>
Opens the output stream for a negotiated format and starts the output
thread. The stream plays as soon as the ring holds the start threshold
(DacConfig::start_threshold_ms) of audio. Only one stream can be open
at a time.
Fails with Error::VolumeUnavailable when the stream’s own route has
no usable hardware volume control and
DacConfig::require_hardware_volume is on; nothing is programmed and
no output thread starts.
listener receives the stream’s events; see DacListener.
Sourcepub fn volume(&self) -> Option<VolumeControl>
pub fn volume(&self) -> Option<VolumeControl>
The hardware volume control, if the DAC has a writable one.
Sourcepub fn set_listener(&self, listener: Option<Arc<dyn DacListener>>)
pub fn set_listener(&self, listener: Option<Arc<dyn DacListener>>)
Sets the listener for events about the device itself (volume changes, device loss) while no stream is open. While a stream is open its listener gets those events too.
Sourcepub fn close(self) -> Result<()>
pub fn close(self) -> Result<()>
Closes the DAC: stops the stream if one is open, hands the volume back
as DacConfig::hand_back says, and releases the session so another
Dac::open can succeed. The host may then release its interfaces and
close its connection after success. If closing times out, keep all host
claims and the connection until Dac::await_usb_retirement returns
true. Dropping the Dac initiates the same cleanup, but cannot report
a timeout; hosts must still wait for retirement before releasing claims.
Sourcepub fn close_with(self, volume: CloseVolume) -> Result<()>
pub fn close_with(self, volume: CloseVolume) -> Result<()>
Like close, but the host says what becomes of the level
the DAC had before the library first changed it, instead of
DacConfig::hand_back deciding at open: write it back (another driver
gets the DAC), keep the record (the host holds on to the DAC or takes it
straight back) or forget it (the DAC was unplugged).
A DAC the library saw disappear is always forgotten: nothing can be written to it and a later attachment must start fresh.
Sourcepub fn set_dsd_overrides(
&self,
big_endian: Option<bool>,
subslot: Option<u8>,
) -> Result<()>
pub fn set_dsd_overrides( &self, big_endian: Option<bool>, subslot: Option<u8>, ) -> Result<()>
Changes the native DSD overrides of the open DAC (DacConfig::dsd_big_endian
and DacConfig::dsd_subslot), for a host whose user can change them
while the DAC stays open. None goes back to the device quirk.
They are read when a format is negotiated and when a stream is opened: a
stream that is already open keeps what it started with, and
capabilities reflects a new subslot size after the
next negotiate. subslot must be 1, 2 or 4.