From f2586fbc19bd8a73eb949dabda3bd7e52b5ef48c Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Tue, 10 Mar 2026 11:50:02 +0100 Subject: [PATCH] livekit_client: Apply correct priority for audio threads (#51178) Release Notes: - N/A Co-authored-by: Piotr Osiewicz --- .../src/livekit_client/playback.rs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/livekit_client/src/livekit_client/playback.rs b/crates/livekit_client/src/livekit_client/playback.rs index 0ebb282dd7ec494886fe1ffc90fe1f8688a762da..4933b05fc51592535c1f729ae8038a62103511ba 100644 --- a/crates/livekit_client/src/livekit_client/playback.rs +++ b/crates/livekit_client/src/livekit_client/playback.rs @@ -29,7 +29,7 @@ use std::cell::RefCell; use std::sync::Weak; use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; use std::time::Duration; -use std::{borrow::Cow, collections::VecDeque, sync::Arc, thread}; +use std::{borrow::Cow, collections::VecDeque, sync::Arc}; use util::{ResultExt as _, maybe}; mod source; @@ -139,8 +139,10 @@ impl AudioStack { let task = Arc::new(self.executor.spawn({ let apm = self.apm.clone(); let mixer = self.mixer.clone(); + let executor = self.executor.clone(); async move { Self::play_output( + executor, apm, mixer, LEGACY_SAMPLE_RATE.get(), @@ -225,8 +227,10 @@ impl AudioStack { let input_audio_device = AudioSettings::try_read_global(cx, |settings| settings.input_audio_device.clone()) .flatten(); + let executor = self.executor.clone(); self.executor.spawn(async move { Self::capture_input( + executor, apm, frame_tx, LEGACY_SAMPLE_RATE.get(), @@ -250,6 +254,7 @@ impl AudioStack { } async fn play_output( + executor: BackgroundExecutor, apm: Arc>, mixer: Arc>, sample_rate: u32, @@ -271,9 +276,8 @@ impl AudioStack { let mut resampler = audio_resampler::AudioResampler::default(); let mut buf = Vec::new(); - thread::Builder::new() - .name("AudioPlayback".to_owned()) - .spawn(move || { + executor + .spawn_with_priority(Priority::RealtimeAudio, async move { let output_stream = output_device.build_output_stream( &output_config.config(), { @@ -324,7 +328,7 @@ impl AudioStack { // Block forever to keep the output stream alive end_on_drop_rx.recv().ok(); }) - .unwrap(); + .detach(); device_change_listener.next().await; drop(end_on_drop_tx) @@ -332,6 +336,7 @@ impl AudioStack { } async fn capture_input( + executor: BackgroundExecutor, apm: Arc>, frame_tx: UnboundedSender>, sample_rate: u32, @@ -346,9 +351,8 @@ impl AudioStack { let frame_tx = frame_tx.clone(); let mut resampler = audio_resampler::AudioResampler::default(); - thread::Builder::new() - .name("AudioCapture".to_owned()) - .spawn(move || { + executor + .spawn_with_priority(Priority::RealtimeAudio, async move { maybe!({ if let Some(desc) = device.description().ok() { log::info!("Using microphone: {}", desc.name()) @@ -420,7 +424,7 @@ impl AudioStack { }) .log_err(); }) - .unwrap(); + .detach(); device_change_listener.next().await; drop(end_on_drop_tx)