Compare commits
1 commit
osx-screen
...
kd/b283-sc
| Author | SHA1 | Date | |
|---|---|---|---|
| 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