-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix ID issue refcount * Fix ID issue refcount
- Loading branch information
Showing
4 changed files
with
114 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use std::{path::PathBuf, thread, time}; | ||
|
||
use screencapturekit::{ | ||
cm_sample_buffer::CMSampleBuffer, | ||
sc_content_filter::{InitParams, SCContentFilter}, | ||
sc_error_handler::StreamErrorHandler, | ||
sc_output_handler::{SCStreamOutputType, StreamOutput}, | ||
sc_shareable_content::SCShareableContent, | ||
sc_stream::SCStream, | ||
sc_stream_configuration::SCStreamConfiguration, | ||
}; | ||
use screencapturekit_sys::os_types::geometry::{CGPoint, CGRect, CGSize}; | ||
|
||
struct ErrorHandler; | ||
impl StreamErrorHandler for ErrorHandler { | ||
fn on_error(&self) { | ||
println!("Error!"); | ||
} | ||
} | ||
|
||
pub struct Capturer {} | ||
|
||
impl Capturer { | ||
pub fn new() -> Self { | ||
println!("Capturer initialized"); | ||
Capturer {} | ||
} | ||
} | ||
|
||
impl StreamErrorHandler for Capturer { | ||
fn on_error(&self) { | ||
eprintln!("ERROR!"); | ||
} | ||
} | ||
|
||
impl StreamOutput for Capturer { | ||
fn did_output_sample_buffer(&self, sample: CMSampleBuffer, of_type: SCStreamOutputType) { | ||
println!("New frame recvd"); | ||
} | ||
} | ||
fn main() { | ||
println!("Starting"); | ||
|
||
let content = SCShareableContent::current(); | ||
let displays = content.displays; | ||
|
||
let display = displays.first().unwrap_or_else(|| { | ||
panic!("Main display not found"); | ||
}); | ||
let display = display.to_owned(); | ||
|
||
let width = display.width; | ||
let height = display.height; | ||
|
||
let params = InitParams::Display(display); | ||
let filter = SCContentFilter::new(params); | ||
|
||
let stream_config = SCStreamConfiguration { | ||
width, | ||
height, | ||
..Default::default() | ||
}; | ||
|
||
let mut stream = SCStream::new(filter, stream_config, ErrorHandler); | ||
let capturer = Capturer::new(); | ||
stream.add_output(capturer, SCStreamOutputType::Screen); | ||
|
||
stream.start_capture(); | ||
|
||
let ten_millis = time::Duration::from_millis(10000); | ||
|
||
thread::sleep(ten_millis); | ||
|
||
stream.stop_capture(); | ||
|
||
println!("Ended"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters