Compare commits

..

1 commit

Author SHA1 Message Date
12248fed71 screencapturekit: audio only on macOS 13+, without this process (Kitedesk B283)
Some checks failed
cpal / clippy-test (push) Failing after 13s
cpal / rustfmt-check (push) Failing after 16s
cpal / cargo-publish (push) Has been skipped
cpal / ubuntu-test (push) Failing after 6s
cpal / linux-check-and-test-armv7 (push) Failing after 15s
cpal / asmjs-wasm32-test (wasm32-unknown-emscripten) (push) Failing after 11s
cpal / wasm32-bindgen-test (wasm32-unknown-unknown) (push) Failing after 13s
cpal / wasm32-wasi-test (wasm32-wasi) (push) Failing after 18s
cpal / android-check (push) Failing after 10s
cpal / android-apk-build (push) Failing after 17s
cpal / wasm-beep-build (push) Failing after 12s
cpal / windows-test (i686) (push) Has been cancelled
cpal / windows-test (x86_64) (push) Has been cancelled
cpal / macos-test (push) Has been cancelled
cpal / ios-build (push) Has been cancelled
The host decided availability by sending setCapturesAudio: and
setExcludesCurrentProcessAudio: to a new SCStreamConfiguration. In a binary
that weak-links ScreenCaptureKit so that it still launches on macOS 10.15,
that class is nil before 12.3. Host::new, Host::is_available, Devices::new
and build_input_stream now ask the OS version first (capturesAudio and
excludesCurrentProcessAudio are macOS 13.0) and touch no ScreenCaptureKit
class below it.

The stream set excludesCurrentProcessAudio to false, so what the capturing
process played itself, a voice call's far end or a remote session's sound,
went back to where it came from. It is true now.

Test: audio_capture_leaves_out_this_process fails on the old configuration
and passes now (macOS 26.5.2, --features screencapturekit); the delegate
tests still pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 03:02:12 +09:00
2 changed files with 59 additions and 19 deletions

View file

