remove crash detection - was false-positive crashing every recording
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, ChildStdin, Command, Stdio};
|
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||||
use std::sync::Arc;
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
@@ -29,7 +28,6 @@ pub struct CaptureSetup {
|
|||||||
pub height: u32,
|
pub height: u32,
|
||||||
pub fps: u32,
|
pub fps: u32,
|
||||||
pub crop: Option<CaptureRect>,
|
pub crop: Option<CaptureRect>,
|
||||||
pub crashed: Arc<AtomicBool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CaptureHandler {
|
pub struct CaptureHandler {
|
||||||
@@ -38,7 +36,6 @@ pub struct CaptureHandler {
|
|||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
scratch: Vec<u8>,
|
scratch: Vec<u8>,
|
||||||
crashed: Arc<AtomicBool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicsCaptureApiHandler for CaptureHandler {
|
impl GraphicsCaptureApiHandler for CaptureHandler {
|
||||||
@@ -100,7 +97,6 @@ impl GraphicsCaptureApiHandler for CaptureHandler {
|
|||||||
width: setup.width,
|
width: setup.width,
|
||||||
height: setup.height,
|
height: setup.height,
|
||||||
scratch: Vec::with_capacity(frame_size),
|
scratch: Vec::with_capacity(frame_size),
|
||||||
crashed: setup.crashed,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,8 +120,7 @@ impl GraphicsCaptureApiHandler for CaptureHandler {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
stdin.write_all(&bytes[..expected]).map_err(|e| {
|
stdin.write_all(&bytes[..expected]).map_err(|e| {
|
||||||
tracing::error!("ffmpeg stdin write failed: {e} - encoder may have crashed");
|
tracing::error!("ffmpeg stdin write failed: {e}");
|
||||||
self.crashed.store(true, Ordering::Release);
|
|
||||||
anyhow!("ffmpeg encoder stopped unexpectedly: {e}")
|
anyhow!("ffmpeg encoder stopped unexpectedly: {e}")
|
||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -147,7 +142,6 @@ pub struct CaptureSession {
|
|||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
pub crop: Option<CaptureRect>,
|
pub crop: Option<CaptureRect>,
|
||||||
pub crashed: Arc<AtomicBool>,
|
|
||||||
control: CaptureControl<CaptureHandler, anyhow::Error>,
|
control: CaptureControl<CaptureHandler, anyhow::Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +204,6 @@ pub fn start(
|
|||||||
|
|
||||||
let (out_w, out_h) = compute_output_dims(width, height, crop);
|
let (out_w, out_h) = compute_output_dims(width, height, crop);
|
||||||
|
|
||||||
let crashed = Arc::new(AtomicBool::new(false));
|
|
||||||
|
|
||||||
let setup = CaptureSetup {
|
let setup = CaptureSetup {
|
||||||
output_path: output_path.clone(),
|
output_path: output_path.clone(),
|
||||||
ffmpeg_path,
|
ffmpeg_path,
|
||||||
@@ -219,7 +211,6 @@ pub fn start(
|
|||||||
height,
|
height,
|
||||||
fps,
|
fps,
|
||||||
crop,
|
crop,
|
||||||
crashed: crashed.clone(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let cursor_setting = if capture_cursor {
|
let cursor_setting = if capture_cursor {
|
||||||
@@ -248,7 +239,6 @@ pub fn start(
|
|||||||
width: out_w,
|
width: out_w,
|
||||||
height: out_h,
|
height: out_h,
|
||||||
crop,
|
crop,
|
||||||
crashed,
|
|
||||||
control,
|
control,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -275,10 +265,6 @@ fn compute_output_dims(monitor_w: u32, monitor_h: u32, crop: Option<CaptureRect>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CaptureSession {
|
impl CaptureSession {
|
||||||
pub fn has_crashed(&self) -> bool {
|
|
||||||
self.crashed.load(Ordering::Acquire)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn stop(self) -> Result<PathBuf> {
|
pub fn stop(self) -> Result<PathBuf> {
|
||||||
self.control
|
self.control
|
||||||
.stop()
|
.stop()
|
||||||
|
|||||||
+4
-16
@@ -420,13 +420,6 @@ fn pause_capture(state: State<'_, AppState>) -> Result<(), String> {
|
|||||||
let session = lock(&state.capture)
|
let session = lock(&state.capture)
|
||||||
.take()
|
.take()
|
||||||
.ok_or_else(|| "no capture in progress".to_string())?;
|
.ok_or_else(|| "no capture in progress".to_string())?;
|
||||||
if session.has_crashed() {
|
|
||||||
tracing::warn!("ffmpeg crashed during recording, discarding incomplete capture");
|
|
||||||
// Drop the session (cleanup), clear related state
|
|
||||||
lock(&state.audio).take();
|
|
||||||
lock(&state.click_recorder).take();
|
|
||||||
return Err("recording failed - ffmpeg encoder crashed".to_string());
|
|
||||||
}
|
|
||||||
let elapsed = session.started_at.elapsed().as_secs_f64();
|
let elapsed = session.started_at.elapsed().as_secs_f64();
|
||||||
let path = session.stop().map_err(|e| format!("{e:#}"))?;
|
let path = session.stop().map_err(|e| format!("{e:#}"))?;
|
||||||
|
|
||||||
@@ -525,15 +518,10 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedCl
|
|||||||
|
|
||||||
let live = lock(&state.capture).take();
|
let live = lock(&state.capture).take();
|
||||||
if let Some(session) = live {
|
if let Some(session) = live {
|
||||||
if session.has_crashed() {
|
let elapsed = session.started_at.elapsed().as_secs_f64();
|
||||||
// ffmpeg crashed - don't try to stop/flush, just clean up
|
let path = session.stop().map_err(|e| format!("{e:#}"))?;
|
||||||
tracing::warn!("ffmpeg crashed during recording, discarding incomplete capture");
|
ss.segments.push(path);
|
||||||
} else {
|
ss.total_recorded_secs += elapsed;
|
||||||
let elapsed = session.started_at.elapsed().as_secs_f64();
|
|
||||||
let path = session.stop().map_err(|e| format!("{e:#}"))?;
|
|
||||||
ss.segments.push(path);
|
|
||||||
ss.total_recorded_secs += elapsed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let live_audio = lock(&state.audio).take();
|
let live_audio = lock(&state.audio).take();
|
||||||
|
|||||||
Reference in New Issue
Block a user