Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/recording/src/sources/screen_capture/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ impl ScreenCaptureConfig<CMSampleBufferCapture> {
&self,
) -> anyhow::Result<(VideoSourceConfig, Option<SystemAudioSourceConfig>)> {
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))
Expand Down Expand Up @@ -128,12 +129,16 @@ impl ScreenCaptureConfig<CMSampleBufferCapture> {

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);
Expand Down
12 changes: 12 additions & 0 deletions crates/scap-screencapturekit/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<sc::StreamCfg> {
self.0
}
Expand Down