Compare commits

..

No commits in common. "kd/b283-sck-audio" and "osx-screencapturekit" have entirely different histories.

2 changed files with 19 additions and 59 deletions

View file

@ -1,6 +1,3 @@
// 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;
@ -13,12 +10,6 @@ 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 {

View file

@ -1,7 +1,3 @@
// 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::{
@ -14,7 +10,8 @@ use crate::{
use cidre::{
arc::Retained,
cm, define_obj_type, dispatch, ns, objc,
cm, define_obj_type, dispatch, ns,
objc::{self, Obj},
sc::{self, StreamOutput, StreamOutputImpl},
};
pub use enumerate::{
@ -25,12 +22,14 @@ pub use enumerate::{
pub mod enumerate;
mod delegate;
/// 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")
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
}
#[derive(Debug)]
@ -38,9 +37,6 @@ pub struct Host;
impl Host {
pub fn new() -> Result<Self, crate::HostUnavailable> {
if !is_supported() {
return Err(crate::HostUnavailable);
}
Ok(Host)
}
}
@ -51,7 +47,7 @@ impl HostTrait for Host {
type Device = Device;
fn is_available() -> bool {
is_supported()
is_selector_available(&sc::StreamCfg::new())
}
fn devices(&self) -> Result<Self::Devices, DevicesError> {
@ -206,13 +202,18 @@ 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_supported() {
if !is_selector_available(&cfg) {
return Err(BuildStreamError::StreamConfigNotSupported);
}
let queue = dispatch::Queue::serial_with_ar_pool();
let cfg = audio_stream_cfg();
unsafe {
cfg.set_captures_audio(true);
cfg.set_excludes_current_process_audio(false);
cfg.set_shows_cursor(false);
}
let windows = ns::Array::new();
let filter = sc::ContentFilter::with_display_excluding_windows(&self.display, &windows);
let error_callback: delegate::ErrorCallback =
@ -429,35 +430,3 @@ 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());
}
}