forge
Explore
Log in

Don't you dare go Hollow

Pay debts — audio-only fallbacks, panic-proof proxy, .part sweep

Browse files at this commit

b05a649de50bbcb500367f25e33e70784c1b6807Ahmet Kaan GümüşParent: 5dcc6c2
  • fix
    • pay debts — audio-only fallbacks, panic-proof proxy, .part sweep
Show full message
🐛 fix(app,engine): pay debts — audio-only fallbacks, panic-proof proxy, .part sweep

Twelve debts paid in one batch:

- engine: NoVideoTrack fallback at every video door — open_stream,
  open_project scaffold, and import() now route a video-extension file
  whose header holds no picture to the audio-only path instead of
  refusing (argv open, saved-project reload, and library import).
- engine: proxy/export worker wrapped in catch_unwind — a decoder panic
  settles the shared slot with Err instead of stranding Making/Cancelling.
- vendor/cros-codecs: AV1 setup_shear multiplies checked — malformed warp
  params are a parse error, not a process abort (live-proven on an AV1 film:
  clean PROXY FAILED notice, slot released, app alive).
- engine: startup sweep of orphan proxy .part files.
- app: Player::has_video probe cache — lane_refuses gates drops on the
  probed kind, not the extension; Silences hidden on soundless clips;
  audio import toast names rate/channels/length; stale no-session proxy
  label cleared.
- tests: audio-only mp4 fixture + gen_fixtures.sh line, 2 engine
  NoVideoTrack tests, toast/lane/view cases (246 bin + 14 audio_files).

