From c322a696ba5bfa9a918d3f169b09953123b9fd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 01:52:40 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(engine):=20reopen=20the=20au?= =?UTF-8?q?dio=20device=20past=20a=20silent=20first=20source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PlaybackSession::open_project pinned the device to the first non-image source (audio_source_of) with no check that source actually had a track. A silent leading source (a clip with no audio) left every later source unheard for the whole session. Now the scaffold walks forward past a silent candidate to the first source that really opens a device. Regression test in audio_files.rs proves the scan reaches a second source's audio (verified via audio_disabled_reason, since this sandbox has no PipeWire device to tap samples from). --- crates/engine/src/playback.rs | 22 ++++++-- crates/engine/tests/audio_files.rs | 86 +++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 7cb2811..90581e4 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -1168,9 +1168,25 @@ impl PlaybackSession { // scaffold unless that one is a still ([`audio_source_of`]): opening a // PNG as the device is a session with no audio at all, however many // clips with sound are on its lanes. - let (audio, audio_disabled) = match audio_source_of(project.sources()) { - Some(source) => open_audio(&source.path, source.audio_stream), - None => (None, None), + // + // `audio_source_of` alone only rules out a still; it says nothing + // about whether the file it lands on actually *has* a track. A device + // pinned to the first candidate that opens silent (no track, or one + // the decoder refuses) would leave every later clip's sound unheard + // for the rest of the session, however many other sources on the + // timeline have real audio -- so this walks forward past a silent + // candidate to the first source that really opens a device, and keeps + // only the last attempt's reason when none of them do (a later + // source's silence is not worth reporting over an earlier one's). + let (audio, audio_disabled) = { + let mut opened = (None, None); + for source in project.sources().iter().filter(|s| !crate::is_image(&s.path)) { + opened = open_audio(&source.path, source.audio_stream); + if opened.0.is_some() { + break; + } + } + opened }; let mut session = Self { meta, diff --git a/crates/engine/tests/audio_files.rs b/crates/engine/tests/audio_files.rs index cd1eec5..2484850 100644 --- a/crates/engine/tests/audio_files.rs +++ b/crates/engine/tests/audio_files.rs @@ -11,9 +11,9 @@ use std::path::{Path, PathBuf}; use engine::export::{ExportSettings, Format}; -use engine::project::Lane; +use engine::project::{Lane, LaneKind}; use engine::scratch::Scratch; -use engine::{AudioSession, Clip, PlaybackSession}; +use engine::{AudioSession, Clip, PlaybackSession, Project}; /// The fixtures `scripts/gen_fixtures.sh` writes: 3 s of 440 Hz left / 880 Hz /// 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() { let _ = std::fs::remove_dir_all(&dir); } +/// DEBT #45: the device the timeline plays through used to be opened once, on +/// the first non-image source ([`audio_source_of`] in `playback.rs`) -- with +/// no check that the source it landed on has a usable audio track at all. A +/// timeline whose *first* source is silent (`test_baseline.mp4` has no audio +/// track) therefore never reopened on a later source that does, and stayed +/// silent for the whole session however many other sources had sound. +/// +/// No PipeWire daemon lives in this sandbox (`AoSession::probe()` is false +/// here), so the device itself cannot be tapped for samples -- this reaches +/// past it instead, onto the one signal `open_audio` still hands back with no +/// device at all: [`PlaybackSession::audio_disabled_reason`]. `test_dts.mkv`'s +/// track has a header (so it is chosen over a source with none) but no +/// decoder (so opening it, unlike the silent baseline, is a reason worth +/// giving) -- the old code never got there, and reports nothing. +#[test] +fn a_silent_first_source_does_not_stop_the_scan_for_one_with_sound() { + let dir = Scratch::dir("ve_silent_first_source"); + let path0 = asset("test_baseline.mp4"); + let path1 = asset("test_dts.mkv"); + let (meta0, _) = engine::demux::Demuxer::open(&path0).expect("open the baseline fixture"); + let (meta1, _) = engine::demux::Demuxer::open(&path1).expect("open the dts fixture"); + + // `Project`, not `PlaybackSession::import`: the session-level import gate + // would itself refuse a real track landing on a silent timeline + // (`audio_matches_probed`, a different corner of the same debt) before + // this test ever reaches `open_project`. + let mut project = Project::single(&path0, meta0.frame_count); + let source1 = project.import(&path1, 0); + let lane2 = project.add_lane(LaneKind::Video); + let clip = Clip { + fade_in: 0, + fade_out: 0, + transition_out: 0, + start: 0, + in_frame: 0, + out_frame: meta1.frame_count, + source: source1, + link: None, + eq: None, + color: None, + fit: Default::default(), + speed: engine::Speed::NORMAL, + transform: None, + }; + assert!(project.place(lane2, 0, clip), "the second source lands"); + + let (sources, lanes, eq, color, transform) = project.without_orphan_sources(); + let file = dir.join("silent_first.edith"); + engine::edith::save( + &file, + &sources, + &lanes, + &project.lane_gains(), + &project.lane_subs(), + project.subtitles(), + &eq, + &color, + &transform, + (meta0.width, meta0.height), + None, + project.tone(), + false, + true, + engine::export::EncoderSeat::default(), + project.limiter(), + None, + 0, + ) + .expect("save"); + + let reloaded = PlaybackSession::open_project(&file).expect("reopen"); + assert!( + reloaded + .audio_disabled_reason() + .is_some_and(|r| r.contains("A_DTS")), + "the scan for a source with sound never reached test_dts.mkv: {:?}", + reloaded.audio_disabled_reason() + ); + drop(reloaded); + let _ = std::fs::remove_dir_all(&dir); +} + /// A *song* as the first import into an empty window: `open_library` takes the /// audio-only fork of `open` (there is no picture to scaffold a canvas from) and /// still leaves the timeline empty. The row is there at the song's own length,