forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'worktree-agent-aee3223768dda4faa'

Browse files at this commit

734ca1498604ecabfb4a1ee10f582eb083e8bbb5Ahmet Kaan GümüşParent: 69ff17ea2d201d
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;
@@ -12311,6 +12530,69 @@ fn clock(secs: f32) -> String {
12311 format!("{}:{:02}", secs / 60, secs % 60)12530 format!("{}:{:02}", secs / 60, secs % 60)
12312 }12531 }
12313 12532
12533+/// How long a stage may sit without moving before the import line stops
12534+/// reading like a progress line and says outright that the wait is the file's,
12535+/// not the window's. Five seconds: a 25 GB remux spends eleven in its header
12536+/// alone, and a person watching a still line for that long has already decided
12537+/// the editor hung.
12538+const IMPORT_STALL: f32 = 5.;
12539+
12540+/// Which of an import's two reads the worker is inside. Travels as one atomic,
12541+/// the way an export's progress does ([`engine::ExportHandle`]) -- there is no
12542+/// fraction to send, because neither read reports where in the file it is.
12543+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
12544+enum ImportStage {
12545+ /// The container header: the sample tables, the cue index, the frame count.
12546+ /// Eleven seconds on a cold 29 GB remux, a hundred and fifty milliseconds
12547+ /// once the pages are warm -- the whole reason this runs off the UI thread.
12548+ Header,
12549+ /// The subtitle tracks inside a Matroska, which is a walk over the file's
12550+ /// blocks rather than a header read (~200 ms on a two-hour film).
12551+ Subtitles,
12552+}
12553+
12554+impl ImportStage {
12555+ /// The atomic the worker writes; `u8` because that is what an
12556+ /// [`AtomicU8`](std::sync::atomic::AtomicU8) carries.
12557+ fn from_u8(n: u8) -> Self {
12558+ match n {
12559+ 0 => Self::Header,
12560+ _ => Self::Subtitles,
12561+ }
12562+ }
12563+
12564+ /// What the line calls this stage.
12565+ fn what(self) -> &'static str {
12566+ match self {
12567+ Self::Header => "reading the header",
12568+ Self::Subtitles => "reading the subtitle tracks",
12569+ }
12570+ }
12571+}
12572+
12573+/// The whole of what an import shows while it runs: which file, which stage,
12574+/// the clock that proves the window is still answering, and what is behind it
12575+/// in the queue.
12576+///
12577+/// `since` is how long the *stage* has stood still, which is the only movement
12578+/// an unmeasurable read has: past [`IMPORT_STALL`] the line says so in words,
12579+/// because a bar that cannot move and a bar that has stopped look identical.
12580+fn import_line(name: &str, stage: ImportStage, elapsed: f32, since: f32, waiting: usize) -> String {
12581+ let tail = match waiting {
12582+ 0 => String::new(),
12583+ n => format!(" · {n} more waiting"),
12584+ };
12585+ let what = stage.what();
12586+ match since >= IMPORT_STALL {
12587+ true => format!(
12588+ "IMPORTING {name} · still {what} — a big file is minutes of reading, and the window is \
12589+ not frozen · {} elapsed{tail}",
12590+ clock(elapsed)
12591+ ),
12592+ false => format!("IMPORTING {name} · {what} · {} elapsed{tail}", clock(elapsed)),
12593+ }
12594+}
12595+
12314 /// How often a progress mark is worth keeping, how far back the rate is12596 /// How often a progress mark is worth keeping, how far back the rate is
12315 /// measured, and the least span that may answer at all. An export crosses12597 /// measured, and the least span that may answer at all. An export crosses
12316 /// hardware and software segments that run at different speeds, so the12598 /// hardware and software segments that run at different speeds, so the
@@ -12388,6 +12670,7 @@ mod tests {
12388 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri,12670 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri,
12389 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,12671 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,
12390 note_progress, px_along,12672 note_progress, px_along,
12673+ IMPORT_STALL, Import, ImportStage, import_line, read_ahead,
12391 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,12674 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
12392 trimmed_clip, unscannable,12675 trimmed_clip, unscannable,
12393 visible_slice,12676 visible_slice,
@@ -15634,6 +15917,110 @@ mod tests {
15634 assert_eq!(clock(-1.), "0:00");15917 assert_eq!(clock(-1.), "0:00");
15635 }15918 }
15636 15919
15920+ /// The import line's own state machine, driven the way a repaint drives
15921+ /// it: the worker writes a stage, the poll notices it changed and restarts
15922+ /// the stall clock, and the line's words change only when a stage has
15923+ /// actually stood still. The whole point is that a stuck read reads as a
15924+ /// stuck read and never as a frozen window.
15925+ #[test]
15926+ fn an_import_line_says_a_stage_has_stopped_moving_and_only_then() {
15927+ use std::sync::Arc;
15928+ use std::sync::atomic::{AtomicU8, Ordering::Relaxed};
15929+ let stage = Arc::new(AtomicU8::new(ImportStage::Header as u8));
15930+ let started = Instant::now() - Duration::from_secs(9);
15931+ let mut import = Import {
15932+ path: PathBuf::from("/films/A Film.mkv"),
15933+ started,
15934+ stage: Arc::clone(&stage),
15935+ seen: ImportStage::Header,
15936+ // As if the header had been running for those nine seconds.
15937+ since: started,
15938+ };
15939+ // Nine seconds inside one stage: past the wait a person tolerates, so
15940+ // the line stops pretending it is a progress line.
15941+ let since = import.poll();
15942+ assert!(since > IMPORT_STALL, "{since}");
15943+ let stalled = import_line("A Film.mkv", import.seen, 9., since, 0);
15944+ assert!(stalled.contains("still reading the header"), "{stalled}");
15945+ assert!(stalled.contains("not frozen"), "{stalled}");
15946+ assert!(stalled.contains("0:09 elapsed"), "{stalled}");
15947+ // The worker moves on: the stall clock restarts even though the elapsed
15948+ // one does not, which is the distinction the two clocks exist for.
15949+ stage.store(ImportStage::Subtitles as u8, Relaxed);
15950+ let since = import.poll();
15951+ assert_eq!(import.seen, ImportStage::Subtitles);
15952+ assert!(since < IMPORT_STALL, "{since}");
15953+ let moving = import_line("A Film.mkv", import.seen, 9., since, 2);
15954+ assert!(
15955+ moving.starts_with("IMPORTING A Film.mkv · reading the subtitle tracks"),
15956+ "{moving}"
15957+ );
15958+ assert!(!moving.contains("still"), "{moving}");
15959+ // ...and what is behind it in the queue, which is what a drop of three
15960+ // files or an argv of three files leaves waiting.
15961+ assert!(moving.ends_with("· 2 more waiting"), "{moving}");
15962+ assert!(!stalled.ends_with("waiting"), "an empty queue says nothing");
15963+ // A stage that does not move is not the same fact as a stage that came
15964+ // back to the same value: the poll only restarts on a change.
15965+ let held = import.since;
15966+ import.poll();
15967+ assert_eq!(import.since, held, "an unchanged stage must not reset it");
15968+ }
15969+
15970+ /// The read-ahead is a *cache warmer* and nothing else: whatever it did or
15971+ /// failed to do, the import that follows lands exactly the rows, lengths
15972+ /// and refusals it landed before there was a worker at all.
15973+ #[test]
15974+ fn reading_ahead_changes_nothing_about_what_an_import_lands() {
15975+ use std::sync::atomic::AtomicU8;
15976+ let stage = AtomicU8::new(ImportStage::Header as u8);
15977+ let plain = {
15978+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
15979+ session.set_gain(0.0);
15980+ session.import(&asset("test_av2.mp4")).expect("av2 matches");
15981+ (
15982+ session.sources().to_vec(),
15983+ session.file_frames(&asset("test_av2.mp4")),
15984+ session.timeline_duration(),
15985+ )
15986+ };
15987+ let warmed = {
15988+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
15989+ session.set_gain(0.0);
15990+ read_ahead(&asset("test_av2.mp4"), &stage);
15991+ session.import(&asset("test_av2.mp4")).expect("av2 matches");
15992+ (
15993+ session.sources().to_vec(),
15994+ session.file_frames(&asset("test_av2.mp4")),
15995+ session.timeline_duration(),
15996+ )
15997+ };
15998+ assert_eq!(plain, warmed);
15999+ // ...and it leaves the stage where the line can read it: a worker that
16000+ // never announced its second read would show one that never ends.
16001+ assert_eq!(
16002+ ImportStage::from_u8(stage.load(std::sync::atomic::Ordering::Relaxed)),
16003+ ImportStage::Subtitles
16004+ );
16005+ // A refusal is still the engine's refusal, warmed or not: a file of
16006+ // another rate is no more importable for having been read first.
16007+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
16008+ session.set_gain(0.0);
16009+ read_ahead(&asset("test_25fps.mp4"), &stage);
16010+ let warmed = session.import(&asset("test_25fps.mp4"));
16011+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
16012+ session.set_gain(0.0);
16013+ assert_eq!(
16014+ warmed.map_err(|e| e.to_string()),
16015+ session
16016+ .import(&asset("test_25fps.mp4"))
16017+ .map_err(|e| e.to_string())
16018+ );
16019+ // A path nothing can read is the worker's business to survive, not to
16020+ // report: the engine says so a moment later, in its own words.
16021+ read_ahead(std::path::Path::new("/no/such/film.mkv"), &stage);
16022+ }
16023+
15637 #[test]16024 #[test]
15638 fn every_codec_row_is_offered_or_says_why_not() {16025 fn every_codec_row_is_offered_or_says_why_not() {
15639 // One row per codec, and the boxes it can go in are the container row's16026 // One row per codec, and the boxes it can go in are the container row's
@@ -16950,36 +17337,17 @@ fn main() {
16950 }17337 }
16951 // The first file makes the timeline -- naming a file to open is a decision17338 // The first file makes the timeline -- naming a file to open is a decision
16952 // about what to watch -- and the rest are imports like any other: rows in17339 // about what to watch -- and the rest are imports like any other: rows in
16953- // the library, dragged onto a lane when they are wanted there. A refusal is17340+ // the library, dragged onto a lane when they are wanted there.
16954- // not fatal -- the others still load -- but the window must not open17341+ //
16955- // silently pretending the file was taken, so the first one seeds the notice.17342+ // Queued rather than read here: three 25 GB remuxes on the command line
16956- for extra in std::env::args().skip(2) {17343+ // used to be half a minute of *no window at all*, and a window that has
16957- let extra = PathBuf::from(&extra);17344+ // not opened cannot say why. They go through the same door a drop does
16958- // Only reachable with a first argument, so there is a timeline.17345+ // ([`Player::import`]), which is the door with a progress line on it, and
16959- let Some(session) = &mut session else {17346+ // the refusals arrive in the notice bar as a drop's do.
16960- continue;17347+ let extras: Vec<PathBuf> = session
16961- };17348+ .is_some()
16962- // A subtitle file named on the command line is not a source: it goes17349+ .then(|| std::env::args().skip(2).map(PathBuf::from).collect())
16963- // through the engine's other door, exactly as a dropped one does.17350+ .unwrap_or_default();
16964- let imported = match is_subtitle(&extra) {
16965- true => session.import_subtitles(&extra).map(|_| 0),
16966- false => session.import(&extra),
16967- };
16968- match imported {
16969- // The file's own tracks with it, as every other import door takes
16970- // them.
16971- Ok(_) => {
16972- if let Some(text) = subtitle_notice(session, &extra) {
16973- eprintln!("{}: {text}", extra.display());
16974- }
16975- }
16976- Err(e) => {
16977- let text = format!("IMPORT FAILED: {e}");
16978- eprintln!("{}: {text}", extra.display());
16979- notice.get_or_insert(text);
16980- }
16981- }
16982- }
16983 // The subtitle tracks inside the file that *is* the timeline, taken at the17351 // The subtitle tracks inside the file that *is* the timeline, taken at the
16984 // launch the window opens from -- the same pickup the drop and the Import17352 // launch the window opens from -- the same pickup the drop and the Import
16985 // button make (`open_media`).17353 // button make (`open_media`).
@@ -17047,6 +17415,7 @@ fn main() {
17047 ..Default::default()17415 ..Default::default()
17048 },17416 },
17049 |window, cx| {17417 |window, cx| {
17418+ let extras = extras.clone();
17050 let player = cx.new(|cx| Player {17419 let player = cx.new(|cx| Player {
17051 // A file named on the command line owes its first frame the17420 // A file named on the command line owes its first frame the
17052 // same repaint a seek's still owes: nothing plays by17421 // same repaint a seek's still owes: nothing plays by
@@ -17153,6 +17522,10 @@ fn main() {
17153 rebinding: None,17522 rebinding: None,
17154 notice: notice.clone().map(SharedString::from),17523 notice: notice.clone().map(SharedString::from),
17155 exported: None,17524 exported: None,
17525+ // The rest of argv, waiting for the first repaint to start
17526+ // them: the window is up before a byte of them is read.
17527+ importing: None,
17528+ imports: extras.into(),
17156 // Nothing pushed yet, and never a real title: the first17529 // Nothing pushed yet, and never a real title: the first
17157 // render is what names the window.17530 // render is what names the window.
17158 titled: String::new(),17531 titled: String::new(),