@@ -11,9 +11,10 @@ use screencapturekit::{
11
11
sc_stream_configuration:: { PixelFormat , SCStreamConfiguration } ,
12
12
sc_types:: SCFrameStatus ,
13
13
} ;
14
+ use screencapturekit_sys:: os_types:: base:: { CMTime , CMTimeScale } ;
14
15
use screencapturekit_sys:: os_types:: geometry:: { CGPoint , CGRect , CGSize } ;
15
16
16
- use crate :: capturer:: { Area , Options , Point , Size } ;
17
+ use crate :: { capturer:: { Area , Options , Point , Size } , frame :: BGRAFrame } ;
17
18
use crate :: frame:: { Frame , FrameType } ;
18
19
use crate :: targets:: Target ;
19
20
use crate :: { capturer:: Resolution , targets} ;
@@ -45,28 +46,43 @@ impl StreamOutput for Capturer {
45
46
let frame_status = & sample. frame_status ;
46
47
47
48
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 {
51
51
FrameType :: YUVFrame => {
52
52
let yuvframe = pixelformat:: create_yuv_frame ( sample) . unwrap ( ) ;
53
- frame = Frame :: YUVFrame ( yuvframe) ;
53
+ Frame :: YUVFrame ( yuvframe)
54
54
}
55
55
FrameType :: RGB => {
56
56
let rgbframe = pixelformat:: create_rgb_frame ( sample) . unwrap ( ) ;
57
- frame = Frame :: RGB ( rgbframe) ;
57
+ Frame :: RGB ( rgbframe)
58
58
}
59
59
FrameType :: BGR0 => {
60
60
let bgrframe = pixelformat:: create_bgr_frame ( sample) . unwrap ( ) ;
61
- frame = Frame :: BGR0 ( bgrframe) ;
61
+ Frame :: BGR0 ( bgrframe)
62
62
}
63
63
FrameType :: BGRAFrame => {
64
64
let bgraframe = pixelformat:: create_bgra_frame ( sample) . unwrap ( ) ;
65
- frame = Frame :: BGRA ( bgraframe) ;
65
+ Frame :: BGRA ( bgraframe)
66
66
}
67
- }
67
+ } ;
68
68
self . tx . send ( frame) . unwrap_or ( ( ) ) ;
69
69
} ,
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
+ } ,
70
86
_ => { }
71
87
}
72
88
}
@@ -160,6 +176,12 @@ pub fn create_capturer(options: &Options, tx: mpsc::Sender<Frame>) -> SCStream {
160
176
source_rect,
161
177
pixel_format,
162
178
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
+ } ,
163
185
..Default :: default ( )
164
186
} ;
165
187
@@ -183,8 +205,8 @@ pub fn get_output_frame_size(options: &Options) -> [u32; 2] {
183
205
184
206
// Calculate the output height & width based on the required resolution
185
207
// 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 ) ;
188
210
// 1200x800
189
211
match options. output_resolution {
190
212
Resolution :: Captured => { }
0 commit comments