diff --git a/crates/recording/src/sources/screen_capture/macos.rs b/crates/recording/src/sources/screen_capture/macos.rs index 4cc228a41b..2482d49abb 100644 --- a/crates/recording/src/sources/screen_capture/macos.rs +++ b/crates/recording/src/sources/screen_capture/macos.rs @@ -68,7 +68,8 @@ impl ScreenCaptureConfig { &self, ) -> anyhow::Result<(VideoSourceConfig, Option)> { let (error_tx, error_rx) = broadcast::channel(1); - let (video_tx, video_rx) = flume::bounded(4); + // Increased from 4 to 12 to provide more buffer tolerance for frame processing delays + let (video_tx, video_rx) = flume::bounded(12); let (mut audio_tx, audio_rx) = if self.system_audio { let (tx, rx) = mpsc::channel(32); (Some(tx), Some(rx)) @@ -128,12 +129,16 @@ impl ScreenCaptureConfig { debug!("size: {:?}", size); + let queue_depth = ((self.config.fps as f32 / 30.0 * 5.0).ceil() as isize).clamp(3, 8); + debug!("Using queue depth: {}", queue_depth); + let mut settings = scap_screencapturekit::StreamCfgBuilder::default() .with_width(size.width() as usize) .with_height(size.height() as usize) .with_fps(self.config.fps as f32) .with_shows_cursor(self.config.show_cursor) .with_captures_audio(self.system_audio) + .with_queue_depth(queue_depth) .build(); settings.set_pixel_format(cv::PixelFormat::_32_BGRA); diff --git a/crates/scap-screencapturekit/src/config.rs b/crates/scap-screencapturekit/src/config.rs index 5787959c70..e99e4a9a7d 100644 --- a/crates/scap-screencapturekit/src/config.rs +++ b/crates/scap-screencapturekit/src/config.rs @@ -35,6 +35,13 @@ impl StreamCfgBuilder { self.0.set_captures_audio(captures_audio); } + /// Sets the queue depth (number of frames to buffer). + /// Higher values provide more tolerance for processing delays but use more memory. + /// Apple's default is 3. Maximum is 8. + pub fn set_queue_depth(&mut self, depth: isize) { + self.0.set_queue_depth(depth.min(8)); + } + /// Logical width of the capture area pub fn with_width(mut self, width: usize) -> Self { self.set_width(width); @@ -68,6 +75,11 @@ impl StreamCfgBuilder { self } + pub fn with_queue_depth(mut self, depth: isize) -> Self { + self.set_queue_depth(depth); + self + } + pub fn build(self) -> arc::R { self.0 }