screencapturekit/stream/configuration/
captured_frames.rs

1use super::internal::SCStreamConfiguration;
2use crate::cm::CMTime;
3
4impl SCStreamConfiguration {
5    /// Set the queue depth for frame buffering
6    pub fn set_queue_depth(&mut self, queue_depth: u32) {
7        // FFI expects isize; u32 may wrap on 32-bit platforms (acceptable)
8        #[allow(clippy::cast_possible_wrap)]
9        unsafe {
10            crate::ffi::sc_stream_configuration_set_queue_depth(
11                self.as_ptr(),
12                queue_depth as isize,
13            );
14        }
15    }
16
17    pub fn get_queue_depth(&self) -> u32 {
18        // FFI returns isize but queue depth is always positive and fits in u32
19        #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
20        unsafe {
21            crate::ffi::sc_stream_configuration_get_queue_depth(self.as_ptr()) as u32
22        }
23    }
24
25    /// Set the minimum frame interval
26    pub fn set_minimum_frame_interval(&mut self, cm_time: &CMTime) {
27        unsafe {
28            crate::ffi::sc_stream_configuration_set_minimum_frame_interval(
29                self.as_ptr(),
30                cm_time.value,
31                cm_time.timescale,
32                cm_time.flags,
33                cm_time.epoch,
34            );
35        }
36    }
37
38    pub fn get_minimum_frame_interval(&self) -> CMTime {
39        unsafe {
40            let mut value: i64 = 0;
41            let mut timescale: i32 = 0;
42            let mut flags: u32 = 0;
43            let mut epoch: i64 = 0;
44
45            crate::ffi::sc_stream_configuration_get_minimum_frame_interval(
46                self.as_ptr(),
47                &mut value,
48                &mut timescale,
49                &mut flags,
50                &mut epoch,
51            );
52
53            CMTime {
54                value,
55                timescale,
56                flags,
57                epoch,
58            }
59        }
60    }
61
62    /// Set the capture resolution for the stream
63    ///
64    /// Available on macOS 14.0+. Controls the resolution at which content is captured.
65    ///
66    /// # Arguments
67    /// * `width` - The width in pixels
68    /// * `height` - The height in pixels
69    pub fn set_capture_resolution(&mut self, width: usize, height: usize) {
70        // FFI expects isize for dimensions (Objective-C NSInteger)
71        #[allow(clippy::cast_possible_wrap)]
72        unsafe {
73            crate::ffi::sc_stream_configuration_set_capture_resolution(
74                self.as_ptr(),
75                width as isize,
76                height as isize,
77            );
78        }
79    }
80
81    /// Get the configured capture resolution
82    ///
83    /// Returns (width, height) tuple
84    pub fn get_capture_resolution(&self) -> (usize, usize) {
85        // FFI returns isize but dimensions are always positive
86        #[allow(clippy::cast_sign_loss)]
87        unsafe {
88            let mut width: isize = 0;
89            let mut height: isize = 0;
90            crate::ffi::sc_stream_configuration_get_capture_resolution(
91                self.as_ptr(),
92                &mut width,
93                &mut height,
94            );
95            (width as usize, height as usize)
96        }
97    }
98}