mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
feat(native): upgrade dispatch2 to 0.3 (#11855)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::ffi::c_void;
|
||||
use std::{cmp::Ordering, ffi::c_void};
|
||||
|
||||
use coreaudio::sys::kAudioHardwareBadStreamError;
|
||||
use objc2::{Encode, Encoding, RefEncode};
|
||||
@@ -229,15 +229,19 @@ impl InputAndOutputAudioBufferList {
|
||||
} else {
|
||||
let len1 = mixed_samples.len();
|
||||
let len2 = processed_output.len();
|
||||
if len1 < len2 {
|
||||
mixed_samples.resize(len2, 0.0);
|
||||
} else if len2 < len1 {
|
||||
let mut padded_output = processed_output;
|
||||
padded_output.resize(len1, 0.0);
|
||||
for (sample1, sample2) in mixed_samples.iter_mut().zip(padded_output.iter()) {
|
||||
*sample1 = (*sample1 + *sample2) / 2.0;
|
||||
match len1.cmp(&len2) {
|
||||
Ordering::Less => {
|
||||
mixed_samples.resize(len2, 0.0);
|
||||
}
|
||||
return Ok(mixed_samples);
|
||||
Ordering::Greater => {
|
||||
let mut padded_output = processed_output;
|
||||
padded_output.resize(len1, 0.0);
|
||||
for (sample1, sample2) in mixed_samples.iter_mut().zip(padded_output.iter()) {
|
||||
*sample1 = (*sample1 + *sample2) / 2.0;
|
||||
}
|
||||
return Ok(mixed_samples);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
for (sample1, sample2) in mixed_samples.iter_mut().zip(processed_output.iter()) {
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
pub(crate) fn create_audio_tap_queue() -> *mut dispatch2::ffi::dispatch_queue_s {
|
||||
let queue_attr = unsafe {
|
||||
dispatch2::ffi::dispatch_queue_attr_make_with_qos_class(
|
||||
dispatch2::ffi::DISPATCH_QUEUE_SERIAL,
|
||||
dispatch2::ffi::dispatch_qos_class_t::QOS_CLASS_USER_INITIATED,
|
||||
0,
|
||||
)
|
||||
};
|
||||
unsafe {
|
||||
dispatch2::ffi::dispatch_queue_create(c"ProcessTapRecorder".as_ptr().cast(), queue_attr)
|
||||
}
|
||||
pub(crate) fn create_audio_tap_queue() -> dispatch2::DispatchRetained<dispatch2::DispatchQueue> {
|
||||
let queue_attr = dispatch2::DispatchQueueAttr::with_qos_class(
|
||||
dispatch2::DispatchQueueAttr::SERIAL,
|
||||
dispatch2::DispatchQoS::UserInteractive,
|
||||
0,
|
||||
);
|
||||
dispatch2::DispatchQueue::new("ProcessTapRecorder", Some(&queue_attr))
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ impl AggregateDevice {
|
||||
AudioDeviceCreateIOProcIDWithBlock(
|
||||
&mut in_proc_id,
|
||||
self.id,
|
||||
queue.cast(),
|
||||
dispatch2::DispatchRetained::as_ptr(&queue).as_ptr().cast(),
|
||||
(&*in_io_block
|
||||
as *const Block<
|
||||
dyn Fn(*mut c_void, *mut c_void, *mut c_void, *mut c_void, *mut c_void) -> i32,
|
||||
@@ -345,6 +345,7 @@ impl AggregateDevice {
|
||||
output_device_id: self.output_device_id,
|
||||
input_proc_id: self.input_proc_id,
|
||||
output_proc_id: self.output_proc_id,
|
||||
queue: Some(queue),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -416,6 +417,7 @@ pub struct AudioTapStream {
|
||||
output_device_id: AudioObjectID,
|
||||
input_proc_id: Option<AudioDeviceIOProcID>,
|
||||
output_proc_id: Option<AudioDeviceIOProcID>,
|
||||
queue: Option<dispatch2::DispatchRetained<dispatch2::DispatchQueue>>,
|
||||
}
|
||||
|
||||
impl AudioTapStream {
|
||||
@@ -530,6 +532,9 @@ impl AudioTapStream {
|
||||
);
|
||||
}
|
||||
|
||||
// destroy the queue
|
||||
drop(self.queue.take());
|
||||
|
||||
// Always return success to prevent errors from bubbling up to JavaScript
|
||||
// since we've made a best effort to clean up
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user