From 20249b43e988e7ed7a3f59b15267908acda58bd3 Mon Sep 17 00:00:00 2001 From: shinyobjectz Date: Mon, 30 Nov 2026 19:06:26 -0800 Subject: [PATCH] One opener for a video (raea_io_media::open_video) and one step of React to a frame (step_react), where the render-cost work had copied each --- engine/page/src/motion.rs | 12 ++---------- io/media/src/lib.rs | 8 ++++++++ io/media/src/mezz.rs | 13 +------------ runtime/export/src/bevy_frame.rs | 8 ++++++++ runtime/export/src/fed.rs | 6 +----- runtime/export/src/keys.rs | 4 +--- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/engine/page/src/motion.rs b/engine/page/src/motion.rs index 7f0df8fa..92a8ec63 100644 --- a/engine/page/src/motion.rs +++ b/engine/page/src/motion.rs @@ -100,14 +100,6 @@ pub struct Videos { tick: u64, } -/// `file`'s decoder: RAEA_MEDIA's, the platform's, the portable one, then the ffmpeg CLI, the first that opens it. A -/// WebM is read by ffmpeg alone (#113: it was refused, "no video track", where the platform's was the only one asked). -fn open(file: &std::path::Path) -> R> { - let mut why = Vec::new(); - let d = raea_io_media::preferred().into_iter().find_map(|b| b.open_video(file).map_err(|e| why.push(format!("{}: {e}", b.name()))).ok()); - d.ok_or_else(|| format!("{}: can't be decoded ({})", file.display(), why.join("; "))) -} - /// Which of a file's readers gives frame `key`: (the reader, whether its last frame is that one). The one that gave /// it last; else the nearest one behind it within AHEAD; else one that has read nothing; else None (open another, or /// take the one asked longest ago). @@ -124,7 +116,7 @@ impl Videos { /// frame (a looped or held clip run long) gives its last frame, as raea-runtime-js's page does. pub fn frame(&mut self, v: &raea_core_wire::tree::VideoAt) -> R> { if !self.readers.contains_key(&v.file) { - self.readers.insert(v.file.clone(), vec![Reader { dec: open(&v.file)?, last: None, used: 0 }]); + self.readers.insert(v.file.clone(), vec![Reader { dec: raea_io_media::open_video(&v.file)?, last: None, used: 0 }]); } let rs = self.readers.get_mut(&v.file).unwrap(); let index = rs[0].dec.index_at(v.at).map(|i| i as i64); @@ -142,7 +134,7 @@ impl Videos { } Some(Some((i, false))) => i, Some(None) if rs.len() < READERS => { - rs.push(Reader { dec: open(&v.file)?, last: None, used: 0 }); + rs.push(Reader { dec: raea_io_media::open_video(&v.file)?, last: None, used: 0 }); rs.len() - 1 } Some(None) => rs.iter().enumerate().min_by_key(|(_, r)| r.used).map_or(0, |(i, _)| i), diff --git a/io/media/src/lib.rs b/io/media/src/lib.rs index dd2a4d29..0d9b97c6 100644 --- a/io/media/src/lib.rs +++ b/io/media/src/lib.rs @@ -71,6 +71,14 @@ pub fn backend_unsigned(name: &str) -> R> { pub mod sign; pub use sign::signs; +/// `file`'s decoder: the first of `preferred` that opens it, else what each said. A WebM is read by ffmpeg alone (#113: +/// it was refused, "no video track", where the platform's was the only one asked). +pub fn open_video(file: &Path) -> Result, String> { + let mut why = Vec::new(); + let d = preferred().into_iter().find_map(|b| b.open_video(file).map_err(|e| why.push(format!("{}: {e}", b.name()))).ok()); + d.ok_or_else(|| format!("{}: no backend reads it ({})", file.display(), why.join("; "))) +} + /// The backends to try for a file, in order: RAEA_MEDIA's, the platform's, the portable one, then the ffmpeg CLI /// (which reads what the others don't: VP9 WebM). pub fn preferred() -> Vec> { diff --git a/io/media/src/mezz.rs b/io/media/src/mezz.rs index ab5da807..739e65f3 100644 --- a/io/media/src/mezz.rs +++ b/io/media/src/mezz.rs @@ -83,18 +83,7 @@ fn encode_at(src: &Path, part: &Path, range: Option<(usize, usize)>, p: &Probe, Some((a, b)) => (a as f64 * p.frame_secs(), (b + 1) as f64 * p.frame_secs()), None => (0.0, p.secs), }; - let mut why = Vec::new(); - let mut dec = None; - for b in crate::preferred() { - match b.open_video(src) { - Ok(d) => { - dec = Some(d); - break; - } - Err(e) => why.push(format!("{}: {e}", b.name())), - } - } - let mut dec = dec.ok_or_else(|| format!("{}: no backend reads it ({})", src.display(), why.join("; ")))?; + let mut dec = crate::open_video(src)?; let info = dec.info().clone(); if info.width % 2 == 1 || info.height % 2 == 1 { return Err(format!("{}: {}x{} has an odd side (H.264's 4:2:0 wants even ones)", src.display(), info.width, info.height)); diff --git a/runtime/export/src/bevy_frame.rs b/runtime/export/src/bevy_frame.rs index 18b628f0..ce683712 100644 --- a/runtime/export/src/bevy_frame.rs +++ b/runtime/export/src/bevy_frame.rs @@ -245,6 +245,14 @@ pub(crate) fn bevy_page_frame(world: &mut World, page: &mut raea_runtime_page::B Ok((px, pics)) } +/// React told the frame is `f` (with `tell`) and settled there, a layout read answered from the page as it is then. +pub(crate) fn step_react(app: &mut App, page: &mut raea_runtime_page::BevyPage, cx: &mut Ctx, (f, fps): (i64, f64), tell: bool) -> R<()> { + if tell { app.world().resource::().send(json!({"t": "event", "name": "raea-frame", "value": f})); } + settle_with(app, Some(f), 20.0, &mut |w, q| layout_answer(w, page, cx, f, fps, q))?; + cx.now = f; + Ok(()) +} + /// A composition's layout read answered by the frame's page (`page.layout`, docs/layout-reads.feature LR1): the page made /// to match the React World as it is mid-settle, at frame `f`'s time, laid out, and every element's boxes by React id. /// Nothing is drawn; the frame's own sync redoes what this did once the frame settles. diff --git a/runtime/export/src/fed.rs b/runtime/export/src/fed.rs index b753ba97..da7e550f 100644 --- a/runtime/export/src/fed.rs +++ b/runtime/export/src/fed.rs @@ -246,11 +246,7 @@ pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, tot } let t_react = std::time::Instant::now(); engine_before(app, cx, f); - if asked != Some(f) { - app.world().resource::().send(json!({"t": "event", "name": "raea-frame", "value": f})); - } - settle_with(app, Some(f), 20.0, &mut |w, q| layout_answer(w, bevy, cx, f, fps, q))?; - cx.now = f; + step_react(app, bevy, cx, (f, fps), asked != Some(f))?; // the next frame asked for now, so React renders it on its own thread while this one's 3D and page are // drawn here: its commits wait in the inbox until the next settle applies them, so nothing this frame // reads changes (the frames come in order; one asked for out of order is asked for again) diff --git a/runtime/export/src/keys.rs b/runtime/export/src/keys.rs index c8ddc0c7..a784fd88 100644 --- a/runtime/export/src/keys.rs +++ b/runtime/export/src/keys.rs @@ -21,9 +21,7 @@ pub(crate) fn write(to: &Path, app: &mut App, page: &mut raea_runtime_page::Bevy let (mut keys, mut has3d) = (Vec::with_capacity(total.max(0) as usize), false); let (mut frames, mut tones) = (Vec::new(), Vec::new()); for f in 0..total { - app.world().resource::().send(json!({"t": "event", "name": "raea-frame", "value": f})); - settle_with(app, Some(f), 20.0, &mut |w, q| layout_answer(w, page, cx, f, fps, q))?; - cx.now = f; + step_react(app, page, cx, (f, fps), true)?; page.at_frame(f, fps); bevy_page_sync(app.world_mut(), page, cx)?; let mut h = std::collections::hash_map::DefaultHasher::new();