forge
Explore
Log in

Don't you dare go Hollow

A pasted still never lands on the audio lane

Browse files at this commit

b586b858f56856f2acbea13ca688d60f3f53b384Ahmet Kaan GümüşParent: 934361c
  • fix
    • a pasted still never lands on the audio lane
Show full message
🐛 fix(timeline): a pasted still never lands on the audio lane

`Project::paste` routed by `is_audio` alone, so a *copied* still clip --
the one door that does not go through `place_stream_at` -- was pasted as
a grouped take across `V1` and `A1`. The A1 half is a PNG the audio
worker demuxes: "file contains a box with a larger size than it", which
silences the whole session rather than that clip, and the save it writes
is one `open_project` then refuses by name. An `is_image` arm mirrors the
audio-only one.

Same-shape sweep of every clip-level door that routes by source kind:
- `Project::paste` (project.rs) -- this defect, fixed.
- `PlaybackSession::place_stream_at` -- already routed, image arm returns
  on the video lane before the audio fork.
- `PlaybackSession::open`/`open_project` -- both directions refused by
  name at load.
- `Project::move_to_lane` -- refuses a move across kinds, so no clip can
  cross by drag. Clean.
- `Project::place`, `split`, `regroup`, `lift`, `delete_in`, `trim` --
  the caller names the lane or the lane never changes. Clean, and the
  loader is the backstop for a hand-written file either way.
- `Player::insert_source` (app) -- guarded both ways already.

Falsification: with the `(_, true) => &[LaneKind::Video]` arm removed the
new test fails at the lane count (A1 1 -> 2), and with that assertion
lifted it fails on the WAV export with the demux error above -- the two
consequences the test names, both reachable.

Two doc corrections found with it: `Still::open` now says alpha is
dropped by `to_rgb8` (a transparent PNG lands opaque, with the blend as
the ponytail), and `first_audio_of` no longer implies an image-first
timeline accepts a later audio import -- it widens which source is
asked, not what "the timeline is silent" means.

