#[non_exhaustive]pub struct StreamFormat {Show 15 fields
pub request: StreamRequest,
pub encoding: Encoding,
pub sample_rate: u32,
pub channels: u16,
pub valid_bits: u8,
pub subslot_bytes: u8,
pub interface_number: u8,
pub alt_setting: u8,
pub endpoint_address: u8,
pub sync_type: SyncKind,
pub explicit_feedback: bool,
pub link_speed: LinkSpeed,
pub service_interval_us: u32,
pub pacing: Pacing,
pub clock: Option<ClockChoice>,
}Expand description
What will go on the wire, as chosen by
Dac::negotiate.
A StreamFormat cannot be built by hand; pass the one negotiate returned
to Dac::open_stream.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.request: StreamRequestThe request this format answers.
encoding: Encoding§sample_rate: u32Frame rate on the wire: the PCM rate, the DoP carrier rate, or for
native DSD the rate of subslot-sized words (bit_rate / (8 * subslot_bytes)).
channels: u16§valid_bits: u8Significant bits of the alternate setting (PCM and DoP carrier). 1 for native DSD.
subslot_bytes: u8Bytes per sample on the wire.
interface_number: u8§alt_setting: u8§endpoint_address: u8§sync_type: SyncKind§explicit_feedback: bool§link_speed: LinkSpeed§service_interval_us: u32§pacing: PacingHow the stream is paced on the endpoint: what the transport does, named
(see Pacing). Consistent with sync_type and explicit_feedback.
clock: Option<ClockChoice>The Clock Source the sample rate was set and verified on, and how it was
reached from the stream’s terminal (see ClockChoice), as resolved by
Dac::negotiate. None when the DAC has no
clock entities to set (UAC 1.0 sets the rate on the endpoint).
Implementations§
Source§impl StreamFormat
impl StreamFormat
Sourcepub fn bytes_per_frame(&self) -> usize
pub fn bytes_per_frame(&self) -> usize
Bytes of one wire frame (one sample for every channel): the unit
DacStream::write counts in. Also the
granularity of everything the stream accepts.
Examples found in repository?
119fn write_loop(stream: &DacStream, state: &Mutex<State>, stop: &AtomicBool) {
120 let frame = stream.format().bytes_per_frame();
121 // About 10 ms per render call.
122 let chunk_frames = (stream.format().sample_rate as usize / 100).max(1);
123 let mut scratch = vec![0u8; chunk_frames * frame];
124 while !stop.load(Ordering::Acquire) {
125 let mut state = lock(state);
126 if state.ended {
127 drop(state);
128 thread::sleep(Duration::from_millis(10));
129 continue;
130 }
131 // Render only when the ring wants more, so the decoder is never ahead of
132 // the configured buffer depth (and a seek never has much to throw away).
133 if state.taken == state.chunk.len() {
134 if stream.writable_bytes() < scratch.len() {
135 drop(state);
136 thread::sleep(Duration::from_millis(2));
137 continue;
138 }
139 let rendered = state.source.render(&mut scratch);
140 if rendered == 0 {
141 // No more audio: let the ring play out, even a short tail.
142 if stream.drain().is_ok() {
143 state.ended = true;
144 }
145 continue;
146 }
147 state.chunk.clear();
148 state.chunk.extend_from_slice(&scratch[..rendered]);
149 state.taken = 0;
150 }
151 match stream.write(&state.chunk[state.taken..]) {
152 Ok(0) => {
153 drop(state);
154 thread::sleep(Duration::from_millis(2));
155 }
156 Ok(taken) => state.taken += taken,
157 Err(error) => {
158 // The stream closed or failed; the listener has the details.
159 eprintln!("writer stopping: {error}");
160 return;
161 }
162 }
163 }
164}Sourcepub fn counter_rate_hz(&self) -> u32
pub fn counter_rate_hz(&self) -> u32
Rate of the unit that played_frames(), latency_frames() and the
stream statistics count in. For PCM and DoP it is the wire frame rate.
For native DSD it is bit_rate / 8: one frame is one DSD byte per
channel (8 DSD bits per channel).
Sourcepub fn rate_differs_from_request(&self) -> bool
pub fn rate_differs_from_request(&self) -> bool
Whether the DAC runs a different rate than requested (only possible
with RatePolicy::NearestSupported).