Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat(native): upgrade dispatch2 to 0.3 (#11855)

Brooooooklyne46ae2f72103
diff --git a/Cargo.lock b/Cargo.lock
index b2c97855e4..fa1550bb47 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -544,9 +544,9 @@ dependencies = [
[[package]]
name = "block2"
-version = "0.6.0"
+version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1d59b4c170e16f0405a2e95aff44432a0d41aa97675f3d52623effe95792a037"
+checksum = "340d2f0bdb2a43c1d3cd40513185b2bd7def0aa1052f956455114bc98f82dcf2"
dependencies = [
"objc2",
]
@@ -1196,9 +1196,9 @@ checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b"
[[package]]
name = "dispatch2"
-version = "0.2.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a0d569e003ff27784e0e14e4a594048698e0c0f0b66cabcb51511be55a7caa0"
+checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
dependencies = [
"bitflags 2.9.0",
"block2",
@@ -2561,9 +2561,9 @@ dependencies = [
[[package]]
name = "objc2"
-version = "0.6.0"
+version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3531f65190d9cff863b77a99857e74c314dd16bf56c538c4b57c7cbc3f3a6e59"
+checksum = "88c6597e14493ab2e44ce58f2fdecf095a51f12ca57bec060a11c57332520551"
dependencies = [
"objc2-encode",
]
diff --git a/Cargo.toml b/Cargo.toml
index f1fc3edf55..4a9f060e32 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -34,7 +34,7 @@ core-foundation = "0.10"
coreaudio-rs = "0.12"
criterion = { version = "0.5", features = ["html_reports"] }
criterion2 = { version = "3", default-features = false }
-dispatch2 = "0.2"
+dispatch2 = "0.3"
docx-parser = { git = "https://github.com/toeverything/docx-parser" }
dotenvy = "0.15"
file-format = { version = "0.26", features = ["reader"] }
diff --git a/packages/frontend/native/media_capture/src/macos/audio_buffer.rs b/packages/frontend/native/media_capture/src/macos/audio_buffer.rs
index 38cc74bb8d..c7c13a6745 100644
--- a/packages/frontend/native/media_capture/src/macos/audio_buffer.rs
+++ b/packages/frontend/native/media_capture/src/macos/audio_buffer.rs
@@ -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()) {
diff --git a/packages/frontend/native/media_capture/src/macos/queue.rs b/packages/frontend/native/media_capture/src/macos/queue.rs
index 9c68249703..653e249ef6 100644
--- a/packages/frontend/native/media_capture/src/macos/queue.rs
+++ b/packages/frontend/native/media_capture/src/macos/queue.rs
@@ -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))
}
diff --git a/packages/frontend/native/media_capture/src/macos/tap_audio.rs b/packages/frontend/native/media_capture/src/macos/tap_audio.rs
index 95aa10538f..4c0ba3c4e9 100644
--- a/packages/frontend/native/media_capture/src/macos/tap_audio.rs
+++ b/packages/frontend/native/media_capture/src/macos/tap_audio.rs
@@ -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(())