Skip to content

Commit 07cab19

Browse files
Kree0Kree0
Kree0
authored andcommitted
Support ScreenCapture loopback
1 parent 582e93c commit 07cab19

File tree

5 files changed

+456
-1
lines changed

5 files changed

+456
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ 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+
cidre = { git = "https://github.com/yury/cidre.git", rev = "f05c428" }
5657

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

src/host/mod.rs

+2
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"))]
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use std::vec::IntoIter as VecIntoIter;
2+
3+
use cidre::sc;
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 (tx, rx) = std::sync::mpsc::channel();
14+
sc::ShareableContent::current_with_ch(move |a, b| {
15+
let mut res = Result::Err(BackendSpecificError {
16+
description: "Failed to get current shareable content".to_string(),
17+
});
18+
if let Some(err) = b {
19+
res = Result::Err(BackendSpecificError {
20+
description: format!("{err}"),
21+
});
22+
}
23+
if let Some(sc) = a {
24+
res = Result::Ok(sc.retained());
25+
}
26+
tx.send(res).unwrap();
27+
});
28+
let sc_shareable_content = rx.recv().unwrap()?;
29+
30+
let mut res = Vec::new();
31+
for display in sc_shareable_content.displays().iter() {
32+
res.push(Device::new(display.retained()));
33+
}
34+
35+
Ok(Devices(res.into_iter()))
36+
}
37+
}
38+
39+
unsafe impl Send for Devices {}
40+
unsafe impl Sync for Devices {}
41+
42+
impl Iterator for Devices {
43+
type Item = Device;
44+
45+
fn next(&mut self) -> Option<Self::Item> {
46+
self.0.next()
47+
}
48+
}
49+
50+
pub fn default_input_device() -> Option<Device> {
51+
let devices = Devices::new().ok()?;
52+
devices.into_iter().next()
53+
}
54+
55+
pub fn default_output_device() -> Option<Device> {
56+
None
57+
}
58+
59+
pub type SupportedInputConfigs = VecIntoIter<SupportedStreamConfigRange>;
60+
pub type SupportedOutputConfigs = VecIntoIter<SupportedStreamConfigRange>;

0 commit comments

Comments
 (0)