forge
Explore
Log in

Don't you dare go Hollow

S6 follow-ups — epsilon frame conversion, drop dead frames()

Browse files at this commit

79c1a91247de4f1dcf172376f4e790de3ad07b80Ahmet Kaan GümüşParent: 5372bfd
  • chore
    • S6 follow-ups — epsilon frame conversion, drop dead frames()
Show full message
🧹 chore(playback): S6 follow-ups — epsilon frame conversion, drop dead frames()

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.rsmodified+27 -8
@@ -138,12 +138,6 @@ impl PlaybackSession {
138 &self.meta138 &self.meta
139 }139 }
140 140
141- /// Decoded frames, in decode order. The channel is bounded, so leaving it
142- /// alone is what pauses the decoder.
143- pub fn frames(&self) -> &Receiver<Frame> {
144- &self.frames
145- }
146-
147 /// The next decoded frame, its `index` rewritten from a source frame to a141 /// The next decoded frame, its `index` rewritten from a source frame to a
148 /// *timeline* frame -- the only frame space that leaves the engine, and the142 /// *timeline* frame -- the only frame space that leaves the engine, and the
149 /// one [`PlaybackSession::now`] is in.143 /// one [`PlaybackSession::now`] is in.
@@ -229,7 +223,7 @@ impl PlaybackSession {
229 /// end, where there would be nothing to split off.223 /// end, where there would be nothing to split off.
230 pub fn cut_at(&mut self, timeline_secs: f64) -> bool {224 pub fn cut_at(&mut self, timeline_secs: f64) -> bool {
231 self.project225 self.project
232- .cut((timeline_secs * self.meta.frame_rate) as u32)226+ .cut(secs_to_frame(timeline_secs, self.meta.frame_rate))
233 }227 }
234 228
235 /// Removes a clip and closes the gap. Unlike a cut this *does* move every229 /// Removes a clip and closes the gap. Unlike a cut this *does* move every
@@ -307,7 +301,7 @@ impl PlaybackSession {
307 let fps = self.meta.frame_rate;301 let fps = self.meta.frame_rate;
308 let total = self.project.timeline_frames();302 let total = self.project.timeline_frames();
309 let t = secs.clamp(0.0, f64::from(total) / fps);303 let t = secs.clamp(0.0, f64::from(total) / fps);
310- let target = ((t * fps) as u32).min(total.saturating_sub(1));304+ let target = secs_to_frame(t, fps).min(total.saturating_sub(1));
311 let was_playing = self.clock.is_playing();305 let was_playing = self.clock.is_playing();
312 306
313 if let Some(audio) = &self.audio {307 if let Some(audio) = &self.audio {
@@ -479,3 +473,28 @@ fn feed(rx: Receiver<AudioChunk>, audio: &Audio, epoch: u64) {
479 }473 }
480 }474 }
481 }475 }
476+
477+/// Timeline seconds to a 0-based frame index, floor semantics: position `t`
478+/// shows the frame whose interval contains it. The epsilon absorbs float error
479+/// at exact frame boundaries -- `123.0/30.0 * 30.0` is `122.999...`, and a
480+/// bare truncation would land one frame early (S6 finding: 4 of every 300
481+/// frames round-trip wrong through `clip_spans()` seconds without this).
482+fn secs_to_frame(secs: f64, fps: f64) -> u32 {
483+ (secs * fps + 1e-6).floor().max(0.0) as u32
484+}
485+
486+#[cfg(test)]
487+mod tests {
488+ use super::secs_to_frame;
489+
490+ #[test]
491+ fn boundary_seconds_round_trip_to_their_own_frame() {
492+ for f in 0u32..300 {
493+ let secs = f64::from(f) / 30.0;
494+ assert_eq!(secs_to_frame(secs, 30.0), f, "frame {f}");
495+ }
496+ // Mid-frame positions still floor, and negatives clamp.
497+ assert_eq!(secs_to_frame(10.5 / 30.0, 30.0), 10);
498+ assert_eq!(secs_to_frame(-0.2, 30.0), 0);
499+ }
500+}