Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add retry limit to video frame queuing

Richie McIlroyb2a9d8e0b160
diff --git a/crates/recording/src/output_pipeline/macos.rs b/crates/recording/src/output_pipeline/macos.rs
index 1f1df6536..2b3a74de5 100644
--- a/crates/recording/src/output_pipeline/macos.rs
+++ b/crates/recording/src/output_pipeline/macos.rs
@@ -63,6 +63,8 @@ impl Muxer for AVFoundationMp4Muxer {
impl VideoMuxer for AVFoundationMp4Muxer {
type VideoFrame = screen_capture::VideoFrame;
+ const MAX_QUEUE_RETRIES: u32 = 500;
+
fn send_video_frame(
&mut self,
frame: Self::VideoFrame,
@@ -76,10 +78,18 @@ impl VideoMuxer for AVFoundationMp4Muxer {
mp4.resume();
}
+ let mut retry_count = 0;
loop {
match mp4.queue_video_frame(frame.sample_buf.clone(), timestamp) {
Ok(()) => break,
Err(QueueFrameError::NotReadyForMore) => {
+ retry_count += 1;
+ if retry_count >= Self::MAX_QUEUE_RETRIES {
+ return Err(anyhow!(
+ "send_video_frame/timeout after {} retries",
+ Self::MAX_QUEUE_RETRIES
+ ));
+ }
std::thread::sleep(Duration::from_millis(2));
continue;
}