good checkpoint

This commit is contained in:
2026-04-10 02:24:09 -03:00
parent 6b6bc64ab8
commit d83576a3ba
2 changed files with 106 additions and 41 deletions

View File

@@ -66,6 +66,25 @@ pub fn run(
// Keep stdout alive for the duration of demuxing.
let _stdout_guard = stdout;
// Watch for stop flag on a separate thread and kill ffmpeg to unblock
// the packet iterator (which is a blocking read on the pipe fd).
let stop_watcher = stop.clone();
let child_pid = child.id();
std::thread::Builder::new()
.name("ffmpeg-stop-watcher".into())
.spawn(move || {
while !stop_watcher.load(Ordering::Relaxed) {
std::thread::sleep(std::time::Duration::from_millis(100));
}
// Send SIGINT to ffmpeg so it flushes and closes stdout,
// which unblocks the packet iterator in demux_and_send.
use nix::sys::signal::{kill, Signal};
use nix::unistd::Pid;
let _ = kill(Pid::from_raw(child_pid as i32), Signal::SIGINT);
info!("Stop watcher: sent SIGINT to ffmpeg pid={child_pid}");
})
.expect("spawn stop watcher");
let result = demux_and_send(fd, packet_tx, stop, &mut child);
// Clean up subprocess regardless of result.