Skip to content

Commit 1844a0c

Browse files
authored
Merge pull request #107 from CapSoftware/main
Upgrades/fixes from Cap fork
2 parents ac7c50b + fedca13 commit 1844a0c

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

src/capturer/engine/mac/mod.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use screencapturekit::{
1111
sc_stream_configuration::{PixelFormat, SCStreamConfiguration},
1212
sc_types::SCFrameStatus,
1313
};
14+
use screencapturekit_sys::os_types::base::{CMTime, CMTimeScale};
1415
use screencapturekit_sys::os_types::geometry::{CGPoint, CGRect, CGSize};
1516

16-
use crate::capturer::{Area, Options, Point, Size};
17+
use crate::{capturer::{Area, Options, Point, Size}, frame::BGRAFrame};
1718
use crate::frame::{Frame, FrameType};
1819
use crate::targets::Target;
1920
use crate::{capturer::Resolution, targets};
@@ -45,28 +46,43 @@ impl StreamOutput for Capturer {
4546
let frame_status = &sample.frame_status;
4647

4748
match frame_status {
48-
SCFrameStatus::Complete => unsafe {
49-
let frame;
50-
match self.output_type {
49+
SCFrameStatus::Complete | SCFrameStatus::Started => unsafe {
50+
let frame = match self.output_type {
5151
FrameType::YUVFrame => {
5252
let yuvframe = pixelformat::create_yuv_frame(sample).unwrap();
53-
frame = Frame::YUVFrame(yuvframe);
53+
Frame::YUVFrame(yuvframe)
5454
}
5555
FrameType::RGB => {
5656
let rgbframe = pixelformat::create_rgb_frame(sample).unwrap();
57-
frame = Frame::RGB(rgbframe);
57+
Frame::RGB(rgbframe)
5858
}
5959
FrameType::BGR0 => {
6060
let bgrframe = pixelformat::create_bgr_frame(sample).unwrap();
61-
frame = Frame::BGR0(bgrframe);
61+
Frame::BGR0(bgrframe)
6262
}
6363
FrameType::BGRAFrame => {
6464
let bgraframe = pixelformat::create_bgra_frame(sample).unwrap();
65-
frame = Frame::BGRA(bgraframe);
65+
Frame::BGRA(bgraframe)
6666
}
67-
}
67+
};
6868
self.tx.send(frame).unwrap_or(());
6969
},
70+
SCFrameStatus::Idle => {
71+
// Quick hack - just send an empty frame, and the caller can figure out how to handle it
72+
match self.output_type {
73+
FrameType::BGRAFrame => {
74+
let display_time = sample.sys_ref.get_presentation_timestamp().value as u64;
75+
let frame = BGRAFrame {
76+
display_time,
77+
width: 0,
78+
height: 0,
79+
data: vec![],
80+
};
81+
self.tx.send(Frame::BGRA(frame)).unwrap_or(());
82+
},
83+
_ => {}
84+
}
85+
},
7086
_ => {}
7187
}
7288
}
@@ -160,6 +176,12 @@ pub fn create_capturer(options: &Options, tx: mpsc::Sender<Frame>) -> SCStream {
160176
source_rect,
161177
pixel_format,
162178
shows_cursor: options.show_cursor,
179+
minimum_frame_interval: CMTime {
180+
value: 1,
181+
timescale: options.fps as CMTimeScale,
182+
epoch: 0,
183+
flags: 1,
184+
},
163185
..Default::default()
164186
};
165187

@@ -183,8 +205,8 @@ pub fn get_output_frame_size(options: &Options) -> [u32; 2] {
183205

184206
// Calculate the output height & width based on the required resolution
185207
// Output width and height need to be multiplied by scale (or dpi)
186-
let mut output_width = (source_rect.size.width as u32) * scale_factor as u32;
187-
let mut output_height = (source_rect.size.height as u32) * scale_factor as u32;
208+
let mut output_width = (source_rect.size.width as u32) * (scale_factor as u32);
209+
let mut output_height = (source_rect.size.height as u32) * (scale_factor as u32);
188210
// 1200x800
189211
match options.output_resolution {
190212
Resolution::Captured => {}

src/main.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,12 @@ fn main() {
2424
}
2525
}
2626

27-
// Get recording targets
28-
let targets = scap::get_all_targets();
29-
println!("🎯 Targets: {:?}", targets);
30-
31-
let vscode_win = targets
32-
.into_iter()
33-
.find(|target| match target {
34-
Target::Display(_) => false,
35-
Target::Window(w) => w.title.contains("Visual Studio Code"),
36-
})
37-
.expect("Visual Studio Code window not found");
27+
// // Get recording targets
28+
// let targets = scap::get_all_targets();
3829

3930
// Create Options
4031
let options = Options {
4132
fps: 60,
42-
target: Some(vscode_win),
4333
show_cursor: true,
4434
show_highlight: true,
4535
excluded_targets: None,

0 commit comments

Comments
 (0)