@ -1,3 +1,6 @@
// Modified by the Kitedesk fork (2026, B283): no display enumeration before macOS 13.0, where a
// weak-linked ScreenCaptureKit may be missing.
use std::vec::IntoIter as VecIntoIter; use std::vec::IntoIter as VecIntoIter;
use cidre::sc; use cidre::sc;
@ -10,6 +13,12 @@ pub struct Devices(VecIntoIter<Device>);
impl Devices { impl Devices {
pub fn new() -> Result<Self, DevicesError> { pub fn new() -> Result<Self, DevicesError> {
if !super::is_supported() {
return Err(BackendSpecificError {
description: "ScreenCaptureKit audio capture needs macOS 13.0 or later".to_string(),
}
.into());
}
let (tx, rx) = std::sync::mpsc::channel(); let (tx, rx) = std::sync::mpsc::channel();
sc::ShareableContent::current_with_ch(move |sc, e| { sc::ShareableContent::current_with_ch(move |sc, e| {
let res = if let Some(err) = e { let res = if let Some(err) = e {

View file

@ -1,3 +1,7 @@
// Modified by the Kitedesk fork (2026, B283): audio capture only on macOS 13.0 or later, checked
// before any ScreenCaptureKit class is touched so a weak-linked framework is safe on older macOS,
// and the stream leaves out the capturing process's own audio.
use std::{cell::RefCell, rc::Rc, time::Duration}; use std::{cell::RefCell, rc::Rc, time::Duration};
use crate::{ use crate::{
@ -10,8 +14,7 @@ use crate::{
use cidre::{ use cidre::{
arc::Retained, arc::Retained,
cm, define_obj_type, dispatch, ns, cm, define_obj_type, dispatch, ns, objc,
objc::{self, Obj},
sc::{self, StreamOutput, StreamOutputImpl}, sc::{self, StreamOutput, StreamOutputImpl},
}; };
pub use enumerate::{ pub use enumerate::{
@ -22,14 +25,12 @@ pub use enumerate::{
pub mod enumerate; pub mod enumerate;
mod delegate; mod delegate;
pub fn is_selector_available(cfg: &sc::StreamCfg) -> bool { /// ScreenCaptureKit captures audio from macOS 13.0 (`capturesAudio`,
for name in [c"setCapturesAudio:", c"setExcludesCurrentProcessAudio:"] { /// `excludesCurrentProcessAudio`), the framework itself exists from 12.3. Ask the OS version, not
let sel = unsafe { objc::sel_reg_name(name.as_ptr() as _) }; /// the classes: in a binary that weak-links the framework, its classes are nil before 12.3.
if !cfg.responds_to_sel(sel) { /// https://developer.apple.com/documentation/screencapturekit/scstreamconfiguration/capturesaudio
return false; fn is_supported() -> bool {
} cidre::api::macos_available("13.0")
}
true
} }
#[derive(Debug)] #[derive(Debug)]
@ -37,6 +38,9 @@ pub struct Host;
impl Host { impl Host {
pub fn new() -> Result<Self, crate::HostUnavailable> { pub fn new() -> Result<Self, crate::HostUnavailable> {
if !is_supported() {
return Err(crate::HostUnavailable);
}
Ok(Host) Ok(Host)
} }
} }
@ -47,7 +51,7 @@ impl HostTrait for Host {
type Device = Device; type Device = Device;
fn is_available() -> bool { fn is_available() -> bool {
is_selector_available(&sc::StreamCfg::new()) is_supported()
} }
fn devices(&self) -> Result<Self::Devices, DevicesError> { fn devices(&self) -> Result<Self::Devices, DevicesError> {
@ -202,18 +206,13 @@ impl Device {
D: FnMut(&Data, &InputCallbackInfo) + Send + 'static, D: FnMut(&Data, &InputCallbackInfo) + Send + 'static,
E: FnMut(StreamError) + Send + 'static, E: FnMut(StreamError) + Send + 'static,
{ {
let queue = dispatch::Queue::serial_with_ar_pool();
let mut cfg = sc::StreamCfg::new();
// This check should always pass because the caller should check `Host::is_available()` first. // This check should always pass because the caller should check `Host::is_available()` first.
// However, we still check it here to be safe. // However, we still check it here to be safe.
if !is_selector_available(&cfg) { if !is_supported() {
return Err(BuildStreamError::StreamConfigNotSupported); return Err(BuildStreamError::StreamConfigNotSupported);
} }
unsafe { let queue = dispatch::Queue::serial_with_ar_pool();
cfg.set_captures_audio(true); let cfg = audio_stream_cfg();
cfg.set_excludes_current_process_audio(false);
cfg.set_shows_cursor(false);
}
let windows = ns::Array::new(); let windows = ns::Array::new();
let filter = sc::ContentFilter::with_display_excluding_windows(&self.display, &windows); let filter = sc::ContentFilter::with_display_excluding_windows(&self.display, &windows);
let error_callback: delegate::ErrorCallback = let error_callback: delegate::ErrorCallback =
@ -430,3 +429,35 @@ fn frames_to_duration(frames: usize, rate: crate::SampleRate) -> std::time::Dura
let nanos = ((secsf - secs as f64) * 1_000_000_000.0) as u32; let nanos = ((secsf - secs as f64) * 1_000_000_000.0) as u32;
std::time::Duration::new(secs, nanos) std::time::Duration::new(secs, nanos)
} }
/// Audio of the whole display except this process: what the process plays itself (a call's far
/// end, a remote session's sound) would otherwise go back to where it came from.
/// https://developer.apple.com/documentation/screencapturekit/scstreamconfiguration/excludescurrentprocessaudio
fn audio_stream_cfg() -> Retained<sc::StreamCfg> {
let mut cfg = sc::StreamCfg::new();
// SAFETY: callers check `is_supported()`, so these macOS 13.0 properties exist.
unsafe {
cfg.set_captures_audio(true);
cfg.set_excludes_current_process_audio(true);
}
cfg.set_shows_cursor(false);
cfg
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn audio_capture_leaves_out_this_process() {
if !is_supported() {
return;
}
let cfg = audio_stream_cfg();
unsafe {
assert!(cfg.captures_audio());
assert!(cfg.excludes_current_process_audio());
}
assert!(!cfg.shows_cursor());
}
}