Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(recording): finalize the camera writer when its encoder thread errors

Richie McIlroy2fc12b2ab17d
diff --git a/crates/recording/src/output_pipeline/macos.rs b/crates/recording/src/output_pipeline/macos.rs
index b491936fb..15ed1a5ea 100644
--- a/crates/recording/src/output_pipeline/macos.rs
+++ b/crates/recording/src/output_pipeline/macos.rs
@@ -1300,14 +1300,34 @@ impl Muxer for AVFoundationCameraMuxer {
let mut can_finish_encoder = true;
- if let Some(handle) = state.encoder_handle.take()
- && let Err(e) =
- wait_for_worker(handle, Duration::from_secs(5), "Camera MP4 encoder thread")
- {
- warn!("{e:#}");
- can_finish_encoder = false;
- if finish_error.is_none() {
- finish_error = Some(e);
+ if let Some(handle) = state.encoder_handle.take() {
+ match wait_for_blocking_thread_finish(
+ handle,
+ Duration::from_secs(5),
+ "Camera MP4 encoder thread",
+ ) {
+ BlockingThreadFinish::Clean => {}
+ // The thread exited with an error (writer failure, disk
+ // exhaustion): the encoder mutex is free and finalizing
+ // is what preserves the moov, so fall through to
+ // encoder.finish() below. Skipping it here used to leave
+ // camera.mp4 headerless and unplayable on every encoder
+ // thread error.
+ BlockingThreadFinish::Failed(error) => {
+ warn!("{error:#}");
+ if finish_error.is_none() {
+ finish_error = Some(error);
+ }
+ }
+ // The thread is still alive and may hold the encoder
+ // mutex; locking it for finish() could block forever.
+ BlockingThreadFinish::TimedOut(error) => {
+ warn!("{error:#}");
+ can_finish_encoder = false;
+ if finish_error.is_none() {
+ finish_error = Some(error);
+ }
+ }
}
}