#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
+22
View File
@@ -674,3 +674,25 @@ fn conformed_flac_audio_reads_back_like_the_decoder() {
assert_eq!(pool.audio_samples(&f, at, 4800, 48_000), decoded);
let _ = std::fs::remove_dir_all(&folder);
}
/// #329: a frame read that is called off (a scrub has moved on) gives up before the decoder
/// seeks and decodes forward from the keyframe, so it no longer holds the decoder the newest
/// frame waits for; the frame decodes as usual when it is wanted again.
#[test]
fn a_called_off_read_does_not_decode() {
use std::sync::atomic::AtomicBool;
let Some(p) = h264_mp4() else { return };
let f = probe(&p).expect("probe");
let pool = MediaPool::new();
let t = t_of(f.frame_rate, 45);
let off = Arc::new(AtomicBool::new(true));
let mut got = None;
pool.cancellable(&off, &mut || got = Some(pool.frame(ItemId(1), &f, t)));
assert!(got.expect("ran").is_none(), "a called-off read decoded its frame");
assert_eq!(pool.stats().frames, 0, "nothing cached for it");
let on = Arc::new(AtomicBool::new(false));
let mut got = None;
pool.cancellable(&on, &mut || got = pool.frame(ItemId(1), &f, t));
let img = got.expect("decoded once wanted again");
assert_eq!((img.width, img.height), (1920, 1080));
}