Merge pull request #784 from vangel76/fix-329-seek-latency

#329: scrubbing a long movie: superseded viewer frames call off their decodes

# Conflicts:
#	crates/media/tests/footage.rs
This commit is contained in:
Brandon Thomas
2026-10-12 03:22:50 -04:00
6 changed files with 260 additions and 13 deletions
+4
View File
@@ -37,6 +37,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>;
@@ -47,6 +50,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
@@ -357,6 +357,8 @@ impl MediaPool {
}
match Inner::frame_at(&self.inner, footage, t, true, size, float) {
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
@@ -806,6 +808,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, FloatCurve::Srgb)
}
+22
View File
@@ -967,3 +967,25 @@ fn cineon_still_shows_code_values() {
assert!(effectcraft_media::probe_bytes("cut.cin", cut).is_err(), "{n}");
}
}
/// #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));
}