mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-05-08 15:18:13 +03:00
refact: seperate audio device for voice call (#8703)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -22,6 +22,10 @@ pub const NAME: &'static str = "audio";
|
||||
pub const AUDIO_DATA_SIZE_U8: usize = 960 * 4; // 10ms in 48000 stereo
|
||||
static RESTARTING: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref VOICE_CALL_INPUT_DEVICE: Arc::<Mutex::<Option<String>>> = Default::default();
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
pub fn new() -> GenericService {
|
||||
let svc = EmptyExtraFieldService::new(NAME.to_owned(), true);
|
||||
@@ -36,6 +40,33 @@ pub fn new() -> GenericService {
|
||||
svc.sp
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_voice_call_input_device() -> Option<String> {
|
||||
VOICE_CALL_INPUT_DEVICE.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_voice_call_input_device(device: Option<String>, set_if_present: bool) {
|
||||
if !set_if_present && VOICE_CALL_INPUT_DEVICE.lock().unwrap().is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
if *VOICE_CALL_INPUT_DEVICE.lock().unwrap() == device {
|
||||
return;
|
||||
}
|
||||
*VOICE_CALL_INPUT_DEVICE.lock().unwrap() = device;
|
||||
restart();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_audio_input() -> String {
|
||||
VOICE_CALL_INPUT_DEVICE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.clone()
|
||||
.unwrap_or(Config::get_option("audio-input"))
|
||||
}
|
||||
|
||||
pub fn restart() {
|
||||
log::info!("restart the audio service, freezing now...");
|
||||
if RESTARTING.load(Ordering::SeqCst) {
|
||||
@@ -62,7 +93,7 @@ mod pa_impl {
|
||||
stream
|
||||
.send(&crate::ipc::Data::Config((
|
||||
"audio-input".to_owned(),
|
||||
Some(Config::get_option("audio-input"))
|
||||
Some(super::get_audio_input())
|
||||
)))
|
||||
.await
|
||||
);
|
||||
@@ -132,6 +163,7 @@ mod cpal_impl {
|
||||
}
|
||||
|
||||
fn run_restart(sp: EmptyExtraFieldService, state: &mut State) -> ResultType<()> {
|
||||
println!("REMOVE ME ========================= run_restart");
|
||||
state.reset();
|
||||
sp.snapshot(|_sps: ServiceSwap<_>| Ok(()))?;
|
||||
match &state.stream {
|
||||
@@ -198,7 +230,8 @@ mod cpal_impl {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_device() -> ResultType<(Device, SupportedStreamConfig)> {
|
||||
let audio_input = Config::get_option("audio-input");
|
||||
let audio_input = super::get_audio_input();
|
||||
println!("REMOVE ME =============================== use audio input: {}", &audio_input);
|
||||
if !audio_input.is_empty() {
|
||||
return get_audio_input(&audio_input);
|
||||
}
|
||||
@@ -219,7 +252,7 @@ mod cpal_impl {
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn get_device() -> ResultType<(Device, SupportedStreamConfig)> {
|
||||
let audio_input = Config::get_option("audio-input");
|
||||
let audio_input = super::get_audio_input();
|
||||
get_audio_input(&audio_input)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user