forked from AugmendTech/CrabGrab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_diagnostic.rs
49 lines (47 loc) · 2.17 KB
/
feature_diagnostic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::time::Duration;
use crabgrab::{feature::diagnostic::FrameDiagnosticExt, prelude::*};
fn main() {
let runtime = tokio::runtime::Builder::new_multi_thread()
.build().unwrap();
let future = runtime.spawn(async {
let token = match CaptureStream::test_access(true) {
Some(token) => token,
None => CaptureStream::request_access(true).await.expect("Expected capture access")
};
let filter = CapturableContentFilter::NORMAL_WINDOWS;
let content = CapturableContent::new(filter).await.unwrap();
let window = content.windows().filter(|window| {
let app_identifier = window.application().identifier();
window.title().len() != 0 && (app_identifier.to_lowercase().contains("terminal") || app_identifier.to_lowercase().contains("explorer"))
}).next();
match window {
Some(window) => {
let config = CaptureConfig::with_window(window, CapturePixelFormat::Bgra8888).unwrap();
let mut diag_done = false;
let mut stream = CaptureStream::new(token, config, move |stream_event| {
match stream_event {
Ok(event) => {
match event {
StreamEvent::Video(frame) => {
if !diag_done {
println!("Frame diagnostic: {:?}", frame.diagnostic());
diag_done = true;
}
},
_ => {}
}
},
Err(error) => {
println!("Stream error: {:?}", error);
}
}
}).unwrap();
tokio::task::block_in_place(|| std::thread::sleep(Duration::from_millis(2000)));
stream.stop().unwrap();
},
None => { println!("Failed to find window"); }
}
});
runtime.block_on(future).unwrap();
runtime.shutdown_timeout(Duration::from_millis(100000));
}