Merge branch 'worktree-agent-abe5dafd1fc480f66'
Browse files at this commit2 changed files +103 -5
crates/engine/src/playback.rsmodified+19 -3
| @@ -1168,9 +1168,25 @@ impl PlaybackSession { | |||
| 1168 | // scaffold unless that one is a still ([`audio_source_of`]): opening a | 1168 | // scaffold unless that one is a still ([`audio_source_of`]): opening a |
| 1169 | // PNG as the device is a session with no audio at all, however many | 1169 | // PNG as the device is a session with no audio at all, however many |
| 1170 | // clips with sound are on its lanes. | 1170 | // clips with sound are on its lanes. |
| 1171 | - let (audio, audio_disabled) = match audio_source_of(project.sources()) { | 1171 | + // |
| 1172 | - Some(source) => open_audio(&source.path, source.audio_stream), | 1172 | + // `audio_source_of` alone only rules out a still; it says nothing |
| 1173 | - None => (None, None), | 1173 | + // about whether the file it lands on actually *has* a track. A device |
| 1174 | + // pinned to the first candidate that opens silent (no track, or one | ||
| 1175 | + // the decoder refuses) would leave every later clip's sound unheard | ||
| 1176 | + // for the rest of the session, however many other sources on the | ||
| 1177 | + // timeline have real audio -- so this walks forward past a silent | ||
| 1178 | + // candidate to the first source that really opens a device, and keeps | ||
| 1179 | + // only the last attempt's reason when none of them do (a later | ||
| 1180 | + // source's silence is not worth reporting over an earlier one's). | ||
| 1181 | + let (audio, audio_disabled) = { | ||
| 1182 | + let mut opened = (None, None); | ||
| 1183 | + for source in project.sources().iter().filter(|s| !crate::is_image(&s.path)) { | ||
| 1184 | + opened = open_audio(&source.path, source.audio_stream); | ||
| 1185 | + if opened.0.is_some() { | ||
| 1186 | + break; | ||
| 1187 | + } | ||
| 1188 | + } | ||
| 1189 | + opened | ||
| 1174 | }; | 1190 | }; |
| 1175 | let mut session = Self { | 1191 | let mut session = Self { |
| 1176 | meta, | 1192 | meta, |
crates/engine/tests/audio_files.rsmodified+84 -2
| @@ -11,9 +11,9 @@ | |||
| 11 | use std::path::{Path, PathBuf}; | 11 | use std::path::{Path, PathBuf}; |
| 12 | 12 | ||
| 13 | use engine::export::{ExportSettings, Format}; | 13 | use engine::export::{ExportSettings, Format}; |
| 14 | -use engine::project::Lane; | 14 | +use engine::project::{Lane, LaneKind}; |
| 15 | use engine::scratch::Scratch; | 15 | use engine::scratch::Scratch; |
| 16 | -use engine::{AudioSession, Clip, PlaybackSession}; | 16 | +use engine::{AudioSession, Clip, PlaybackSession, Project}; |
| 17 | 17 | ||
| 18 | /// The fixtures `scripts/gen_fixtures.sh` writes: 3 s of 440 Hz left / 880 Hz | 18 | /// The fixtures `scripts/gen_fixtures.sh` writes: 3 s of 440 Hz left / 880 Hz |
| 19 | /// right at 44.1k stereo, under a 1 Hz volume pulse -- the same tone | 19 | /// right at 44.1k stereo, under a 1 Hz volume pulse -- the same tone |
| @@ -359,6 +359,88 @@ fn an_audio_only_project_saves_reloads_and_exports_its_sound() { | |||
| 359 | let _ = std::fs::remove_dir_all(&dir); | 359 | let _ = std::fs::remove_dir_all(&dir); |
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | +/// DEBT #45: the device the timeline plays through used to be opened once, on | ||
| 363 | +/// the first non-image source ([`audio_source_of`] in `playback.rs`) -- with | ||
| 364 | +/// no check that the source it landed on has a usable audio track at all. A | ||
| 365 | +/// timeline whose *first* source is silent (`test_baseline.mp4` has no audio | ||
| 366 | +/// track) therefore never reopened on a later source that does, and stayed | ||
| 367 | +/// silent for the whole session however many other sources had sound. | ||
| 368 | +/// | ||
| 369 | +/// No PipeWire daemon lives in this sandbox (`AoSession::probe()` is false | ||
| 370 | +/// here), so the device itself cannot be tapped for samples -- this reaches | ||
| 371 | +/// past it instead, onto the one signal `open_audio` still hands back with no | ||
| 372 | +/// device at all: [`PlaybackSession::audio_disabled_reason`]. `test_dts.mkv`'s | ||
| 373 | +/// track has a header (so it is chosen over a source with none) but no | ||
| 374 | +/// decoder (so opening it, unlike the silent baseline, is a reason worth | ||
| 375 | +/// giving) -- the old code never got there, and reports nothing. | ||
| 376 | +#[test] | ||
| 377 | +fn a_silent_first_source_does_not_stop_the_scan_for_one_with_sound() { | ||
| 378 | + let dir = Scratch::dir("ve_silent_first_source"); | ||
| 379 | + let path0 = asset("test_baseline.mp4"); | ||
| 380 | + let path1 = asset("test_dts.mkv"); | ||
| 381 | + let (meta0, _) = engine::demux::Demuxer::open(&path0).expect("open the baseline fixture"); | ||
| 382 | + let (meta1, _) = engine::demux::Demuxer::open(&path1).expect("open the dts fixture"); | ||
| 383 | + | ||
| 384 | + // `Project`, not `PlaybackSession::import`: the session-level import gate | ||
| 385 | + // would itself refuse a real track landing on a silent timeline | ||
| 386 | + // (`audio_matches_probed`, a different corner of the same debt) before | ||
| 387 | + // this test ever reaches `open_project`. | ||
| 388 | + let mut project = Project::single(&path0, meta0.frame_count); | ||
| 389 | + let source1 = project.import(&path1, 0); | ||
| 390 | + let lane2 = project.add_lane(LaneKind::Video); | ||
| 391 | + let clip = Clip { | ||
| 392 | + fade_in: 0, | ||
| 393 | + fade_out: 0, | ||
| 394 | + transition_out: 0, | ||
| 395 | + start: 0, | ||
| 396 | + in_frame: 0, | ||
| 397 | + out_frame: meta1.frame_count, | ||
| 398 | + source: source1, | ||
| 399 | + link: None, | ||
| 400 | + eq: None, | ||
| 401 | + color: None, | ||
| 402 | + fit: Default::default(), | ||
| 403 | + speed: engine::Speed::NORMAL, | ||
| 404 | + transform: None, | ||
| 405 | + }; | ||
| 406 | + assert!(project.place(lane2, 0, clip), "the second source lands"); | ||
| 407 | + | ||
| 408 | + let (sources, lanes, eq, color, transform) = project.without_orphan_sources(); | ||
| 409 | + let file = dir.join("silent_first.edith"); | ||
| 410 | + engine::edith::save( | ||
| 411 | + &file, | ||
| 412 | + &sources, | ||
| 413 | + &lanes, | ||
| 414 | + &project.lane_gains(), | ||
| 415 | + &project.lane_subs(), | ||
| 416 | + project.subtitles(), | ||
| 417 | + &eq, | ||
| 418 | + &color, | ||
| 419 | + &transform, | ||
| 420 | + (meta0.width, meta0.height), | ||
| 421 | + None, | ||
| 422 | + project.tone(), | ||
| 423 | + false, | ||
| 424 | + true, | ||
| 425 | + engine::export::EncoderSeat::default(), | ||
| 426 | + project.limiter(), | ||
| 427 | + None, | ||
| 428 | + 0, | ||
| 429 | + ) | ||
| 430 | + .expect("save"); | ||
| 431 | + | ||
| 432 | + let reloaded = PlaybackSession::open_project(&file).expect("reopen"); | ||
| 433 | + assert!( | ||
| 434 | + reloaded | ||
| 435 | + .audio_disabled_reason() | ||
| 436 | + .is_some_and(|r| r.contains("A_DTS")), | ||
| 437 | + "the scan for a source with sound never reached test_dts.mkv: {:?}", | ||
| 438 | + reloaded.audio_disabled_reason() | ||
| 439 | + ); | ||
| 440 | + drop(reloaded); | ||
| 441 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 442 | +} | ||
| 443 | + | ||
| 362 | /// A *song* as the first import into an empty window: `open_library` takes the | 444 | /// A *song* as the first import into an empty window: `open_library` takes the |
| 363 | /// audio-only fork of `open` (there is no picture to scaffold a canvas from) and | 445 | /// audio-only fork of `open` (there is no picture to scaffold a canvas from) and |
| 364 | /// still leaves the timeline empty. The row is there at the song's own length, | 446 | /// still leaves the timeline empty. The row is there at the song's own length, |