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

This commit is contained in:
shinyobjectz committed 2026-11-30 19:06:26 -08:00
1 parent 88223b9388
commit 20249b43e9
6 files changed
+21 -30

No files matched your search

+2 -10
View File
@@ -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<Box<dyn raea_io_media::VideoDecoder>> {
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<Option<raea_io_media::Frame>> {
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),
+8
View File
@@ -71,6 +71,14 @@ pub fn backend_unsigned(name: &str) -> R<Box<dyn Backend>> {
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<Box<dyn VideoDecoder>, 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<Box<dyn Backend>> {
+1 -12
View File
@@ -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));
+8
View File
@@ -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::<ReactOutbox>().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.
+1 -5
View File
@@ -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::<ReactOutbox>().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)
+1 -3
View File
@@ -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::<ReactOutbox>().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();