forge
Explore
Log in

Don't you dare go Hollow

A Proxies switch in the panel, and the stand-ins made without being asked

Browse files at this commit

892f81332dd94f32ffbbd87939b66adc5da2e4c0Ahmet Kaan GümüşParent: 79c69dd
  • feat
    • a Proxies switch in the panel, and the stand-ins made without being asked
Show full message
✨ feat(app): a Proxies switch in the panel, and the stand-ins made without being asked

A film this machine cannot cut at speed -- bigger than 1080p, or HEVC or
AV1 at any size -- gets its stand-in started the moment it lands in the
library, two at a time so ten dropped files cannot start ten encodes
over one hardware seat. The library row says how far it has got and then
that there is one; the PROJECT panel's Proxies button says which way the
switch is set and carries the least-finished percentage beside it, so a
switch thrown before anything is ready says so rather than doing
nothing.

The switch is an action like every other: ctrl+p, on the actions card,
and a button that is both the state and the door -- the two tests that
already hold every action to that pass it unchanged.

A stand-in that cannot be made is a line and no more: the film itself is
what plays, which is what plays until one is ready anyway.
crates/app/src/export_ui.rsmodified+7 -0
@@ -645,6 +645,13 @@ pub(crate) fn export_settings(
645645 // caller that writes a file; the rest of them are asking about the
646646 // bitrate and the format.
647647 subtitles: Vec::new(),
648+ // Neither is a delivery setting: both belong to the stand-ins
649+ // [`engine::proxy`] writes -- every frame a key frame costs bits
650+ // nobody delivering wants, and a file kept in its source's colour
651+ // space is one for this editor to read back rather than to hand
652+ // anybody.
653+ intra_only: false,
654+ keep_source_colour: false,
648655 }
649656 }
650657
crates/app/src/importing.rsmodified+37 -0
@@ -62,6 +62,43 @@ pub(crate) enum Wave {
6262 Peaks(Arc<Vec<(f32, f32)>>),
6363 }
6464
65+/// What a source's stand-in is up to ([`engine::proxy`]). Kept per file and
66+/// filled like every other library fact -- presence means "asked", so a repaint
67+/// mid-encode cannot start a second one.
68+pub(crate) enum Proxy {
69+ /// The header is being read to find out whether this file wants one. Its
70+ /// own state because it is what makes "how many are in flight" a number:
71+ /// the answer comes back on a worker, and until it does this file may still
72+ /// turn into an encode.
73+ Asked,
74+ /// A file this machine cuts at speed as it is: no stand-in, and none
75+ /// wanted ([`engine::proxy::wanted`]).
76+ Native,
77+ /// Being made, in the background, while the film keeps playing.
78+ Making(engine::proxy::Job),
79+ /// There is one in the cache. What the switch actually plays.
80+ Ready,
81+ /// It could not be made: the film itself is what plays, and the row says
82+ /// so rather than leaving a bar that never fills.
83+ Failed,
84+}
85+
86+impl Proxy {
87+ /// What the library row says about it, or nothing at all for a file that
88+ /// never wanted one -- a row per source is not the place to announce that
89+ /// nothing is happening.
90+ pub(crate) fn detail(&self) -> String {
91+ match self {
92+ Self::Asked | Self::Native => String::new(),
93+ // Rounded down: a bar that says 100% while the encoder is still
94+ // writing is the one number a progress line must never show.
95+ Self::Making(job) => format!("proxy {}%", (job.progress() * 100.) as u32),
96+ Self::Ready => "proxy".to_string(),
97+ Self::Failed => "no proxy".to_string(),
98+ }
99+ }
100+}
101+
65102 /// The import a worker is reading, as the line above the panel shows it. No
66103 /// fraction anywhere: neither read reports how far into the file it has come,
67104 /// so what is honest is the file's name, the stage, and two clocks -- one that
crates/app/src/keymap.rsmodified+18 -1
@@ -110,6 +110,11 @@ actions! {
110110 Mix,
111111 ToggleSnap,
112112 ToggleSubtitles,
113+ /// Cut on the stand-ins or on the films themselves
114+ /// ([`engine::proxy`]): what the picture is decoded from, and nothing
115+ /// else -- the sound and every export stay the film's whichever way it
116+ /// is set.
117+ ToggleProxies,
113118 /// The window's own colours, which belong to the person looking at them and
114119 /// not to the project: a list of the palettes, opened here and from the
115120 /// toolbar's Theme button. It was a build feature once, which made it a
@@ -173,6 +178,7 @@ impl ActionId {
173178 ActionId::Mix => "Mix: track volumes and the limiter…",
174179 ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)",
175180 ActionId::ToggleSubtitles => "Subtitles on / off over the picture",
181+ ActionId::ToggleProxies => "Proxies on / off for the picture",
176182 ActionId::Theme => "Theme: the window's colours…",
177183 ActionId::CancelExport => "Cancel export",
178184 ActionId::ShowActions => "All actions and their keys…",
@@ -227,6 +233,7 @@ impl ActionId {
227233 ActionId::Mix => "mix",
228234 ActionId::ToggleSnap => "toggle-snap",
229235 ActionId::ToggleSubtitles => "toggle-subtitles",
236+ ActionId::ToggleProxies => "toggle-proxies",
230237 ActionId::Theme => "theme",
231238 ActionId::CancelExport => "cancel-export",
232239 ActionId::ShowActions => "show-actions",
@@ -279,6 +286,10 @@ impl ActionId {
279286 | ActionId::ZoomOut
280287 | ActionId::ZoomFit
281288 | ActionId::ToggleSubtitles
289+ // ...and which file the picture is decoded from, which changes
290+ // nothing that is saved and nothing that is exported: a stand-in
291+ // is what one watches while cutting, not what one delivers.
292+ | ActionId::ToggleProxies
282293 // ...and what the whole window is painted in: it edits nothing at
283294 // all, it is what one is looking *with*.
284295 | ActionId::Theme => Category::View,
@@ -811,6 +822,11 @@ impl Keymap {
811822 // the rest of the things one *looks* at, and nowhere near the
812823 // two keys that delete.
813824 b(ActionId::ToggleSubtitles, "t", false),
825+ // The stand-ins take ctrl+p, the p of the word: the unshifted
826+ // one is the fit policy, and a ctrl chord is right for a switch
827+ // thrown once for a whole session rather than one wanted under
828+ // a hand -- the theme takes ctrl+h for that reason.
829+ b(ActionId::ToggleProxies, "p", true),
814830 // The theme takes ctrl+h -- the h of the word, since "t" is the
815831 // subtitles and ctrl+t takes one off -- and a ctrl chord because
816832 // it is a preference set once, not a stroke wanted under a hand
@@ -1085,7 +1101,8 @@ mod tests {
10851101 #[test]
10861102 fn every_default_stroke_reaches_its_action() {
10871103 let k = Keymap::defaults();
1088- assert_eq!(k.entries().len(), 49);
1104+ assert_eq!(k.entries().len(), 50);
1105+ assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies));
10891106 assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions));
10901107 assert_eq!(k.lookup("h", true), Some(ActionId::Theme));
10911108 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
crates/app/src/layout.rsmodified+5 -0
@@ -38,6 +38,11 @@ pub(crate) const LABEL_MIN_W: f32 = 36.;
3838 /// a shape. Ceiling: [`View::max_zoom`]'s 8 frames across the bed. The upgrade
3939 /// is a second, finer pass over the visible span only, cached like `waves` is.
4040 pub(crate) const WAVE_BPS: u32 = 40;
41+/// How many stand-ins ([`engine::proxy`]) may be in flight at once. Two, not
42+/// one per core: each is a whole film through a decoder and an encoder, and the
43+/// hardware seat they queue on is a single one -- more of them at once is the
44+/// same work done later, with the editor slower while it happens.
45+pub(crate) const PROXIES_AT_ONCE: usize = 2;
4146 /// Pixels per envelope column. Coarser than a pixel: the eye reads the shape,
4247 /// and a path with a point per pixel is a path per repaint.
4348 pub(crate) const WAVE_COL: f32 = 2.;
crates/app/src/main.rsmodified+7 -0
@@ -149,6 +149,12 @@ struct Player {
149149 /// the key is inserted the moment the decode is *started*: presence means
150150 /// "asked", so a repaint mid-decode cannot ask again.
151151 waves: HashMap<(PathBuf, usize), Wave>,
152+ /// What each source's stand-in is up to ([`engine::proxy`]), filled like
153+ /// `waves`: presence means "asked", so the encode is started once per file
154+ /// however many times the library is drawn. The switch that decides whether
155+ /// they are *played* is the session's own -- it is the project's and is
156+ /// saved with it, where this map is this window's view of the cache.
157+ proxies: HashMap<PathBuf, Proxy>,
152158 /// Which audio streams each imported file has, as its header describes
153159 /// them: one library row per entry. Keyed and filled like `waves` --
154160 /// presence means "asked" -- and an empty list is a silent file, which is
@@ -602,6 +608,7 @@ fn main() {
602608 selected_asset: None,
603609 library_tab: LibraryTab::Media,
604610 waves: HashMap::new(),
611+ proxies: HashMap::new(),
605612 streams: HashMap::new(),
606613 bitrates: HashMap::new(),
607614 sizes: HashMap::new(),
crates/app/src/player/actions.rsmodified+1 -0
@@ -87,6 +87,7 @@ impl Player {
8787 ActionId::Mix => self.open_mix(None, cx),
8888 ActionId::ToggleSnap => self.toggle_snap(cx),
8989 ActionId::ToggleSubtitles => self.toggle_subtitles(cx),
90+ ActionId::ToggleProxies => self.toggle_proxies(cx),
9091 // The keyboard's door to the same list the toolbar button opens.
9192 // At the window's corner, since a stroke names no place -- and
9293 // [`menu_at`] keeps it on screen from there.
crates/app/src/player/export.rsmodified+45 -0
@@ -111,6 +111,51 @@ impl Player {
111111 })
112112 .detach();
113113 }
114+ // A stand-in for every film this machine cannot cut at speed, started
115+ // the moment the file arrives and made while the editor keeps running
116+ // ([`engine::proxy`]). Off the render thread for the reason the sync
117+ // walk above is -- the decision reads the same header -- and the encode
118+ // itself is the engine's own worker, so what comes back here is a
119+ // handle to poll and not a wait.
120+ for path in unseen_paths(session.sources(), &self.proxies) {
121+ // Two at a time, and the rest at the next repaint: a stand-in is a
122+ // whole film re-encoded, and a library of ten dropped at once would
123+ // otherwise start ten encodes fighting over the one hardware seat.
124+ // The unstarted ones simply stay out of the map, which is what
125+ // brings them back here ([`unseen_paths`]).
126+ if self.in_flight_proxies() >= PROXIES_AT_ONCE {
127+ break;
128+ }
129+ self.proxies.insert(path.clone(), Proxy::Asked);
130+ let started = cx.background_executor().spawn({
131+ let path = path.clone();
132+ async move { engine::proxy::generate_if_wanted(&path) }
133+ });
134+ cx.spawn(async move |this, cx| {
135+ let started = started.await;
136+ this.update(cx, |this, cx| {
137+ let state = match started {
138+ Ok(Some(job)) => Proxy::Making(job),
139+ // A film that needs none keeps the state it was
140+ // inserted with, which is what it is.
141+ Ok(None) => Proxy::Native,
142+ Err(e) => {
143+ let text = format!(
144+ "NO PROXY for {} — {e} — the film itself is what plays",
145+ file_name(&path)
146+ );
147+ eprintln!("{text}");
148+ this.notify_user(text.into());
149+ Proxy::Failed
150+ }
151+ };
152+ this.proxies.insert(path, state);
153+ cx.notify();
154+ })
155+ .ok();
156+ })
157+ .detach();
158+ }
114159 for key in unseen_sources(session.sources(), &self.waves) {
115160 self.waves.insert(key.clone(), Wave::Loading);
116161 let decoded = cx.background_executor().spawn({
crates/app/src/player/library.rsmodified+111 -0
@@ -296,6 +296,117 @@ impl Player {
296296 /// ...and starts whatever is queued behind it, which is the one place the
297297 /// files argv named can begin: they are put in the queue before there is a
298298 /// context to spawn a worker from.
299+ /// Takes each finished stand-in's verdict, once. Sampled here rather than
300+ /// while drawing, for [`Player::poll_export`]'s reason -- and it is the one
301+ /// place a proxy job's outcome is read, so "ready" on a row and the file in
302+ /// the cache are the same fact.
303+ ///
304+ /// Nothing waits for it: until a proxy is ready the film itself is what
305+ /// plays, switch or no switch ([`engine::PlaybackSession::picture_path`]),
306+ /// so a failure costs a line and no more.
307+ pub(crate) fn poll_proxies(&mut self, cx: &mut Context<Self>) {
308+ let done: Vec<(PathBuf, engine::Result<PathBuf>)> = self
309+ .proxies
310+ .iter()
311+ .filter_map(|(path, state)| match state {
312+ Proxy::Making(job) => Some((path.clone(), job.outcome()?)),
313+ _ => None,
314+ })
315+ .collect();
316+ for (path, outcome) in done {
317+ let text = match &outcome {
318+ Ok(_) => format!(
319+ "PROXY READY for {} — Proxies on cuts on it",
320+ file_name(&path)
321+ ),
322+ Err(e) => format!(
323+ "PROXY FAILED for {} — {e} — the film itself is what plays",
324+ file_name(&path)
325+ ),
326+ };
327+ eprintln!("{text}");
328+ self.notify_user(text.into());
329+ let state = match outcome {
330+ Ok(_) => Proxy::Ready,
331+ Err(_) => Proxy::Failed,
332+ };
333+ self.proxies.insert(path, state);
334+ cx.notify();
335+ }
336+ }
337+
338+ /// What the Proxies button says after the state: how far the stand-ins
339+ /// have got, since "on" with nothing made yet and "on" with the whole
340+ /// library standing in are two different things to be looking at. Empty
341+ /// where no film here wants one, which is the ordinary case.
342+ pub(crate) fn proxy_tail(&self) -> String {
343+ let making = self.proxies.values().filter_map(|p| match p {
344+ Proxy::Making(job) => Some(job.progress()),
345+ _ => None,
346+ });
347+ // The one furthest along would read as done while three others sit at
348+ // nothing: the *least* finished is what the button reports.
349+ match making.fold(f32::INFINITY, f32::min) {
350+ least if least.is_finite() => format!(" · {}%", (least * 100.) as u32),
351+ _ => String::new(),
352+ }
353+ }
354+
355+ /// Whether any stand-in is still being made -- what keeps the frame loop
356+ /// alive while one is, so its percentage moves on screen.
357+ pub(crate) fn making_proxies(&self) -> bool {
358+ self.proxies
359+ .values()
360+ .any(|p| matches!(p, Proxy::Making(_)))
361+ }
362+
363+ /// How many films are between "shall we?" and "done": the number the start
364+ /// of another is held against ([`PROXIES_AT_ONCE`]). A header being read
365+ /// counts, because the answer may be an encode.
366+ pub(crate) fn in_flight_proxies(&self) -> usize {
367+ self.proxies
368+ .values()
369+ .filter(|p| matches!(p, Proxy::Asked | Proxy::Making(_)))
370+ .count()
371+ }
372+
373+ /// Cuts on the stand-ins, or on the films themselves. The picture and only
374+ /// the picture: the sound is the film's either way, and so is every frame
375+ /// an export writes.
376+ pub(crate) fn toggle_proxies(&mut self, cx: &mut Context<Self>) {
377+ let Some(session) = &mut self.session else {
378+ return;
379+ };
380+ let on = !session.proxies();
381+ session.set_proxies(on);
382+ // What is really under the switch, said in the same breath: a project
383+ // whose films have no stand-in yet would otherwise read as a switch
384+ // that does nothing.
385+ let ready = self
386+ .proxies
387+ .values()
388+ .filter(|p| matches!(p, Proxy::Ready))
389+ .count();
390+ let making = self
391+ .proxies
392+ .values()
393+ .filter(|p| matches!(p, Proxy::Making(_)))
394+ .count();
395+ let text = match (on, ready, making) {
396+ (false, ..) => "PROXIES OFF — the films themselves are what play".to_string(),
397+ (true, 0, 0) => {
398+ "PROXIES ON — no film here has one, so the films themselves play".to_string()
399+ }
400+ (true, 0, n) => format!("PROXIES ON — {n} still being made; the films play until then"),
401+ (true, n, 0) => format!("PROXIES ON — cutting on {n}"),
402+ (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"),
403+ };
404+ eprintln!("{text}");
405+ self.notify_user(text.into());
406+ self.reset_after_reseek();
407+ cx.notify();
408+ }
409+
299410 pub(crate) fn poll_import(&mut self, cx: &mut Context<Self>) {
300411 match &mut self.importing {
301412 Some(import) => {
crates/app/src/render.rsmodified+5 -0
@@ -23,6 +23,7 @@ impl Render for Player {
2323 self.poll_export();
2424 self.poll_import(cx);
2525 self.poll_silence();
26+ self.poll_proxies(cx);
2627 // Every way a source can arrive -- argv, an import, a project load --
2728 // has been through a repaint by the time its clips are drawn, so this
2829 // is the one place that has to notice a new one.
@@ -57,6 +58,10 @@ impl Render for Player {
5758 // the screen on a repaint, and a still line is the very thing this
5859 // card was rewritten to disprove.
5960 || self.silence_scan.is_some()
61+ // ...and a stand-in being made: its percentage on the library row
62+ // only reaches the screen on a repaint, and a bar that never moves
63+ // is exactly what a person reads as a hung encode.
64+ || self.making_proxies()
6065 {
6166 window.request_animation_frame();
6267 }
crates/app/src/ui/inspector.rsmodified+18 -0
@@ -284,6 +284,24 @@ impl Player {
284284 this.open_picker(Pick::Tone, event.position(), cx)
285285 }),
286286 ))
287+ // Its own rect and a label that *is* the state, the rule
288+ // the snap toggle writes down: a button that resized itself
289+ // on every press made the row shuffle under the pointer.
290+ .child(self.action_control(
291+ "proxies",
292+ TONE_SLOT_W,
293+ BG_RAISED(),
294+ None,
295+ match self.session.as_ref().map(PlaybackSession::proxies) {
296+ Some(true) => format!("Proxies on{}", self.proxy_tail()),
297+ Some(false) => format!("Proxies off{}", self.proxy_tail()),
298+ None => "Proxies".to_string(),
299+ },
300+ "cuts on small stand-ins of the big films; the sound and every export \
301+ stay the film's own",
302+ ActionId::ToggleProxies,
303+ cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_proxies(cx)),
304+ ))
287305 .child(self.action_control(
288306 "inspect-mix",
289307 0.,
crates/app/src/ui/library.rsmodified+10 -0
@@ -112,6 +112,16 @@ impl Player {
112112 &timecode(f64::from(row.frames) / self.fps, self.fps),
113113 ),
114114 };
115+ // ...and what this file's stand-in is up to, after its length: a
116+ // percentage while one is being made, the word while there is one,
117+ // and nothing at all for a film that wants none ([`Proxy::detail`]).
118+ let under = join_detail(
119+ &under,
120+ &self
121+ .proxies
122+ .get(&row.path)
123+ .map_or_else(String::new, Proxy::detail),
124+ );
115125 let usable = row.unusable.is_none();
116126 let (path, stream) = (row.path.clone(), row.stream);
117127 let dragged = (path.clone(), stream);
crates/engine/src/proxy.rsmodified+30 -3
@@ -178,18 +178,45 @@ impl Job {
178178 /// back through [`Job::outcome`], so a caller has two places to look and not
179179 /// twenty.
180180 pub fn generate(source: &Path) -> crate::Result<Job> {
181+ Ok(started(source, |_| true)?.expect("nothing was filtered out"))
182+}
183+
184+/// The same, for a file that is worth standing in for and nobody else
185+/// ([`wanted`]) -- `Ok(None)` is a film this machine already cuts at speed.
186+///
187+/// The header is read *once* for both questions: on a Matroska that read is the
188+/// cluster walk, so asking `wanted` and then `generate` separately would pay
189+/// for it twice.
190+pub fn generate_if_wanted(source: &Path) -> crate::Result<Option<Job>> {
191+ started(source, wanted)
192+}
193+
194+/// Both doors: the cache is looked at, the header is read once, and `only_if`
195+/// decides off that header whether there is anything to do.
196+fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Option<Job>> {
181197 let out = path_for(source).ok_or("no cache directory to keep a proxy in")?;
182198 if out.is_file() {
183- return Ok(Job { out, handle: None });
199+ return Ok(Some(Job { out, handle: None }));
184200 }
185201 // The source's own header: its rate and length are the proxy's (a stand-in
186202 // that ran at another rate or stopped early would put every cut on another
187203 // frame), and only its picture size changes.
188204 let (meta, _) = Demuxer::open(source)?;
205+ if !only_if(&meta) {
206+ return Ok(None);
207+ }
189208 let (width, height) = size_for(&meta);
190209 if let Some(dir) = out.parent() {
191210 std::fs::create_dir_all(dir)?;
192211 }
212+ // What a killed editor left behind: the export worker deletes its own part
213+ // file when it is cancelled or fails, but nothing can delete it for a
214+ // process that was killed -- and a proxy of a feature film is hundreds of
215+ // megabytes of cache nothing would ever look at again. The key is the same,
216+ // so this is that same film's own leftover and not somebody else's.
217+ let mut part = out.clone().into_os_string();
218+ part.push(".part");
219+ let _ = std::fs::remove_file(PathBuf::from(part));
193220 // One video lane, one clip, the whole file -- and *no* audio lane, which is
194221 // what makes the proxy picture-only: the export walk codes the lanes it is
195222 // given and there is no sound among them.
@@ -232,10 +259,10 @@ pub fn generate(source: &Path) -> crate::Result<Job> {
232259 ..Default::default()
233260 },
234261 );
235- Ok(Job {
262+ Ok(Some(Job {
236263 out,
237264 handle: Some(handle),
238- })
265+ }))
239266 }
240267
241268 #[cfg(test)]