forge
Explore
Log in

Don't you dare go Hollow

The window is up before the film is read, and says which film

Browse files at this commit

544d97b8eef72f0bac863c453d8602f97a000df5Ahmet Kaan GümüşParent: 95fb78d
  • perf
    • the window is up before the film is read, and says which film
Show full message
⚡ perf(launch): the window is up before the film is read, and says which film

`edith <25 GB film>` on a cold cache showed nothing at all for twelve
seconds: the window was only created after argv[1] had been opened, and a
window that does not exist cannot say what it is waiting for.

argv is now sorted, not read: every file it names -- the first one included
-- goes into the queue a drop uses, and the window comes up empty in 47 ms
with the file's name in the title and an OPENING line under the panel
naming the read that is running. The first file is the one queued file that
is not an import, so its worker *opens* it outright and hands the session
over whole (`open_ahead` -> `Landed::Media`/`Project` -> `install_media`/
`install_project`), which is also what keeps a warm launch paying for one
header walk instead of two. Everything derived from the file -- canvas, fps,
title, export and save paths, subtitle tracks -- is set where it always was,
one repaint later; a refused file now says OPEN FAILED in the notice bar
instead of exiting before the window.

Measured (harness, timestamped sway-IPC + app log): cold 29.6 GB remux,
exec -> window 12.95 s / 18.73 s -> 0.047 s, exec -> timeline unchanged
(12.9 s -> 12.8 s); warm 2.9 GB film, window 0.73 s -> 0.048 s, timeline
0.68 s -> 0.71 s. The window resizes and repaints throughout the read.
crates/app/src/main.rsmodified+321 -120
@@ -1189,6 +1189,14 @@ struct Player {
1189 /// this holds is the line above the panel ([`Player::import_bar`]).1189 /// this holds is the line above the panel ([`Player::import_bar`]).
1190 importing: Option<Import>,1190 importing: Option<Import>,
1191 imports: std::collections::VecDeque<PathBuf>,1191 imports: std::collections::VecDeque<PathBuf>,
1192+ /// The file argv named, until its read lands. It goes through the queue
1193+ /// above like any other file -- that is what puts the window on screen
1194+ /// before a byte of a 25 GB film is read -- and this is what tells
1195+ /// [`Player::take_import`] that this one is an *open* and not an import:
1196+ /// it becomes the timeline, and the clock, the title and the export path
1197+ /// come from it. Cleared the moment it lands, so a later drop of the very
1198+ /// same path is an import like any other.
1199+ opening: Option<PathBuf>,
1192 /// Where an export writes. Built once from the source path, which is not1200 /// Where an export writes. Built once from the source path, which is not
1193 /// otherwise kept.1201 /// otherwise kept.
1194 export_path: PathBuf,1202 export_path: PathBuf,
@@ -3923,9 +3931,16 @@ impl Player {
3923 return;3931 return;
3924 };3932 };
3925 let stage = Arc::new(std::sync::atomic::AtomicU8::new(ImportStage::Header as u8));3933 let stage = Arc::new(std::sync::atomic::AtomicU8::new(ImportStage::Header as u8));
3934+ // The fork is made here, once, and carried to the landing: an import is
3935+ // *read* on the worker and opened again warm, while the file argv named
3936+ // is *opened* on the worker and handed over whole. Both leave the UI
3937+ // thread free for the twelve seconds a cold 25 GB header walk takes;
3938+ // opening the timeline outright is what keeps it from paying the walk
3939+ // twice on a warm one.
3940+ let what = arrival(self.opening.as_deref(), &path);
3926 let read = cx.background_executor().spawn({3941 let read = cx.background_executor().spawn({
3927 let (path, stage) = (path.clone(), Arc::clone(&stage));3942 let (path, stage) = (path.clone(), Arc::clone(&stage));
3928- async move { read_ahead(&path, &stage) }3943+ async move { open_ahead(what, &path, &stage) }
3929 });3944 });
3930 let now = Instant::now();3945 let now = Instant::now();
3931 self.importing = Some(Import {3946 self.importing = Some(Import {
@@ -3936,10 +3951,10 @@ impl Player {
3936 since: now,3951 since: now,
3937 });3952 });
3938 cx.spawn(async move |this, cx| {3953 cx.spawn(async move |this, cx| {
3939- read.await;3954+ let landed = read.await;
3940 this.update(cx, |this, cx| {3955 this.update(cx, |this, cx| {
3941 this.importing = None;3956 this.importing = None;
3942- this.take_import(&path, cx);3957+ this.take_import(&path, landed, cx);
3943 // The next one is started by the repaint this notified, which3958 // The next one is started by the repaint this notified, which
3944 // is also what starts the files argv named ([`poll_import`]).3959 // is also what starts the files argv named ([`poll_import`]).
3945 })3960 })
@@ -3974,10 +3989,45 @@ impl Player {
3974 /// The export guard again, and not for the caller's sake: an export can3989 /// The export guard again, and not for the caller's sake: an export can
3975 /// have started during the seconds the worker was reading, and a drop3990 /// have started during the seconds the worker was reading, and a drop
3976 /// during an export has always been a silent no-op.3991 /// during an export has always been a silent no-op.
3977- fn take_import(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {3992+ fn take_import(&mut self, path: &std::path::Path, landed: Landed, cx: &mut Context<Self>) {
3978 if self.exporting().is_some() {3993 if self.exporting().is_some() {
3979 return;3994 return;
3980 }3995 }
3996+ // The file argv named is the one file in the queue that is not an
3997+ // import: it *is* the timeline, and the worker has already opened it.
3998+ // All that is left here is to hang everything derived from it off the
3999+ // window -- the clock, the title, where an export and a save go -- and
4000+ // that is arithmetic, not a read.
4001+ match landed {
4002+ Landed::Read => {}
4003+ what => {
4004+ self.opening = None;
4005+ match what {
4006+ Landed::Project(opened) => self.install_project(path, opened, cx),
4007+ Landed::Media(opened) => {
4008+ let text = self.install_media(path, opened, true);
4009+ eprintln!("{text}");
4010+ self.notice = Some(text.into());
4011+ cx.notify();
4012+ }
4013+ Landed::Read => unreachable!("matched above"),
4014+ }
4015+ // The line a launch has always printed, now printed when the
4016+ // file actually arrives: it is the mark that says the timeline
4017+ // is up, as the window's own appearance is the other one.
4018+ if let Some(meta) = self.session.as_ref().map(PlaybackSession::meta) {
4019+ println!(
4020+ "{}: {}x{} @ {:.2} fps, {} samples",
4021+ path.display(),
4022+ meta.width,
4023+ meta.height,
4024+ meta.frame_rate,
4025+ meta.frame_count
4026+ );
4027+ }
4028+ return;
4029+ }
4030+ }
3981 // An empty window has no library to add to yet: the file opens one, and4031 // An empty window has no library to add to yet: the file opens one, and
3982 // the timeline under it stays empty, because an import is an import4032 // the timeline under it stays empty, because an import is an import
3983 // whether or not a session was already up. A file *named at launch* is4033 // whether or not a session was already up. A file *named at launch* is
@@ -4042,19 +4092,26 @@ impl Player {
4042 /// *opened* is the timeline, one *imported* into an empty window fills the4092 /// *opened* is the timeline, one *imported* into an empty window fills the
4043 /// library and leaves the lanes empty for a drag.4093 /// library and leaves the lanes empty for a drag.
4044 fn open_media(&mut self, path: &std::path::Path, place: bool) -> String {4094 fn open_media(&mut self, path: &std::path::Path, place: bool) -> String {
4045- let opened = match place {4095+ self.install_media(path, open_session(path, place), place)
4046- true => PlaybackSession::open(path),4096+ }
4047- false => PlaybackSession::open_library(path),4097+
4048- };4098+ /// The second half of it: everything the window derives from a session that
4099+ /// has already been opened. Split from the open itself because the file
4100+ /// argv named is opened on a worker ([`open_ahead`]) -- the twelve seconds
4101+ /// of a cold header walk are not the UI thread's to spend -- and lands
4102+ /// here, where nothing is read and nothing blocks.
4103+ fn install_media(
4104+ &mut self,
4105+ path: &std::path::Path,
4106+ opened: Result<(PlaybackSession, String), String>,
4107+ place: bool,
4108+ ) -> String {
4049 match opened {4109 match opened {
4050- Ok(mut session) => {4110+ Ok((session, subs)) => {
4051 self.fps = session.meta().frame_rate;4111 self.fps = session.meta().frame_rate;
4052 // Read before the session moves: a file that plays silent says4112 // Read before the session moves: a file that plays silent says
4053 // so here or nowhere.4113 // so here or nowhere.
4054 let silent = audio_notice(&session);4114 let silent = audio_notice(&session);
4055- // ...and the subtitle tracks the file carries inside it, taken
4056- // now: nothing else ever opens this container again.
4057- let subs = subtitle_notice(&mut session, path).unwrap_or_default();
4058 // A file replaces the one that was open, and track 3 of that one4115 // A file replaces the one that was open, and track 3 of that one
4059 // is not track 3 of this.4116 // is not track 3 of this.
4060 self.sub_track = 0;4117 self.sub_track = 0;
@@ -4117,10 +4174,23 @@ impl Player {
4117 /// The new session is built before anything is replaced, so a refusal is4174 /// The new session is built before anything is replaced, so a refusal is
4118 /// shown as the engine worded it and leaves what is playing alone.4175 /// shown as the engine worded it and leaves what is playing alone.
4119 fn load_project(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {4176 fn load_project(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {
4177+ let opened = PlaybackSession::open_project(path).map_err(|e| e.to_string());
4178+ self.install_project(path, opened, cx);
4179+ }
4180+
4181+ /// The second half of it, for [`Player::install_media`]'s reason: a
4182+ /// `.edith` named on the command line is opened on a worker and only
4183+ /// installed here.
4184+ fn install_project(
4185+ &mut self,
4186+ path: &std::path::Path,
4187+ opened: Result<PlaybackSession, String>,
4188+ cx: &mut Context<Self>,
4189+ ) {
4120 if self.exporting().is_some() {4190 if self.exporting().is_some() {
4121 return;4191 return;
4122 }4192 }
4123- let text = match PlaybackSession::open_project(path) {4193+ let text = match opened {
4124 Ok(session) => {4194 Ok(session) => {
4125 self.fps = session.meta().frame_rate;4195 self.fps = session.meta().frame_rate;
4126 let silent = audio_notice(&session);4196 let silent = audio_notice(&session);
@@ -6631,6 +6701,7 @@ impl Player {
6631 elapsed,6701 elapsed,
6632 import.since.elapsed().as_secs_f32(),6702 import.since.elapsed().as_secs_f32(),
6633 self.imports.len(),6703 self.imports.len(),
6704+ arrival(self.opening.as_deref(), &import.path) != Landing::Import,
6634 );6705 );
6635 // A quarter of the bar, crossing it every three seconds and wrapping.6706 // A quarter of the bar, crossing it every three seconds and wrapping.
6636 // Tied to the elapsed clock, so it moves for as long as the read does6707 // Tied to the elapsed clock, so it moves for as long as the read does
@@ -9994,6 +10065,68 @@ fn is_matroska(path: &std::path::Path) -> bool {
9994 .is_some_and(|e| matches!(e.to_ascii_lowercase().as_str(), "mkv" | "webm"))10065 .is_some_and(|e| matches!(e.to_ascii_lowercase().as_str(), "mkv" | "webm"))
9995 }10066 }
9996 10067
10068+/// What a worker hands back, which is the fork [`arrival`] made when it was
10069+/// started. An import is *read* and thrown away; the file argv named is opened
10070+/// outright, because nothing else is going to open it afterwards.
10071+enum Landed {
10072+ /// An import: pages warmed, nothing kept. [`Player::take_import`] opens the
10073+ /// file again, warm, and that second open is the 150 ms one.
10074+ Read,
10075+ /// The media argv named, with the tail its subtitle tracks earn: a whole
10076+ /// timeline, ready to be hung off the window, or the engine's refusal.
10077+ Media(Result<(PlaybackSession, String), String>),
10078+ /// The `.edith` argv named, restored.
10079+ Project(Result<PlaybackSession, String>),
10080+}
10081+
10082+/// A media file opened as a session, with the subtitle tracks it carries inside
10083+/// it taken in the same breath -- the two reads a file costs, in the one place
10084+/// both doors ([`Player::open_media`] and the worker below) go through.
10085+///
10086+/// `place` is which door: a file *opened* is the timeline, one *imported* into
10087+/// an empty window fills the library and leaves the lanes empty for a drag.
10088+fn open_session(path: &std::path::Path, place: bool) -> Result<(PlaybackSession, String), String> {
10089+ let opened = match place {
10090+ true => PlaybackSession::open(path),
10091+ false => PlaybackSession::open_library(path),
10092+ };
10093+ let mut session = opened.map_err(|e| e.to_string())?;
10094+ let subs = subtitle_notice(&mut session, path).unwrap_or_default();
10095+ Ok((session, subs))
10096+}
10097+
10098+/// The whole of what a queued file costs, off the UI thread. An import only
10099+/// needs its pages warmed ([`read_ahead`]); the file argv named is *opened*
10100+/// here instead, and that is the difference between a warm launch paying for
10101+/// one header walk and paying for two -- the window is up either way.
10102+fn open_ahead(
10103+ what: Landing,
10104+ path: &std::path::Path,
10105+ stage: &std::sync::atomic::AtomicU8,
10106+) -> Landed {
10107+ use std::sync::atomic::Ordering::Relaxed;
10108+ match what {
10109+ Landing::Import => {
10110+ read_ahead(path, stage);
10111+ Landed::Read
10112+ }
10113+ Landing::Project => {
10114+ let opened = PlaybackSession::open_project(path).map_err(|e| e.to_string());
10115+ Landed::Project(opened)
10116+ }
10117+ Landing::Open => {
10118+ let opened = PlaybackSession::open(path).map_err(|e| e.to_string());
10119+ // The same two stages a read reports, because they are the same two
10120+ // reads: the container, and then the tracks inside it.
10121+ stage.store(ImportStage::Subtitles as u8, Relaxed);
10122+ Landed::Media(opened.map(|mut session| {
10123+ let subs = subtitle_notice(&mut session, path).unwrap_or_default();
10124+ (session, subs)
10125+ }))
10126+ }
10127+ }
10128+}
10129+
9997 /// Reads, off the UI thread, exactly what the import that follows is about to10130 /// Reads, off the UI thread, exactly what the import that follows is about to
9998 /// read -- and throws every byte away. The point is the page cache: a cold10131 /// read -- and throws every byte away. The point is the page cache: a cold
9999 /// header walk of a 29 GB remux is 11 s and a warm one is 150 ms (measured,10132 /// header walk of a 29 GB remux is 11 s and a warm one is 150 ms (measured,
@@ -10042,8 +10175,9 @@ fn read_ahead(path: &std::path::Path, stage: &std::sync::atomic::AtomicU8) {
10042 /// The walk reads the whole file for its cues10175 /// The walk reads the whole file for its cues
10043 /// (`engine::subtitle::of_matroska`) -- ~200 ms on a two-hour 4K remux, and an10176 /// (`engine::subtitle::of_matroska`) -- ~200 ms on a two-hour 4K remux, and an
10044 /// *import* pays it on a worker first ([`read_ahead`]), so what happens here is10177 /// *import* pays it on a worker first ([`read_ahead`]), so what happens here is
10045-/// the warm second pass. A file *opened* at launch still pays it cold: there is10178+/// the warm second pass. A file *opened* at launch pays it cold and pays it
10046-/// no window yet to say so in.10179+/// once -- this runs on the worker beside the open itself ([`open_ahead`]),
10180+/// with the window already up and naming the read.
10047 fn subtitle_notice(session: &mut PlaybackSession, path: &std::path::Path) -> Option<String> {10181 fn subtitle_notice(session: &mut PlaybackSession, path: &std::path::Path) -> Option<String> {
10048 if !is_matroska(path) {10182 if !is_matroska(path) {
10049 return None;10183 return None;
@@ -12848,6 +12982,44 @@ impl ImportStage {
12848 }12982 }
12849 }12983 }
12850 12984
12985+/// argv sorted into the file that becomes the timeline and the queue every
12986+/// named file is read through, in the order they were named. The whole of what
12987+/// a launch does before the window is on screen -- and it touches no disk,
12988+/// which is the point: the header walk happens on a worker with the window
12989+/// already up ([`Player::take_import`]).
12990+fn launch_queue(
12991+ args: impl Iterator<Item = PathBuf>,
12992+) -> (Option<PathBuf>, std::collections::VecDeque<PathBuf>) {
12993+ let queue: std::collections::VecDeque<PathBuf> = args.collect();
12994+ (queue.front().cloned(), queue)
12995+}
12996+
12997+/// What a queued file turns into. Every file goes through one queue -- argv's
12998+/// first file, argv's extras, a drop, the Import button -- and this is the fork
12999+/// its worker is started on.
13000+#[derive(PartialEq, Eq, Debug, Clone, Copy)]
13001+enum Landing {
13002+ /// The media argv named: it becomes the timeline, and the canvas, the fps,
13003+ /// the title and the export path come from it.
13004+ Open,
13005+ /// A `.edith` argv named: a whole timeline restored, not a source.
13006+ Project,
13007+ /// Everything else: a row in the library, the timeline untouched.
13008+ Import,
13009+}
13010+
13011+/// Which of the three a queued file is (`landing` above is the drag's).
13012+/// `opening` is the one path argv named and is cleared as it lands, so a second
13013+/// arrival of the same path -- a drop of the film that is already open -- is an
13014+/// import, which is what a drop has always been.
13015+fn arrival(opening: Option<&std::path::Path>, path: &std::path::Path) -> Landing {
13016+ match opening == Some(path) {
13017+ false => Landing::Import,
13018+ true if is_project(path) => Landing::Project,
13019+ true => Landing::Open,
13020+ }
13021+}
13022+
12851 /// The whole of what an import shows while it runs: which file, which stage,13023 /// The whole of what an import shows while it runs: which file, which stage,
12852 /// the clock that proves the window is still answering, and what is behind it13024 /// the clock that proves the window is still answering, and what is behind it
12853 /// in the queue.13025 /// in the queue.
@@ -12855,19 +13027,35 @@ impl ImportStage {
12855 /// `since` is how long the *stage* has stood still, which is the only movement13027 /// `since` is how long the *stage* has stood still, which is the only movement
12856 /// an unmeasurable read has: past [`IMPORT_STALL`] the line says so in words,13028 /// an unmeasurable read has: past [`IMPORT_STALL`] the line says so in words,
12857 /// because a bar that cannot move and a bar that has stopped look identical.13029 /// because a bar that cannot move and a bar that has stopped look identical.
12858-fn import_line(name: &str, stage: ImportStage, elapsed: f32, since: f32, waiting: usize) -> String {13030+///
13031+/// `opening` is the file argv named, which is read through the same queue and
13032+/// says so in the same words -- except that it is being *opened*, and a line
13033+/// that called it an import would be describing the wrong thing to the one
13034+/// person who typed the name.
13035+fn import_line(
13036+ name: &str,
13037+ stage: ImportStage,
13038+ elapsed: f32,
13039+ since: f32,
13040+ waiting: usize,
13041+ opening: bool,
13042+) -> String {
12859 let tail = match waiting {13043 let tail = match waiting {
12860 0 => String::new(),13044 0 => String::new(),
12861 n => format!(" · {n} more waiting"),13045 n => format!(" · {n} more waiting"),
12862 };13046 };
12863 let what = stage.what();13047 let what = stage.what();
13048+ let verb = match opening {
13049+ true => "OPENING",
13050+ false => "IMPORTING",
13051+ };
12864 match since >= IMPORT_STALL {13052 match since >= IMPORT_STALL {
12865 true => format!(13053 true => format!(
12866- "IMPORTING {name} · still {what} — a big file is minutes of reading, and the window is \13054+ "{verb} {name} · still {what} — a big file is minutes of reading, and the window is \
12867 not frozen · {} elapsed{tail}",13055 not frozen · {} elapsed{tail}",
12868 clock(elapsed)13056 clock(elapsed)
12869 ),13057 ),
12870- false => format!("IMPORTING {name} · {what} · {} elapsed{tail}", clock(elapsed)),13058+ false => format!("{verb} {name} · {what} · {} elapsed{tail}", clock(elapsed)),
12871 }13059 }
12872 }13060 }
12873 13061
@@ -12997,6 +13185,7 @@ mod tests {
12997 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,13185 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,
12998 note_progress, px_along,13186 note_progress, px_along,
12999 IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanPlan, SilenceScan, import_line,13187 IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanPlan, SilenceScan, import_line,
13188+ Landing, arrival, launch_queue,
13000 read_ahead, scan_plan, seek_line, silence_line, stash_or_write,13189 read_ahead, scan_plan, seek_line, silence_line, stash_or_write,
13001 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,13190 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
13002 trimmed_clip, unscannable,13191 trimmed_clip, unscannable,
@@ -16267,7 +16456,7 @@ mod tests {
16267 // the line stops pretending it is a progress line.16456 // the line stops pretending it is a progress line.
16268 let since = import.poll();16457 let since = import.poll();
16269 assert!(since > IMPORT_STALL, "{since}");16458 assert!(since > IMPORT_STALL, "{since}");
16270- let stalled = import_line("A Film.mkv", import.seen, 9., since, 0);16459+ let stalled = import_line("A Film.mkv", import.seen, 9., since, 0, false);
16271 assert!(stalled.contains("still reading the header"), "{stalled}");16460 assert!(stalled.contains("still reading the header"), "{stalled}");
16272 assert!(stalled.contains("not frozen"), "{stalled}");16461 assert!(stalled.contains("not frozen"), "{stalled}");
16273 assert!(stalled.contains("0:09 elapsed"), "{stalled}");16462 assert!(stalled.contains("0:09 elapsed"), "{stalled}");
@@ -16277,7 +16466,7 @@ mod tests {
16277 let since = import.poll();16466 let since = import.poll();
16278 assert_eq!(import.seen, ImportStage::Subtitles);16467 assert_eq!(import.seen, ImportStage::Subtitles);
16279 assert!(since < IMPORT_STALL, "{since}");16468 assert!(since < IMPORT_STALL, "{since}");
16280- let moving = import_line("A Film.mkv", import.seen, 9., since, 2);16469+ let moving = import_line("A Film.mkv", import.seen, 9., since, 2, false);
16281 assert!(16470 assert!(
16282 moving.starts_with("IMPORTING A Film.mkv · reading the subtitle tracks"),16471 moving.starts_with("IMPORTING A Film.mkv · reading the subtitle tracks"),
16283 "{moving}"16472 "{moving}"
@@ -16294,6 +16483,74 @@ mod tests {
16294 assert_eq!(import.since, held, "an unchanged stage must not reset it");16483 assert_eq!(import.since, held, "an unchanged stage must not reset it");
16295 }16484 }
16296 16485
16486+ /// The launch, from argv to the window being up: nothing named on the
16487+ /// command line is read before there is a window, so all a launch does is
16488+ /// sort argv into the file that becomes the timeline and the queue that is
16489+ /// read through -- and a run with no arguments has neither, exactly as it
16490+ /// had none before.
16491+ #[test]
16492+ fn a_launch_queues_the_file_it_names_instead_of_opening_it() {
16493+ let film = PathBuf::from("/films/Dune.mkv");
16494+ let extra = PathBuf::from("/films/Titles.mov");
16495+ let (arg, queue) = launch_queue([film.clone(), extra.clone()].into_iter());
16496+ assert_eq!(arg.as_deref(), Some(film.as_path()), "argv[1] is the open");
16497+ // In the order they were named, the timeline's file first: six header
16498+ // walks racing over one disk finish no sooner than six in a row, and
16499+ // the one the person is waiting to watch goes first.
16500+ assert_eq!(queue, [film, extra], "argv, in arrival order");
16501+ // ...and no argument at all is still the empty window: nothing to open
16502+ // and nothing to read.
16503+ let (arg, queue) = launch_queue(std::iter::empty());
16504+ assert_eq!(arg, None);
16505+ assert!(queue.is_empty(), "no argv, nothing queued");
16506+ }
16507+
16508+ /// Which door a queued file goes through. One queue carries the file argv
16509+ /// named and every import behind it, so this fork -- made when the worker
16510+ /// starts and carried to the landing as a [`Landed`] -- is the whole state
16511+ /// machine: the named file becomes the timeline (a `.edith` restoring a
16512+ /// whole one), everything else joins the library, including the very same
16513+ /// film dropped again once the open has landed.
16514+ #[test]
16515+ fn the_file_argv_named_lands_as_the_timeline_and_everything_behind_it_as_imports() {
16516+ let film = PathBuf::from("/films/Dune.mkv");
16517+ let extra = PathBuf::from("/films/Titles.mov");
16518+ let project = PathBuf::from("/films/Dune.edith");
16519+ assert_eq!(arrival(Some(&film), &film), Landing::Open);
16520+ assert_eq!(arrival(Some(&project), &project), Landing::Project);
16521+ assert_eq!(arrival(Some(&film), &extra), Landing::Import);
16522+ // Cleared as it lands: a drop of the film already on the timeline is an
16523+ // import, which is what a drop has always been.
16524+ assert_eq!(arrival(None, &film), Landing::Import);
16525+ // A window opened empty has no named file at all, and everything that
16526+ // arrives at it is an import.
16527+ assert_eq!(arrival(None, &project), Landing::Import);
16528+ }
16529+
16530+ /// What the window says while the file argv named is being read: the file's
16531+ /// name, the read that is running, and a clock proving the window is
16532+ /// answering -- in the *opening* wording, because the one person who typed
16533+ /// that name is not importing anything.
16534+ #[test]
16535+ fn the_named_file_is_read_under_an_opening_line_not_an_importing_one() {
16536+ let opening = import_line("Dune.mkv", ImportStage::Header, 0.4, 0.4, 1, true);
16537+ assert!(
16538+ opening.starts_with("OPENING Dune.mkv · reading the header"),
16539+ "{opening}"
16540+ );
16541+ assert!(opening.ends_with("· 1 more waiting"), "{opening}");
16542+ // Twelve seconds into a cold 25 GB header walk, which is the whole
16543+ // reason the window is up: it says the read is still moving through the
16544+ // same stage and that this is not a freeze.
16545+ let stalled = import_line("Dune.mkv", ImportStage::Header, 12., 12., 0, true);
16546+ assert!(stalled.starts_with("OPENING Dune.mkv · still"), "{stalled}");
16547+ assert!(stalled.contains("not frozen"), "{stalled}");
16548+ assert!(stalled.contains("0:12 elapsed"), "{stalled}");
16549+ // The files behind it are imports and still say so.
16550+ let import = import_line("Titles.mov", ImportStage::Header, 0.4, 0.4, 0, false);
16551+ assert!(import.starts_with("IMPORTING Titles.mov"), "{import}");
16552+ }
16553+
16297 /// One gesture over the real gate, with the plumbing around it spelled out:16554 /// One gesture over the real gate, with the plumbing around it spelled out:
16298 /// a write reseeks (the worker owes a frame again), a landed frame clears16555 /// a write reseeks (the worker owes a frame again), a landed frame clears
16299 /// that and flushes what is held, and the release flushes whatever the16556 /// that and flushes what is held, and the release flushes whatever the
@@ -17784,103 +18041,40 @@ mod tests {
17784 }18041 }
17785 18042
17786 fn main() {18043 fn main() {
17787- let arg = std::env::args().nth(1).map(PathBuf::from);
17788- // A `.edith` restores a whole timeline, anything else *is* the timeline.
17789- // Either way the rest of argv is imported into its library. No argument at
17790- // all opens the window empty -- the library then arrives by drop or by the
17791- // Import button, and everything below is derived from it at that point
17792- // instead.
17793- let mut session = match &arg {
17794- Some(arg) => {
17795- let opened = if is_project(arg) {
17796- PlaybackSession::open_project(arg)
17797- } else {
17798- PlaybackSession::open(arg)
17799- };
17800- match opened {
17801- Ok(v) => Some(v),
17802- Err(e) => {
17803- // A failed load by drop leaves the running session alone;
17804- // here a file was named and could not be opened, so the
17805- // refusal is the whole run.
17806- eprintln!("cannot open {}: {e}", arg.display());
17807- std::process::exit(1);
17808- }
17809- }
17810- }
17811- None => None,
17812- };
17813 // A keymap file that cannot be read leaves the defaults in force, and takes18044 // A keymap file that cannot be read leaves the defaults in force, and takes
17814- // the notice slot ahead of an import refusal below: it is about every key18045+ // the notice slot ahead of an open or import refusal: it is about every key
17815- // the window has, and the import refusal is on stderr either way.18046+ // the window has, and those refusals are on stderr either way.
17816- let (keymap, mut notice) = Keymap::load();18047+ let (keymap, notice) = Keymap::load();
17817 if let Some(text) = &notice {18048 if let Some(text) = &notice {
17818 eprintln!("{text}");18049 eprintln!("{text}");
17819 }18050 }
17820- // The first file makes the timeline -- naming a file to open is a decision18051+ // Nothing named on the command line is read here. The first file makes the
17821- // about what to watch -- and the rest are imports like any other: rows in18052+ // timeline -- a `.edith` restores a whole one, anything else *is* one --
17822- // the library, dragged onto a lane when they are wanted there.18053+ // and the rest are imports like any other: rows in the library, dragged
18054+ // onto a lane when they are wanted there. All of them go through the queue
18055+ // a drop uses ([`Player::import`]), which is the door with a progress line
18056+ // on it, and their refusals arrive in the notice bar as a drop's do.
17823 //18057 //
17824- // Queued rather than read here: three 25 GB remuxes on the command line18058+ // Queued rather than opened because a 25 GB film cold is twelve seconds of
17825- // used to be half a minute of *no window at all*, and a window that has18059+ // header walk, and it used to be twelve seconds of *no window at all* -- a
17826- // not opened cannot say why. They go through the same door a drop does18060+ // window that has not opened cannot say what it is waiting for. Now the
17827- // ([`Player::import`]), which is the door with a progress line on it, and18061+ // window is up in the time it takes to make one, naming the file and the
17828- // the refusals arrive in the notice bar as a drop's do.18062+ // read that is running, and the timeline appears when that read lands
17829- let extras: Vec<PathBuf> = session18063+ // ([`Player::take_import`]).
17830- .is_some()18064+ //
17831- .then(|| std::env::args().skip(2).map(PathBuf::from).collect())18065+ // No argument at all opens the window empty, exactly as before: the library
17832- .unwrap_or_default();18066+ // then arrives by drop or by the Import button.
17833- // The subtitle tracks inside the file that *is* the timeline, taken at the18067+ let (arg, queue) = launch_queue(std::env::args().skip(1).map(PathBuf::from));
17834- // launch the window opens from -- the same pickup the drop and the Import
17835- // button make (`open_media`).
17836- if let (Some(session), Some(arg)) = (&mut session, &arg)
17837- && let Some(text) = subtitle_notice(session, arg)
17838- {
17839- eprintln!("{text}");
17840- }
17841- // A file that plays silent is as much news at launch as it is on a drop, and
17842- // behind the keymap notice for the same reason an import refusal is.
17843- if let Some(reason) = session
17844- .as_ref()
17845- .and_then(PlaybackSession::audio_disabled_reason)
17846- {
17847- let text = format!("NO AUDIO: {reason}");
17848- eprintln!("{text}");
17849- notice.get_or_insert(text);
17850- }
17851- let meta = session.as_ref().map(|session| *session.meta());
17852- // Beside the media even for a project: an export has never landed anywhere
17853- // but next to the picture it came from.
17854- let out = session.as_ref().map_or_else(PathBuf::new, |session| {
17855- export_path(&session.sources()[0].path)
17856- });
17857- let project = match &arg {
17858- Some(arg) if is_project(arg) => arg.clone(),
17859- Some(arg) => project_path(arg),
17860- // Chosen with the file, once there is one to choose it from.
17861- None => PathBuf::new(),
17862- };
17863 let name: SharedString = arg18068 let name: SharedString = arg
17864 .as_deref()18069 .as_deref()
17865 .map_or_else(|| NO_FILE.into(), |arg| file_name(arg).into());18070 .map_or_else(|| NO_FILE.into(), |arg| file_name(arg).into());
17866- if let (Some(arg), Some(meta)) = (&arg, &meta) {
17867- println!(
17868- "{}: {}x{} @ {:.2} fps, {} samples",
17869- arg.display(),
17870- meta.width,
17871- meta.height,
17872- meta.frame_rate,
17873- meta.frame_count
17874- );
17875- }
17876 18071
17877 Application::new().run(move |cx: &mut App| {18072 Application::new().run(move |cx: &mut App| {
17878- // The picture's own size, or 720p when there is no picture yet: the18073+ // 720p: the picture's own size is not known yet -- knowing it is the
17879- // empty window is a landing pad, not a sliver.18074+ // twelve seconds this window exists to be up during -- and a window
17880- let (w, h) = meta.map_or((1280., 720.), |meta| {18075+ // that resized itself under a hand already dragging it would be worse
17881- (meta.width as f32, meta.height as f32)18076+ // than one that opened at the size the empty window has always used.
17882- });18077+ let bounds = Bounds::centered(None, size(px(1280.), px(720.)), cx);
17883- let bounds = Bounds::centered(None, size(px(w), px(h)), cx);
17884 cx.open_window(18078 cx.open_window(
17885 WindowOptions {18079 WindowOptions {
17886 window_bounds: Some(WindowBounds::Windowed(bounds)),18080 window_bounds: Some(WindowBounds::Windowed(bounds)),
@@ -17897,14 +18091,14 @@ fn main() {
17897 ..Default::default()18091 ..Default::default()
17898 },18092 },
17899 |window, cx| {18093 |window, cx| {
17900- let extras = extras.clone();18094+ let queue = queue.clone();
17901 let player = cx.new(|cx| Player {18095 let player = cx.new(|cx| Player {
17902- // A file named on the command line owes its first frame the18096+ // Nothing to wait for yet: the file named on the command
17903- // same repaint a seek's still owes: nothing plays by18097+ // line is still queued, and the repaint that carries its
17904- // itself, so this is what carries the poster frame to the18098+ // poster frame to the screen is asked for when it lands
17905- // screen. An empty window has none to wait for.18099+ // (`open_media` -> `reset_after_reseek`).
17906- seek_since: session.is_some().then(Instant::now),18100+ seek_since: None,
17907- session,18101+ session: None,
17908 // Full and unmuted, which is what the session it was just18102 // Full and unmuted, which is what the session it was just
17909 // handed is already set to: nothing to push at startup.18103 // handed is already set to: nothing to push at startup.
17910 volume: Volume::default(),18104 volume: Volume::default(),
@@ -17912,7 +18106,10 @@ fn main() {
17912 volume_dragging: false,18106 volume_dragging: false,
17913 // Only ever used with a timeline; 30 keeps the empty18107 // Only ever used with a timeline; 30 keeps the empty
17914 // timecode reading in frames rather than in NaN.18108 // timecode reading in frames rather than in NaN.
17915- fps: meta.map_or(30., |meta| meta.frame_rate),18109+ fps: 30.,
18110+ // The file being opened, from the first frame the window
18111+ // draws: the title bar and the header name it while its
18112+ // header is still being read.
17916 name: name.clone(),18113 name: name.clone(),
17917 image: None,18114 image: None,
17918 sub_image: None,18115 sub_image: None,
@@ -17948,8 +18145,11 @@ fn main() {
17948 cancelling: false,18145 cancelling: false,
17949 export_started: None,18146 export_started: None,
17950 export_marks: Vec::new(),18147 export_marks: Vec::new(),
17951- export_path: out.clone(),18148+ // Both derived from the file when it lands, by the same
17952- project_path: project.clone(),18149+ // `open_media`/`load_project` a drop goes through: an
18150+ // export beside the picture, a save beside it too.
18151+ export_path: PathBuf::new(),
18152+ project_path: PathBuf::new(),
17953 keymap: keymap.clone(),18153 keymap: keymap.clone(),
17954 keys_open: false,18154 keys_open: false,
17955 keys_search: String::new(),18155 keys_search: String::new(),
@@ -18007,10 +18207,11 @@ fn main() {
18007 rebinding: None,18207 rebinding: None,
18008 notice: notice.clone().map(SharedString::from),18208 notice: notice.clone().map(SharedString::from),
18009 exported: None,18209 exported: None,
18010- // The rest of argv, waiting for the first repaint to start18210+ // The whole of argv, waiting for the first repaint to start
18011- // them: the window is up before a byte of them is read.18211+ // it: the window is up before a byte of it is read.
18012 importing: None,18212 importing: None,
18013- imports: extras.into(),18213+ imports: queue,
18214+ opening: arg.clone(),
18014 // Nothing pushed yet, and never a real title: the first18215 // Nothing pushed yet, and never a real title: the first
18015 // render is what names the window.18216 // render is what names the window.
18016 titled: String::new(),18217 titled: String::new(),