Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(rendering): request frame slack is four f32 steps of the request time, not a twentieth of a frame
Richie McIlroyc8978600bdb2
diff --git a/crates/rendering/src/decoder/mod.rs b/crates/rendering/src/decoder/mod.rsindex 573a69eb9..0620f0ed5 100644--- a/crates/rendering/src/decoder/mod.rs+++ b/crates/rendering/src/decoder/mod.rs@@ -704,17 +704,19 @@ pub(crate) fn probe_yuv_matrix(path: &std::path::Path) -> YuvMatrix {.unwrap_or_default()}-/// Frames of slack in [`request_frame`]. A request time is an f32, so the-/// time of frame `n` can come out a hair below `n / fps` (126 / 30 s is-/// 4.1999998 s) and floor to the frame before. The f32 error stays under 0.05-/// frames for two hours at 120 fps, and the slack moves a frame boundary by-/// at most 0.05 frames.-const REQUEST_SLACK_FRAMES: f64 = 0.05;+/// f32 steps of slack in [`request_frame`]. The time of frame `n` is the+/// f32 nearest `n / fps`, up to half a step below it (126 / 30 s is+/// 4.1999998 s), plus a step or two from the offsets added on the way; a+/// plain floor then asks for the frame before.+const REQUEST_SLACK_STEPS: f32 = 4.0;/// The decoder grid index a request for `time` asks for: the frame on screen-/// at `time`, `floor(time * fps)` up to [`REQUEST_SLACK_FRAMES`].+/// at `time`, `floor(time * fps)` once `time` is lifted by+/// [`REQUEST_SLACK_STEPS`] f32 steps.pub fn request_frame(time: f32, fps: u32) -> u32 {- (f64::from(time) * f64::from(fps) + REQUEST_SLACK_FRAMES).floor() as u32+ let magnitude = time.abs();+ let step = f32::from_bits(magnitude.to_bits() + 1) - magnitude;+ ((f64::from(time) + f64::from(step * REQUEST_SLACK_STEPS)) * f64::from(fps)).floor() as u32}pub fn pts_to_frame(pts: i64, time_base: Rational, fps: u32) -> u32 {diff --git a/crates/rendering/src/decoder/model/expectations.toml b/crates/rendering/src/decoder/model/expectations.tomlindex def17c753..edb3f5db6 100644--- a/crates/rendering/src/decoder/model/expectations.toml+++ b/crates/rendering/src/decoder/model/expectations.toml@@ -53,21 +53,21 @@ link = ""[[xfail]]case = "decoder-model/ffmpeg/cfr/keyframe-seeks/playback"class = "grid-rounding"-seeds = "12 23 39 46 56 62 65 79 90 107 115 117 122 129 140-141 147-149 161 181 183 188 194 199-201 203 206-207 209 216 222-223 234-235 237 239 241 248 250 266 268 275 291 294"+seeds = "8 12 23 39 46 56 62 65 79 90 107 115 117 119 122 129 140-141 147-149 154 161 169 181 183 188 192 194-195 197 199-201 203 205-207 209 216 222-223 234-235 237 239 241 248 250 253 256 266 268 275 283 291 294"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""[[xfail]]case = "decoder-model/ffmpeg/cfr/random-seeks/playback"class = "grid-rounding"-seeds = "31 52 57 61 63 69 74 80 93 117 120 126 153 166 180 182 196 279 297"+seeds = "31 52 57 61 63 69 74 80 93 117 120 126 153 166 180 182 196 251 279 297"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""[[xfail]]case = "decoder-model/ffmpeg/cfr/scrub/playback"class = "grid-rounding"-seeds = "30 63 107 122 126 143 149 187"+seeds = "30 62-63 107 122 126 143 149 187 199"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""@@ -88,35 +88,35 @@ link = ""[[xfail]]case = "decoder-model/ffmpeg/cfr/transition/playback"class = "grid-rounding"-seeds = "29 42 51 66"+seeds = "19 29 42 51 65-66"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""[[xfail]]case = "decoder-model/ffmpeg/dense/random-seeks/playback"class = "grid-rounding"-seeds = "1 7 15 21-22 25 33 35-36 45 47 55 64 70 82 86 90 100 103 114-115 121 126 144"+seeds = "1 7 15 17 21-22 25 33 35-36 45 47-48 55 64 70 82 86 90 100 103 114-115 121 126 144"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""[[xfail]]case = "decoder-model/ffmpeg/vfr/keyframe-seeks/playback"class = "grid-rounding"-seeds = "2 4-5 9 11 13 18 23 27 29 31-32 36 41 50 59 62-63 70-73 76 81-82 84 88-90 95"+seeds = "2 4-5 9 11 13 18 23 27 29 31-32 36 41 48 50 59 62-63 70-73 76 81-82 84 88-91 95"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""[[xfail]]case = "decoder-model/ffmpeg/vfr/random-seeks/playback"class = "grid-rounding"-seeds = "3 16 20 34 46 58-59 77-78 86 117 137 144 160 168 196"+seeds = "3 12 16 20 34 46 58-59 64 77-78 86 117 137 144 160 168 196"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""[[xfail]]case = "decoder-model/ffmpeg/vfr/scrub/playback"class = "grid-rounding"-seeds = "30 114"+seeds = "23 30 46 114"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""@@ -137,6 +137,6 @@ link = ""[[xfail]]case = "decoder-model/ffmpeg/vfr/transition/playback"class = "grid-rounding"-seeds = "13 16 20 48 62 70 75 77"+seeds = "13 16 20 34 48 62 70 75 77"reason = "NEW: the FFmpeg decoder seeks to the exact request time, so after a reset it answers with the frame on screen at that time even when its rounded grid label is after the request; sequential playback shows the previous frame for the same request"link = ""diff --git a/crates/rendering/src/decoder/model/mod.rs b/crates/rendering/src/decoder/model/mod.rsindex aa53994cd..db96c0672 100644--- a/crates/rendering/src/decoder/model/mod.rs+++ b/crates/rendering/src/decoder/model/mod.rs@@ -13,7 +13,7 @@//! a sample is labelled `round(fps * pts_seconds)` on the decoder grid, where//! FFmpeg measures pts from the stream start time and AVAssetReader from//! zero. A request for time `t` asks for grid index `request_frame(t, fps)`,-//! `floor(t * fps)` with slack for the f32 request time. The+//! `floor(t * fps)` with a few f32 steps of slack for the request time. The//! correct answer is the newest sample whose label is at or before that index//! (the frame on screen at `t`); when several samples share that label any of//! them is accepted. A request before the first sample is answered with the