fix: voice call, select audio input device (#7922)

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-05-07 16:18:48 +08:00
committed by GitHub
parent f08933f93c
commit 2c1595d0d5
50 changed files with 305 additions and 79 deletions

View File

@@ -103,6 +103,7 @@ mod pa_impl {
#[cfg(not(any(target_os = "linux", target_os = "android")))]
mod cpal_impl {
use self::service::{Reset, ServiceSwap};
use super::*;
use cpal::{
traits::{DeviceTrait, HostTrait, StreamTrait},
@@ -125,7 +126,23 @@ mod cpal_impl {
}
}
pub fn run(sp: EmptyExtraFieldService, state: &mut State) -> ResultType<()> {
fn run_restart(sp: EmptyExtraFieldService, state: &mut State) -> ResultType<()> {
state.reset();
sp.snapshot(|_sps: ServiceSwap<_>| Ok(()))?;
match &state.stream {
None => {
state.stream = Some(play(&sp)?);
}
_ => {}
}
if let Some((_, format)) = &state.stream {
sp.send_shared(format.clone());
}
RESTARTING.store(false, Ordering::SeqCst);
Ok(())
}
fn run_serv_snapshot(sp: EmptyExtraFieldService, state: &mut State) -> ResultType<()> {
sp.snapshot(|sps| {
match &state.stream {
None => {
@@ -141,6 +158,14 @@ mod cpal_impl {
Ok(())
}
pub fn run(sp: EmptyExtraFieldService, state: &mut State) -> ResultType<()> {
if !RESTARTING.load(Ordering::SeqCst) {
run_serv_snapshot(sp, state)
} else {
run_restart(sp, state)
}
}
fn send(
data: Vec<f32>,
sample_rate0: u32,