Skip to content

Commit

Permalink
Support ScreenCapture loopback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kree0 authored and Kree0 committed Jul 4, 2024
1 parent 0246442 commit dfca186
Show file tree
Hide file tree
Showing 5 changed files with 432 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jack = { version = "0.11", optional = true }
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation-sys = "0.8.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
mach2 = "0.4" # For access to mach_timebase type.
screencapturekit = "0.2.8"
screencapturekit-sys = "0.2.8"

[target.'cfg(target_os = "macos")'.dependencies]
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio"] }
Expand Down
2 changes: 2 additions & 0 deletions src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub(crate) mod jack;
pub(crate) mod null;
#[cfg(target_os = "android")]
pub(crate) mod oboe;
#[cfg(target_os = "macos")]
pub(crate) mod screencapturekit;
#[cfg(windows)]
pub(crate) mod wasapi;
#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
Expand Down
46 changes: 46 additions & 0 deletions src/host/screencapturekit/enumerate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use screencapturekit::sc_shareable_content::SCShareableContent;

use std::vec::IntoIter as VecIntoIter;

use crate::{BackendSpecificError, DevicesError, SupportedStreamConfigRange};

use super::Device;

pub struct Devices(VecIntoIter<Device>);

impl Devices {
pub fn new() -> Result<Self, DevicesError> {
let sc_shareable_content = SCShareableContent::try_current()
.map_err(|description| BackendSpecificError { description })?;

let mut res = Vec::new();
for display in sc_shareable_content.displays.into_iter() {
res.push(Device::new(display));
}

Ok(Devices(res.into_iter()))
}
}

unsafe impl Send for Devices {}
unsafe impl Sync for Devices {}

impl Iterator for Devices {
type Item = Device;

fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}

pub fn default_input_device() -> Option<Device> {
let devices = Devices::new().ok()?;
devices.into_iter().next()
}

pub fn default_output_device() -> Option<Device> {
None
}

pub type SupportedInputConfigs = VecIntoIter<SupportedStreamConfigRange>;
pub type SupportedOutputConfigs = VecIntoIter<SupportedStreamConfigRange>;
Loading

0 comments on commit dfca186

Please sign in to comment.