The clock stops where the timeline does
Browse files at this commitd93bb5f289598183bc48420cf6ab1797fee571aaParent: bb16b0d- fix
- the clock stops where the timeline does
2 changed files +93 -1
- crates/app/src/main.rs +74 -1
- crates/engine/src/playback.rs +19 -0
crates/app/src/main.rsmodified+74 -1
| @@ -805,6 +805,19 @@ impl Player { | |||
| 805 | // state does, not just on the crossing: nothing else is coming. | 805 | // state does, not just on the crossing: nothing else is coming. |
| 806 | self.pending_seek = false; | 806 | self.pending_seek = false; |
| 807 | if was != Transport::Ended { | 807 | if was != Transport::Ended { |
| 808 | + // Ended is a *stopped* transport, so the clock stops with it, | ||
| 809 | + // on the out point the timecode and the playhead have been | ||
| 810 | + // showing all along. Nothing else ever stopped it: past the | ||
| 811 | + // last frame wall time takes over and `now()` walks off the end | ||
| 812 | + // of the timeline for as long as the window is left open -- and | ||
| 813 | + // the playhead is what a cut, a paste, an insert and the | ||
| 814 | + // analyser all act at, so every one of them was aiming into | ||
| 815 | + // empty space (measured: a 5 s timeline recognised its end at | ||
| 816 | + // clock 17.5 s under a slow renderer). End of stream is left | ||
| 817 | + // set, so this is still `Ended` and the next press restarts. | ||
| 818 | + if let Some(session) = &mut self.session { | ||
| 819 | + session.halt_at_end(); | ||
| 820 | + } | ||
| 808 | let elapsed = self.started.map_or(0.0, |t| t.elapsed().as_secs_f64()); | 821 | let elapsed = self.started.map_or(0.0, |t| t.elapsed().as_secs_f64()); |
| 809 | eprintln!( | 822 | eprintln!( |
| 810 | "eof after {elapsed:.3}s wall: {} frames displayed, {} dropped, clock {:.3}s", | 823 | "eof after {elapsed:.3}s wall: {} frames displayed, {} dropped, clock {:.3}s", |
| @@ -6810,7 +6823,7 @@ mod tests { | |||
| 6810 | use gpui::{Bounds, Pixels, point, px, size}; | 6823 | use gpui::{Bounds, Pixels, point, px, size}; |
| 6811 | use std::collections::HashMap; | 6824 | use std::collections::HashMap; |
| 6812 | use std::path::{Path, PathBuf}; | 6825 | use std::path::{Path, PathBuf}; |
| 6813 | - use std::time::Duration; | 6826 | + use std::time::{Duration, Instant}; |
| 6814 | 6827 | ||
| 6815 | fn asset(name: &str) -> PathBuf { | 6828 | fn asset(name: &str) -> PathBuf { |
| 6816 | Path::new(env!("CARGO_MANIFEST_DIR")) | 6829 | Path::new(env!("CARGO_MANIFEST_DIR")) |
| @@ -8220,6 +8233,66 @@ mod tests { | |||
| 8220 | } | 8233 | } |
| 8221 | } | 8234 | } |
| 8222 | 8235 | ||
| 8236 | + /// The half of `Ended` the eye cannot see: the clock. Wall time takes over | ||
| 8237 | + /// at the last frame and nothing used to stop it, so the playhead walked off | ||
| 8238 | + /// the end of the timeline in real time -- and the playhead is what a cut, a | ||
| 8239 | + /// paste, an insert and the analyser all act at. `pump` pauses on the | ||
| 8240 | + /// crossing; this is the engine contract that rests on, driven exactly as | ||
| 8241 | + /// the pump drives it. | ||
| 8242 | + #[test] | ||
| 8243 | + fn the_clock_stops_where_the_timeline_does_and_the_end_still_restarts() { | ||
| 8244 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 8245 | + session.set_gain(0.0); | ||
| 8246 | + // Start a breath short of the end: the tail is what this is about, and | ||
| 8247 | + // playing the whole five seconds would say nothing more. | ||
| 8248 | + session.seek(4.8); | ||
| 8249 | + session.play(); | ||
| 8250 | + | ||
| 8251 | + // The pump's own loop -- tick, drain, ask where the transport is -- | ||
| 8252 | + // with a deadline so a fixture that will not decode fails as a failure | ||
| 8253 | + // rather than as a hang. | ||
| 8254 | + let deadline = Instant::now() + Duration::from_secs(20); | ||
| 8255 | + let mut state = transport(session.is_playing(), session.is_eos()); | ||
| 8256 | + while state != Transport::Ended { | ||
| 8257 | + assert!(Instant::now() < deadline, "never reached the end of a 5s file"); | ||
| 8258 | + session.tick(); | ||
| 8259 | + while session.try_frame().is_some() {} | ||
| 8260 | + state = transport(session.is_playing(), session.is_eos()); | ||
| 8261 | + } | ||
| 8262 | + | ||
| 8263 | + // What `pump` does on the crossing, and the whole point of it: the | ||
| 8264 | + // position holds still afterwards instead of counting on past the end, | ||
| 8265 | + // and it holds still *on the out point* -- where the timecode and the | ||
| 8266 | + // playhead have been showing it. The clock at the moment the end is | ||
| 8267 | + // recognised is not that: a slow renderer reaches EOF with the clock | ||
| 8268 | + // seconds past the timeline, which is why this repositions rather than | ||
| 8269 | + // only freezing. | ||
| 8270 | + session.halt_at_end(); | ||
| 8271 | + let stopped_at = session.now(); | ||
| 8272 | + assert_eq!(stopped_at, session.timeline_duration()); | ||
| 8273 | + std::thread::sleep(Duration::from_millis(250)); | ||
| 8274 | + assert_eq!(session.now(), stopped_at, "the clock kept running past EOF"); | ||
| 8275 | + // And it is still the end: pausing must not spend the state the glyph | ||
| 8276 | + // and the restart both read. | ||
| 8277 | + assert!(session.is_eos()); | ||
| 8278 | + assert_eq!( | ||
| 8279 | + transport(session.is_playing(), session.is_eos()), | ||
| 8280 | + Transport::Ended | ||
| 8281 | + ); | ||
| 8282 | + | ||
| 8283 | + // The restart path off that frozen end, which is what the button and | ||
| 8284 | + // the play key do from `Ended`: back to the top, and running. | ||
| 8285 | + session.seek(0.); | ||
| 8286 | + session.play(); | ||
| 8287 | + assert!(!session.is_eos(), "a seek revives the session"); | ||
| 8288 | + assert!(session.now() < 1.0); | ||
| 8289 | + assert_eq!( | ||
| 8290 | + transport(session.is_playing(), session.is_eos()), | ||
| 8291 | + Transport::Playing | ||
| 8292 | + ); | ||
| 8293 | + session.pause(); | ||
| 8294 | + } | ||
| 8295 | + | ||
| 8223 | /// Both ends hold under a key held down: the ABI only accepts `0.0..=1.0`, | 8296 | /// Both ends hold under a key held down: the ABI only accepts `0.0..=1.0`, |
| 8224 | /// and a wrapped step count would hand it something else. | 8297 | /// and a wrapped step count would hand it something else. |
| 8225 | #[test] | 8298 | #[test] |
crates/engine/src/playback.rsmodified+19 -0
| @@ -1474,6 +1474,25 @@ impl PlaybackSession { | |||
| 1474 | } | 1474 | } |
| 1475 | } | 1475 | } |
| 1476 | 1476 | ||
| 1477 | + /// Stops the transport where the timeline stops: the clock is paused and put | ||
| 1478 | + /// on the out point. | ||
| 1479 | + /// | ||
| 1480 | + /// Playing past the last frame is wall time counting on past the end of the | ||
| 1481 | + /// media -- there is no picture left to pace it -- so a session left at EOF | ||
| 1482 | + /// reports a `now()` that walks off the end of the timeline in real time, | ||
| 1483 | + /// and a caller that reads the playhead (a cut, a paste, an insert) then | ||
| 1484 | + /// acts at a position no clip is at. How far off depends only on how long | ||
| 1485 | + /// the window was left open, so no clamp in a caller is worth writing. | ||
| 1486 | + /// | ||
| 1487 | + /// End of stream is deliberately left set: the picture is still the last | ||
| 1488 | + /// frame and this is still the end. That is what makes it safe to call on | ||
| 1489 | + /// the crossing into it -- the state the transport shows does not change, | ||
| 1490 | + /// only the running clock stops. | ||
| 1491 | + pub fn halt_at_end(&mut self) { | ||
| 1492 | + self.pause(); | ||
| 1493 | + self.clock.seek_to(self.timeline_duration()); | ||
| 1494 | + } | ||
| 1495 | + | ||
| 1477 | /// Sets the monitoring gain, 0.0 (silent) to 1.0. Mute is a gain of 0.0: | 1496 | /// Sets the monitoring gain, 0.0 (silent) to 1.0. Mute is a gain of 0.0: |
| 1478 | /// one knob, because muting and turning it down are the same thing to the | 1497 | /// one knob, because muting and turning it down are the same thing to the |
| 1479 | /// device, and *which* the user meant is a question only the UI can answer | 1498 | /// device, and *which* the user meant is a question only the UI can answer |