A picture edit reuses the decoder instead of reopening the file
Browse files at this commit91e631643a9f88c85300761f3afd06223497e1deParent: 86a2cd7- fix
- a picture edit reuses the decoder instead of reopening the file
2 changed files +60 -5
crates/engine/src/decode.rsmodified+9 -3
| @@ -840,9 +840,15 @@ fn span_worker( | |||
| 840 | 840 | ||
| 841 | /// How long a parked worker keeps its hardware session before closing it. Long | 841 | /// How long a parked worker keeps its hardware session before closing it. Long |
| 842 | /// enough that a seek, a scrub step and a clip boundary all find the decoder | 842 | /// enough that a seek, a scrub step and a clip boundary all find the decoder |
| 843 | -/// where they left it; short enough that a session left alone is not holding | 843 | +/// where they left it -- and long enough for the think-time between two |
| 844 | -/// libva when the process exits. | 844 | +/// samples of a live slider drag (a colour or transform card nudge), which |
| 845 | -const IDLE: std::time::Duration = std::time::Duration::from_secs(2); | 845 | +/// reseeks the very same worker and paid the *closed* half of this window |
| 846 | +/// every time a person paused a beat to look before nudging again: a session | ||
| 847 | +/// found the hardware gone and rebuilt it (measured seconds on a big file) | ||
| 848 | +/// for what should have cost one `hw.seek`. Short enough that a session left | ||
| 849 | +/// alone for real (the window switched away from, a scrub that stopped) is | ||
| 850 | +/// not holding libva when the process exits. | ||
| 851 | +const IDLE: std::time::Duration = std::time::Duration::from_secs(8); | ||
| 846 | 852 | ||
| 847 | /// How many pictures in a row a worker may drop for being late before it hands | 853 | /// How many pictures in a row a worker may drop for being late before it hands |
| 848 | /// one over regardless. The policy needs a floor of its own: a machine that | 854 | /// one over regardless. The policy needs a floor of its own: a machine that |
crates/engine/src/playback.rsmodified+51 -2
| @@ -536,7 +536,11 @@ impl PlaybackSession { | |||
| 536 | } | 536 | } |
| 537 | 537 | ||
| 538 | fn open_stream(path: impl AsRef<Path>, audio_stream: usize) -> crate::Result<Self> { | 538 | fn open_stream(path: impl AsRef<Path>, audio_stream: usize) -> crate::Result<Self> { |
| 539 | - let path = path.as_ref().to_path_buf(); | 539 | + // Canonical from the first byte: the project canonicalizes every |
| 540 | + // source ([`Source::new`]), and [`Worker::reseek`] reuses a decoder | ||
| 541 | + // only when the paths match textually -- a raw path here would make | ||
| 542 | + // every later picture edit pay a full reopen instead of a seek. | ||
| 543 | + let path = crate::project::canonical(path.as_ref()); | ||
| 540 | // A timeline is normally scaffolded from source 0's picture -- its size, | 544 | // A timeline is normally scaffolded from source 0's picture -- its size, |
| 541 | // its frame rate, its clock. A song has none of that, so it scaffolds | 545 | // its frame rate, its clock. A song has none of that, so it scaffolds |
| 542 | // the *canvas* instead and its own sound keeps the clock: an audio-only | 546 | // the *canvas* instead and its own sound keeps the clock: an audio-only |
| @@ -4135,7 +4139,9 @@ fn blend_bgra(a: &[u8], b: &[u8], t: f32) -> Vec<u8> { | |||
| 4135 | 4139 | ||
| 4136 | #[cfg(test)] | 4140 | #[cfg(test)] |
| 4137 | mod tests { | 4141 | mod tests { |
| 4138 | - use super::{Edge, Lane, PlaybackSession, Source, audio_source_of, blend_bgra, secs_to_frame}; | 4142 | + use super::{ |
| 4143 | + Edge, Lane, PlaybackSession, Source, TransformParams, audio_source_of, blend_bgra, secs_to_frame, | ||
| 4144 | + }; | ||
| 4139 | use std::path::PathBuf; | 4145 | use std::path::PathBuf; |
| 4140 | 4146 | ||
| 4141 | fn asset(name: &str) -> PathBuf { | 4147 | fn asset(name: &str) -> PathBuf { |
| @@ -4464,4 +4470,47 @@ mod tests { | |||
| 4464 | assert_eq!(secs_to_frame(10.5 / 30.0, 30.0), 10); | 4470 | assert_eq!(secs_to_frame(10.5 / 30.0, 30.0), 10); |
| 4465 | assert_eq!(secs_to_frame(-0.2, 30.0), 0); | 4471 | assert_eq!(secs_to_frame(-0.2, 30.0), 0); |
| 4466 | } | 4472 | } |
| 4473 | + | ||
| 4474 | + /// A paused transform nudge -- `set_transform_live` at the position the | ||
| 4475 | + /// picture already stands on -- never pays a full decoder restart: the | ||
| 4476 | + /// worker is reused (`Worker::reseek`), never replaced | ||
| 4477 | + /// (`PlaybackSession::retire`), so `restarts()` does not move. Guards the | ||
| 4478 | + /// path a card's live edits go through against a future change routing | ||
| 4479 | + /// them back through `seek`/a fresh worker, and a gap left between two | ||
| 4480 | + /// edits (a person's think-time between nudges) longer than the *old* | ||
| 4481 | + /// hardware-idle window still counts zero restarts -- a decoder worker | ||
| 4482 | + /// outliving its span is not a "restart" this counter (or a caller) sees, | ||
| 4483 | + /// whatever the hardware session inside it did. | ||
| 4484 | + #[test] | ||
| 4485 | + fn a_paused_transform_nudge_reuses_the_worker_not_a_restart() { | ||
| 4486 | + let mut s = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 4487 | + s.set_gain(0.0); | ||
| 4488 | + let poll = |s: &mut PlaybackSession| -> crate::decode::Frame { | ||
| 4489 | + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(20); | ||
| 4490 | + loop { | ||
| 4491 | + if let Some(f) = s.try_frame() { | ||
| 4492 | + return f; | ||
| 4493 | + } | ||
| 4494 | + assert!(std::time::Instant::now() < deadline, "no frame within 20s"); | ||
| 4495 | + std::thread::sleep(std::time::Duration::from_millis(10)); | ||
| 4496 | + } | ||
| 4497 | + }; | ||
| 4498 | + let first = poll(&mut s); | ||
| 4499 | + let before = s.restarts(); | ||
| 4500 | + | ||
| 4501 | + // A gap past the pre-fix 2s hardware-idle window: the whole point of | ||
| 4502 | + // widening it is that a nudge landing here still reuses the worker. | ||
| 4503 | + std::thread::sleep(std::time::Duration::from_millis(2500)); | ||
| 4504 | + | ||
| 4505 | + let clip = s.video_clip_at(s.now()).expect("a clip under the playhead"); | ||
| 4506 | + let params = TransformParams { | ||
| 4507 | + scale: 1.2, | ||
| 4508 | + ..Default::default() | ||
| 4509 | + }; | ||
| 4510 | + assert!(s.set_transform_live(clip.0, clip.1, Some(params)), "the edit took"); | ||
| 4511 | + let next = poll(&mut s); | ||
| 4512 | + | ||
| 4513 | + assert_eq!(before, s.restarts(), "a live transform edit must reuse the worker"); | ||
| 4514 | + assert_eq!(next.index, first.index, "paused: same timeline position before and after"); | ||
| 4515 | + } | ||
| 4467 | } | 4516 | } |