Skip to content

Commit 6751589

Browse files
Kree0Kree0
Kree0
authored and
Kree0
committed
Support ScreenCapture loopback
1 parent 0246442 commit 6751589

File tree

5 files changed

+433
-1
lines changed

5 files changed

+433
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ mach2 = "0.4" # For access to mach_timebase type.
5353

5454
[target.'cfg(target_os = "macos")'.dependencies]
5555
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio"] }
56+
screencapturekit = "0.2.8"
57+
screencapturekit-sys = "0.2.8"
5658

5759
[target.'cfg(target_os = "ios")'.dependencies]
5860
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio", "audio_toolbox"] }

src/host/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub(crate) mod jack;
2424
pub(crate) mod null;
2525
#[cfg(target_os = "android")]
2626
pub(crate) mod oboe;
27+
#[cfg(target_os = "macos")]
28+
pub(crate) mod screencapturekit;
2729
#[cfg(windows)]
2830
pub(crate) mod wasapi;
2931
#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use screencapturekit::sc_shareable_content::SCShareableContent;
2+
3+
use std::vec::IntoIter as VecIntoIter;
4+
5+
use crate::{BackendSpecificError, DevicesError, SupportedStreamConfigRange};
6+
7+
use super::Device;
8+
9+
pub struct Devices(VecIntoIter<Device>);
10+
11+
impl Devices {
12+
pub fn new() -> Result<Self, DevicesError> {
13+
let sc_shareable_content = SCShareableContent::try_current()
14+
.map_err(|description| BackendSpecificError { description })?;
15+
16+
let mut res = Vec::new();
17+
for display in sc_shareable_content.displays.into_iter() {
18+
res.push(Device::new(display));
19+
}
20+
21+
Ok(Devices(res.into_iter()))
22+
}
23+
}
24+
25+
unsafe impl Send for Devices {}
26+
unsafe impl Sync for Devices {}
27+
28+
impl Iterator for Devices {
29+
type Item = Device;
30+
31+
fn next(&mut self) -> Option<Self::Item> {
32+
self.0.next()
33+
}
34+
}
35+
36+
pub fn default_input_device() -> Option<Device> {
37+
let devices = Devices::new().ok()?;
38+
devices.into_iter().next()
39+
}
40+
41+
pub fn default_output_device() -> Option<Device> {
42+
None
43+
}
44+
45+
pub type SupportedInputConfigs = VecIntoIter<SupportedStreamConfigRange>;
46+
pub type SupportedOutputConfigs = VecIntoIter<SupportedStreamConfigRange>;

0 commit comments

Comments
 (0)