Skip to content

Commit 8f7df12

Browse files
committed
Break with errors instead of panicking -_-
1 parent b21dab0 commit 8f7df12

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

crates/media/src/sources/screen_capture.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,9 @@ impl PipelineSourceTask for ScreenCaptureSource<AVFrameCapture> {
578578
let now = Instant::now();
579579
let frame_dropped = match video_tx.try_send((buffer, elapsed.as_secs_f64())) {
580580
Err(flume::TrySendError::Disconnected(_)) => {
581-
error!("Pipeline is unreachable. Shutting down recording.");
582-
return ControlFlow::Break(());
581+
return ControlFlow::Break(Err(
582+
"Pipeline is unreachable. Shutting down recording".to_string(),
583+
));
583584
}
584585
Err(flume::TrySendError::Full(_)) => {
585586
warn!("Screen capture sender is full, dropping frame");
@@ -608,8 +609,7 @@ impl PipelineSourceTask for ScreenCaptureSource<AVFrameCapture> {
608609
total_count,
609610
window_duration.as_secs()
610611
);
611-
panic!("Recording can't keep up with screen capture. Try reducing your display's resolution or refresh rate.");
612-
return ControlFlow::Break(());
612+
return ControlFlow::Break(Err("Recording can't keep up with screen capture. Try reducing your display's resolution or refresh rate.".to_string()));
613613
}
614614

615615
// Periodic logging of drop rate
@@ -642,10 +642,7 @@ impl PipelineSourceTask for ScreenCaptureSource<AVFrameCapture> {
642642
ControlFlow::Continue(())
643643
}
644644
Ok(_) => panic!("Unsupported video format"),
645-
Err(error) => {
646-
error!("Capture error: {error}");
647-
ControlFlow::Break(())
648-
}
645+
Err(error) => ControlFlow::Break(Err(format!("Capture error: {error}"))),
649646
},
650647
)
651648
}
@@ -655,7 +652,7 @@ fn inner<T: ScreenCaptureFormat>(
655652
source: &mut ScreenCaptureSource<T>,
656653
ready_signal: crate::pipeline::task::PipelineReadySignal,
657654
mut control_signal: crate::pipeline::control::PipelineControlSignal,
658-
mut get_frame: impl FnMut(&mut Capturer) -> ControlFlow<()>,
655+
mut get_frame: impl FnMut(&mut Capturer) -> ControlFlow<Result<(), String>>,
659656
) {
660657
trace!("Preparing screen capture source thread...");
661658

@@ -702,8 +699,13 @@ fn inner<T: ScreenCaptureFormat>(
702699
}
703700

704701
match get_frame(&mut capturer) {
705-
ControlFlow::Break(_) => {
702+
ControlFlow::Break(res) => {
706703
warn!("breaking from loop");
704+
705+
if let Err(e) = res {
706+
error!("Capture loop broke with error: {}", e)
707+
}
708+
707709
break;
708710
}
709711
ControlFlow::Continue(_) => {
@@ -847,10 +849,7 @@ impl PipelineSourceTask for ScreenCaptureSource<CMSampleBufferCapture> {
847849

848850
ControlFlow::Continue(())
849851
}
850-
Err(error) => {
851-
eprintln!("Capture error: {error}");
852-
ControlFlow::Break(())
853-
}
852+
Err(error) => ControlFlow::Break(Err(format!("Capture error: {error}"))),
854853
},
855854
)
856855
}

0 commit comments

Comments
 (0)