mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-14 16:51:04 +03:00
fix mis-align problem when converting &[u8] to &[f32] (#9986)
* fix: windows, improve audio buffer (#9770) * . * fix statics does not record and avoid channel changing when drio audio when audio is stero * add some commence * fix mis-align problem when converting &[u8] to &[f32] * add safety commence * revert client.rs * avoid tmp lifetime extends * avoid move in loop * avoid use after drop * another use after free * another use after free * make code more reasonable --------- Co-authored-by: zylthinking <zhaoyulong@qianxin.com>
This commit is contained in:
@@ -78,6 +78,19 @@ pub fn restart() {
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
mod pa_impl {
|
||||
use super::*;
|
||||
|
||||
// SAFETY: constrains of hbb_common::mem::aligned_u8_vec must be held
|
||||
unsafe fn align_to_32(data: Vec<u8>) -> Vec<u8> {
|
||||
if (data.as_ptr() as usize & 3) == 0 {
|
||||
return data;
|
||||
}
|
||||
|
||||
let mut buf = vec![];
|
||||
buf = unsafe { hbb_common::mem::aligned_u8_vec(data.len(), 4) };
|
||||
buf.extend_from_slice(data.as_ref());
|
||||
buf
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn run(sp: EmptyExtraFieldService) -> ResultType<()> {
|
||||
hbb_common::sleep(0.1).await; // one moment to wait for _pa ipc
|
||||
@@ -106,23 +119,29 @@ mod pa_impl {
|
||||
sps.send(create_format_msg(crate::platform::PA_SAMPLE_RATE, 2));
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
if let Ok(data) = stream.next_raw().await {
|
||||
if data.len() == 0 {
|
||||
send_f32(&zero_audio_frame, &mut encoder, &sp);
|
||||
continue;
|
||||
}
|
||||
|
||||
if data.len() != AUDIO_DATA_SIZE_U8 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let data = unsafe { align_to_32(data.into()) };
|
||||
let data = unsafe {
|
||||
std::slice::from_raw_parts::<f32>(data.as_ptr() as _, data.len() / 4)
|
||||
};
|
||||
send_f32(data, &mut encoder, &sp);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
if scrap::android::ffi::get_audio_raw(&mut android_data, &mut vec![]).is_some() {
|
||||
let data = unsafe {
|
||||
android_data = align_to_32(android_data);
|
||||
std::slice::from_raw_parts::<f32>(
|
||||
android_data.as_ptr() as _,
|
||||
android_data.len() / 4,
|
||||
|
||||
Reference in New Issue
Block a user