forge
Explore
Log in

Don't you dare go Hollow

A 25 GB film reads on a worker, and the window says so while it does

Browse files at this commit

a2d201dd7ea458a0823bf2b8fadc80f22a3c4788Ahmet Kaan GümüşParent: 27097e2
  • feat
    • a 25 GB film reads on a worker, and the window says so while it does
Show full message
✨ feat(import): a 25 GB film reads on a worker, and the window says so while it does

The freeze was one call: `Demuxer::open` on a cold 29 GB remux is 11 s
(measured), and it ran on the UI thread at every import door. Nothing else
came close -- the subtitle walk is 200 ms, and the two reads that really are
slow (probe_streams 3 s, waveform 55 s) were already off the render thread.

So a queued worker reads what the import is about to read and throws it away:
the second read costs 150 ms because the pages are warm. The timeline keeps
playing through the eleven seconds, and a line above the panel names the file,
the stage and an elapsed clock -- and, past five seconds in one stage, says
outright that the wait is the file's and not the window's. No percentage
anywhere: neither read reports where in the file it has come to, and a bar that
invented one would be the lie the freeze already tells.

The rest of argv goes through the same door now. Three films on the command
line used to be half a minute of no window at all, and a window that has not
opened cannot say why.
crates/app/src/main.rsmodified+414 -41
@@ -336,6 +336,39 @@ enum Wave {
336 Peaks(Arc<Vec<(f32, f32)>>),336 Peaks(Arc<Vec<(f32, f32)>>),
337 }337 }
338 338
339+/// The import a worker is reading, as the line above the panel shows it. No
340+/// fraction anywhere: neither read reports how far into the file it has come,
341+/// so what is honest is the file's name, the stage, and two clocks -- one that
342+/// proves the window is answering, one that says the stage has not moved.
343+struct Import {
344+ path: PathBuf,
345+ /// When the worker started, for the elapsed clock.
346+ started: Instant,
347+ /// Written by the worker between its two reads, read here every repaint.
348+ stage: Arc<std::sync::atomic::AtomicU8>,
349+ /// The stage the line last saw and when it last changed. The pair is the
350+ /// whole stall detector: a stage older than [`IMPORT_STALL`] is what the
351+ /// honest wording is for.
352+ seen: ImportStage,
353+ since: Instant,
354+}
355+
356+impl Import {
357+ /// Reads the worker's stage and keeps the stall clock: it restarts when the
358+ /// stage actually changes and at no other time, which is what makes "has
359+ /// not moved in five seconds" a fact rather than a guess about the elapsed
360+ /// clock. Hands back how long the current stage has stood, so the line has
361+ /// one place to ask.
362+ fn poll(&mut self) -> f32 {
363+ let stage = ImportStage::from_u8(self.stage.load(std::sync::atomic::Ordering::Relaxed));
364+ if stage != self.seen {
365+ self.seen = stage;
366+ self.since = Instant::now();
367+ }
368+ self.since.elapsed().as_secs_f32()
369+ }
370+}
371+
339 /// A library row being dragged: the file and which of its audio streams that372 /// A library row being dragged: the file and which of its audio streams that
340 /// row is, which is the whole of what a row names. Where it lands does not373 /// row is, which is the whole of what a row names. Where it lands does not
341 /// change what is inserted.374 /// change what is inserted.
@@ -1114,6 +1147,12 @@ struct Player {
1114 /// rolling-window estimate the progress line reads; see [`note_progress`].1147 /// rolling-window estimate the progress line reads; see [`note_progress`].
1115 export_started: Option<Instant>,1148 export_started: Option<Instant>,
1116 export_marks: Vec<(f32, f32)>,1149 export_marks: Vec<(f32, f32)>,
1150+ /// The file an import worker is reading right now, and the files waiting
1151+ /// behind it in arrival order. Unlike an export, an import owns nothing:
1152+ /// the editor stays live, the timeline keeps playing, and the only thing
1153+ /// this holds is the line above the panel ([`Player::import_bar`]).
1154+ importing: Option<Import>,
1155+ imports: std::collections::VecDeque<PathBuf>,
1117 /// Where an export writes. Built once from the source path, which is not1156 /// Where an export writes. Built once from the source path, which is not
1118 /// otherwise kept.1157 /// otherwise kept.
1119 export_path: PathBuf,1158 export_path: PathBuf,
@@ -3673,12 +3712,86 @@ impl Player {
3673 Some((info.sample_rate, info.channels))3712 Some((info.sample_rate, info.channels))
3674 }3713 }
3675 3714
3676- /// Takes a file into the library and nowhere else: the timeline is not3715+ /// Queues a file for the library. Nothing is read here: the reading is
3677- /// touched, and the row is dragged onto a lane when it is wanted there. A3716+ /// [`read_ahead`] on a worker, and [`Player::take_import`] is what finally
3678- /// drop is not a key press, so the export guard on the key handler does not3717+ /// touches the timeline, one repaint later and with the pages warm. A drop
3679- /// cover it and this checks for itself. Nothing moves, so nothing reseeks;3718+ /// is not a key press, so the export guard on the key handler does not
3680- /// a refusal is shown as the engine worded it and changes nothing.3719+ /// cover it and this checks for itself.
3720+ ///
3721+ /// One file at a time, in arrival order: a drop can carry six and argv can
3722+ /// name more, and six header walks racing over one disk finish no sooner
3723+ /// than six in a row -- while the line above the panel has exactly one file
3724+ /// to name.
3681 fn import(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {3725 fn import(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {
3726+ if self.exporting().is_some() {
3727+ return;
3728+ }
3729+ self.imports.push_back(path.to_path_buf());
3730+ self.start_import(cx);
3731+ }
3732+
3733+ /// Starts the worker for the next queued file, if no worker is running.
3734+ /// Called again as each import lands, which is what drains the queue.
3735+ fn start_import(&mut self, cx: &mut Context<Self>) {
3736+ if self.importing.is_some() {
3737+ return;
3738+ }
3739+ let Some(path) = self.imports.pop_front() else {
3740+ return;
3741+ };
3742+ let stage = Arc::new(std::sync::atomic::AtomicU8::new(ImportStage::Header as u8));
3743+ let read = cx.background_executor().spawn({
3744+ let (path, stage) = (path.clone(), Arc::clone(&stage));
3745+ async move { read_ahead(&path, &stage) }
3746+ });
3747+ let now = Instant::now();
3748+ self.importing = Some(Import {
3749+ path: path.clone(),
3750+ started: now,
3751+ stage,
3752+ seen: ImportStage::Header,
3753+ since: now,
3754+ });
3755+ cx.spawn(async move |this, cx| {
3756+ read.await;
3757+ this.update(cx, |this, cx| {
3758+ this.importing = None;
3759+ this.take_import(&path, cx);
3760+ // The next one is started by the repaint this notified, which
3761+ // is also what starts the files argv named ([`poll_import`]).
3762+ })
3763+ .ok();
3764+ })
3765+ .detach();
3766+ cx.notify();
3767+ }
3768+
3769+ /// Keeps the import line's two clocks honest: the elapsed one runs from the
3770+ /// worker, and the stall one from the last time the stage it is naming
3771+ /// actually changed. Sampled here rather than while drawing, for
3772+ /// [`Player::poll_export`]'s reason.
3773+ ///
3774+ /// ...and starts whatever is queued behind it, which is the one place the
3775+ /// files argv named can begin: they are put in the queue before there is a
3776+ /// context to spawn a worker from.
3777+ fn poll_import(&mut self, cx: &mut Context<Self>) {
3778+ match &mut self.importing {
3779+ Some(import) => {
3780+ import.poll();
3781+ }
3782+ None => self.start_import(cx),
3783+ }
3784+ }
3785+
3786+ /// Takes a read-ahead file into the library and nowhere else: the timeline
3787+ /// is not touched, and the row is dragged onto a lane when it is wanted
3788+ /// there. Nothing moves, so nothing reseeks; a refusal is shown as the
3789+ /// engine worded it and changes nothing.
3790+ ///
3791+ /// The export guard again, and not for the caller's sake: an export can
3792+ /// have started during the seconds the worker was reading, and a drop
3793+ /// during an export has always been a silent no-op.
3794+ fn take_import(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {
3682 if self.exporting().is_some() {3795 if self.exporting().is_some() {
3683 return;3796 return;
3684 }3797 }
@@ -4371,6 +4484,7 @@ impl Render for Player {
4371 }4484 }
4372 self.pump(window);4485 self.pump(window);
4373 self.poll_export();4486 self.poll_export();
4487+ self.poll_import(cx);
4374 // Every way a source can arrive -- argv, an import, a project load --4488 // Every way a source can arrive -- argv, an import, a project load --
4375 // has been through a repaint by the time its clips are drawn, so this4489 // has been through a repaint by the time its clips are drawn, so this
4376 // is the one place that has to notice a new one.4490 // is the one place that has to notice a new one.
@@ -4394,7 +4508,14 @@ impl Render for Player {
4394 // the screen on a repaint. A notice does not: it waits to be dismissed4508 // the screen on a repaint. A notice does not: it waits to be dismissed
4395 // rather than for a clock, so keeping the loop alive for it would spin4509 // rather than for a clock, so keeping the loop alive for it would spin
4396 // the GPU until someone answered it.4510 // the GPU until someone answered it.
4397- if state.is_playing() || self.pending_seek || self.export.is_some() {4511+ // An import does too, and for the same reason: its clock and its sweep
4512+ // only reach the screen on a repaint, and a still line is the very
4513+ // thing it exists to disprove.
4514+ if state.is_playing()
4515+ || self.pending_seek
4516+ || self.export.is_some()
4517+ || self.importing.is_some()
4518+ {
4398 window.request_animation_frame();4519 window.request_animation_frame();
4399 }4520 }
4400 4521
@@ -4981,7 +5102,10 @@ impl Render for Player {
4981 ),5102 ),
4982 )5103 )
4983 // Above the panel and only when there is one to show, so it costs5104 // Above the panel and only when there is one to show, so it costs
4984- // the picture nothing the rest of the time.5105+ // the picture nothing the rest of the time. The import's line sits
5106+ // over the notice's: a notice is about something that has already
5107+ // happened, and this is about something still happening.
5108+ .children(self.import_bar())
4985 .children(self.notice_bar(cx))5109 .children(self.notice_bar(cx))
4986 .child(self.panel(position, duration, state, cx))5110 .child(self.panel(position, duration, state, cx))
4987 // Over the panel it was opened on, and under the cards: it is only5111 // Over the panel it was opened on, and under the cards: it is only
@@ -6284,6 +6408,63 @@ impl Player {
6284 .children(strip)6408 .children(strip)
6285 }6409 }
6286 6410
6411+ /// The running import holds its own bar above the notice's, for the notice
6412+ /// bar's reason: the message is the point. Not a notice, though -- nothing
6413+ /// dismisses it, because it is about work still going on, and it leaves by
6414+ /// itself when the file lands.
6415+ ///
6416+ /// The bar under the words is a *sweep*, not a fill: neither read reports
6417+ /// where in the file it is, so a fill would have to invent the one number
6418+ /// this cannot know. What it does say truthfully is "something is still
6419+ /// running", which is exactly the question a frozen-looking window raises.
6420+ fn import_bar(&self) -> Option<impl IntoElement> {
6421+ let import = self.importing.as_ref()?;
6422+ let elapsed = import.started.elapsed().as_secs_f32();
6423+ let line = import_line(
6424+ &file_name(&import.path),
6425+ import.seen,
6426+ elapsed,
6427+ import.since.elapsed().as_secs_f32(),
6428+ self.imports.len(),
6429+ );
6430+ // A quarter of the bar, crossing it every three seconds and wrapping.
6431+ // Tied to the elapsed clock, so it moves for as long as the read does
6432+ // and stops dead the instant the file lands.
6433+ const SWEEP: f32 = 0.25;
6434+ let at = (elapsed / 3.).fract() * (1. + SWEEP) - SWEEP;
6435+ Some(
6436+ div()
6437+ .flex_none()
6438+ .flex()
6439+ .flex_col()
6440+ .gap(px(4.))
6441+ .px(px(12.))
6442+ .py(px(6.))
6443+ .bg(rgb(SURFACE))
6444+ .child(div().flex_1().min_w(px(0.)).child(line))
6445+ .child(
6446+ div()
6447+ .relative()
6448+ .w_full()
6449+ .h(px(2.))
6450+ .bg(rgb(HOVER))
6451+ .child(
6452+ div()
6453+ .absolute()
6454+ .top_0()
6455+ .left(relative(at.max(0.)))
6456+ // Clipped at both ends by hand: the segment
6457+ // enters from the left edge and leaves past the
6458+ // right one, and a width that overhung would
6459+ // paint outside the track.
6460+ .w(relative((at + SWEEP).min(1.) - at.max(0.)))
6461+ .h(px(2.))
6462+ .bg(rgb(ACCENT)),
6463+ ),
6464+ ),
6465+ )
6466+ }
6467+
6287 /// A notice holds its own bar, full width, until it is answered: any key6468 /// A notice holds its own bar, full width, until it is answered: any key
6288 /// retires it (the key handler) and so does a click on it. Its own surface6469 /// retires it (the key handler) and so does a click on it. Its own surface
6289 /// because the message is the point -- a failure cut to the timecode's slot6470 /// because the message is the point -- a failure cut to the timecode's slot
@@ -9535,6 +9716,43 @@ fn is_matroska(path: &std::path::Path) -> bool {
9535 .is_some_and(|e| matches!(e.to_ascii_lowercase().as_str(), "mkv" | "webm"))9716 .is_some_and(|e| matches!(e.to_ascii_lowercase().as_str(), "mkv" | "webm"))
9536 }9717 }
9537 9718
9719+/// Reads, off the UI thread, exactly what the import that follows is about to
9720+/// read -- and throws every byte away. The point is the page cache: a cold
9721+/// header walk of a 29 GB remux is 11 s and a warm one is 150 ms (measured,
9722+/// `a real 4K HEVC film` 2160p h265), so this call is the eleven seconds and
9723+/// [`Player::take_import`] is the hundred and fifty milliseconds. The window
9724+/// keeps painting through the eleven.
9725+///
9726+/// Errors are dropped on purpose: a file that cannot be read is refused by the
9727+/// engine a moment later, in the engine's own words, and a refusal read twice
9728+/// is a refusal worded twice.
9729+///
9730+/// `stage` is what the line above the panel is naming while this runs.
9731+///
9732+/// ponytail: the cache is the whole handoff, so a machine that evicts those
9733+/// pages between this read and the next frame pays the cold walk on the UI
9734+/// thread after all. Ceiling: memory pressure inside one repaint of a 25 GB
9735+/// file. The upgrade is an engine door that takes the header this already
9736+/// parsed ([`PlaybackSession::import`] opens the demuxer again today).
9737+fn read_ahead(path: &std::path::Path, stage: &std::sync::atomic::AtomicU8) {
9738+ use std::sync::atomic::Ordering::Relaxed;
9739+ stage.store(ImportStage::Header as u8, Relaxed);
9740+ // The three doors an import goes through, each warmed by the call the
9741+ // engine will make: a song is measured by its duration, a still by its
9742+ // header, and everything else by the container's.
9743+ if engine::is_audio(path) {
9744+ engine::AudioSession::duration_secs(path).ok();
9745+ } else if !engine::is_image(path) && !is_subtitle(path) {
9746+ engine::demux::Demuxer::open(path).ok();
9747+ }
9748+ stage.store(ImportStage::Subtitles as u8, Relaxed);
9749+ // ...and the tracks inside it, which `subtitle_notice` walks straight
9750+ // after. A standalone `.srt` is small enough to be nobody's wait.
9751+ if is_matroska(path) {
9752+ engine::subtitle::of_matroska(path).ok();
9753+ }
9754+}
9755+
9538 /// The subtitle tracks a media file carries, taken into the session as it is9756 /// The subtitle tracks a media file carries, taken into the session as it is
9539 /// opened, and the tail the notice grows for them: an mkv with subtitles in it9757 /// opened, and the tail the notice grows for them: an mkv with subtitles in it
9540 /// arrives with its subtitles, because a track nobody imported is a track nobody9758 /// arrives with its subtitles, because a track nobody imported is a track nobody
@@ -9543,10 +9761,11 @@ fn is_matroska(path: &std::path::Path) -> bool {
9543 /// A refusal is a tail too, never a failure of the open: the picture and the9761 /// A refusal is a tail too, never a failure of the open: the picture and the
9544 /// sound of a film whose subtitle tracks cannot be walked are still the film.9762 /// sound of a film whose subtitle tracks cannot be walked are still the film.
9545 ///9763 ///
9546-/// ponytail: the walk reads the whole file for its cues9764+/// The walk reads the whole file for its cues
9547-/// (`engine::subtitle::of_matroska`), so a long film pauses at the open it is9765+/// (`engine::subtitle::of_matroska`) -- ~200 ms on a two-hour 4K remux, and an
9548-/// part of. Ceiling: a two-hour remux. The upgrade is the background executor9766+/// *import* pays it on a worker first ([`read_ahead`]), so what happens here is
9549-/// the waveforms already use, with the rows arriving when it lands.9767+/// the warm second pass. A file *opened* at launch still pays it cold: there is
9768+/// no window yet to say so in.
9550 fn subtitle_notice(session: &mut PlaybackSession, path: &std::path::Path) -> Option<String> {9769 fn subtitle_notice(session: &mut PlaybackSession, path: &std::path::Path) -> Option<String> {
9551 if !is_matroska(path) {9770 if !is_matroska(path) {
9552 return None;9771 return None;
@@ -12288,6 +12507,69 @@ fn clock(secs: f32) -> String {
12288 format!("{}:{:02}", secs / 60, secs % 60)12507 format!("{}:{:02}", secs / 60, secs % 60)
12289 }12508 }
12290 12509
12510+/// How long a stage may sit without moving before the import line stops
12511+/// reading like a progress line and says outright that the wait is the file's,
12512+/// not the window's. Five seconds: a 25 GB remux spends eleven in its header
12513+/// alone, and a person watching a still line for that long has already decided
12514+/// the editor hung.
12515+const IMPORT_STALL: f32 = 5.;
12516+
12517+/// Which of an import's two reads the worker is inside. Travels as one atomic,
12518+/// the way an export's progress does ([`engine::ExportHandle`]) -- there is no
12519+/// fraction to send, because neither read reports where in the file it is.
12520+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
12521+enum ImportStage {
12522+ /// The container header: the sample tables, the cue index, the frame count.
12523+ /// Eleven seconds on a cold 29 GB remux, a hundred and fifty milliseconds
12524+ /// once the pages are warm -- the whole reason this runs off the UI thread.
12525+ Header,
12526+ /// The subtitle tracks inside a Matroska, which is a walk over the file's
12527+ /// blocks rather than a header read (~200 ms on a two-hour film).
12528+ Subtitles,
12529+}
12530+
12531+impl ImportStage {
12532+ /// The atomic the worker writes; `u8` because that is what an
12533+ /// [`AtomicU8`](std::sync::atomic::AtomicU8) carries.
12534+ fn from_u8(n: u8) -> Self {
12535+ match n {
12536+ 0 => Self::Header,
12537+ _ => Self::Subtitles,
12538+ }
12539+ }
12540+
12541+ /// What the line calls this stage.
12542+ fn what(self) -> &'static str {
12543+ match self {
12544+ Self::Header => "reading the header",
12545+ Self::Subtitles => "reading the subtitle tracks",
12546+ }
12547+ }
12548+}
12549+
12550+/// The whole of what an import shows while it runs: which file, which stage,
12551+/// the clock that proves the window is still answering, and what is behind it
12552+/// in the queue.
12553+///
12554+/// `since` is how long the *stage* has stood still, which is the only movement
12555+/// an unmeasurable read has: past [`IMPORT_STALL`] the line says so in words,
12556+/// because a bar that cannot move and a bar that has stopped look identical.
12557+fn import_line(name: &str, stage: ImportStage, elapsed: f32, since: f32, waiting: usize) -> String {
12558+ let tail = match waiting {
12559+ 0 => String::new(),
12560+ n => format!(" · {n} more waiting"),
12561+ };
12562+ let what = stage.what();
12563+ match since >= IMPORT_STALL {
12564+ true => format!(
12565+ "IMPORTING {name} · still {what} — a big file is minutes of reading, and the window is \
12566+ not frozen · {} elapsed{tail}",
12567+ clock(elapsed)
12568+ ),
12569+ false => format!("IMPORTING {name} · {what} · {} elapsed{tail}", clock(elapsed)),
12570+ }
12571+}
12572+
12291 /// How often a progress mark is worth keeping, how far back the rate is12573 /// How often a progress mark is worth keeping, how far back the rate is
12292 /// measured, and the least span that may answer at all. An export crosses12574 /// measured, and the least span that may answer at all. An export crosses
12293 /// hardware and software segments that run at different speeds, so the12575 /// hardware and software segments that run at different speeds, so the
@@ -12365,6 +12647,7 @@ mod tests {
12365 ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri,12647 ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri,
12366 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,12648 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,
12367 note_progress, px_along,12649 note_progress, px_along,
12650+ IMPORT_STALL, Import, ImportStage, import_line, read_ahead,
12368 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,12651 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
12369 trimmed_clip, unscannable,12652 trimmed_clip, unscannable,
12370 visible_slice,12653 visible_slice,
@@ -15547,6 +15830,110 @@ mod tests {
15547 assert_eq!(clock(-1.), "0:00");15830 assert_eq!(clock(-1.), "0:00");
15548 }15831 }
15549 15832
15833+ /// The import line's own state machine, driven the way a repaint drives
15834+ /// it: the worker writes a stage, the poll notices it changed and restarts
15835+ /// the stall clock, and the line's words change only when a stage has
15836+ /// actually stood still. The whole point is that a stuck read reads as a
15837+ /// stuck read and never as a frozen window.
15838+ #[test]
15839+ fn an_import_line_says_a_stage_has_stopped_moving_and_only_then() {
15840+ use std::sync::Arc;
15841+ use std::sync::atomic::{AtomicU8, Ordering::Relaxed};
15842+ let stage = Arc::new(AtomicU8::new(ImportStage::Header as u8));
15843+ let started = Instant::now() - Duration::from_secs(9);
15844+ let mut import = Import {
15845+ path: PathBuf::from("/films/A Film.mkv"),
15846+ started,
15847+ stage: Arc::clone(&stage),
15848+ seen: ImportStage::Header,
15849+ // As if the header had been running for those nine seconds.
15850+ since: started,
15851+ };
15852+ // Nine seconds inside one stage: past the wait a person tolerates, so
15853+ // the line stops pretending it is a progress line.
15854+ let since = import.poll();
15855+ assert!(since > IMPORT_STALL, "{since}");
15856+ let stalled = import_line("A Film.mkv", import.seen, 9., since, 0);
15857+ assert!(stalled.contains("still reading the header"), "{stalled}");
15858+ assert!(stalled.contains("not frozen"), "{stalled}");
15859+ assert!(stalled.contains("0:09 elapsed"), "{stalled}");
15860+ // The worker moves on: the stall clock restarts even though the elapsed
15861+ // one does not, which is the distinction the two clocks exist for.
15862+ stage.store(ImportStage::Subtitles as u8, Relaxed);
15863+ let since = import.poll();
15864+ assert_eq!(import.seen, ImportStage::Subtitles);
15865+ assert!(since < IMPORT_STALL, "{since}");
15866+ let moving = import_line("A Film.mkv", import.seen, 9., since, 2);
15867+ assert!(
15868+ moving.starts_with("IMPORTING A Film.mkv · reading the subtitle tracks"),
15869+ "{moving}"
15870+ );
15871+ assert!(!moving.contains("still"), "{moving}");
15872+ // ...and what is behind it in the queue, which is what a drop of three
15873+ // files or an argv of three files leaves waiting.
15874+ assert!(moving.ends_with("· 2 more waiting"), "{moving}");
15875+ assert!(!stalled.ends_with("waiting"), "an empty queue says nothing");
15876+ // A stage that does not move is not the same fact as a stage that came
15877+ // back to the same value: the poll only restarts on a change.
15878+ let held = import.since;
15879+ import.poll();
15880+ assert_eq!(import.since, held, "an unchanged stage must not reset it");
15881+ }
15882+
15883+ /// The read-ahead is a *cache warmer* and nothing else: whatever it did or
15884+ /// failed to do, the import that follows lands exactly the rows, lengths
15885+ /// and refusals it landed before there was a worker at all.
15886+ #[test]
15887+ fn reading_ahead_changes_nothing_about_what_an_import_lands() {
15888+ use std::sync::atomic::AtomicU8;
15889+ let stage = AtomicU8::new(ImportStage::Header as u8);
15890+ let plain = {
15891+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
15892+ session.set_gain(0.0);
15893+ session.import(&asset("test_av2.mp4")).expect("av2 matches");
15894+ (
15895+ session.sources().to_vec(),
15896+ session.file_frames(&asset("test_av2.mp4")),
15897+ session.timeline_duration(),
15898+ )
15899+ };
15900+ let warmed = {
15901+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
15902+ session.set_gain(0.0);
15903+ read_ahead(&asset("test_av2.mp4"), &stage);
15904+ session.import(&asset("test_av2.mp4")).expect("av2 matches");
15905+ (
15906+ session.sources().to_vec(),
15907+ session.file_frames(&asset("test_av2.mp4")),
15908+ session.timeline_duration(),
15909+ )
15910+ };
15911+ assert_eq!(plain, warmed);
15912+ // ...and it leaves the stage where the line can read it: a worker that
15913+ // never announced its second read would show one that never ends.
15914+ assert_eq!(
15915+ ImportStage::from_u8(stage.load(std::sync::atomic::Ordering::Relaxed)),
15916+ ImportStage::Subtitles
15917+ );
15918+ // A refusal is still the engine's refusal, warmed or not: a file of
15919+ // another rate is no more importable for having been read first.
15920+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
15921+ session.set_gain(0.0);
15922+ read_ahead(&asset("test_25fps.mp4"), &stage);
15923+ let warmed = session.import(&asset("test_25fps.mp4"));
15924+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
15925+ session.set_gain(0.0);
15926+ assert_eq!(
15927+ warmed.map_err(|e| e.to_string()),
15928+ session
15929+ .import(&asset("test_25fps.mp4"))
15930+ .map_err(|e| e.to_string())
15931+ );
15932+ // A path nothing can read is the worker's business to survive, not to
15933+ // report: the engine says so a moment later, in its own words.
15934+ read_ahead(std::path::Path::new("/no/such/film.mkv"), &stage);
15935+ }
15936+
15550 #[test]15937 #[test]
15551 fn every_codec_row_is_offered_or_says_why_not() {15938 fn every_codec_row_is_offered_or_says_why_not() {
15552 // One row per codec, and the boxes it can go in are the container row's15939 // One row per codec, and the boxes it can go in are the container row's
@@ -16863,36 +17250,17 @@ fn main() {
16863 }17250 }
16864 // The first file makes the timeline -- naming a file to open is a decision17251 // The first file makes the timeline -- naming a file to open is a decision
16865 // about what to watch -- and the rest are imports like any other: rows in17252 // about what to watch -- and the rest are imports like any other: rows in
16866- // the library, dragged onto a lane when they are wanted there. A refusal is17253+ // the library, dragged onto a lane when they are wanted there.
16867- // not fatal -- the others still load -- but the window must not open17254+ //
16868- // silently pretending the file was taken, so the first one seeds the notice.17255+ // Queued rather than read here: three 25 GB remuxes on the command line
16869- for extra in std::env::args().skip(2) {17256+ // used to be half a minute of *no window at all*, and a window that has
16870- let extra = PathBuf::from(&extra);17257+ // not opened cannot say why. They go through the same door a drop does
16871- // Only reachable with a first argument, so there is a timeline.17258+ // ([`Player::import`]), which is the door with a progress line on it, and
16872- let Some(session) = &mut session else {17259+ // the refusals arrive in the notice bar as a drop's do.
16873- continue;17260+ let extras: Vec<PathBuf> = session
16874- };17261+ .is_some()
16875- // A subtitle file named on the command line is not a source: it goes17262+ .then(|| std::env::args().skip(2).map(PathBuf::from).collect())
16876- // through the engine's other door, exactly as a dropped one does.17263+ .unwrap_or_default();
16877- let imported = match is_subtitle(&extra) {
16878- true => session.import_subtitles(&extra).map(|_| 0),
16879- false => session.import(&extra),
16880- };
16881- match imported {
16882- // The file's own tracks with it, as every other import door takes
16883- // them.
16884- Ok(_) => {
16885- if let Some(text) = subtitle_notice(session, &extra) {
16886- eprintln!("{}: {text}", extra.display());
16887- }
16888- }
16889- Err(e) => {
16890- let text = format!("IMPORT FAILED: {e}");
16891- eprintln!("{}: {text}", extra.display());
16892- notice.get_or_insert(text);
16893- }
16894- }
16895- }
16896 // The subtitle tracks inside the file that *is* the timeline, taken at the17264 // The subtitle tracks inside the file that *is* the timeline, taken at the
16897 // launch the window opens from -- the same pickup the drop and the Import17265 // launch the window opens from -- the same pickup the drop and the Import
16898 // button make (`open_media`).17266 // button make (`open_media`).
@@ -16960,6 +17328,7 @@ fn main() {
16960 ..Default::default()17328 ..Default::default()
16961 },17329 },
16962 |window, cx| {17330 |window, cx| {
17331+ let extras = extras.clone();
16963 let player = cx.new(|cx| Player {17332 let player = cx.new(|cx| Player {
16964 // A file named on the command line owes its first frame the17333 // A file named on the command line owes its first frame the
16965 // same repaint a seek's still owes: nothing plays by17334 // same repaint a seek's still owes: nothing plays by
@@ -17066,6 +17435,10 @@ fn main() {
17066 rebinding: None,17435 rebinding: None,
17067 notice: notice.clone().map(SharedString::from),17436 notice: notice.clone().map(SharedString::from),
17068 exported: None,17437 exported: None,
17438+ // The rest of argv, waiting for the first repaint to start
17439+ // them: the window is up before a byte of them is read.
17440+ importing: None,
17441+ imports: extras.into(),
17069 // Nothing pushed yet, and never a real title: the first17442 // Nothing pushed yet, and never a real title: the first
17070 // render is what names the window.17443 // render is what names the window.
17071 titled: String::new(),17444 titled: String::new(),