Skip to main content

measure_buffer_latency

Function measure_buffer_latency 

Source
pub fn measure_buffer_latency(
    audio_service: State<'_, Mutex<AudioService>>,
) -> Result<BufferLatencyDto, String>
Expand description

Estimates the I/O buffer latency from the current CPAL stream configuration.

Reads the configured frame count for both the input and output streams and converts them to milliseconds using (frames / sample_rate) × 1000. If either stream uses BufferSize::Default, a fallback of 256 frames is used.

The result is logged at info level and returned to the frontend.

§Returns

Ok(latency) — a BufferLatencyDto with input_buffer_latency_ms, output_buffer_latency_ms, and total_buffer_latency_ms.

§Errors

Returns Err if the AudioService mutex cannot be locked.