Fixed mute and deafen
This commit is contained in:
@@ -46,6 +46,7 @@ pub struct VoiceState {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct VoiceStateInner {
|
pub struct VoiceStateInner {
|
||||||
pub session: Mutex<Option<VoiceSession>>,
|
pub session: Mutex<Option<VoiceSession>>,
|
||||||
|
pub backend_config: Arc<Mutex<BackendConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VoiceSession {
|
pub struct VoiceSession {
|
||||||
@@ -532,10 +533,7 @@ pub fn connect_to_vc(
|
|||||||
producer_in: Arc::clone(&shared_producer_in),
|
producer_in: Arc::clone(&shared_producer_in),
|
||||||
consumer_out: Arc::clone(&shared_consumer_out),
|
consumer_out: Arc::clone(&shared_consumer_out),
|
||||||
|
|
||||||
backend_config: Arc::new(Mutex::new(BackendConfig {
|
backend_config: Arc::clone(&voice_state.inner.backend_config),
|
||||||
is_muted: false,
|
|
||||||
is_deaf: false,
|
|
||||||
})),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
session.setup_input(config.input_device_name.clone(), Arc::clone(&state_inner))?;
|
session.setup_input(config.input_device_name.clone(), Arc::clone(&state_inner))?;
|
||||||
@@ -641,6 +639,7 @@ pub fn connect_to_vc(
|
|||||||
let shutdown = shutdown.clone();
|
let shutdown = shutdown.clone();
|
||||||
let cipher = cipher.clone();
|
let cipher = cipher.clone();
|
||||||
let backend_config = session.backend_config.clone();
|
let backend_config = session.backend_config.clone();
|
||||||
|
let consumer_out = session.consumer_out.clone();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut packets: BTreeMap<u32, Vec<f32>> = BTreeMap::new();
|
let mut packets: BTreeMap<u32, Vec<f32>> = BTreeMap::new();
|
||||||
@@ -651,9 +650,17 @@ pub fn connect_to_vc(
|
|||||||
let mut next_frame_time = Instant::now();
|
let mut next_frame_time = Instant::now();
|
||||||
|
|
||||||
while !shutdown.load(Ordering::Relaxed) {
|
while !shutdown.load(Ordering::Relaxed) {
|
||||||
let is_deaf = { backend_config.lock().unwrap().is_deaf };
|
let (is_muted, is_deaf) = {
|
||||||
|
let cfg = backend_config.lock().unwrap();
|
||||||
|
(cfg.is_muted, cfg.is_deaf)
|
||||||
|
};
|
||||||
|
|
||||||
if is_deaf {
|
if is_muted || is_deaf {
|
||||||
|
// Drop any audio already buffered for playback so that on
|
||||||
|
// unmute/undeafen we don't replay stale audio from the past.
|
||||||
|
if let Ok(mut cons) = consumer_out.lock() {
|
||||||
|
cons.clear();
|
||||||
|
}
|
||||||
packets.clear();
|
packets.clear();
|
||||||
is_prebuffering = true;
|
is_prebuffering = true;
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ pub fn get_config(app: AppHandle, state: State<ConfigState>) -> Result<Config, S
|
|||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BackendConfig {
|
pub struct BackendConfig {
|
||||||
pub is_muted: bool,
|
pub is_muted: bool,
|
||||||
@@ -115,9 +115,7 @@ pub fn update_backend_config(
|
|||||||
voice_state: State<'_, VoiceState>,
|
voice_state: State<'_, VoiceState>,
|
||||||
config: BackendConfig,
|
config: BackendConfig,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
if let Some(v) = &mut *voice_state.inner.session.lock().unwrap() {
|
*voice_state.inner.backend_config.lock().unwrap() = config;
|
||||||
*v.backend_config.lock().unwrap() = config
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user