fix android get raw data (#8171)

If `std::ptr::copy_nonoverlapping` is not in `take`, it's not protected by the lock.

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-05-28 16:35:59 +08:00
committed by GitHub
parent 278d593580
commit 010b17509a
3 changed files with 21 additions and 15 deletions

View File

@@ -68,6 +68,8 @@ mod pa_impl {
);
#[cfg(target_os = "linux")]
let zero_audio_frame: Vec<f32> = vec![0.; AUDIO_DATA_SIZE_U8 / 4];
#[cfg(target_os = "android")]
let mut android_data = vec![];
while sp.ok() && !RESTARTING.load(Ordering::SeqCst) {
sp.snapshot(|sps| {
sps.send(create_format_msg(crate::platform::PA_SAMPLE_RATE, 2));
@@ -88,9 +90,12 @@ mod pa_impl {
send_f32(data, &mut encoder, &sp);
}
#[cfg(target_os = "android")]
if let Some(data) = scrap::android::ffi::get_audio_raw() {
if scrap::android::ffi::get_audio_raw(&mut android_data, &mut vec![]).is_some() {
let data = unsafe {
std::slice::from_raw_parts::<f32>(data.as_ptr() as _, data.len() / 4)
std::slice::from_raw_parts::<f32>(
android_data.as_ptr() as _,
android_data.len() / 4,
)
};
send_f32(data, &mut encoder, &sp);
} else {