From 79c1a91247de4f1dcf172376f4e790de3ad07b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 9 Aug 2026 17:42:54 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20chore(playback):=20S6=20follow-u?= =?UTF-8?q?ps=20=E2=80=94=20epsilon=20frame=20conversion,=20drop=20dead=20?= =?UTF-8?q?frames()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit secs_to_frame with 1e-6 epsilon: bare truncation landed one frame early for boundary seconds (122.999... -> 122); floor semantics kept for mid-frame positions. frames() getter had zero callers since the app moved to try_frame(). --- crates/engine/src/playback.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 6299886..1e421d3 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -138,12 +138,6 @@ impl PlaybackSession { &self.meta } - /// Decoded frames, in decode order. The channel is bounded, so leaving it - /// alone is what pauses the decoder. - pub fn frames(&self) -> &Receiver { - &self.frames - } - /// The next decoded frame, its `index` rewritten from a source frame to a /// *timeline* frame -- the only frame space that leaves the engine, and the /// one [`PlaybackSession::now`] is in. @@ -229,7 +223,7 @@ impl PlaybackSession { /// end, where there would be nothing to split off. pub fn cut_at(&mut self, timeline_secs: f64) -> bool { self.project - .cut((timeline_secs * self.meta.frame_rate) as u32) + .cut(secs_to_frame(timeline_secs, self.meta.frame_rate)) } /// Removes a clip and closes the gap. Unlike a cut this *does* move every @@ -307,7 +301,7 @@ impl PlaybackSession { let fps = self.meta.frame_rate; let total = self.project.timeline_frames(); let t = secs.clamp(0.0, f64::from(total) / fps); - let target = ((t * fps) as u32).min(total.saturating_sub(1)); + let target = secs_to_frame(t, fps).min(total.saturating_sub(1)); let was_playing = self.clock.is_playing(); if let Some(audio) = &self.audio { @@ -479,3 +473,28 @@ fn feed(rx: Receiver, audio: &Audio, epoch: u64) { } } } + +/// Timeline seconds to a 0-based frame index, floor semantics: position `t` +/// shows the frame whose interval contains it. The epsilon absorbs float error +/// at exact frame boundaries -- `123.0/30.0 * 30.0` is `122.999...`, and a +/// bare truncation would land one frame early (S6 finding: 4 of every 300 +/// frames round-trip wrong through `clip_spans()` seconds without this). +fn secs_to_frame(secs: f64, fps: f64) -> u32 { + (secs * fps + 1e-6).floor().max(0.0) as u32 +} + +#[cfg(test)] +mod tests { + use super::secs_to_frame; + + #[test] + fn boundary_seconds_round_trip_to_their_own_frame() { + for f in 0u32..300 { + let secs = f64::from(f) / 30.0; + assert_eq!(secs_to_frame(secs, 30.0), f, "frame {f}"); + } + // Mid-frame positions still floor, and negatives clamp. + assert_eq!(secs_to_frame(10.5 / 30.0, 30.0), 10); + assert_eq!(secs_to_frame(-0.2, 30.0), 0); + } +}