rustdesk 2021-12-25 00:18:54 +08:00
parent 589177fc94
commit 3d39d9c27c
2 changed files with 31 additions and 33 deletions

View File

@ -36,35 +36,31 @@ mod pa_impl {
use super::*;
#[tokio::main(flavor = "current_thread")]
pub async fn run(sp: GenericService) -> ResultType<()> {
if let Ok(mut stream) = crate::ipc::connect(1000, "_pa").await {
let mut encoder =
Encoder::new(crate::platform::linux::PA_SAMPLE_RATE, Stereo, LowDelay)?;
allow_err!(
stream
.send(&crate::ipc::Data::Config((
"audio-input".to_owned(),
Some(Config::get_option("audio-input"))
)))
.await
);
while sp.ok() {
sp.snapshot(|sps| {
sps.send(create_format_msg(crate::platform::linux::PA_SAMPLE_RATE, 2));
Ok(())
})?;
if let Some(data) = stream.next_timeout2(1000).await {
match data? {
Some(crate::ipc::Data::RawMessage(bytes)) => {
let data = unsafe {
std::slice::from_raw_parts::<f32>(
bytes.as_ptr() as _,
bytes.len() / 4,
)
};
send_f32(data, &mut encoder, &sp);
}
_ => {}
hbb_common::sleep(0.1).await; // one moment to wait for _pa ipc
let mut stream = crate::ipc::connect(1000, "_pa").await?;
let mut encoder = Encoder::new(crate::platform::linux::PA_SAMPLE_RATE, Stereo, LowDelay)?;
allow_err!(
stream
.send(&crate::ipc::Data::Config((
"audio-input".to_owned(),
Some(Config::get_option("audio-input"))
)))
.await
);
while sp.ok() {
sp.snapshot(|sps| {
sps.send(create_format_msg(crate::platform::linux::PA_SAMPLE_RATE, 2));
Ok(())
})?;
if let Some(data) = stream.next_timeout2(1000).await {
match data? {
Some(crate::ipc::Data::RawMessage(bytes)) => {
let data = unsafe {
std::slice::from_raw_parts::<f32>(bytes.as_ptr() as _, bytes.len() / 4)
};
send_f32(data, &mut encoder, &sp);
}
_ => {}
}
}
}

View File

@ -405,12 +405,13 @@ async fn start_pa() {
break;
}
let spec = pulse::sample::Spec {
format: pulse::sample::Format::F32be,
format: pulse::sample::Format::F32le,
channels: 2,
rate: crate::platform::linux::PA_SAMPLE_RATE,
};
log::info!("pa monitor: {:?}", device);
if let Ok(s) = psimple::Simple::new(
// systemctl --user status pulseaudio.service
match psimple::Simple::new(
None, // Use the default server
APP_NAME, // Our applications name
pulse::stream::Direction::Record, // We want a record stream
@ -420,7 +421,7 @@ async fn start_pa() {
None, // Use default channel map
None, // Use default buffering attributes
) {
loop {
Ok(s) => loop {
if let Some(Err(_)) = stream.next_timeout2(1).await {
break;
}
@ -433,9 +434,10 @@ async fn start_pa() {
allow_err!(stream.send(&Data::RawMessage(out)).await);
}
}
},
Err(err) => {
log::error!("Could not create simple pulse: {}", err);
}
} else {
log::error!("Could not create simple pulse");
}
}
Err(err) => {