forge
Explore
Log in

Don't you dare go Hollow

A failed waveform decode is asked again

Browse files at this commit

43e146d27ead5c6e4cd15ee6e19f1b2fb19ee6c6Ahmet Kaan GümüşParent: 9c53bb8
  • fix
    • a failed waveform decode is asked again
Show full message
🐛 fix(player): a failed waveform decode is asked again

Presence in the wave map means asked, so one transient failure -- a file imported while it was still being copied, a disk hiccup -- left a lane with no envelope for the rest of the session. The failure carries the moment it happened now and a repaint past a five second cooldown asks again, which is the engine's own rule that a failure is never memoized; a file with no audio stays an answer that is never re-asked.
crates/app/src/importing.rsmodified+9 -4
@@ -18,10 +18,15 @@ pub(crate) enum Wave {
1818 Loading,
1919 /// The file has no audio track. An answer, not a miss.
2020 Silent,
21- /// The decode failed. Drawn as its own mark rather than as [`Self::Silent`]:
22- /// "this file's sound could not be read" and "this file has no sound" look
23- /// the same on a lane, and the first is a bug report waiting to happen.
24- Failed,
21+ /// The decode failed, at the moment it did. Drawn as its own mark rather
22+ /// than as [`Self::Silent`]: "this file's sound could not be read" and
23+ /// "this file has no sound" look the same on a lane, and the first is a
24+ /// bug report waiting to happen. It is *not* an answer, though: a failure
25+ /// may have had a reason that has since gone away (a file still being
26+ /// copied when it arrived), so [`crate::subs::unseen_sources`] asks again
27+ /// once the stamp is older than its cooldown -- which is what the stamp is
28+ /// for.
29+ Failed(std::time::Instant),
2530 Peaks(Arc<Vec<(f32, f32)>>),
2631 }
2732
crates/app/src/player/export.rsmodified+7 -2
@@ -2,6 +2,7 @@
22 //! two of them decide.
33
44 use crate::*;
5+use std::time::Instant;
56
67 impl Player {
78 /// What [`timeline_math::lane_refuses`] asks to decide a video lane's
@@ -231,7 +232,7 @@ impl Player {
231232 }
232233 starting.push(path);
233234 }
234- for key in unseen_sources(session.sources(), &self.waves) {
235+ for key in unseen_sources(session.sources(), &self.waves, Instant::now()) {
235236 self.waves.insert(key.clone(), Wave::Loading);
236237 let decoded = cx.background_executor().spawn({
237238 let (path, stream) = key.clone();
@@ -254,7 +255,11 @@ impl Player {
254255 // A file whose sound we could not read is not a
255256 // silent one, and a lane that drew it as silent is
256257 // how a broken decode passes for a design choice.
257- Err(_) => Wave::Failed,
258+ // Stamped, and not an answer: a repaint past
259+ // [`WAVE_RETRY`] asks again, so a failure whose
260+ // cause went away (a file still being copied when
261+ // it arrived) draws its envelope without a reopen.
262+ Err(_) => Wave::Failed(Instant::now()),
258263 },
259264 );
260265 cx.notify();
crates/app/src/subs.rsmodified+21 -7
@@ -333,9 +333,7 @@ pub(crate) fn subtitle_tail(session: &mut PlaybackSession, subs: Subs) -> Option
333333 match subs {
334334 Ok(tracks) => match session.add_subtitle_tracks(tracks) {
335335 0 => None,
336- n => Some(format!(
337- " · {n} subtitle track(s)"
338- )),
336+ n => Some(format!(" · {n} subtitle track(s)")),
339337 },
340338 Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")),
341339 }
@@ -705,17 +703,33 @@ pub(crate) fn cues_at(cues: &[engine::subtitle::Cue], at: f64) -> Vec<&engine::s
705703 .collect()
706704 }
707705
708-/// The sources a repaint has not asked about yet. A key that is already there
709-/// means "asked", whatever state it is in, which is what stops a decode already
710-/// running from being started again by the next of sixty repaints a second.
706+/// How long a failed waveform decode is left alone before the next repaint asks
707+/// again: long enough that sixty repaints a second do not become sixty decodes,
708+/// short enough that a file which arrived mid-copy has its envelope a moment
709+/// after it lands. The engine memoizes no failure for the same reason
710+/// ([`engine::waveform`]): the reason one failed may have gone away.
711+pub(crate) const WAVE_RETRY: std::time::Duration = std::time::Duration::from_secs(5);
712+
713+/// The sources a repaint has not asked about yet, as of `now`. A key that is
714+/// already there means "asked", whatever state it is in -- which is what stops
715+/// a decode already running from being started again by the next of sixty
716+/// repaints a second -- with one exception: a [`Wave::Failed`] older than
717+/// [`WAVE_RETRY`] is asked again, because a decode that failed once is not an
718+/// answer about the file, only about the moment it was tried. A file with no
719+/// audio (`Wave::Silent`) is an answer like any other and is never re-asked.
711720 pub(crate) fn unseen_sources(
712721 sources: &[Source],
713722 waves: &HashMap<(PathBuf, usize), Wave>,
723+ now: std::time::Instant,
714724 ) -> Vec<(PathBuf, usize)> {
715725 sources
716726 .iter()
717727 .map(|s| (s.path.clone(), s.audio_stream))
718- .filter(|key| !waves.contains_key(key))
728+ .filter(|key| match waves.get(key) {
729+ None => true,
730+ Some(Wave::Failed(at)) => now.duration_since(*at) >= WAVE_RETRY,
731+ Some(_) => false,
732+ })
719733 .collect()
720734 }
721735
crates/app/src/tests/editing.rsmodified+109 -114
@@ -109,11 +109,9 @@ fn a_song_opens_the_window_by_itself() {
109109 // ...and it places, on the audio lane, through the door `insert_source`
110110 // uses: a second copy of the song at the playhead.
111111 session.seek(1.0);
112- assert!(
113- session
114- .place_stream_at(1.0, &path, 0, Some(Lane::A1))
115- .expect("its own file is on this timeline")
116- );
112+ assert!(session
113+ .place_stream_at(1.0, &path, 0, Some(Lane::A1))
114+ .expect("its own file is on this timeline"));
117115 assert_eq!(session.lane_clips(Lane::A1).len(), 2);
118116 assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture");
119117
@@ -345,13 +343,11 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() {
345343 );
346344 // ...and the same reading with a clip under it is the clip menu, untouched:
347345 // the flag is off wherever a `Clip` was clicked.
348- assert!(
349- menu_items(Ctx {
350- timeline: true,
351- ..Ctx::default()
352- })
353- .contains(&ActionId::Cut)
354- );
346+ assert!(menu_items(Ctx {
347+ timeline: true,
348+ ..Ctx::default()
349+ })
350+ .contains(&ActionId::Cut));
355351 }
356352
357353 /// A timeline with a subtitle palette and an empty subtitle lane: what a
@@ -939,16 +935,14 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
939935 }
940936 assert!(!whole(ActionId::Delete, live).yes());
941937 assert!(!whole(ActionId::Paste, live).yes());
942- assert!(
943- whole(
944- ActionId::Paste,
945- Ctx {
946- clipboard: true,
947- ..live
948- }
949- )
950- .yes()
951- );
938+ assert!(whole(
939+ ActionId::Paste,
940+ Ctx {
941+ clipboard: true,
942+ ..live
943+ }
944+ )
945+ .yes());
952946 assert!(!whole(ActionId::CancelExport, live).yes());
953947 let busy = Ctx {
954948 exporting: true,
@@ -988,7 +982,10 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
988982 assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.));
989983 assert_eq!(
990984 menu_at(point(px(700.), px(380.)), viewport, 150.),
991- (800. - crate::layout::MENU_EDGE - MENU_W, 400. - crate::layout::MENU_EDGE - 150.)
985+ (
986+ 800. - crate::layout::MENU_EDGE - MENU_W,
987+ 400. - crate::layout::MENU_EDGE - 150.
988+ )
992989 );
993990 // A window smaller than the menu loses its bottom, never its top: the
994991 // top-left margin wins over the bottom-right one, because the items are
@@ -1165,16 +1162,14 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() {
11651162 assert!(row_enable(RowItem::RemoveWithClips, placed).yes());
11661163 let unplaced = row_items(live);
11671164 assert!(unplaced.contains(&RowItem::Remove) && !unplaced.contains(&RowItem::RemoveWithClips));
1168- assert!(
1169- !row_enable(
1170- RowItem::RemoveWithClips,
1171- RowCtx {
1172- exporting: true,
1173- ..placed
1174- }
1175- )
1176- .yes()
1177- );
1165+ assert!(!row_enable(
1166+ RowItem::RemoveWithClips,
1167+ RowCtx {
1168+ exporting: true,
1169+ ..placed
1170+ }
1171+ )
1172+ .yes());
11781173 assert!(!row_enable(RowItem::Add, RowCtx::default()).yes());
11791174 // Every refusal is short enough to sit in the hint column beside its
11801175 // label, the clip menu's rule.
@@ -1282,7 +1277,11 @@ fn the_hanging_menus_mount_at_the_room_root_and_their_rows_wear_chords_not_prose
12821277 }
12831278 // §9: no junk drawer. A label that fits the plate whole beside its
12841279 // chord, and never a sentence.
1285- assert!(item.label().split_whitespace().count() <= 4, "{}", item.label());
1280+ assert!(
1281+ item.label().split_whitespace().count() <= 4,
1282+ "{}",
1283+ item.label()
1284+ );
12861285 }
12871286 // The two removes must not read as the same verb now that the column
12881287 // beside them is empty.
@@ -1604,11 +1603,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() {
16041603 let frames = session.file_frames(&second);
16051604 // Through the engine door `insert_source` uses, with the row's own
16061605 // stream: the button, the drop and this are one call.
1607- assert!(
1608- session
1609- .place_stream_at(2.0, &second, 0, None)
1610- .expect("av2 is already on the timeline")
1611- );
1606+ assert!(session
1607+ .place_stream_at(2.0, &second, 0, None)
1608+ .expect("av2 is already on the timeline"));
16121609 // The whole of source 1 went in and nothing was painted over: the
16131610 // timeline is longer by exactly that file.
16141611 assert_eq!(session.timeline_duration(), 9.0);
@@ -1635,11 +1632,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() {
16351632 let path = session.sources()[0].path.clone();
16361633 let frames = session.file_frames(&path);
16371634 let end = session.timeline_duration();
1638- assert!(
1639- session
1640- .place_stream_at(end, &path, 1, None)
1641- .expect("the French track shares the timeline's parameters")
1642- );
1635+ assert!(session
1636+ .place_stream_at(end, &path, 1, None)
1637+ .expect("the French track shares the timeline's parameters"));
16431638 assert_eq!(session.sources()[1].audio_stream, 1);
16441639 assert_eq!(session.timeline_duration(), end * 2.0);
16451640 // Both rows are the same file, so both rows are that file's length --
@@ -1689,11 +1684,9 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() {
16891684
16901685 // ...and what the release does with it: the frame back through the same
16911686 // rate every box is drawn at, into the door the Add button uses too.
1692- assert!(
1693- session
1694- .place_stream_at(f64::from(at) / fps, &second, 0, None)
1695- .expect("av2 is already on this timeline")
1696- );
1687+ assert!(session
1688+ .place_stream_at(f64::from(at) / fps, &second, 0, None)
1689+ .expect("av2 is already on this timeline"));
16971690 let head = |lane| {
16981691 session
16991692 .lane_clips(lane)
@@ -1727,11 +1720,9 @@ fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() {
17271720 session.import(&asset("test_av2.mp4")).expect("av2 matches");
17281721 let second = session.sources()[1].path.clone();
17291722 let end = session.timeline_duration();
1730- assert!(
1731- session
1732- .place_stream_at(end, &second, 0, None)
1733- .expect("a file just imported is on this timeline")
1734- );
1723+ assert!(session
1724+ .place_stream_at(end, &second, 0, None)
1725+ .expect("a file just imported is on this timeline"));
17351726 let streams = HashMap::new();
17361727 let rows = |session: &PlaybackSession| {
17371728 library_rows(session.sources(), &streams, &HashMap::new(), None, |_| 0).len()
@@ -2058,11 +2049,9 @@ fn a_track_can_be_added_dropped_on_edited_and_taken_back() {
20582049 // A library row let go over that row: the same door the Add button
20592050 // uses, told which lane it was let go over.
20602051 let path = session.sources()[0].path.clone();
2061- assert!(
2062- session
2063- .place_stream_at(1.0, &path, 0, Some(v2))
2064- .expect("its own file is on this timeline")
2065- );
2052+ assert!(session
2053+ .place_stream_at(1.0, &path, 0, Some(v2))
2054+ .expect("its own file is on this timeline"));
20662055 assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2");
20672056 assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead");
20682057 // ...with the sound it came with, on the row of its own the drop added:
@@ -2149,22 +2138,18 @@ fn a_selection_drag_moves_every_pick_by_the_same_delta() {
21492138
21502139 // clip0 on V1 at the fixture's own start; clip1 on V1 ten seconds in,
21512140 // appended to the open bed and rippling nothing.
2152- assert!(
2153- session
2154- .place_stream_at(10.0, &second, 0, None)
2155- .expect("av2 is on this timeline")
2156- );
2141+ assert!(session
2142+ .place_stream_at(10.0, &second, 0, None)
2143+ .expect("av2 is on this timeline"));
21572144 let clip0 = session.lane_clips(Lane::V1)[0];
21582145 let clip1 = session.lane_clips(Lane::V1)[1];
21592146 assert_eq!((clip0.start, clip1.start), (0, 300));
21602147
21612148 // clipC on a second video row, well past both of the above.
21622149 let v2 = session.add_lane(LaneKind::Video);
2163- assert!(
2164- session
2165- .place_stream_at(20.0, &path, 0, Some(v2))
2166- .expect("test_av.mp4 is on this timeline")
2167- );
2150+ assert!(session
2151+ .place_stream_at(20.0, &path, 0, Some(v2))
2152+ .expect("test_av.mp4 is on this timeline"));
21682153 let clip_c = session.lane_clips(v2)[0];
21692154 assert_eq!(clip_c.start, 600);
21702155
@@ -2217,28 +2202,22 @@ fn a_selection_drag_refuses_as_one_set_when_any_pick_cannot_land() {
22172202 session.import(&asset("test_av2.mp4")).expect("av2 matches");
22182203 let second = session.sources()[1].path.clone();
22192204
2220- assert!(
2221- session
2222- .place_stream_at(10.0, &second, 0, None)
2223- .expect("av2 is on this timeline")
2224- );
2205+ assert!(session
2206+ .place_stream_at(10.0, &second, 0, None)
2207+ .expect("av2 is on this timeline"));
22252208 let clip0 = session.lane_clips(Lane::V1)[0];
22262209 let clip1 = session.lane_clips(Lane::V1)[1];
22272210
22282211 let v2 = session.add_lane(LaneKind::Video);
2229- assert!(
2230- session
2231- .place_stream_at(0.0, &path, 0, Some(v2))
2232- .expect("test_av.mp4 is on this timeline")
2233- );
2212+ assert!(session
2213+ .place_stream_at(0.0, &path, 0, Some(v2))
2214+ .expect("test_av.mp4 is on this timeline"));
22342215 let clip_c = session.lane_clips(v2)[0];
22352216 // A clip clip1 is not picked, blocking the road on V2 the drag is about
22362217 // to try: clip1 dragged onto V2 lands its head inside this one.
2237- assert!(
2238- session
2239- .place_stream_at(10.0, &second, 0, Some(v2))
2240- .expect("av2 is on this timeline")
2241- );
2218+ assert!(session
2219+ .place_stream_at(10.0, &second, 0, Some(v2))
2220+ .expect("av2 is on this timeline"));
22422221 let blocker = session.lane_clips(v2)[1];
22432222 assert_eq!(blocker.start, 300);
22442223
@@ -2293,20 +2272,16 @@ fn a_three_pick_copy_paste_preserves_gaps_and_lane_assignment() {
22932272 session.import(&asset("test_av2.mp4")).expect("av2 matches");
22942273 let second = session.sources()[1].path.clone();
22952274
2296- assert!(
2297- session
2298- .place_stream_at(10.0, &second, 0, None)
2299- .expect("av2 is on this timeline")
2300- );
2275+ assert!(session
2276+ .place_stream_at(10.0, &second, 0, None)
2277+ .expect("av2 is on this timeline"));
23012278 let clip0 = session.lane_clips(Lane::V1)[0];
23022279 let clip1 = session.lane_clips(Lane::V1)[1];
23032280
23042281 let v2 = session.add_lane(LaneKind::Video);
2305- assert!(
2306- session
2307- .place_stream_at(20.0, &path, 0, Some(v2))
2308- .expect("test_av.mp4 is on this timeline")
2309- );
2282+ assert!(session
2283+ .place_stream_at(20.0, &path, 0, Some(v2))
2284+ .expect("test_av.mp4 is on this timeline"));
23102285 let clip_c = session.lane_clips(v2)[0];
23112286
23122287 // Copied in click order, out of the lanes each was clicked in -- exactly
@@ -2354,20 +2329,16 @@ fn a_colliding_set_paste_refuses_whole() {
23542329 session.import(&asset("test_av2.mp4")).expect("av2 matches");
23552330 let second = session.sources()[1].path.clone();
23562331
2357- assert!(
2358- session
2359- .place_stream_at(10.0, &second, 0, None)
2360- .expect("av2 is on this timeline")
2361- );
2332+ assert!(session
2333+ .place_stream_at(10.0, &second, 0, None)
2334+ .expect("av2 is on this timeline"));
23622335 let clip0 = session.lane_clips(Lane::V1)[0];
23632336 let clip1 = session.lane_clips(Lane::V1)[1];
23642337
23652338 let v2 = session.add_lane(LaneKind::Video);
2366- assert!(
2367- session
2368- .place_stream_at(20.0, &path, 0, Some(v2))
2369- .expect("test_av.mp4 is on this timeline")
2370- );
2339+ assert!(session
2340+ .place_stream_at(20.0, &path, 0, Some(v2))
2341+ .expect("test_av.mp4 is on this timeline"));
23712342 let clip_c = session.lane_clips(v2)[0];
23722343
23732344 let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)];
@@ -2422,11 +2393,9 @@ fn a_grouped_clip_on_an_added_lane_closes_its_hole_with_its_caption() {
24222393 let (mut session, sub_lane) = with_subtitle_lane();
24232394 let v2 = session.add_lane(LaneKind::Video);
24242395 let path = session.sources()[0].path.clone();
2425- assert!(
2426- session
2427- .place_stream_at(0.0, &path, 0, Some(v2))
2428- .expect("its own file is on this timeline")
2429- );
2396+ assert!(session
2397+ .place_stream_at(0.0, &path, 0, Some(v2))
2398+ .expect("its own file is on this timeline"));
24302399 session
24312400 .place_sub(sub_lane, 0, one_second(0))
24322401 .expect("the caption goes down");
@@ -2486,20 +2455,38 @@ fn a_source_is_only_ever_asked_for_its_peaks_once() {
24862455 .collect::<Vec<_>>()
24872456 };
24882457 let mut waves: HashMap<(PathBuf, usize), Wave> = HashMap::new();
2489- assert_eq!(unseen_sources(&sources, &waves), keys(&sources));
2458+ assert_eq!(
2459+ unseen_sources(&sources, &waves, std::time::Instant::now()),
2460+ keys(&sources)
2461+ );
24902462 // The entry goes in when the decode *starts*, so the sixty repaints a
24912463 // second that happen while it runs must not start it again -- which is
24922464 // what this asserts about a key whose value is not an answer yet.
24932465 waves.insert((a.clone(), 0), Wave::Loading);
24942466 assert_eq!(
2495- unseen_sources(&sources, &waves),
2467+ unseen_sources(&sources, &waves, std::time::Instant::now()),
24962468 keys(&sources[1..]),
24972469 "the file's other stream is a key of its own"
24982470 );
24992471 // A file with no audio is an answer like any other: never re-asked.
25002472 waves.insert((a, 1), Wave::Silent);
25012473 waves.insert((b.clone(), 0), Wave::Silent);
2502- assert!(unseen_sources(&sources, &waves).is_empty());
2474+ assert!(unseen_sources(&sources, &waves, std::time::Instant::now()).is_empty());
2475+ // A decode that *failed* is not an answer: the reason may have gone away
2476+ // (the file was still being copied when it arrived), so it is asked again
2477+ // -- once the stamp is older than the cooldown, so sixty repaints a second
2478+ // do not become sixty decodes.
2479+ let now = std::time::Instant::now();
2480+ waves.insert((b.clone(), 0), Wave::Failed(now));
2481+ assert!(
2482+ unseen_sources(&sources, &waves, now).is_empty(),
2483+ "a failure that just landed is not re-asked at once"
2484+ );
2485+ assert_eq!(
2486+ unseen_sources(&sources, &waves, now + crate::subs::WAVE_RETRY),
2487+ keys(&sources[2..]),
2488+ "and is asked again once the cooldown is out"
2489+ );
25032490 // The stream probe is per *file*: the two entries of `a` ask once.
25042491 let mut streams: HashMap<PathBuf, Vec<StreamInfo>> = HashMap::new();
25052492 assert_eq!(
@@ -2802,13 +2789,21 @@ fn every_verb_the_spine_carried_is_a_right_click_row() {
28022789 // Every menu is a list of actions the keyboard already reaches, so every
28032790 // row can wear its chord (DESIGN §4): a row built here out of an id the
28042791 // registry never files would print an empty column.
2805- for action in MENU_ITEMS.into_iter().chain(BENCH_ITEMS).chain(heads.iter().copied()) {
2792+ for action in MENU_ITEMS
2793+ .into_iter()
2794+ .chain(BENCH_ITEMS)
2795+ .chain(heads.iter().copied())
2796+ {
28062797 assert!(
28072798 ActionId::ALL.contains(&action),
28082799 "{action:?} is a menu row and not a registered action"
28092800 );
28102801 }
2811- for list in [MENU_ITEMS.to_vec(), BENCH_ITEMS.to_vec(), lane_items(Lane::A1)] {
2802+ for list in [
2803+ MENU_ITEMS.to_vec(),
2804+ BENCH_ITEMS.to_vec(),
2805+ lane_items(Lane::A1),
2806+ ] {
28122807 let first = list.iter().position(|&a| destructive(a));
28132808 if let Some(first) = first {
28142809 assert!(