#329: superseded viewer frames call off their footage decodes

Problem: scrubbing a long movie showed the frame under the pointer
seconds after the pointer stopped. Every viewer frame a free frame-pool
thread had started kept running: each seeked the movie's one decoder and
decoded up to a GOP, and the newest frame waited behind all of them on
the decoder's lock (45 min 1080p H.264/HEVC, GOP 250: 1.8-3.6 s for the
last frame of a drag; a single jump is 0.1-0.4 s). FilmCraft's decoder
already polls a cancellation flag, but nothing set one.

Fix: FootageSource::cancellable / called_off and CancellableFootage (a
per-render view whose frame reads run under the render's own flag, so
reads on other threads answer to the right render). MediaPool runs them
under filmcraft_media::cancel::with_cancel. The frame workers render
through it, and a newer viewer frame calls off the comp's running viewer
frames of other times. A called-off render is not cached (frames, disk,
layer cache). Drag latency is now 0.1-0.3 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-10-11 13:01:54 +02:00
co-authored by Claude Opus 5.5
parent 9a7d3e7699
commit a0decc80dd
6 changed files with 260 additions and 13 deletions
+4
View File
@@ -35,6 +35,9 @@ pub enum MediaError {
Unsupported(String),
#[error("decode error: {0}")]
Decode(String),
/// The read was called off before it finished (see [`effectcraft_render::FootageSource::cancellable`]).
#[error("cancelled")]
Cancelled,
}
pub type Result<T> = std::result::Result<T, MediaError>;
@@ -45,6 +48,7 @@ impl From<filmcraft_media::MediaError> for MediaError {
match e {
F::Unsupported(s) => MediaError::Unsupported(s),
F::Io(s) | F::Offline(s) => MediaError::Io(s),
F::Cancelled => MediaError::Cancelled,
other => MediaError::Decode(other.to_string()),
}
}
+8
View File
@@ -355,6 +355,8 @@ impl MediaPool {
}
match Inner::frame_at(&self.inner, footage, t, true, size) {
Ok(img) => Some(img),
// nobody wants the frame any more (`cancellable`): not an error
Err(MediaError::Cancelled) => None,
Err(e) => {
log::warn!("media: frame of {} at {:?}: {e}", footage.path, t);
None
@@ -791,6 +793,12 @@ impl FootageSource for MediaPool {
fn cache_budget(&self) -> Option<usize> {
Some(self.budget())
}
/// A movie's decoder gives up on a seek (before it, and between samples while it decodes
/// forward from the keyframe) once `cancel` is set: a scrub's superseded frames no longer
/// hold the decoder the frame under the pointer waits for (#329).
fn cancellable(&self, cancel: &Arc<AtomicBool>, f: &mut dyn FnMut()) {
filmcraft_media::cancel::with_cancel(cancel, f)
}
fn frame(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<Image>> {
self.frame_sized(item, footage, t, None)
}