An empty timeline is refused by the engine, in every format
Browse files at this commitdc82aff1c168ead7958df4fabaf1fdf1dc03e1b8Parent: c600c52- fix
- an empty timeline is refused by the engine, in every format
3 changed files +44 -1
- crates/app/src/main.rs +4 -1
- crates/engine/src/export.rs +11 -0
- crates/engine/tests/playback.rs +29 -0
crates/app/src/main.rsmodified+4 -1
| @@ -1553,7 +1553,10 @@ impl Player { | |||
| 1553 | return; | 1553 | return; |
| 1554 | }; | 1554 | }; |
| 1555 | // An emptied timeline is a timeline; it is simply not a file. Refused by | 1555 | // An emptied timeline is a timeline; it is simply not a file. Refused by |
| 1556 | - // name here rather than written as a project of no frames. | 1556 | + // name here rather than written as a project of no frames -- and the |
| 1557 | + // engine refuses it again on the worker (`export::start`), so a caller | ||
| 1558 | + // that is not this button cannot get past it either. Two fences on | ||
| 1559 | + // purpose: this one is the one with a keystroke to blame. | ||
| 1557 | if session.is_empty() { | 1560 | if session.is_empty() { |
| 1558 | self.notice = Some("NOTHING TO EXPORT — the timeline is empty".into()); | 1561 | self.notice = Some("NOTHING TO EXPORT — the timeline is empty".into()); |
| 1559 | cx.notify(); | 1562 | cx.notify(); |
crates/engine/src/export.rsmodified+11 -0
| @@ -165,7 +165,18 @@ pub fn start( | |||
| 165 | // The rename is the last step and the only one that publishes a file | 165 | // The rename is the last step and the only one that publishes a file |
| 166 | // under the name the caller asked for; it stays on the same directory, | 166 | // under the name the caller asked for; it stays on the same directory, |
| 167 | // so it is atomic. | 167 | // so it is atomic. |
| 168 | + // | ||
| 169 | + // An emptied timeline is a legal project and an illegal file: no | ||
| 170 | + // picture, no sound, and a muxer that is never created because no coded | ||
| 171 | + // frame arrives. Refused by name here -- before the format is even | ||
| 172 | + // looked at, so an mp4 and a WAV refuse in the same words -- rather than | ||
| 173 | + // left to write a file of no frames that nothing opens. Every caller of | ||
| 174 | + // `start` comes through this, the app's own door | ||
| 175 | + // (`PlaybackSession::is_empty`) being only the first fence. | ||
| 168 | let written = match settings.format { | 176 | let written = match settings.format { |
| 177 | + _ if project.timeline_frames() == 0 => { | ||
| 178 | + Err("the timeline is empty: there is nothing to export".into()) | ||
| 179 | + } | ||
| 169 | Format::Mp4 => run(&project, &meta, &part, &worker, &settings), | 180 | Format::Mp4 => run(&project, &meta, &part, &worker, &settings), |
| 170 | format => run_audio(&project, &meta, &part, &worker, format), | 181 | format => run_audio(&project, &meta, &part, &worker, format), |
| 171 | }; | 182 | }; |
crates/engine/tests/playback.rsmodified+29 -0
| @@ -11,6 +11,7 @@ use std::path::{Path, PathBuf}; | |||
| 11 | use std::thread::sleep; | 11 | use std::thread::sleep; |
| 12 | use std::time::{Duration, Instant}; | 12 | use std::time::{Duration, Instant}; |
| 13 | 13 | ||
| 14 | +use engine::export::{ExportSettings, Format}; | ||
| 14 | use engine::project::Lane; | 15 | use engine::project::Lane; |
| 15 | use engine::{DecodeSession, Frame, PlaybackSession}; | 16 | use engine::{DecodeSession, Frame, PlaybackSession}; |
| 16 | 17 | ||
| @@ -1170,6 +1171,34 @@ fn an_emptied_timeline_plays_black_saves_loads_and_undoes() { | |||
| 1170 | assert!(session.is_eos(), "an empty timeline is played out at once"); | 1171 | assert!(session.is_eos(), "an empty timeline is played out at once"); |
| 1171 | session.pause(); | 1172 | session.pause(); |
| 1172 | 1173 | ||
| 1174 | + // Exporting nothing is a refusal in words, not a file of no frames -- and | ||
| 1175 | + // in the *same* words whichever format asked, because the fence sits in | ||
| 1176 | + // `export::start` ahead of the format, not in the mp4 path alone. | ||
| 1177 | + for format in [Format::Mp4, Format::Wav, Format::Flac] { | ||
| 1178 | + let out = std::env::temp_dir().join(format!("ve_nothing_{}", std::process::id())); | ||
| 1179 | + let handle = session.export_to_with( | ||
| 1180 | + &out, | ||
| 1181 | + &ExportSettings { | ||
| 1182 | + format, | ||
| 1183 | + ..ExportSettings::default() | ||
| 1184 | + }, | ||
| 1185 | + ); | ||
| 1186 | + let deadline = Instant::now() + Duration::from_secs(10); | ||
| 1187 | + let err = loop { | ||
| 1188 | + if let Some(result) = handle.result() { | ||
| 1189 | + break result.expect_err("an empty timeline cannot be exported"); | ||
| 1190 | + } | ||
| 1191 | + assert!(Instant::now() < deadline, "{format:?} export never settled"); | ||
| 1192 | + sleep(Duration::from_millis(10)); | ||
| 1193 | + }; | ||
| 1194 | + assert_eq!( | ||
| 1195 | + err.to_string(), | ||
| 1196 | + "the timeline is empty: there is nothing to export", | ||
| 1197 | + "{format:?}" | ||
| 1198 | + ); | ||
| 1199 | + assert!(!out.exists(), "{format:?} wrote a file anyway"); | ||
| 1200 | + } | ||
| 1201 | + | ||
| 1173 | // It saves and loads back -- still a project, still two lanes, and still | 1202 | // It saves and loads back -- still a project, still two lanes, and still |
| 1174 | // naming the file whose frame rate the timeline counts in. | 1203 | // naming the file whose frame rate the timeline counts in. |
| 1175 | let dir = std::env::temp_dir().join(format!("ve_empty_{}", std::process::id())); | 1204 | let dir = std::env::temp_dir().join(format!("ve_empty_{}", std::process::id())); |