| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | use std::path::{Path, PathBuf}; |
| 11 | |
| 12 | use engine::PlaybackSession; |
| 13 | use engine::scratch::Scratch; |
| 14 | |
| 15 | fn asset(name: &str) -> PathBuf { |
| 16 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 17 | .join("../../assets") |
| 18 | .join(name) |
| 19 | } |
| 20 | |
| 21 | fn copy_in(dir: &Path, name: &str) -> PathBuf { |
| 22 | let to = dir.join(name); |
| 23 | std::fs::copy(asset(name), &to).expect("copy the fixture"); |
| 24 | to |
| 25 | } |
| 26 | |
| 27 | |
| 28 | fn save_and_reopen(session: &PlaybackSession, path: &Path) -> PlaybackSession { |
| 29 | session.save_project(path).expect("save"); |
| 30 | let loaded = PlaybackSession::open_project(path).unwrap_or_else(|e| { |
| 31 | panic!("a project with an audio-only mp4 must reopen: {e}") |
| 32 | }); |
| 33 | assert_eq!(loaded.sources(), session.sources()); |
| 34 | assert_eq!(loaded.timeline_duration(), session.timeline_duration()); |
| 35 | loaded |
| 36 | } |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | #[test] |
| 42 | fn audio_only_mp4_reopens_in_every_source_position() { |
| 43 | let dir = Scratch::dir("ve_audio_only_mp4_positions"); |
| 44 | let video = copy_in(&dir, "test_av.mp4"); |
| 45 | let audio = copy_in(&dir, "test_audio_only.mp4"); |
| 46 | |
| 47 | |
| 48 | { |
| 49 | let session = PlaybackSession::open(&audio).expect("open the audio-only file"); |
| 50 | session.set_gain(0.0); |
| 51 | let path = dir.join("alone.edith"); |
| 52 | save_and_reopen(&session, &path); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | { |
| 57 | let mut session = PlaybackSession::open(&audio).expect("open the audio-only file"); |
| 58 | session.set_gain(0.0); |
| 59 | session.import(&video).expect("import the picture file second"); |
| 60 | let path = dir.join("first.edith"); |
| 61 | save_and_reopen(&session, &path); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | { |
| 66 | let mut session = PlaybackSession::open(&video).expect("open the picture file"); |
| 67 | session.set_gain(0.0); |
| 68 | session.import(&audio).expect("import the audio-only file second"); |
| 69 | let path = dir.join("second.edith"); |
| 70 | save_and_reopen(&session, &path); |
| 71 | } |
| 72 | |
| 73 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |
| 78 | #[test] |
| 79 | fn clips_from_an_audio_only_mp4_survive_a_reopen() { |
| 80 | let dir = Scratch::dir("ve_audio_only_mp4_clips"); |
| 81 | let video = copy_in(&dir, "test_av.mp4"); |
| 82 | let audio = copy_in(&dir, "test_audio_only.mp4"); |
| 83 | |
| 84 | let mut session = PlaybackSession::open(&video).expect("open the picture file"); |
| 85 | session.set_gain(0.0); |
| 86 | session.import(&audio).expect("import the audio-only file"); |
| 87 | let end = session.timeline_duration(); |
| 88 | assert!( |
| 89 | session |
| 90 | .place_stream_at(end, &audio, 0, None) |
| 91 | .expect("the audio-only file is placeable on the timeline"), |
| 92 | "the placement was accepted" |
| 93 | ); |
| 94 | |
| 95 | session |
| 96 | .place_stream_at(0.0, &audio, 0, None) |
| 97 | .expect("a second clip from the audio-only file"); |
| 98 | |
| 99 | let path = dir.join("clips.edith"); |
| 100 | let loaded = save_and_reopen(&session, &path); |
| 101 | for lane in session.lanes() { |
| 102 | assert_eq!( |
| 103 | loaded.lane_clips(lane).len(), |
| 104 | session.lane_clips(lane).len(), |
| 105 | "clip count on {lane:?}" |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | let frame = loaded |
| 111 | .compose_at(0, 320, 180) |
| 112 | .expect("the reopened timeline composes a frame"); |
| 113 | assert_eq!((frame.width, frame.height), (320, 180)); |
| 114 | |
| 115 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 116 | } |