diff --git a/crates/engine/src/decode.rs b/crates/engine/src/decode.rs index 3a8a3cd..6fe674b 100644 --- a/crates/engine/src/decode.rs +++ b/crates/engine/src/decode.rs @@ -44,6 +44,15 @@ impl Worker { self.cancel.store(true, Ordering::Release); } + /// Whether the thread has already returned, i.e. dropping this would not + /// wait. `true` for a worker that never had a thread. What lets a caller + /// park cancelled workers and reap them without ever blocking. + pub(crate) fn is_finished(&self) -> bool { + self.handle + .as_ref() + .is_none_or(thread::JoinHandle::is_finished) + } + /// Lets the worker run on unwatched -- what the public API does, since it /// hands out the flag alone. fn detach(mut self) -> Arc { diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 36e503b..390309d 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -84,10 +84,21 @@ impl Audio { pub struct PlaybackSession { meta: VideoMeta, frames: Receiver, - /// The current decode worker. Replacing or dropping this field cancels and - /// joins the previous one, so no abandoned worker outlives the session -- - /// which is what keeps a worker out of the driver's teardown at exit. + /// The current decode worker. worker: Worker, + /// Workers cancelled by a seek or a clip change, waiting to be reaped. + /// Joining one inline costs whatever VA-API init it is still inside (98 ms + /// measured worst case), which is a visible hitch on the caller's thread; + /// parking it here instead makes that free, and [`retire`] drops the ones + /// that have already returned every time it adds another. + /// + /// Never a leak, and that is the invariant: everything in here is joined + /// when the session drops (`Vec`'s own drop does it, one + /// [`Worker::drop`] each), so no decode worker can outlive the session and + /// meet Mesa's `atexit` handlers from inside libva. + /// + /// [`retire`]: PlaybackSession::retire + retired: Vec, clock: PlaybackClock, audio: Option