Skip to content

Commit e851e41

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

File tree

5 files changed

+456
-1
lines changed

5 files changed

+456
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
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

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: 60 additions & 0 deletions
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 |sc, e| {
15+
let res = if let Some(err) = e {
16+
Result::Err(BackendSpecificError {
17+
description: format!("{err}"),
18+
})
19+
} else if let Some(sc) = sc {
20+
Result::Ok(sc.retained())
21+
} else {
22+
Result::Err(BackendSpecificError {
23+
description: "Failed to get current shareable content".to_string(),
24+
})
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy