Skip to content

Commit 79aa1ba

Browse files
authored
Increase SCK queue depth to avoid timeouts (#1344)
* Increase SCK queue depth to avoid timeouts * max out queueDepth at 8 as instructed by apple docs
1 parent 7766a65 commit 79aa1ba

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/recording/src/sources/screen_capture/macos.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ impl ScreenCaptureConfig<CMSampleBufferCapture> {
6868
&self,
6969
) -> anyhow::Result<(VideoSourceConfig, Option<SystemAudioSourceConfig>)> {
7070
let (error_tx, error_rx) = broadcast::channel(1);
71-
let (video_tx, video_rx) = flume::bounded(4);
71+
// Increased from 4 to 12 to provide more buffer tolerance for frame processing delays
72+
let (video_tx, video_rx) = flume::bounded(12);
7273
let (mut audio_tx, audio_rx) = if self.system_audio {
7374
let (tx, rx) = mpsc::channel(32);
7475
(Some(tx), Some(rx))
@@ -128,12 +129,16 @@ impl ScreenCaptureConfig<CMSampleBufferCapture> {
128129

129130
debug!("size: {:?}", size);
130131

132+
let queue_depth = ((self.config.fps as f32 / 30.0 * 5.0).ceil() as isize).clamp(3, 8);
133+
debug!("Using queue depth: {}", queue_depth);
134+
131135
let mut settings = scap_screencapturekit::StreamCfgBuilder::default()
132136
.with_width(size.width() as usize)
133137
.with_height(size.height() as usize)
134138
.with_fps(self.config.fps as f32)
135139
.with_shows_cursor(self.config.show_cursor)
136140
.with_captures_audio(self.system_audio)
141+
.with_queue_depth(queue_depth)
137142
.build();
138143

139144
settings.set_pixel_format(cv::PixelFormat::_32_BGRA);

crates/scap-screencapturekit/src/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ impl StreamCfgBuilder {
3535
self.0.set_captures_audio(captures_audio);
3636
}
3737

38+
/// Sets the queue depth (number of frames to buffer).
39+
/// Higher values provide more tolerance for processing delays but use more memory.
40+
/// Apple's default is 3. Maximum is 8.
41+
pub fn set_queue_depth(&mut self, depth: isize) {
42+
self.0.set_queue_depth(depth.min(8));
43+
}
44+
3845
/// Logical width of the capture area
3946
pub fn with_width(mut self, width: usize) -> Self {
4047
self.set_width(width);
@@ -68,6 +75,11 @@ impl StreamCfgBuilder {
6875
self
6976
}
7077

78+
pub fn with_queue_depth(mut self, depth: isize) -> Self {
79+
self.set_queue_depth(depth);
80+
self
81+
}
82+
7183
pub fn build(self) -> arc::R<sc::StreamCfg> {
7284
self.0
7385
}

0 commit comments

Comments
 (0)