Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Adjust queue and frame pool sizes based on frame rate

Richie McIlroybc6850f98fd8
diff --git a/crates/recording/src/output_pipeline/win.rs b/crates/recording/src/output_pipeline/win.rs
index a9c5a756e..5b635396d 100644
--- a/crates/recording/src/output_pipeline/win.rs
+++ b/crates/recording/src/output_pipeline/win.rs
@@ -113,7 +113,9 @@ impl Muxer for WindowsMuxer {
let output_size = config.output_size.unwrap_or(input_size);
let fragmented = config.fragmented;
let frag_duration_us = config.frag_duration_us;
- let (video_tx, video_rx) = sync_channel::<Option<(scap_direct3d::Frame, Duration)>>(8);
+ let queue_depth = ((config.frame_rate as f32 / 30.0 * 5.0).ceil() as usize).clamp(3, 12);
+ let (video_tx, video_rx) =
+ sync_channel::<Option<(scap_direct3d::Frame, Duration)>>(queue_depth);
let mut output = ffmpeg::format::output(&output_path)?;
diff --git a/crates/recording/src/output_pipeline/win_segmented.rs b/crates/recording/src/output_pipeline/win_segmented.rs
index bdb839304..7976712d6 100644
--- a/crates/recording/src/output_pipeline/win_segmented.rs
+++ b/crates/recording/src/output_pipeline/win_segmented.rs
@@ -354,7 +354,9 @@ impl WindowsSegmentedMuxer {
};
let output_size = self.output_size.unwrap_or(input_size);
- let (video_tx, video_rx) = sync_channel::<Option<(scap_direct3d::Frame, Duration)>>(8);
+ let queue_depth = ((self.frame_rate as f32 / 30.0 * 5.0).ceil() as usize).clamp(3, 12);
+ let (video_tx, video_rx) =
+ sync_channel::<Option<(scap_direct3d::Frame, Duration)>>(queue_depth);
let (ready_tx, ready_rx) = sync_channel::<anyhow::Result<()>>(1);
let output = ffmpeg::format::output(&segment_path)?;
let output = Arc::new(Mutex::new(output));
diff --git a/crates/recording/src/sources/screen_capture/windows.rs b/crates/recording/src/sources/screen_capture/windows.rs
index a62d59e3c..a73932037 100644
--- a/crates/recording/src/sources/screen_capture/windows.rs
+++ b/crates/recording/src/sources/screen_capture/windows.rs
@@ -99,6 +99,8 @@ impl ScreenCaptureConfig<Direct3DCapture> {
Some(Duration::from_secs_f64(1.0 / self.config.fps as f64));
}
+ settings.fps = Some(self.config.fps);
+
// Store the display ID instead of GraphicsCaptureItem to avoid COM threading issues
// The GraphicsCaptureItem will be created on the capture thread
Ok((
diff --git a/crates/scap-direct3d/src/lib.rs b/crates/scap-direct3d/src/lib.rs
index c7f3bcd32..77ebf6140 100644
--- a/crates/scap-direct3d/src/lib.rs
+++ b/crates/scap-direct3d/src/lib.rs
@@ -164,6 +164,7 @@ pub struct Settings {
pub min_update_interval: Option<Duration>,
pub pixel_format: PixelFormat,
pub crop: Option<D3D11_BOX>,
+ pub fps: Option<u32>,
}
impl Settings {
@@ -298,10 +299,15 @@ impl Capturer {
})()
.map_err(NewCapturerError::Direct3DDevice)?;
+ let frame_pool_size = settings
+ .fps
+ .map(|fps| ((fps as f32 / 30.0 * 2.0).ceil() as i32).clamp(2, 4))
+ .unwrap_or(2);
+
let frame_pool = Direct3D11CaptureFramePool::CreateFreeThreaded(
&direct3d_device,
settings.pixel_format.as_directx(),
- 1,
+ frame_pool_size,
item.Size().map_err(NewCapturerError::ItemSize)?,
)
.map_err(NewCapturerError::FramePool)?;