|
1 | | -use scap_targets::Display; |
2 | | -use std::time::Duration; |
3 | | - |
4 | | -use futures::executor::block_on; |
5 | | -use scap_screencapturekit::{Capturer, StreamCfgBuilder}; |
6 | | - |
7 | 1 | fn main() { |
8 | | - let display = Display::primary(); |
9 | | - let display = display.raw_handle(); |
10 | | - |
11 | | - // let windows = block_on(Window::list()).expect("Failed to list windows"); |
12 | | - // let window = windows |
13 | | - // .iter() |
14 | | - // .find(|w| w.title().map(|t| t.starts_with("native")).unwrap_or(false)) |
15 | | - // .expect("No native window found"); |
16 | | - |
17 | | - let config = StreamCfgBuilder::default() |
18 | | - .with_fps(60.0) |
19 | | - .with_width(display.physical_size().width() as usize) |
20 | | - .with_height(display.physical_size().height() as usize) |
21 | | - .build(); |
22 | | - |
23 | | - let capturer = Capturer::builder( |
24 | | - block_on(display.as_content_filter()).expect("Failed to get display as content filter"), |
25 | | - config, |
26 | | - ) |
27 | | - .with_output_sample_buf_cb(|frame| { |
28 | | - dbg!(frame.output_type()); |
29 | | - // if let Some(image_buf) = buf.image_buf() { |
30 | | - // image_buf.show(); |
31 | | - // } |
32 | | - }) |
33 | | - .with_stop_with_err_cb(|stream, error| { |
34 | | - dbg!(stream, error); |
35 | | - }) |
36 | | - .build() |
37 | | - .expect("Failed to build capturer"); |
38 | | - |
39 | | - block_on(capturer.start()).expect("Failed to start capturing"); |
40 | | - |
41 | | - std::thread::sleep(Duration::from_secs(3)); |
42 | | - |
43 | | - block_on(capturer.stop()).expect("Failed to stop capturing"); |
44 | | - |
45 | | - std::thread::sleep(Duration::from_secs(1)); |
| 2 | + #[cfg(target_os = "macos")] |
| 3 | + macos::main(); |
| 4 | +} |
| 5 | + |
| 6 | +#[cfg(target_os = "macos")] |
| 7 | +mod macos { |
| 8 | + |
| 9 | + use scap_targets::Display; |
| 10 | + use std::time::Duration; |
| 11 | + |
| 12 | + use futures::executor::block_on; |
| 13 | + use scap_screencapturekit::{Capturer, StreamCfgBuilder}; |
| 14 | + |
| 15 | + fn main() { |
| 16 | + let display = Display::primary(); |
| 17 | + let display = display.raw_handle(); |
| 18 | + |
| 19 | + // let windows = block_on(Window::list()).expect("Failed to list windows"); |
| 20 | + // let window = windows |
| 21 | + // .iter() |
| 22 | + // .find(|w| w.title().map(|t| t.starts_with("native")).unwrap_or(false)) |
| 23 | + // .expect("No native window found"); |
| 24 | + |
| 25 | + let config = StreamCfgBuilder::default() |
| 26 | + .with_fps(60.0) |
| 27 | + .with_width(display.physical_size().width() as usize) |
| 28 | + .with_height(display.physical_size().height() as usize) |
| 29 | + .build(); |
| 30 | + |
| 31 | + let capturer = Capturer::builder( |
| 32 | + block_on(display.as_content_filter()).expect("Failed to get display as content filter"), |
| 33 | + config, |
| 34 | + ) |
| 35 | + .with_output_sample_buf_cb(|frame| { |
| 36 | + dbg!(frame.output_type()); |
| 37 | + // if let Some(image_buf) = buf.image_buf() { |
| 38 | + // image_buf.show(); |
| 39 | + // } |
| 40 | + }) |
| 41 | + .with_stop_with_err_cb(|stream, error| { |
| 42 | + dbg!(stream, error); |
| 43 | + }) |
| 44 | + .build() |
| 45 | + .expect("Failed to build capturer"); |
| 46 | + |
| 47 | + block_on(capturer.start()).expect("Failed to start capturing"); |
| 48 | + |
| 49 | + std::thread::sleep(Duration::from_secs(3)); |
| 50 | + |
| 51 | + block_on(capturer.stop()).expect("Failed to stop capturing"); |
| 52 | + |
| 53 | + std::thread::sleep(Duration::from_secs(1)); |
| 54 | + } |
46 | 55 | } |
0 commit comments