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
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>
This commit is contained in:
parent
96d4da121b
commit
12248fed71
2 changed files with 59 additions and 19 deletions
|
|
@ -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 cidre::sc;
|
||||
|
|
@ -10,6 +13,12 @@ pub struct Devices(VecIntoIter<Device>);
|
|||
|
||||
impl Devices {
|
||||
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();
|
||||
sc::ShareableContent::current_with_ch(move |sc, e| {
|
||||
let res = if let Some(err) = e {
|
||||
|
|
|
|||
|
|
@ -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 crate::{
|
||||
|
|
@ -10,8 +14,7 @@ use crate::{
|
|||
|
||||
use cidre::{
|
||||
arc::Retained,
|
||||
cm, define_obj_type, dispatch, ns,
|
||||
objc::{self, Obj},
|
||||
cm, define_obj_type, dispatch, ns, objc,
|
||||
sc::{self, StreamOutput, StreamOutputImpl},
|
||||
};
|
||||
pub use enumerate::{
|
||||
|
|
@ -22,14 +25,12 @@ pub use enumerate::{
|
|||
pub mod enumerate;
|
||||
mod delegate;
|
||||
|
||||
pub fn is_selector_available(cfg: &sc::StreamCfg) -> bool {
|
||||
for name in [c"setCapturesAudio:", c"setExcludesCurrentProcessAudio:"] {
|
||||
let sel = unsafe { objc::sel_reg_name(name.as_ptr() as _) };
|
||||
if !cfg.responds_to_sel(sel) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
/// ScreenCaptureKit captures audio from macOS 13.0 (`capturesAudio`,
|
||||
/// `excludesCurrentProcessAudio`), the framework itself exists from 12.3. Ask the OS version, not
|
||||
/// the classes: in a binary that weak-links the framework, its classes are nil before 12.3.
|
||||
/// https://developer.apple.com/documentation/screencapturekit/scstreamconfiguration/capturesaudio
|
||||
fn is_supported() -> bool {
|
||||
cidre::api::macos_available("13.0")
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -37,6 +38,9 @@ pub struct Host;
|
|||
|
||||
impl Host {
|
||||
pub fn new() -> Result<Self, crate::HostUnavailable> {
|
||||
if !is_supported() {
|
||||
return Err(crate::HostUnavailable);
|
||||
}
|
||||
Ok(Host)
|
||||
}
|
||||
}
|
||||
|
|
@ -47,7 +51,7 @@ impl HostTrait for Host {
|
|||
type Device = Device;
|
||||
|
||||
fn is_available() -> bool {
|
||||
is_selector_available(&sc::StreamCfg::new())
|
||||
is_supported()
|
||||
}
|
||||
|
||||
fn devices(&self) -> Result<Self::Devices, DevicesError> {
|
||||
|
|
@ -202,18 +206,13 @@ impl Device {
|
|||
D: FnMut(&Data, &InputCallbackInfo) + 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.
|
||||
// However, we still check it here to be safe.
|
||||
if !is_selector_available(&cfg) {
|
||||
if !is_supported() {
|
||||
return Err(BuildStreamError::StreamConfigNotSupported);
|
||||
}
|
||||
unsafe {
|
||||
cfg.set_captures_audio(true);
|
||||
cfg.set_excludes_current_process_audio(false);
|
||||
cfg.set_shows_cursor(false);
|
||||
}
|
||||
let queue = dispatch::Queue::serial_with_ar_pool();
|
||||
let cfg = audio_stream_cfg();
|
||||
let windows = ns::Array::new();
|
||||
let filter = sc::ContentFilter::with_display_excluding_windows(&self.display, &windows);
|
||||
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;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue