pub fn measure_round_trip_latency(
audio_service: State<'_, Mutex<AudioService>>,
) -> Result<RoundTripLatencyDto, String>Expand description
Measures true end-to-end round-trip latency using dedicated CPAL streams.
This is the only latency command that performs a real hardware measurement rather than an analytical estimate. The procedure is:
- The
AudioServicemutex is locked just long enough to clone the handler arc, then released so the main loopback and UI remain unblocked. - A dedicated OS thread is spawned that calls
AudioLatencyMeasurementService::measure_round_trip_latency, which in turn opens its own CPAL input/output streams, runs calibration and impulse detection, and returns the averaged result. - The command blocks until the thread finishes (typically 3–15 s depending on warmup and timeout settings), then logs and returns the result.
§Physical requirement
The audio interface output must be physically (or virtually) connected back to its input. Without this loopback the impulse can never be detected and the measurement will time out.
§Returns
Ok(result) — a RoundTripLatencyDto with:
is_valid = trueandlatency_msset on success.is_valid = falseand a human-readableerroron failure (e.g. timeout or no echo).
§Errors
Returns Err only if the AudioService mutex cannot be locked or the
measurement thread panics unexpectedly.