mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-02-17 14:07:28 +08:00
fix chatgpt review
This commit is contained in:
@@ -621,22 +621,24 @@ mod ios_impl {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref AUDIO_SENDER: Arc<Mutex<Option<Sender<Vec<f32>>>>> = Arc::new(Mutex::new(None));
|
||||
}
|
||||
|
||||
fn setup_ios_audio_callback(sender: Sender<Vec<f32>>) {
|
||||
// Set up the audio callback from iOS
|
||||
unsafe {
|
||||
// Check current audio permission setting
|
||||
let audio_enabled = Config::get_option("enable-audio") != "N";
|
||||
unsafe {
|
||||
scrap::ios::ffi::enable_audio(audio_enabled, false);
|
||||
|
||||
// Set the audio callback
|
||||
scrap::ios::ffi::set_audio_callback(Some(audio_callback));
|
||||
|
||||
// Store sender in a global for the callback
|
||||
AUDIO_SENDER = Some(Box::into_raw(Box::new(sender)));
|
||||
}
|
||||
}
|
||||
|
||||
static mut AUDIO_SENDER: Option<*mut Sender<Vec<f32>>> = None;
|
||||
// Store sender in a thread-safe way
|
||||
*AUDIO_SENDER.lock().unwrap() = Some(sender);
|
||||
}
|
||||
|
||||
extern "C" fn audio_callback(data: *const u8, size: u32, is_mic: bool) {
|
||||
// Only process microphone audio when enabled
|
||||
@@ -644,20 +646,19 @@ mod ios_impl {
|
||||
return;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
if let Some(sender_ptr) = AUDIO_SENDER {
|
||||
let sender = &*sender_ptr;
|
||||
|
||||
if let Some(ref sender) = *AUDIO_SENDER.lock().unwrap() {
|
||||
// Convert audio data from bytes to f32
|
||||
// Assuming audio comes as 16-bit PCM stereo at 48kHz
|
||||
let samples = size as usize / 2; // 16-bit = 2 bytes per sample
|
||||
let mut float_data = Vec::with_capacity(samples);
|
||||
|
||||
unsafe {
|
||||
let data_slice = std::slice::from_raw_parts(data as *const i16, samples);
|
||||
for &sample in data_slice {
|
||||
// Convert i16 to f32 normalized to [-1.0, 1.0]
|
||||
float_data.push(sample as f32 / 32768.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Send in chunks matching our frame size
|
||||
for chunk in float_data.chunks(FRAMES_PER_BUFFER * CHANNELS as usize) {
|
||||
@@ -668,4 +669,3 @@ mod ios_impl {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user