tests: images 7/7 (new `pasting_a_copied_still_never_reaches_the_audio_lane`
asserts no A1 clip, no audio clip from a picture, the WAV export still
carries the sound, and the save reopens), engine lib 155, saveload 12,
audio_files 16, lanes 5 (serial), bin 56.
crates/engine/src/decode.rsmodified+10 -0
@@ -446,6 +446,16 @@ impl Still {
446 /// Decodes `path`. Refused by name for a picture that is not one446 /// Decodes `path`. Refused by name for a picture that is not one
447 /// ([`crate::is_resolution`]): an 8K limit that a keystroke and a project447 /// ([`crate::is_resolution`]): an 8K limit that a keystroke and a project
448 /// file are both held to cannot be walked around by a 30000-pixel-wide PNG.448 /// file are both held to cannot be walked around by a 30000-pixel-wide PNG.
449+ ///
450+ /// Alpha is *dropped*, not composited: `to_rgb8` discards the channel, so a
451+ /// transparent PNG arrives fully opaque over its own colours rather than
452+ /// over the clip beneath it. I420 has nowhere to carry it and this engine
453+ /// composes one picture per frame (topmost lane wins), so there is nothing
454+ /// for a blend to blend with.
455+ ///
456+ /// ponytail: the ceiling is a logo with a transparent background, which
457+ /// lands as a rectangle. Upgrade path is keeping the alpha plane here and
458+ /// giving `scale::Composer` a blend over the lane below.
449 pub(crate) fn open(path: &Path) -> crate::Result<Self> {459 pub(crate) fn open(path: &Path) -> crate::Result<Self> {
450 let reader = image::ImageReader::open(path)?.with_guessed_format()?;460 let reader = image::ImageReader::open(path)?.with_guessed_format()?;
451 let rgb = reader461 let rgb = reader
crates/engine/src/playback.rsmodified+9 -3
@@ -1637,9 +1637,15 @@ fn matches_timeline(
1637 /// export time (`AudioSession::copy_multi_streams`).1637 /// export time (`AudioSession::copy_multi_streams`).
1638 /// What a timeline's audio is held to: the probe of the first source that could1638 /// What a timeline's audio is held to: the probe of the first source that could
1639 /// have any. A still image is never it -- a picture defines no rate and no1639 /// have any. A still image is never it -- a picture defines no rate and no
1640-/// layout, and taking its silence for the timeline's would refuse every sound1640+/// layout, so a PNG at index 0 would otherwise be *probed* as a broken mp4 and
1641-/// imported after it. `Ok(None)` for a timeline of nothing but stills, which is1641+/// fail the open outright.
1642-/// a silent one.1642+///
1643+/// `Ok(None)` for a timeline whose first such source is silent, and for one of
1644+/// nothing but stills. That is a silent timeline, and a file with sound is
1645+/// still refused by [`audio_matches`] in the words it always used ("the file
1646+/// has audio, the timeline is silent") -- the same answer a silent *video* as
1647+/// source 0 has always given. This function widens which source is asked, not
1648+/// what the answer means.
1643 fn first_audio_of(sources: &[Source]) -> crate::Result<Option<crate::AudioProbe>> {1649 fn first_audio_of(sources: &[Source]) -> crate::Result<Option<crate::AudioProbe>> {
1644 match sources.iter().find(|s| !crate::is_image(&s.path)) {1650 match sources.iter().find(|s| !crate::is_image(&s.path)) {
1645 Some(first) => AudioSession::probe(&first.path, first.audio_stream),1651 Some(first) => AudioSession::probe(&first.path, first.audio_stream),
crates/engine/src/project.rsmodified+13 -6
@@ -1390,8 +1390,10 @@ impl Project {
1390 /// twice over (and leave an mp4 export with two tracks to copy). A clip of a1390 /// twice over (and leave an mp4 export with two tracks to copy). A clip of a
1391 /// source with no picture ([`crate::is_audio`]) reaches `A1` only -- on a1391 /// source with no picture ([`crate::is_audio`]) reaches `A1` only -- on a
1392 /// video lane it is a clip that decodes to nothing, and a save carrying one1392 /// video lane it is a clip that decodes to nothing, and a save carrying one
1393- /// does not open again. The room is still opened everywhere, or the lanes it1393+ /// does not open again -- and a still image ([`crate::is_image`]) reaches
1394- /// was not inserted into would slide out of step with the ones it was.1394+ /// `V1` only, for the mirror of that reason. The room is still opened
1395+ /// everywhere, or the lanes it was not inserted into would slide out of step
1396+ /// with the ones it was.
1395 ///1397 ///
1396 /// Exactly one history snapshot, so one [`Project::undo`] takes it back.1398 /// Exactly one history snapshot, so one [`Project::undo`] takes it back.
1397 /// Changes the timeline->source mapping: the caller must reseek. Refused for1399 /// Changes the timeline->source mapping: the caller must reseek. Refused for
@@ -1407,6 +1409,11 @@ impl Project {
1407 return false;1409 return false;
1408 }1410 }
1409 let audio_only = crate::is_audio(&source.path);1411 let audio_only = crate::is_audio(&source.path);
1412+ // ...and its mirror: a still is a picture and no sound, so a copy of one
1413+ // reaches `V1` only. Pasted onto `A1` as well it is a PNG the audio
1414+ // worker tries to demux -- which silences the *whole session*, not just
1415+ // that clip -- and a save the engine's own `open_project` then refuses.
1416+ let picture_only = crate::is_image(&source.path);
1410 let at = timeline_frame.min(self.timeline_frames());1417 let at = timeline_frame.min(self.timeline_frames());
1411 let len = clip.len();1418 let len = clip.len();
1412 // Room for it: `open_room` adds `len` to every start from `at` on, and a1419 // Room for it: `open_room` adds `len` to every start from `at` on, and a
@@ -1433,10 +1440,10 @@ impl Project {
1433 // an audio lane and nowhere else, exactly as `place_stream_at` decides1440 // an audio lane and nowhere else, exactly as `place_stream_at` decides
1434 // it for an import. On a video lane it would decode to nothing, and the1441 // it for an import. On a video lane it would decode to nothing, and the
1435 // save it wrote would not open again.1442 // save it wrote would not open again.
1436- let kinds: &[LaneKind] = if audio_only {1443+ let kinds: &[LaneKind] = match (audio_only, picture_only) {
1437- &[LaneKind::Audio]1444+ (true, _) => &[LaneKind::Audio],
1438- } else {1445+ (_, true) => &[LaneKind::Video],
1439- &[LaneKind::Video, LaneKind::Audio]1446+ _ => &[LaneKind::Video, LaneKind::Audio],
1440 };1447 };
1441 let takes: Vec<usize> = kinds1448 let takes: Vec<usize> = kinds
1442 .iter()1449 .iter()
crates/engine/tests/images.rsmodified+77 -0
@@ -15,6 +15,7 @@ use std::path::PathBuf;
15 use std::sync::Once;15 use std::sync::Once;
16 use std::time::{Duration, Instant};16 use std::time::{Duration, Instant};
17 17
18+use engine::export::{ExportSettings, Format};
18 use engine::project::{Edge, Lane, LaneKind};19 use engine::project::{Edge, Lane, LaneKind};
19 use engine::{DecodeSession, ExportHandle, PlaybackSession};20 use engine::{DecodeSession, ExportHandle, PlaybackSession};
20 21
@@ -209,6 +210,82 @@ fn a_still_trims_out_to_its_cap_and_no_further() {
209 assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60);210 assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60);
210 }211 }
211 212
213+/// The *clipboard* door, which is the second way a clip picks its lanes and
214+/// the one that does not go through `place_stream_at`: a copied still pasted at
215+/// the playhead is a grouped take everywhere else, and a take of a picture with
216+/// no sound is one lane. Pasted onto `A1` as well it would be a PNG the audio
217+/// worker demuxes -- which silences the whole session, not just that clip --
218+/// and a save the engine's own loader then refuses.
219+///
220+/// Both consequences are asserted, not just the lane count: the failure this
221+/// guards against was invisible in the clip list.
222+#[test]
223+fn pasting_a_copied_still_never_reaches_the_audio_lane() {
224+ pin_software();
225+ let dir = std::env::temp_dir().join(format!("ve_images_paste_{}", std::process::id()));
226+ let _ = std::fs::remove_dir_all(&dir);
227+ std::fs::create_dir_all(&dir).expect("scratch dir");
228+ let media = dir.join("test_av.mp4");
229+ let still = dir.join("test_still.png");
230+ std::fs::copy(asset("test_av.mp4"), &media).expect("copy the video");
231+ std::fs::copy(asset("test_still.png"), &still).expect("copy the still");
232+
233+ let mut session = PlaybackSession::open(&media).expect("open the fixture");
234+ session.set_gain(0.0);
235+ session.import(&still).expect("a picture");
236+ let end = session.timeline_duration();
237+ assert!(
238+ session
239+ .place_stream_at(end, &still, 0, Some(Lane::V1))
240+ .expect("a still joins any timeline")
241+ );
242+ let audio_clips = session.lane_clips(Lane::A1).len();
243+
244+ // Copy the still clip and paste it at the playhead, exactly as the app's
245+ // ctrl+c / ctrl+v pair does (`Player::copy` takes `clip_at`, `Player::paste`
246+ // hands it to `paste_at`).
247+ let last = session.lane_clips(Lane::V1).len() - 1;
248+ let copied = session.clip_at(last).expect("the clipboard sees the still");
249+ session.seek(0.0);
250+ assert!(session.paste_at(0.0, copied), "the paste takes");
251+
252+ assert_eq!(
253+ session.lane_clips(Lane::A1).len(),
254+ audio_clips,
255+ "a still is silent: the audio lane gains nothing from a paste"
256+ );
257+ assert!(
258+ session
259+ .lane_clips(Lane::A1)
260+ .iter()
261+ .all(|c| !engine::is_image(&session.sources()[c.source].path)),
262+ "no audio clip may play from a picture"
263+ );
264+ // The sound itself, through the one public door that reads the same play
265+ // list playback feeds from (`audio_segments_from` ->
266+ // `open_mixed_streams_eq`): a WAV export. With a PNG on the audio lane this
267+ // is the demux error that silences the session, not a file.
268+ let wav = dir.join("pasted.wav");
269+ let settings = ExportSettings {
270+ format: Format::Wav,
271+ ..ExportSettings::default()
272+ };
273+ wait(
274+ &session.export_to_with(&wav, &settings),
275+ Duration::from_secs(120),
276+ )
277+ .expect("the timeline's sound is still there");
278+ assert!(
279+ std::fs::metadata(&wav).expect("the wav exists").len() > 1_000,
280+ "a silent-by-failure export would be the header alone"
281+ );
282+ // ...and the save the engine writes is one the engine can open.
283+ let project = dir.join("pasted.edith");
284+ session.save_project(&project).expect("save");
285+ PlaybackSession::open_project(&project).expect("the engine's own save reopens");
286+ let _ = std::fs::remove_dir_all(&dir);
287+}
288+
212 /// Saved and reopened: the clip that comes back plays the same picture for the289 /// Saved and reopened: the clip that comes back plays the same picture for the
213 /// same frames. The reload recomputes the still's length, so a clip trimmed out290 /// same frames. The reload recomputes the still's length, so a clip trimmed out
214 /// to the cap has to still be inside it -- `open_project` refuses one that is291 /// to the cap has to still be inside it -- `open_project` refuses one that is