Harness-proven this batch (runs 20260826-2306..2315): split-at-playhead
with undo, lane-remove mouse door, fade-out drag, argv audio-only open,
AV1 proxy clean failure.
crates/app/src/main.rsmodified+14 -0
@@ -255,6 +255,14 @@ struct Player {
255 /// `None` is a file with no picture to report (every source that is not an255 /// `None` is a file with no picture to report (every source that is not an
256 /// image, and one whose header would not read).256 /// image, and one whose header would not read).
257 sizes: HashMap<PathBuf, Option<(u32, u32)>>,257 sizes: HashMap<PathBuf, Option<(u32, u32)>>,
258+ /// Whether a source's own header says it carries a picture at all,
259+ /// probed once and kept: what [`Player::has_video`] reads for the lane a
260+ /// drag may land on ([`timeline_math::lane_refuses`]). An extension can
261+ /// lie -- a song muxed into an `.mp4` -- and only the header says the
262+ /// truth (`engine::demux::NoVideoTrack`). Filled like `sizes`: presence
263+ /// means "asked", and until the probe answers a file is read by its
264+ /// extension, the same guess the ghost always made.
265+ has_video: HashMap<PathBuf, bool>,
258 /// Every frame of each source a decoder may be started from -- its sync266 /// Every frame of each source a decoder may be started from -- its sync
259 /// points ([`engine::demux::sync_points`]), which are the frames a cut may267 /// points ([`engine::demux::sync_points`]), which are the frames a cut may
260 /// be placed on for an export to *copy* the film instead of coding all of268 /// be placed on for an export to *copy* the film instead of coding all of
@@ -770,6 +778,11 @@ struct Player {
770 mod tests;778 mod tests;
771 779
772 fn main() {780 fn main() {
781+ // What a killed editor left behind: `.part` proxies from an encode that
782+ // never got to unlink its own half-written file. Run once, here, before
783+ // anything in this process could claim one of its own -- every `.part` on
784+ // disk at this instant belongs to nobody still running.
785+ engine::proxy::sweep_stale_parts();
773 // A keymap file that cannot be read leaves the defaults in force, and takes786 // A keymap file that cannot be read leaves the defaults in force, and takes
774 // the notice slot ahead of an open or import refusal: it is about every key787 // the notice slot ahead of an open or import refusal: it is about every key
775 // the window has, and those refusals are on stderr either way.788 // the window has, and those refusals are on stderr either way.
@@ -905,6 +918,7 @@ fn main() {
905 thumbs: HashMap::new(),918 thumbs: HashMap::new(),
906 proxies: HashMap::new(),919 proxies: HashMap::new(),
907 streams: HashMap::new(),920 streams: HashMap::new(),
921+ has_video: HashMap::new(),
908 bitrates: HashMap::new(),922 bitrates: HashMap::new(),
909 sizes: HashMap::new(),923 sizes: HashMap::new(),
910 syncs: HashMap::new(),924 syncs: HashMap::new(),
crates/app/src/oracle.rsmodified+7 -0
@@ -61,6 +61,12 @@ pub(crate) struct Ctx {
61 /// reach at all -- not the lane's business, because a still sits on a video61 /// reach at all -- not the lane's business, because a still sits on a video
62 /// lane exactly like a take whose sound is one lane down.62 /// lane exactly like a take whose sound is one lane down.
63 pub(crate) image: bool,63 pub(crate) image: bool,
64+ /// The clip's source is known, from the probed stream table
65+ /// ([`Player::streams`]), to carry no audio track at all -- a video shot
66+ /// mute, not merely a video whose sound is quiet. `false` (the default)
67+ /// covers both "has sound" and "not probed yet": a row nobody has asked
68+ /// about is not one this hides a working action from.
69+ pub(crate) no_sound: bool,
64 pub(crate) playhead: u32,70 pub(crate) playhead: u32,
65 /// A timeline is open.71 /// A timeline is open.
66 pub(crate) timeline: bool,72 pub(crate) timeline: bool,
@@ -221,6 +227,7 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable {
221 // `unscannable` says after the fact, said before the row is drawn so227 // `unscannable` says after the fact, said before the row is drawn so
222 // there is no row left to click.228 // there is no row left to click.
223 ActionId::Silence if ctx.image => Enable::Hidden("this clip is a still"),229 ActionId::Silence if ctx.image => Enable::Hidden("this clip is a still"),
230+ ActionId::Silence if ctx.no_sound => Enable::Hidden("this clip has no sound"),
224 // -- state: true of this clip now, and the next playhead click or the231 // -- state: true of this clip now, and the next playhead click or the
225 // next selection changes the answer. Splits this clip only from inside232 // next selection changes the answer. Splits this clip only from inside
226 // it: at either edge there is nothing to split off -- and, on a speeded233 // it: at either edge there is nothing to split off -- and, on a speeded
crates/app/src/player/actions.rsmodified+12 -0
@@ -370,6 +370,18 @@ impl Player {
370 .get(clip.source)370 .get(clip.source)
371 .is_some_and(|s| engine::is_image(&s.path))371 .is_some_and(|s| engine::is_image(&s.path))
372 }),372 }),
373+ // The probed stream table again, this time asking the other
374+ // question of it: an empty list is a silent file
375+ // ([`Player::streams`]), and a clip cut from one has no sound to
376+ // scan whatever lane it sits on -- said before the row is drawn
377+ // rather than after the scan comes back empty
378+ // ([`Player::start_silence_scan`]'s `Ok(None)` arm).
379+ no_sound: clip.is_some_and(|(clip, _)| {
380+ session
381+ .sources()
382+ .get(clip.source)
383+ .is_some_and(|s| self.streams.get(&s.path).is_some_and(Vec::is_empty))
384+ }),
373 playhead: frame_at(session.now(), self.fps),385 playhead: frame_at(session.now(), self.fps),
374 timeline: true,386 timeline: true,
375 clipboard: !self.clipboard.is_empty(),387 clipboard: !self.clipboard.is_empty(),
crates/app/src/player/export.rsmodified+45 -0
@@ -4,6 +4,17 @@
4 use crate::*;4 use crate::*;
5 5
6 impl Player {6 impl Player {
7+ /// What [`timeline_math::lane_refuses`] asks to decide a video lane's
8+ /// refusal: the probed answer if `cache_media` has one yet, and the
9+ /// extension's own guess -- the same one every door used before the
10+ /// probe existed -- while it is still asking.
11+ pub(crate) fn has_video(&self, path: &Path) -> bool {
12+ self.has_video
13+ .get(path)
14+ .copied()
15+ .unwrap_or_else(|| !engine::is_audio(path))
16+ }
17+
7 /// Starts a peak decode -- and a stream probe -- for every source that has18 /// Starts a peak decode -- and a stream probe -- for every source that has
8 /// arrived since the last19 /// arrived since the last
9 /// repaint. One call from the render rather than three at the doors,20 /// repaint. One call from the render rather than three at the doors,
@@ -48,6 +59,40 @@ impl Player {
48 })59 })
49 .detach();60 .detach();
50 }61 }
62+ // Whether a file's own header carries a picture at all, for the lane
63+ // a drag may land on ([`Player::has_video`]). The two kinds whose
64+ // extension already tells the truth (`engine::is_audio`,
65+ // `engine::is_image`) are answered inline; the rest is the one case
66+ // an extension can lie about -- a song muxed into an `.mp4` -- so it
67+ // costs the same header open [`engine::decode::probe`] pays and goes
68+ // off the render thread for the same reason.
69+ for path in unseen_paths(session.sources(), &self.has_video) {
70+ if engine::is_audio(&path) {
71+ self.has_video.insert(path, false);
72+ continue;
73+ }
74+ if engine::is_image(&path) {
75+ self.has_video.insert(path, true);
76+ continue;
77+ }
78+ self.has_video.insert(path.clone(), true);
79+ let probed = cx.background_executor().spawn({
80+ let path = path.clone();
81+ async move {
82+ !matches!(engine::demux::Demuxer::open(&path),
83+ Err(e) if engine::demux::NoVideoTrack::is_it(&e))
84+ }
85+ });
86+ cx.spawn(async move |this, cx| {
87+ let probed = probed.await;
88+ this.update(cx, |this, cx| {
89+ this.has_video.insert(path, probed);
90+ cx.notify();
91+ })
92+ .ok();
93+ })
94+ .detach();
95+ }
51 // What each file is coded at, for the card that says so. Header and96 // What each file is coded at, for the card that says so. Header and
52 // sample table only, but a Matroska indexes no samples and its open97 // sample table only, but a Matroska indexes no samples and its open
53 // walks every cluster header -- 6.7 s on a 12.9 GB film -- so this of98 // walks every cluster header -- 6.7 s on a 12.9 GB film -- so this of
crates/app/src/player/library.rsmodified+22 -4
@@ -97,7 +97,7 @@ impl Player {
97 // ([`lane_refuses`]). The Add button names no lane and so is never97 // ([`lane_refuses`]). The Add button names no lane and so is never
98 // refused here -- where a file goes when nobody says is the engine's98 // refused here -- where a file goes when nobody says is the engine's
99 // choice, in `place_stream_at`, not one made twice here.99 // choice, in `place_stream_at`, not one made twice here.
100- if let Some(why) = onto.and_then(|lane| lane_refuses(path, lane)) {100+ if let Some(why) = onto.and_then(|lane| lane_refuses(path, lane, self.has_video(path))) {
101 self.notify_user(why.into());101 self.notify_user(why.into());
102 cx.notify();102 cx.notify();
103 return;103 return;
@@ -325,6 +325,7 @@ impl Player {
325 self.bitrates.clear();325 self.bitrates.clear();
326 self.sizes.clear();326 self.sizes.clear();
327 self.syncs.clear();327 self.syncs.clear();
328+ self.has_video.clear();
328 // Scanned off sources that are not in the library any more.329 // Scanned off sources that are not in the library any more.
329 self.silence_levels.clear();330 self.silence_levels.clear();
330 // ...and every background read still chasing one of them: cancelled331 // ...and every background read still chasing one of them: cancelled
@@ -805,6 +806,13 @@ impl Player {
805 /// library standing in are two different things to be looking at. Empty806 /// library standing in are two different things to be looking at. Empty
806 /// where no film here wants one, which is the ordinary case.807 /// where no film here wants one, which is the ordinary case.
807 pub(crate) fn proxy_tail(&self) -> String {808 pub(crate) fn proxy_tail(&self) -> String {
809+ // No session, no library row could be making anything: a prior
810+ // session's jobs (never cleared out of `self.proxies` on close, since
811+ // a proxy is derived and re-checked from disk on next open rather
812+ // than tracked per session) must not print as this one's progress.
813+ if self.session.is_none() {
814+ return String::new();
815+ }
808 let making = self.proxies.values().filter_map(|p| match p {816 let making = self.proxies.values().filter_map(|p| match p {
809 Proxy::Making(job) => Some(job.progress()),817 Proxy::Making(job) => Some(job.progress()),
810 _ => None,818 _ => None,
@@ -1073,8 +1081,13 @@ impl Player {
1073 // ([`engine::PlaybackSession::import`]); a window whose timeline went1081 // ([`engine::PlaybackSession::import`]); a window whose timeline went
1074 // away while the worker read falls to the slow door below, which is the1082 // away while the worker read falls to the slow door below, which is the
1075 // one that can still open one.1083 // one that can still open one.
1084+ // A refusal that only says "no picture" is not a refusal here: the
1085+ // slow door below re-reads the file and lands it as audio, the same
1086+ // fallback every other door in makes.
1087+ let no_video = matches!(&probe, Some(Err(e)) if engine::demux::NoVideoTrack::is_it(e));
1076 let registered = match (self.session.as_mut(), probe) {1088 let registered = match (self.session.as_mut(), probe) {
1077 (Some(session), Some(Ok(probe))) => Some(session.import_probed(path, probe)),1089 (Some(session), Some(Ok(probe))) => Some(session.import_probed(path, probe)),
1090+ (Some(session), Some(Err(_))) if no_video => Some(session.import(path)),
1078 (Some(_), Some(Err(refused))) => Some(Err(refused)),1091 (Some(_), Some(Err(refused))) => Some(Err(refused)),
1079 (Some(session), None) => Some(session.import(path)),1092 (Some(session), None) => Some(session.import(path)),
1080 (None, _) => None,1093 (None, _) => None,
@@ -1091,8 +1104,9 @@ impl Player {
1091 .and_then(|session| subtitle_tail(session, subs))1104 .and_then(|session| subtitle_tail(session, subs))
1092 .unwrap_or_default();1105 .unwrap_or_default();
1093 format!(1106 format!(
1094- "IMPORTED {} to the library — drag it onto a lane to place it{tail}",1107+ "IMPORTED {} to the library — drag it onto a lane to place it{tail}{}",
1095- file_name(path)1108+ file_name(path),
1109+ audio_import_tail(path, self.has_video(path) && !no_video)
1096 )1110 )
1097 }1111 }
1098 // Named, because two files can fail in one launch and the queue now1112 // Named, because two files can fail in one launch and the queue now
@@ -1186,7 +1200,11 @@ impl Player {
1186 format!("IMPORTED {name} to the library — drag it onto a lane to place it")1200 format!("IMPORTED {name} to the library — drag it onto a lane to place it")
1187 }1201 }
1188 };1202 };
1189- format!("{what}{}{subs}", silent.unwrap_or_default())1203+ let audio = match place {
1204+ true => String::new(),
1205+ false => audio_import_tail(path, self.has_video(path)),
1206+ };
1207+ format!("{what}{}{subs}{audio}", silent.unwrap_or_default())
1190 }1208 }
1191 Err(e) => format!("OPEN FAILED: {e}"),1209 Err(e) => format!("OPEN FAILED: {e}"),
1192 }1210 }
crates/app/src/player/timeline_edit.rsmodified+1 -1
@@ -980,7 +980,7 @@ impl Player {
980 // A path with no source entry has no colour of its own, and the980 // A path with no source entry has no colour of its own, and the
981 // shadow wears the lane's own instead of borrowing another file's.981 // shadow wears the lane's own instead of borrowing another file's.
982 tint: file_tint(self.sources(), path).unwrap_or(BG_RAISED()),982 tint: file_tint(self.sources(), path).unwrap_or(BG_RAISED()),
983- refused: lane_refuses(path, to).is_some(),983+ refused: lane_refuses(path, to, self.has_video(path)).is_some(),
984 };984 };
985 self.set_ghost(vec![ghost], cx);985 self.set_ghost(vec![ghost], cx);
986 }986 }
crates/app/src/subs.rsmodified+22 -0
@@ -243,6 +243,28 @@ pub(crate) fn read_ahead(
243 Landed::Read(walk_subtitles(path), probe)243 Landed::Read(walk_subtitles(path), probe)
244 }244 }
245 245
246+/// The toast's own words for a standalone audio import -- rate, channel
247+/// count and rounded length -- appended after every other tail, so an
248+/// audio-only file's IMPORTED line reads the numbers a properties card would
249+/// otherwise take a click to open. `has_video` is the caller's probed answer
250+/// ([`Player::has_video`], or the import's own `NoVideoTrack` refusal): a
251+/// film's toast is unchanged, an audio-only container gets the numbers the
252+/// same as a song, and a song whose own small header read comes back empty
253+/// stays plain.
254+pub(crate) fn audio_import_tail(path: &std::path::Path, has_video: bool) -> String {
255+ if has_video {
256+ return String::new();
257+ }
258+ let probe = engine::AudioSession::probe(path, 0).ok().flatten();
259+ let secs = engine::AudioSession::duration_secs(path).ok().flatten();
260+ match (probe, secs) {
261+ (Some(p), Some(secs)) => {
262+ format!(" — {} Hz, {} ch, {}s", p.sample_rate, p.channels, secs.round() as u64)
263+ }
264+ _ => String::new(),
265+ }
266+}
267+
246 /// Every subtitle track a file carries, cues and all -- the walk that costs, in268 /// Every subtitle track a file carries, cues and all -- the walk that costs, in
247 /// the one place every door that pays it goes through. `Ok` and empty for a file269 /// the one place every door that pays it goes through. `Ok` and empty for a file
248 /// with none to read, which is what a file that is neither a container we can270 /// with none to read, which is what a file that is neither a container we can
crates/app/src/tests/editing.rsmodified+16 -0
@@ -839,6 +839,22 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
839 ),839 ),
840 Enable::Hidden(_)840 Enable::Hidden(_)
841 ));841 ));
842+ // A video clip the probed stream table says has no audio track at all --
843+ // the row is hidden rather than offered and refused after a scan comes
844+ // back with nothing to report (`Player::start_silence_scan`'s `Ok(None)`).
845+ assert!(matches!(
846+ enable(
847+ ActionId::Silence,
848+ Ctx {
849+ clip: Some((clip, v1)),
850+ no_sound: true,
851+ playhead: 60,
852+ timeline: true,
853+ ..Ctx::default()
854+ }
855+ ),
856+ Enable::Hidden(_)
857+ ));
842 // The editor as a whole, which is how the actions card asks: with no858 // The editor as a whole, which is how the actions card asks: with no
843 // timeline nothing is offered, an export leaves only its own cancel,859 // timeline nothing is offered, an export leaves only its own cancel,
844 // and the three that act on the marked clip say so when none is.860 // and the three that act on the marked clip say so when none is.
crates/app/src/tests/media.rsmodified+16 -1
@@ -6,10 +6,25 @@ use crate::player::library::{
6 auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref,6 auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref,
7 };7 };
8 use crate::subs::{8 use crate::subs::{
9- SUB_SIZE_RANGE, load_subtitle_style, save_subtitle_style, sub_line_h_for, subtitle_style_path,9+ SUB_SIZE_RANGE, audio_import_tail, load_subtitle_style, save_subtitle_style, sub_line_h_for,
10+ subtitle_style_path,
10 };11 };
11 use crate::ui::preview::{bgra_to_rgba, screenshot_path};12 use crate::ui::preview::{bgra_to_rgba, screenshot_path};
12 13
14+/// The toast tail an audio import earns: rate, channel count and rounded
15+/// length, in the words the IMPORTED line appends them in
16+/// ([`Player::take_import`], [`Player::install_media`]). A film gets none of
17+/// it -- the gate is the probed has-video answer, not the extension, so an
18+/// audio-only container wearing .mp4 reads its numbers too.
19+#[test]
20+fn an_audio_import_names_its_rate_channels_and_length() {
21+ let tail = audio_import_tail(&asset("test_tone.mp3"), false);
22+ assert_eq!(tail, " — 44100 Hz, 2 ch, 3s", "{tail}");
23+ assert_eq!(audio_import_tail(&asset("test_av.mp4"), true), "");
24+ let mp4 = audio_import_tail(&asset("test_audio_only.mp4"), false);
25+ assert_eq!(mp4, " — 44100 Hz, 1 ch, 3s", "{mp4}");
26+}
27+
13 /// The import line's own state machine, driven the way a repaint drives28 /// The import line's own state machine, driven the way a repaint drives
14 /// it: the worker writes a stage, the poll notices it changed and restarts29 /// it: the worker writes a stage, the poll notices it changed and restarts
15 /// the stall clock, and the line's words change only when a stage has30 /// the stall clock, and the line's words change only when a stage has
crates/app/src/tests/view.rsmodified+16 -8
@@ -110,26 +110,34 @@ fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() {
110 let still = Path::new("/media/card.png");110 let still = Path::new("/media/card.png");
111 let movie = Path::new("/media/take.mp4");111 let movie = Path::new("/media/take.mp4");
112 assert_eq!(112 assert_eq!(
113- lane_refuses(sound, video).as_deref(),113+ lane_refuses(sound, video, false).as_deref(),
114 Some("NOT ON V1 — take.mp3 has no picture; drop it on an audio lane")114 Some("NOT ON V1 — take.mp3 has no picture; drop it on an audio lane")
115 );115 );
116 assert_eq!(116 assert_eq!(
117- lane_refuses(still, audio).as_deref(),117+ lane_refuses(still, audio, true).as_deref(),
118 Some("NOT ON A1 — card.png is a still image; drop it on a video lane")118 Some("NOT ON A1 — card.png is a still image; drop it on a video lane")
119 );119 );
120 // ...and every lane a file *can* go on says nothing at all, which is a120 // ...and every lane a file *can* go on says nothing at all, which is a
121 // ghost drawn in the file's own colour.121 // ghost drawn in the file's own colour.
122- assert_eq!(lane_refuses(sound, audio), None);122+ assert_eq!(lane_refuses(sound, audio, false), None);
123- assert_eq!(lane_refuses(still, video), None);123+ assert_eq!(lane_refuses(still, video, true), None);
124- assert_eq!(lane_refuses(movie, video), None);124+ assert_eq!(lane_refuses(movie, video, true), None);
125 // A file with a picture is not refused by an audio lane here: the125 // A file with a picture is not refused by an audio lane here: the
126 // engine takes its sound onto one, and the words for a video-only file126 // engine takes its sound onto one, and the words for a video-only file
127 // are its own.127 // are its own.
128- assert_eq!(lane_refuses(movie, audio), None);128+ assert_eq!(lane_refuses(movie, audio, true), None);
129+ // The extension lies and the probe corrects it: a song muxed into an
130+ // `.mp4` still names a video lane refused, in the exact words the .mp3
131+ // twin above got -- `has_video` is what decides it now, not the suffix.
132+ assert_eq!(
133+ lane_refuses(movie, video, false).as_deref(),
134+ Some("NOT ON V1 — take.mp4 has no picture; drop it on an audio lane")
135+ );
129 // ...and a subtitle lane holds none of the three: a caption comes off the136 // ...and a subtitle lane holds none of the three: a caption comes off the
130 // Subtitles list, which is where the refusal points.137 // Subtitles list, which is where the refusal points.
131- for file in [sound, still, movie] {138+ for (file, has_video) in [(sound, false), (still, true), (movie, true)] {
132- let why = lane_refuses(file, Lane::S1).expect("a subtitle lane takes no media");139+ let why =
140+ lane_refuses(file, Lane::S1, has_video).expect("a subtitle lane takes no media");
133 assert!(why.starts_with("NOT ON S1 — "), "{why}");141 assert!(why.starts_with("NOT ON S1 — "), "{why}");
134 assert!(why.contains("Subtitles list"), "{why}");142 assert!(why.contains("Subtitles list"), "{why}");
135 }143 }
crates/app/src/timeline_math.rsmodified+6 -2
@@ -651,11 +651,15 @@ pub(crate) fn landing(
651 /// cannot go. Asked twice: by the ghost tinting itself as refused on the way651 /// cannot go. Asked twice: by the ghost tinting itself as refused on the way
652 /// down, and by the insert that commits ([`Player::insert_source`]), so what is652 /// down, and by the insert that commits ([`Player::insert_source`]), so what is
653 /// shown as impossible is exactly what is refused.653 /// shown as impossible is exactly what is refused.
654-pub(crate) fn lane_refuses(path: &Path, lane: Lane) -> Option<String> {654+///
655+/// `has_video` is [`Player::has_video`]'s answer for `path`: the probed truth
656+/// where the header has been read, and an extension's guess otherwise -- never
657+/// `engine::is_audio` alone, which a song muxed into an `.mp4` lies to.
658+pub(crate) fn lane_refuses(path: &Path, lane: Lane, has_video: bool) -> Option<String> {
655 let name = file_name(path);659 let name = file_name(path);
656 let label = lane.label();660 let label = lane.label();
657 match lane.kind {661 match lane.kind {
658- LaneKind::Video if engine::is_audio(path) => Some(format!(662+ LaneKind::Video if !has_video => Some(format!(
659 "NOT ON {label} — {name} has no picture; drop it on an audio lane"663 "NOT ON {label} — {name} has no picture; drop it on an audio lane"
660 )),664 )),
661 LaneKind::Audio if engine::is_image(path) => Some(format!(665 LaneKind::Audio if engine::is_image(path) => Some(format!(
crates/engine/src/export.rsmodified+22 -0
@@ -494,6 +494,13 @@ pub fn start(
494 encoders: Mutex::new(None),494 encoders: Mutex::new(None),
495 });495 });
496 let worker = Arc::clone(&shared);496 let worker = Arc::clone(&shared);
497+ // A second handle to the same slot, held outside the caught body below --
498+ // what settles it if that body never gets to its own [`settle`] call at
499+ // all, because a codec parser deep inside `run` panicked instead of
500+ // returning the parse error it should have. Without this a panic there
501+ // strands the slot: [`ExportHandle::is_finished`] never flips, and a
502+ // proxy or export that hit a malformed frame sits in "Making" forever.
503+ let panic_worker = Arc::clone(&worker);
497 let out = out.to_path_buf();504 let out = out.to_path_buf();
498 // `<out>.part`, appended rather than substituted: the temporary of505 // `<out>.part`, appended rather than substituted: the temporary of
499 // `a.export.mp4` is `a.export.mp4.part`, which no other export claims.506 // `a.export.mp4` is `a.export.mp4.part`, which no other export claims.
@@ -501,6 +508,7 @@ pub fn start(
501 part.push(".part");508 part.push(".part");
502 let part = PathBuf::from(part);509 let part = PathBuf::from(part);
503 let spawned = thread::Builder::new().name("export".into()).spawn(move || {510 let spawned = thread::Builder::new().name("export".into()).spawn(move || {
511+ let caught = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
504 // Every file this export will read, named before a byte of one is.512 // Every file this export will read, named before a byte of one is.
505 // These are the project's own sources and can be nothing else: a513 // These are the project's own sources and can be nothing else: a
506 // stand-in ([`crate::proxy`]) is a substitution playback makes when it514 // stand-in ([`crate::proxy`]) is a substitution playback makes when it
@@ -579,6 +587,20 @@ pub fn start(
579 let _ = std::fs::remove_file(&part);587 let _ = std::fs::remove_file(&part);
580 }588 }
581 settle(&worker, result);589 settle(&worker, result);
590+ }));
591+ if let Err(payload) = caught {
592+ // The body above panicked before it could settle its own slot --
593+ // the panic message becomes the outcome, so a caller sees a
594+ // failure and a notice rather than a bar that never moves again.
595+ let message = payload
596+ .downcast_ref::<&str>()
597+ .map(ToString::to_string)
598+ .or_else(|| payload.downcast_ref::<String>().cloned())
599+ .unwrap_or_else(|| "unknown panic".to_string());
600+ if !panic_worker.finished.load(Ordering::Acquire) {
601+ settle(&panic_worker, Err(format!("export worker panicked: {message}").into()));
602+ }
603+ }
582 });604 });
583 if let Err(e) = spawned {605 if let Err(e) = spawned {
584 settle(&shared, Err(e.into()));606 settle(&shared, Err(e.into()));
crates/engine/src/playback.rsmodified+55 -11
@@ -24,7 +24,7 @@ use crate::clock::{ClockSource, PlaybackClock};
24 use crate::color::ColorParams;24 use crate::color::ColorParams;
25 use crate::colorspace::{ColorDescription, ContentLight};25 use crate::colorspace::{ColorDescription, ContentLight};
26 use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};26 use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};
27-use crate::demux::{Codec, Demuxer, VideoMeta};27+use crate::demux::{Codec, Demuxer, NoVideoTrack, VideoMeta};
28 use crate::eq::EqParams;28 use crate::eq::EqParams;
29 use crate::project::{29 use crate::project::{
30 Clip, Edge, GapSweep, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip,30 Clip, Edge, GapSweep, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip,
@@ -571,7 +571,7 @@ impl PlaybackSession {
571 // Passthrough: a freshly opened file *is* the project resolution, so571 // Passthrough: a freshly opened file *is* the project resolution, so
572 // there is nothing to place it on. Every later span goes through572 // there is nothing to place it on. Every later span goes through
573 // `start_span`, which builds the canvas from the project.573 // `start_span`, which builds the canvas from the project.
574- let (meta, stream) = DecodeSession::open_worker(574+ let opened = DecodeSession::open_worker(
575 &path,575 &path,
576 0,576 0,
577 u32::MAX,577 u32::MAX,
@@ -581,7 +581,17 @@ impl PlaybackSession {
581 // The default rendition: a file just opened is a project nobody has581 // The default rendition: a file just opened is a project nobody has
582 // picked one for, exactly as it is a project nobody has graded.582 // picked one for, exactly as it is a project nobody has graded.
583 crate::tonemap::Preset::default(),583 crate::tonemap::Preset::default(),
584- )?;584+ );
585+ // `is_audio` above is the extension's word, and an extension can lie: a
586+ // song muxed into an `.mp4` reads as a film until the header is actually
587+ // walked. The demuxer's own `NoVideoTrack` is that walk saying there was
588+ // never a picture in it, and the fallback is the same audio-only door the
589+ // extension check would have taken up front -- not a fault, a type.
590+ let (meta, stream) = match opened {
591+ Ok(opened) => opened,
592+ Err(e) if NoVideoTrack::is_it(&e) => return Self::open_audio_only(&path, audio_stream),
593+ Err(e) => return Err(e),
594+ };
585 // A file is opened on its first audio stream by default, like595 // A file is opened on its first audio stream by default, like
586 // `Project::single` names it -- unless a caller through596 // `Project::single` names it -- unless a caller through
587 // `open_with_audio_stream` picked another.597 // `open_with_audio_stream` picked another.
@@ -924,7 +934,13 @@ impl PlaybackSession {
924 } else {934 } else {
925 Demuxer::open(&first.path).map(|(_, d)| d.light()).unwrap_or_default()935 Demuxer::open(&first.path).map(|(_, d)| d.light()).unwrap_or_default()
926 };936 };
927- let (mut meta, stream) = match crate::is_audio(&first.path) {937+ // The extension's word, corrected below the moment the header disagrees
938+ // with it (`NoVideoTrack`, the same fallback `open_stream` takes): every
939+ // later question in this function about source 0 asks *this*, not
940+ // `crate::is_audio` again, so a discovered song stays one for the rest
941+ // of the scaffold.
942+ let mut audio_only = crate::is_audio(&first.path);
943+ let (mut meta, stream) = match audio_only {
928 true => {944 true => {
929 let (width, height, canvas_fps) = AUDIO_ONLY_CANVAS;945 let (width, height, canvas_fps) = AUDIO_ONLY_CANVAS;
930 let frame_rate = saved_fps.unwrap_or(canvas_fps);946 let frame_rate = saved_fps.unwrap_or(canvas_fps);
@@ -964,7 +980,7 @@ impl PlaybackSession {
964 )?;980 )?;
965 (meta, stream)981 (meta, stream)
966 }982 }
967- false => DecodeSession::open_worker(983+ false => match DecodeSession::open_worker(
968 &first.path,984 &first.path,
969 0,985 0,
970 u32::MAX,986 u32::MAX,
@@ -975,8 +991,30 @@ impl PlaybackSession {
975 // project (which is built below): this placeholder is what the991 // project (which is built below): this placeholder is what the
976 // window shows until the `seek` at the end reopens the span.992 // window shows until the `seek` at the end reopens the span.
977 doc.tone,993 doc.tone,
978- )994+ ) {
979- .map_err(|e| format!("source {}: {e}", first.path.display()))?,995+ Ok(opened) => opened,
996+ // A saved source whose extension named a film but whose header
997+ // names no picture: the same door a fresh open falls to
998+ // (`open_stream`), so a project first cut around a song muxed
999+ // into an `.mp4` reloads instead of refusing on a track that was
1000+ // never there to begin with.
1001+ Err(e) if NoVideoTrack::is_it(&e) => {
1002+ audio_only = true;
1003+ let (width, height, canvas_fps) = AUDIO_ONLY_CANVAS;
1004+ let frame_rate = saved_fps.unwrap_or(canvas_fps);
1005+ let meta = VideoMeta {
1006+ width,
1007+ height,
1008+ frame_rate,
1009+ frame_count: audio_frames(&first.path, frame_rate)
1010+ .map_err(|e| format!("source {}: {e}", first.path.display()))?,
1011+ codec: Codec::H264,
1012+ color: ColorDescription::default(),
1013+ };
1014+ (meta, DecodeSession::open_black(width, height, 1))
1015+ }
1016+ Err(e) => return Err(format!("source {}: {e}", first.path.display()).into()),
1017+ },
980 };1018 };
981 // The project's own resolution, which is source 0's picture unless the1019 // The project's own resolution, which is source 0's picture unless the
982 // file says otherwise -- every dialect before v7 had no way to say it,1020 // file says otherwise -- every dialect before v7 had no way to say it,
@@ -994,7 +1032,7 @@ impl PlaybackSession {
994 // ([`set_frame_rate`](Self::set_frame_rate)) comes back at it rather1032 // ([`set_frame_rate`](Self::set_frame_rate)) comes back at it rather
995 // than at the media's, which would leave every clip number counted in1033 // than at the media's, which would leave every clip number counted in
996 // frames the timeline no longer has.1034 // frames the timeline no longer has.
997- let native_fps = match crate::is_audio(&first.path) {1035+ let native_fps = match audio_only {
998 true => AUDIO_ONLY_CANVAS.2,1036 true => AUDIO_ONLY_CANVAS.2,
999 false if crate::is_image(&first.path) => IMAGE_ONLY_RATE,1037 false if crate::is_image(&first.path) => IMAGE_ONLY_RATE,
1000 false => meta.frame_rate,1038 false => meta.frame_rate,
@@ -1006,7 +1044,7 @@ impl PlaybackSession {
1006 // their length above was counted in the timeline's frames already,1044 // their length above was counted in the timeline's frames already,
1007 // whatever those are. A file with pictures is read through [`Rate`] like1045 // whatever those are. A file with pictures is read through [`Rate`] like
1008 // any other source when the project is cut at another rate.1046 // any other source when the project is cut at another rate.
1009- let made_up = crate::is_audio(&first.path) || crate::is_image(&first.path);1047+ let made_up = audio_only || crate::is_image(&first.path);
1010 let scaffold_rate = match made_up || native_fps == meta.frame_rate {1048 let scaffold_rate = match made_up || native_fps == meta.frame_rate {
1011 true => Rate::REAL_TIME,1049 true => Rate::REAL_TIME,
1012 false => Rate::from_fps(native_fps, meta.frame_rate)1050 false => Rate::from_fps(native_fps, meta.frame_rate)
@@ -3236,8 +3274,14 @@ impl PlaybackSession {
3236 // Both halves on this thread, which is what a caller with nothing else3274 // Both halves on this thread, which is what a caller with nothing else
3237 // to do wants; a front-end splits them across a worker instead3275 // to do wants; a front-end splits them across a worker instead
3238 // ([`probe_import`](Self::probe_import)).3276 // ([`probe_import`](Self::probe_import)).
3239- let probe = Self::probe_import(self.import_gate(), path)?;3277+ // A container with sound but no picture is a song wearing a video
3240- Ok(self.take_probe(path, probe))3278+ // extension -- the same fallback `open_stream` and the project
3279+ // scaffold make, so every door in agrees on what the file is.
3280+ match Self::probe_import(self.import_gate(), path) {
3281+ Ok(probe) => Ok(self.take_probe(path, probe)),
3282+ Err(e) if crate::demux::NoVideoTrack::is_it(&e) => self.import_audio(path),
3283+ Err(e) => Err(e),
3284+ }
3241 }3285 }
3242 3286
3243 /// Everything an import is *checked against*, taken off this timeline in3287 /// Everything an import is *checked against*, taken off this timeline in
crates/engine/src/proxy.rsmodified+58 -0
@@ -217,6 +217,41 @@ fn sweep(dir: &Path, cap: u64) -> u64 {
217 total217 total
218 }218 }
219 219
220+/// Deletes every `.part` in `dir`: the leftover of an encoder that never got
221+/// to unlink its own half-written file, because the process holding it was
222+/// killed rather than let finish or cancel cleanly.
223+///
224+/// Unlike the one removal in [`started`], which clears only *this film's* own
225+/// `.part` right before a new encode of it starts, this clears everyone
226+/// else's too -- which is safe to do only because nothing in this process has
227+/// claimed a `.part` yet at the point it runs ([`sweep_stale_parts`]).
228+fn sweep_parts(dir: &Path) {
229+ let Ok(entries) = std::fs::read_dir(dir) else {
230+ return;
231+ };
232+ for entry in entries.flatten() {
233+ let path = entry.path();
234+ if path.extension().is_some_and(|e| e == "part") && std::fs::remove_file(&path).is_ok() {
235+ eprintln!("proxy cache: swept stale {}", path.display());
236+ }
237+ }
238+}
239+
240+/// Run once, at launch, ahead of anything that could claim a stand-in for
241+/// itself: clears every orphan `.part` a killed editor left in the proxy
242+/// cache. "Stale" needs no age check here -- at launch [`IN_FLIGHT`] is empty
243+/// by construction, so *every* `.part` on disk belongs to nobody still
244+/// running. A no-op where the machine has no cache directory at all.
245+pub fn sweep_stale_parts() {
246+ if let Some(dir) = crate::demux::cache_dir(
247+ std::env::var_os("XDG_CACHE_HOME"),
248+ std::env::var_os("HOME"),
249+ "proxies",
250+ ) {
251+ sweep_parts(&dir);
252+ }
253+}
254+
220 /// The proxy of `source` if one has already been made, `None` otherwise. The255 /// The proxy of `source` if one has already been made, `None` otherwise. The
221 /// answer a session asks at open: a hit costs one `stat`.256 /// answer a session asks at open: a hit costs one `stat`.
222 pub fn cached(source: &Path) -> Option<PathBuf> {257 pub fn cached(source: &Path) -> Option<PathBuf> {
@@ -661,6 +696,29 @@ mod tests {
661 assert!(fresh.exists());696 assert!(fresh.exists());
662 }697 }
663 698
699+ /// What a killed editor leaves behind piles up as `.part` files nothing
700+ /// ever revisits (nothing but the one film's own next start clears its
701+ /// own, [`started`]) -- the launch-time sweep takes every one of them,
702+ /// and leaves the finished stand-ins beside them alone.
703+ #[test]
704+ fn the_launch_sweep_takes_every_orphan_part() {
705+ let dir = crate::scratch::Scratch::dir("proxy-part-sweep");
706+ let write = |name: &str| {
707+ let path = dir.join(name);
708+ std::fs::write(&path, b"orphaned mid-encode").expect("write");
709+ path
710+ };
711+ let orphan_a = write("aaaa.mp4.part");
712+ let orphan_b = write("bbbb.mp4.part");
713+ let finished = write("cccc.mp4");
714+
715+ sweep_parts(&dir);
716+
717+ assert!(!orphan_a.exists(), "one orphan part survived the sweep");
718+ assert!(!orphan_b.exists(), "the other orphan part survived it");
719+ assert!(finished.exists(), "a finished stand-in was swept too");
720+ }
721+
664 /// A song and a still are not films: they are answered `None` -- the same722 /// A song and a still are not films: they are answered `None` -- the same
665 /// answer a 1080p H.264 film gets -- rather than opened, failed on and723 /// answer a 1080p H.264 film gets -- rather than opened, failed on and
666 /// reported. The bug this pins said "NO PROXY for tone.wav" to a person who724 /// reported. The bug this pins said "NO PROXY for tone.wav" to a person who
crates/engine/tests/audio_files.rsmodified+33 -0
@@ -578,3 +578,36 @@ fn a_pasted_song_never_lands_on_the_video_lane() {
578 assert_eq!(reloaded.lane_clips(Lane::V1).len(), video_after.len());578 assert_eq!(reloaded.lane_clips(Lane::V1).len(), video_after.len());
579 let _ = std::fs::remove_dir_all(&dir);579 let _ = std::fs::remove_dir_all(&dir);
580 }580 }
581+
582+/// A song muxed into an `.mp4` -- the extension names a film, the header names
583+/// no picture. `open` falls to the audio-only door on the demuxer's own
584+/// `NoVideoTrack` rather than refusing "no H.264, HEVC, VP9 or AV1 video track
585+/// in file", exactly as it would have if the file had been named `.mp3`.
586+#[test]
587+fn an_audio_only_file_wearing_an_mp4_extension_still_opens() {
588+ let session = open(asset("test_audio_only.mp4"));
589+ assert!(session.lane_clips(Lane::V1).is_empty(), "no picture anywhere");
590+ assert_eq!(session.lane_clips(Lane::A1).len(), 1);
591+ assert!((session.timeline_duration() - 3.0).abs() < 0.1);
592+}
593+
594+/// The same fallback in [`PlaybackSession::open_project`]'s scaffold branch: a
595+/// project whose first source is one of these files reloads instead of failing
596+/// the open a save never had trouble with the first time.
597+#[test]
598+fn a_project_scaffolded_from_an_audio_only_mp4_reloads() {
599+ let dir = Scratch::dir("ve_audio_only_mp4");
600+ let mp4 = asset("test_audio_only.mp4");
601+ let session = open(&mp4);
602+ let project = dir.join("song_mp4.edith");
603+ session.save_project(&project).expect("save");
604+ drop(session);
605+ let reloaded =
606+ PlaybackSession::open_project(&project).expect("reload a project scaffolded from it");
607+ reloaded.set_gain(0.0);
608+ assert!(reloaded.lane_clips(Lane::V1).is_empty());
609+ assert_eq!(reloaded.lane_clips(Lane::A1).len(), 1);
610+ assert!((reloaded.timeline_duration() - 3.0).abs() < 0.1);
611+ drop(reloaded);
612+ let _ = std::fs::remove_dir_all(&dir);
613+}
scripts/gen_fixtures.shmodified+6 -0
@@ -526,4 +526,10 @@ ffmpeg -y -f lavfi -i "testsrc2=size=320x240:rate=30:duration=2" \
526 -f lavfi -i "sine=frequency=440:duration=60" \526 -f lavfi -i "sine=frequency=440:duration=60" \
527 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p \527 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
528 -c:a aac -b:a 64k assets/test_short_video_long_audio.mp4528 -c:a aac -b:a 64k assets/test_short_video_long_audio.mp4
529+# A song wearing a film's extension: AAC audio, no video track, muxed into an
530+# `.mp4` -- the shape a phone's voice memo or a stripped remux takes, and the
531+# one `crate::is_audio` cannot see (`tests/audio_files.rs`).
532+ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3" \
533+ -c:a aac -b:a 128k assets/test_audio_only.mp4
534+
529 echo "fixtures written to assets/"535 echo "fixtures written to assets/"
vendor/cros-codecs/src/codec/av1/parser.rsmodified+30 -4
@@ -2905,14 +2905,26 @@ impl Parser {
2905 let v = (v * i64::from(div_factor)) as i32;2905 let v = (v * i64::from(div_factor)) as i32;
2906 let gamma0 = helpers::clip3(-32678, 32767, helpers::round2signed(v, div_shift)?);2906 let gamma0 = helpers::clip3(-32678, 32767, helpers::round2signed(v, div_shift)?);
2907 2907
2908- let w = warp_params[3] * warp_params[4];2908+ // --- edith patch: a malformed bitstream's warp params (Troy.mkv's
2909+ // AV1 track panicked here, "attempt to multiply with overflow") can
2910+ // put i32::MAX-adjacent values in warp_params[3]/[4]/div_factor --
2911+ // upstream trusted a conformant encoder never to. A checked multiply
2912+ // turns that into the parse error this function already returns for
2913+ // every other malformed field, instead of taking the whole process
2914+ // down. ---
2915+ let w = warp_params[3]
2916+ .checked_mul(warp_params[4])
2917+ .ok_or_else(|| "warp params overflow: w = warp_params[3] * warp_params[4]".to_string())?;
2918+
2919+ let wd = w
2920+ .checked_mul(div_factor)
2921+ .ok_or_else(|| "warp params overflow: w * div_factor".to_string())?;
2922+ // --- end edith patch ---
2909 2923
2910 let delta0 = helpers::clip3(2924 let delta0 = helpers::clip3(
2911 -32768,2925 -32768,
2912 32767,2926 32767,
2913- warp_params[5]2927+ warp_params[5] - helpers::round2signed(wd, div_shift)? - (1 << WARPEDMODEL_PREC_BITS),
2914- - helpers::round2signed(w * div_factor, div_shift)?
2915- - (1 << WARPEDMODEL_PREC_BITS),
2916 );2928 );
2917 2929
2918 let alpha =2930 let alpha =
@@ -4054,6 +4066,20 @@ mod tests {
4054 4066
4055 use super::ObuType;4067 use super::ObuType;
4056 4068
4069+ /// Repro for the panic hit on Troy.Director's.Cut.2004...AV1.mkv:
4070+ /// `warp_params[3] * warp_params[4]` (and its `* div_factor` beside it)
4071+ /// overflowed an `i32` on a malformed global-motion syntax and took the
4072+ /// whole process down with it -- `setup_shear` must answer a parse error
4073+ /// instead, exactly as it already does for every other malformed field.
4074+ #[test]
4075+ fn overflowing_warp_params_are_a_parse_error_not_a_panic() {
4076+ let overflowing = [0, 0, i32::MAX, i32::MAX, i32::MAX, i32::MAX];
4077+ assert!(
4078+ Parser::setup_shear(&overflowing).is_err(),
4079+ "a malformed global-motion syntax must fail the parse, not panic"
4080+ );
4081+ }
4082+
4057 /// Same as test-25fps.av1.ivf from Chromium4083 /// Same as test-25fps.av1.ivf from Chromium
4058 const STREAM_TEST_25_FPS: &[u8] = include_bytes!("test_data/test-25fps.ivf.av1");4084 const STREAM_TEST_25_FPS: &[u8] = include_bytes!("test_data/test-25fps.ivf.av1");
4059 4085