Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Improve atomic ordering and error handling in output pipeline

Richie McIlroy458df6bba949
diff --git a/crates/recording/src/output_pipeline/core.rs b/crates/recording/src/output_pipeline/core.rs
index f2cf4331b..0767f0af9 100644
--- a/crates/recording/src/output_pipeline/core.rs
+++ b/crates/recording/src/output_pipeline/core.rs
@@ -53,7 +53,7 @@ impl SharedPauseState {
.lock()
.map_err(|e| anyhow!("Lock poisoned: {e}"))?;
- if self.flag.load(Ordering::Relaxed) {
+ if self.flag.load(Ordering::Acquire) {
if inner.paused_at.is_none() {
inner.paused_at = Some(timestamp);
}
@@ -791,11 +791,11 @@ impl OutputPipeline {
}
pub fn pause(&self) {
- self.pause_flag.store(true, atomic::Ordering::Relaxed);
+ self.pause_flag.store(true, atomic::Ordering::Release);
}
pub fn resume(&self) {
- self.pause_flag.store(false, atomic::Ordering::Relaxed);
+ self.pause_flag.store(false, atomic::Ordering::Release);
}
pub fn video_info(&self) -> Option<VideoInfo> {
diff --git a/crates/recording/src/output_pipeline/macos_fragmented_m4s.rs b/crates/recording/src/output_pipeline/macos_fragmented_m4s.rs
index 8dcf21a57..0246c8f8f 100644
--- a/crates/recording/src/output_pipeline/macos_fragmented_m4s.rs
+++ b/crates/recording/src/output_pipeline/macos_fragmented_m4s.rs
@@ -216,7 +216,10 @@ impl Muxer for MacOSFragmentedM4SMuxer {
}
}
Err(_) => {
- warn!("Encoder mutex poisoned during finish");
+ error!("Encoder mutex poisoned during finish - encoder thread likely panicked");
+ return Ok(Err(anyhow!(
+ "Encoder mutex poisoned - recording may be corrupt or incomplete"
+ )));
}
}
}
@@ -305,7 +308,8 @@ impl MacOSFragmentedM4SMuxer {
}
}
Err(_) => {
- warn!("Encoder mutex poisoned, skipping frame");
+ error!("Encoder mutex poisoned - encoder thread likely panicked, stopping");
+ return Err(anyhow!("Encoder mutex poisoned - all subsequent frames would be lost"));
}
}
@@ -706,7 +710,12 @@ impl Muxer for MacOSFragmentedM4SCameraMuxer {
}
}
Err(_) => {
- warn!("Camera encoder mutex poisoned during finish");
+ error!(
+ "Camera encoder mutex poisoned during finish - encoder thread likely panicked"
+ );
+ return Ok(Err(anyhow!(
+ "Camera encoder mutex poisoned - recording may be corrupt or incomplete"
+ )));
}
}
}
@@ -797,7 +806,8 @@ impl MacOSFragmentedM4SCameraMuxer {
}
}
Err(_) => {
- warn!("Camera encoder mutex poisoned, skipping frame");
+ error!("Camera encoder mutex poisoned - encoder thread likely panicked, stopping");
+ return Err(anyhow!("Camera encoder mutex poisoned - all subsequent frames would be lost"));
}
}
diff --git a/crates/recording/src/output_pipeline/win.rs b/crates/recording/src/output_pipeline/win.rs
index 2f4b1a8d6..48eb9e4f6 100644
--- a/crates/recording/src/output_pipeline/win.rs
+++ b/crates/recording/src/output_pipeline/win.rs
@@ -39,7 +39,7 @@ impl PauseTracker {
}
fn adjust(&mut self, timestamp: Duration) -> anyhow::Result<Option<Duration>> {
- if self.flag.load(Ordering::Relaxed) {
+ if self.flag.load(Ordering::Acquire) {
if self.paused_at.is_none() {
self.paused_at = Some(timestamp);
}
diff --git a/crates/recording/src/output_pipeline/win_fragmented_m4s.rs b/crates/recording/src/output_pipeline/win_fragmented_m4s.rs
index 4afc996e1..44148b827 100644
--- a/crates/recording/src/output_pipeline/win_fragmented_m4s.rs
+++ b/crates/recording/src/output_pipeline/win_fragmented_m4s.rs
@@ -218,7 +218,10 @@ impl Muxer for WindowsFragmentedM4SMuxer {
}
}
Err(_) => {
- warn!("Encoder mutex poisoned during finish");
+ error!("Encoder mutex poisoned during finish - encoder thread likely panicked");
+ return Ok(Err(anyhow!(
+ "Encoder mutex poisoned - recording may be corrupt or incomplete"
+ )));
}
}
}
@@ -295,7 +298,8 @@ impl WindowsFragmentedM4SMuxer {
}
}
Err(_) => {
- warn!("Encoder mutex poisoned, skipping frame");
+ error!("Encoder mutex poisoned - encoder thread likely panicked, stopping");
+ return Err(anyhow!("Encoder mutex poisoned - all subsequent frames would be lost"));
}
}
@@ -536,7 +540,12 @@ impl Muxer for WindowsFragmentedM4SCameraMuxer {
}
}
Err(_) => {
- warn!("Camera encoder mutex poisoned during finish");
+ error!(
+ "Camera encoder mutex poisoned during finish - encoder thread likely panicked"
+ );
+ return Ok(Err(anyhow!(
+ "Camera encoder mutex poisoned - recording may be corrupt or incomplete"
+ )));
}
}
}
@@ -614,7 +623,8 @@ impl WindowsFragmentedM4SCameraMuxer {
}
}
Err(_) => {
- warn!("Camera encoder mutex poisoned, skipping frame");
+ error!("Camera encoder mutex poisoned - encoder thread likely panicked, stopping");
+ return Err(anyhow!("Camera encoder mutex poisoned - all subsequent frames would be lost"));
}
}
diff --git a/crates/recording/src/output_pipeline/win_segmented.rs b/crates/recording/src/output_pipeline/win_segmented.rs
index ab8e29a14..69b36ef5f 100644
--- a/crates/recording/src/output_pipeline/win_segmented.rs
+++ b/crates/recording/src/output_pipeline/win_segmented.rs
@@ -103,7 +103,7 @@ impl PauseTracker {
}
fn adjust(&mut self, timestamp: Duration) -> anyhow::Result<Option<Duration>> {
- if self.flag.load(Ordering::Relaxed) {
+ if self.flag.load(Ordering::Acquire) {
if self.paused_at.is_none() {
self.paused_at = Some(timestamp);
}
diff --git a/crates/recording/src/output_pipeline/win_segmented_camera.rs b/crates/recording/src/output_pipeline/win_segmented_camera.rs
index c6081da7b..ee3618db2 100644
--- a/crates/recording/src/output_pipeline/win_segmented_camera.rs
+++ b/crates/recording/src/output_pipeline/win_segmented_camera.rs
@@ -103,7 +103,7 @@ impl PauseTracker {
}
fn adjust(&mut self, timestamp: Duration) -> anyhow::Result<Option<Duration>> {
- if self.flag.load(Ordering::Relaxed) {
+ if self.flag.load(Ordering::Acquire) {
if self.paused_at.is_none() {
self.paused_at = Some(timestamp);
}