Skip to content

Commit db662d8

Browse files
committed
bruh
1 parent 197d2b9 commit db662d8

File tree

4 files changed

+60
-46
lines changed

4 files changed

+60
-46
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/enc-mediafoundation/examples/cli.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ mod win {
161161
}
162162
}
163163
MediaFoundation::METransformHaveOutput => {
164-
let output_sample = video_encoder.handle_has_output().unwrap();
165-
sample_writer.write(stream_index, &output_sample).unwrap();
164+
if let Some(output_sample) =
165+
video_encoder.handle_has_output().unwrap()
166+
{
167+
sample_writer.write(stream_index, &output_sample).unwrap();
168+
}
166169
}
167170
_ => {}
168171
}
Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,55 @@
1-
use scap_targets::Display;
2-
use std::time::Duration;
3-
4-
use futures::executor::block_on;
5-
use scap_screencapturekit::{Capturer, StreamCfgBuilder};
6-
71
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+
}
4655
}

crates/scap-targets/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ windows = { workspace = true, features = [
2828
"Win32_UI_HiDpi",
2929
"Win32_Graphics_Dwm",
3030
"Win32_Graphics_Gdi",
31+
"Win32_Graphics_Capture",
3132
"Win32_Storage_FileSystem",
3233
] }

0 commit comments

Comments
 (0)