Fix switch audio input device failed in index page on Linux.
This commit is contained in:
parent
8460c1ac42
commit
aa5c7cc38e
@ -515,6 +515,10 @@ pub fn set_option(key: &str, value: &str) {
|
|||||||
set_options(options).ok();
|
set_options(options).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn restart_autdio_input() {
|
||||||
|
crate::audio_service::restart();
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
pub async fn set_options(value: HashMap<String, String>) -> ResultType<()> {
|
pub async fn set_options(value: HashMap<String, String>) -> ResultType<()> {
|
||||||
let mut c = connect(1000, "").await?;
|
let mut c = connect(1000, "").await?;
|
||||||
|
@ -14,9 +14,11 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use magnum_opus::{Application::*, Channels::*, Encoder};
|
use magnum_opus::{Application::*, Channels::*, Encoder};
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
pub const NAME: &'static str = "audio";
|
pub const NAME: &'static str = "audio";
|
||||||
pub const AUDIO_DATA_SIZE_U8: usize = 960 * 4; // 10ms in 48000 stereo
|
pub const AUDIO_DATA_SIZE_U8: usize = 960 * 4; // 10ms in 48000 stereo
|
||||||
|
static RESTARTING: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
pub fn new() -> GenericService {
|
pub fn new() -> GenericService {
|
||||||
@ -32,12 +34,21 @@ pub fn new() -> GenericService {
|
|||||||
sp
|
sp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn restart() {
|
||||||
|
log::info!("restart the audio service, freezing now...");
|
||||||
|
if RESTARTING.load(Ordering::SeqCst) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RESTARTING.store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
mod pa_impl {
|
mod pa_impl {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
pub async fn run(sp: GenericService) -> ResultType<()> {
|
pub async fn run(sp: GenericService) -> ResultType<()> {
|
||||||
hbb_common::sleep(0.1).await; // one moment to wait for _pa ipc
|
hbb_common::sleep(0.1).await; // one moment to wait for _pa ipc
|
||||||
|
RESTARTING.store(false, Ordering::SeqCst);
|
||||||
let mut stream = crate::ipc::connect(1000, "_pa").await?;
|
let mut stream = crate::ipc::connect(1000, "_pa").await?;
|
||||||
unsafe {
|
unsafe {
|
||||||
AUDIO_ZERO_COUNT = 0;
|
AUDIO_ZERO_COUNT = 0;
|
||||||
@ -61,7 +72,7 @@ mod pa_impl {
|
|||||||
if data.len() == 0 {
|
if data.len() == 0 {
|
||||||
send_f32(&zero_audio_frame, &mut encoder, &sp);
|
send_f32(&zero_audio_frame, &mut encoder, &sp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if data.len() != AUDIO_DATA_SIZE_U8 {
|
if data.len() != AUDIO_DATA_SIZE_U8 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -364,6 +364,10 @@ impl UI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn refresh_audio_input(&self) {
|
||||||
|
ipc::restart_autdio_input();
|
||||||
|
}
|
||||||
|
|
||||||
fn install_path(&mut self) -> String {
|
fn install_path(&mut self) -> String {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
return crate::platform::windows::get_install_info().1;
|
return crate::platform::windows::get_install_info().1;
|
||||||
@ -701,6 +705,7 @@ impl sciter::EventHandler for UI {
|
|||||||
fn create_shortcut(String);
|
fn create_shortcut(String);
|
||||||
fn discover();
|
fn discover();
|
||||||
fn get_lan_peers();
|
fn get_lan_peers();
|
||||||
|
fn refresh_audio_input();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +131,7 @@ class AudioInputs: Reactor.Component {
|
|||||||
if (v == this.get_value()) return;
|
if (v == this.get_value()) return;
|
||||||
if (v == this.get_default()) v = "";
|
if (v == this.get_default()) v = "";
|
||||||
handler.set_option("audio-input", v);
|
handler.set_option("audio-input", v);
|
||||||
|
handler.refresh_audio_input();
|
||||||
this.toggleMenuState();
|
this.toggleMenuState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user