forge
Explore
Log in

Don't you dare go Hollow

🔀 merge(A5): import stops gatekeeping — silent files land as silence, mixed codecs play per-clip, refusals name the missing decoder

Browse files at this commit

680220d45bb94ef41d33453219a45123735a442cAhmet Kaan GümüşParent: eee9e6e80ecf3d
crates/app/src/main.rsmodified+5 -4
@@ -10706,11 +10706,12 @@ mod tests {
1070610706 // Silent like the engine suite: this opens the real device.
1070710707 session.set_gain(0.0);
1070810708 assert_eq!(session.sources().len(), 1);
10709- // 640x360 would join now (the project canvas places it); this file is
10710- // also silent, and a silent file cannot join a timeline with sound.
10709+ // 640x360 joins now (the project canvas places it), and so does a file
10710+ // with no sound (it plays silence over its span). What is left is one
10711+ // output device: a mono track cannot join a stereo timeline.
1071110712 let refusal = session
10712- .import(&asset("test_mismatch.mp4"))
10713- .expect_err("a silent file must not join a timeline with audio")
10713+ .import(&asset("test_ac3.mp4"))
10714+ .expect_err("a mono track must not join a stereo timeline")
1071410715 .to_string();
1071510716 assert!(refusal.contains("audio"), "refusal must name it: {refusal}");
1071610717 assert_eq!(session.sources().len(), 1, "a refusal added a row");
crates/engine/src/audio.rsmodified+116 -65
@@ -203,10 +203,14 @@ impl AudioSession {
203203 /// pause — the master clock counts what the device has been fed, so a hole
204204 /// that fed nothing would stall the whole timeline on it.
205205 ///
206+ /// A segment naming a source that has **no track** is the same silence: a
207+ /// clip of a silent file is a hole with a picture over it, and the timeline
208+ /// let it in on exactly that footing ([`crate::PlaybackSession::import`]).
209+ ///
206210 /// Only the sources some segment names are opened. `Ok(None)` when `sources`
207- /// is empty or its first entry has no AAC track; a later source that is
208- /// missing audio or disagrees on rate/layout is an `Err` — import refuses
209- /// those up front (one timeline, one output device), this is the backstop.
211+ /// is empty or its first entry has no AAC track; a later source that
212+ /// disagrees on rate/layout is an `Err` — import refuses those up front (one
213+ /// timeline, one output device), this is the backstop.
210214 pub fn open_multi_segments(
211215 sources: &[PathBuf],
212216 segs: &[(Option<usize>, f64, f64)],
@@ -294,11 +298,18 @@ impl AudioSession {
294298 first.check_decoder()?;
295299
296300 let mut tracks: Vec<Option<Track>> = sources.iter().map(|_| None).collect();
301+ // ...and which of them turned out to have no track at all, so a silent
302+ // source is opened once like any other rather than once per segment
303+ // naming it.
304+ let mut silent: Vec<bool> = sources.iter().map(|_| false).collect();
297305 tracks[at] = Some(first);
298306 for &(source, ..) in segs {
299307 let Some(source) = source else {
300308 continue; // a gap opens no file
301309 };
310+ if silent.get(source) == Some(&true) {
311+ continue;
312+ }
302313 let slot = tracks
303314 .get_mut(source)
304315 .ok_or_else(|| format!("segment names source {source} of {}", sources.len()))?;
@@ -306,8 +317,14 @@ impl AudioSession {
306317 continue; // already opened, and the checks below already ran
307318 }
308319 let (path, stream) = &sources[source];
309- let track = Track::open(path, *stream)?
310- .ok_or_else(|| format!("source {source} has no audio track"))?;
320+ // A source with no audio track at all is not a failure: its
321+ // segments are silence, exactly as a gap's are, and the slot stays
322+ // empty to say so. That is what a silent clip on an audio lane
323+ // means -- a picture over a hole.
324+ let Some(track) = Track::open(path, *stream)? else {
325+ silent[source] = true;
326+ continue;
327+ };
311328 if (track.sample_rate(), track.channels()?) != (meta.sample_rate, meta.channels) {
312329 return Err(format!(
313330 "source {source} is {} Hz {} ch, the timeline is {} Hz {} ch",
@@ -324,14 +341,15 @@ impl AudioSession {
324341
325342 let segments: Vec<Segment> = segs
326343 .iter()
327- .map(|&(source, start_secs, end_secs)| match source {
328- Some(source) => tracks[source]
329- .as_ref()
330- .expect("opened above")
331- .segment(source, start_secs, end_secs),
332- None => Segment::silence(
333- ((end_secs - start_secs).max(0.0) * f64::from(meta.sample_rate)) as u64,
334- ),
344+ // A gap, and a source with no track to decode, are the same stretch
345+ // of nothing: as many frames of silence as the window is long.
346+ .map(|&(source, start_secs, end_secs)| {
347+ match source.and_then(|source| Some((source, tracks[source].as_ref()?))) {
348+ Some((source, track)) => track.segment(source, start_secs, end_secs),
349+ None => Segment::silence(
350+ ((end_secs - start_secs).max(0.0) * f64::from(meta.sample_rate)) as u64,
351+ ),
352+ }
335353 })
336354 .collect();
337355 // Chunk numbering is continuous across every join, counted from the first
@@ -622,7 +640,11 @@ impl AudioSession {
622640 decodable: matches!(track.channels, 1 | 2),
623641 }]);
624642 }
625- let Ok(track) = SymTrack::open(path) else {
643+ // No audio track lists as the silent source it is; a track that
644+ // will not open at all is an `Err` here, as it is in
645+ // [`Track::open`] -- a listing that quietly came back empty for a
646+ // broken file is how a lane ends up silent with nothing to go on.
647+ let Some(track) = SymTrack::open(path)? else {
626648 return Ok(Vec::new());
627649 };
628650 return Ok(vec![StreamInfo {
@@ -635,7 +657,7 @@ impl AudioSession {
635657 }]);
636658 }
637659 if crate::is_audio(path) {
638- let track = SymTrack::open(path)?;
660+ let track = SymTrack::open_required(path)?;
639661 return Ok(vec![StreamInfo {
640662 index: 0,
641663 codec: track.codec.into(),
@@ -762,15 +784,18 @@ impl AudioSession {
762784 /// half a packet over the whole list however many files it spans, and the
763785 /// extra priming packet is still the very first segment's alone.
764786 ///
765- /// Every source must declare the same [`AacTrackParams`]: the copy becomes
766- /// one output track with one esds. Import refuses a mismatch up front; the
767- /// check here is the backstop, as is the missing-track `Err`.
787+ /// Every source that *has* a track must declare the same
788+ /// [`AacTrackParams`]: the copy becomes one output track with one esds.
789+ /// Import refuses a mismatch up front; the check here is the backstop.
768790 ///
769791 /// A segment naming **no** source is a gap, and is copied as that many
770792 /// packets of [`silent_packet`] silence — the rounding debt carried through
771793 /// it like any other, so the hole occupies its exact duration and the audio
772794 /// after it stays in sync with the picture. A gap the track *opens* on gets
773- /// one silent packet more, which is the priming a reader drops.
795+ /// one silent packet more, which is the priming a reader drops. A segment
796+ /// naming a *silent* source is written the same way: a clip whose file has
797+ /// no audio track is a hole with a picture over it, and the timeline it
798+ /// joined already said so ([`crate::PlaybackSession::import`]).
774799 pub fn copy_multi_segments(
775800 sources: &[PathBuf],
776801 segs: &[(Option<usize>, f64, f64)],
@@ -789,24 +814,34 @@ impl AudioSession {
789814 sources: &[(PathBuf, usize)],
790815 segs: &[(Option<usize>, f64, f64)],
791816 ) -> crate::Result<Option<(AacTrackParams, Vec<AacPacket>)>> {
792- let Some(&(Some(first), ..)) = segs.iter().find(|s| s.0.is_some()) else {
817+ // The output track is declared from the first source that has one --
818+ // not simply the first one named, which may be a silent clip. Such a
819+ // clip defines no rate and no layout; it is written as silence below
820+ // and the track goes on being the audible sources' track.
821+ let mut tracks: Vec<Option<Option<AacTrack>>> = sources.iter().map(|_| None).collect();
822+ let mut first = None;
823+ for &(source, ..) in segs {
824+ let Some(source) = source else { continue };
825+ if let Some(track) = source_at(&mut tracks, sources, source)? {
826+ first = Some(track.track_params());
827+ break;
828+ }
829+ }
830+ let Some(params) = first else {
793831 return Ok(None); // no segments, or nothing but silence
794832 };
795- let (path, stream) = sources
796- .get(first)
797- .ok_or_else(|| format!("segment names source {first} of {}", sources.len()))?;
798- let Some(track) = copy_track(path, *stream)? else {
799- return Ok(None); // silent source, silent export
800- };
801- let params = track.track_params();
802- let mut tracks: Vec<Option<AacTrack>> = sources.iter().map(|_| None).collect();
803- tracks[first] = Some(track);
804833
805834 let sample_rate = params.sample_rate;
806835 let mut err = 0i64;
807836 let mut packets: Vec<AacPacket> = Vec::new();
808837 for &(source, start_secs, end_secs) in segs {
809- let Some(source) = source else {
838+ // A gap, and a clip whose source carries no track, are the same hole
839+ // to write: silence for as long as the window is.
840+ let named = match source {
841+ Some(source) => source_at(&mut tracks, sources, source)?.map(|t| (source, t)),
842+ None => None,
843+ };
844+ let Some((source, track)) = named else {
810845 let ideal = ((end_secs - start_secs).max(0.0) * f64::from(sample_rate)) as i64;
811846 let bytes = silent_packet(params.chan_conf)?;
812847 // A reader drops the first packet of an AAC track as the
@@ -824,7 +859,6 @@ impl AudioSession {
824859 }
825860 continue;
826861 };
827- let track = source_at(&mut tracks, sources, source)?;
828862 if track.track_params() != params {
829863 return Err(format!(
830864 "source {source} audio is {:?}, the timeline's is {params:?}",
@@ -885,24 +919,25 @@ fn silent_packet(chan_conf: u8) -> crate::Result<Vec<u8>> {
885919 }
886920 }
887921
888-/// The source at `index`, on the stream it names, opened on first use. Sources
889-/// a segment list never names are never touched: a project's list only grows.
922+/// The source at `index`, on the stream it names, opened on first use -- and
923+/// `None` for a source that has no track at all, which the caller writes as
924+/// silence exactly as it writes a gap. The outer `Option` is "has it been
925+/// opened", the inner one "was there anything in it", so a silent source is
926+/// opened once like any other. Sources a segment list never names are never
927+/// touched: a project's list only grows.
890928 fn source_at<'a>(
891- tracks: &'a mut [Option<AacTrack>],
929+ tracks: &'a mut [Option<Option<AacTrack>>],
892930 sources: &[(PathBuf, usize)],
893931 index: usize,
894-) -> crate::Result<&'a mut AacTrack> {
932+) -> crate::Result<Option<&'a mut AacTrack>> {
895933 let slot = tracks
896934 .get_mut(index)
897935 .ok_or_else(|| format!("segment names source {index} of {}", sources.len()))?;
898936 if slot.is_none() {
899937 let (path, stream) = &sources[index];
900- *slot = Some(
901- copy_track(path, *stream)?
902- .ok_or_else(|| format!("source {index} has no audio track"))?,
903- );
938+ *slot = Some(copy_track(path, *stream)?);
904939 }
905- Ok(slot.as_mut().expect("just opened"))
940+ Ok(slot.as_mut().expect("just opened").as_mut())
906941 }
907942
908943 /// A source's track for the *copy* path, which needs raw AAC access units.
@@ -994,8 +1029,8 @@ impl Track {
9941029 // decoder straight out of the blocks ([`MkvAc3Track`]). Sound neither
9951030 // one can decode (Opus, DTS) leaves the source the silent one it always
9961031 // was, which `AudioSession::unsupported` puts into words, rather than
997- // failing the import of a file whose picture is fine -- and so does an
998- // AC-3 track that will not open, a laced block say.
1032+ // failing the import of a file whose picture is fine. A track that will
1033+ // not open at all is *not* in that group: see below.
9991034 if crate::demux::is_matroska(path) {
10001035 if stream > 0 {
10011036 return Err(format!("{}: audio stream {stream} of 1 stream", path.display()).into());
@@ -1003,24 +1038,27 @@ impl Track {
10031038 match MkvAc3Track::open(path) {
10041039 Ok(Some(track)) => return Ok(Some(Self::Mkv(track))),
10051040 Ok(None) => {}
1006- // Named on the way past for the same reason symphonia's failure
1007- // is, below: an AC-3 track that broke is a bug, not a codec we
1008- // never had.
1041+ // Named on the way past rather than returned: symphonia gets the
1042+ // same file next and may read the track perfectly well (a laced
1043+ // block is [`MkvAc3Track`]'s limitation, not the file's), and
1044+ // if it cannot either, *its* `Err` is the one that comes back.
10091045 Err(e) => eprintln!("matroska audio: {}: {e}", path.display()),
10101046 }
1011- // Logged on the way past: "silent" here covers both a codec nothing
1012- // decodes and a track that genuinely broke, and only the second is a
1013- // bug -- with no trace at all it reaches the user as a lane that
1014- // drew no waveform and nothing else to go on.
1015- return Ok(SymTrack::open(path)
1016- .inspect_err(|e| eprintln!("matroska audio: {}: {e}", path.display()))
1017- .ok()
1018- .filter(|t| {
1019- t.decoder()
1020- .inspect_err(|e| eprintln!("matroska audio: {}: {e}", path.display()))
1021- .is_ok()
1022- })
1023- .map(Self::Sym));
1047+ // Two things are silent here and no more: a file with no audio
1048+ // track at all, and a track whose codec nothing in this project
1049+ // decodes (Opus, DTS -- [`AudioSession::unsupported`] is what puts
1050+ // that into words). A track that will not *open* is an `Err`, the
1051+ // same answer the mp4 arm gives: turned into silence it would play
1052+ // and export as a hole with only an eprintln to say why, which is a
1053+ // bug wearing a feature's clothes.
1054+ let Some(track) = SymTrack::open(path)? else {
1055+ return Ok(None);
1056+ };
1057+ if let Err(e) = track.decoder() {
1058+ eprintln!("matroska audio: {}: {e}", path.display());
1059+ return Ok(None);
1060+ }
1061+ return Ok(Some(Self::Sym(track)));
10241062 }
10251063 let audio_file = crate::is_audio(path);
10261064 // Ahead of the AAC reader, because that one answers "not AAC" for a
@@ -1041,7 +1079,7 @@ impl Track {
10411079 if stream > 0 {
10421080 return Err(format!("{}: audio stream {stream} of 1 stream", path.display()).into());
10431081 }
1044- SymTrack::open(path).map(|track| Some(Self::Sym(track)))
1082+ SymTrack::open_required(path).map(|track| Some(Self::Sym(track)))
10451083 }
10461084
10471085 fn sample_rate(&self) -> u32 {
@@ -1166,7 +1204,13 @@ struct SymTrack {
11661204 }
11671205
11681206 impl SymTrack {
1169- fn open(path: &Path) -> crate::Result<Self> {
1207+ /// `Ok(None)` for a container that opened and holds no audio track at all --
1208+ /// a silent source, which is a thing a file is allowed to be. Everything
1209+ /// else that goes wrong here is an `Err`: a file that will not open, will
1210+ /// not parse, or carries a track it cannot describe is *broken*, and the
1211+ /// difference matters because silence is played and exported without a word
1212+ /// while an `Err` is shown ([`Track::open`]).
1213+ fn open(path: &Path) -> crate::Result<Option<Self>> {
11701214 let mss = MediaSourceStream::new(Box::new(File::open(path)?), Default::default());
11711215 // The extension is a hint, not a decision: the probe reads the magic and
11721216 // is free to disagree, which is what makes a mislabelled file work.
@@ -1180,9 +1224,9 @@ impl SymTrack {
11801224 FormatOptions::default(),
11811225 MetadataOptions::default(),
11821226 )?;
1183- let track = reader
1184- .default_track(SymKind::Audio)
1185- .ok_or_else(|| format!("{} has no audio track", path.display()))?;
1227+ let Some(track) = reader.default_track(SymKind::Audio) else {
1228+ return Ok(None);
1229+ };
11861230 let (track_id, num_frames, delay) = (track.id, track.num_frames, track.delay);
11871231 let time_base = track
11881232 .time_base
@@ -1203,7 +1247,7 @@ impl SymTrack {
12031247 let codec = symphonia::default::get_codecs()
12041248 .get_audio_decoder(params.codec)
12051249 .map_or("an unsupported format", |d| d.codec.info.short_name);
1206- Ok(Self {
1250+ Ok(Some(Self {
12071251 reader,
12081252 track_id,
12091253 sample_rate,
@@ -1217,7 +1261,14 @@ impl SymTrack {
12171261 time_base,
12181262 params,
12191263 codec,
1220- })
1264+ }))
1265+ }
1266+
1267+ /// [`open`](Self::open) where having no audio track is itself the error:
1268+ /// what a standalone audio file is held to, since a song with no sound in
1269+ /// it is a broken file and not a silent source.
1270+ fn open_required(path: &Path) -> crate::Result<Self> {
1271+ Self::open(path)?.ok_or_else(|| format!("{} has no audio track", path.display()).into())
12211272 }
12221273
12231274 /// A fresh decoder: seeking mid-stream leaves state that belongs to the
crates/engine/src/playback.rsmodified+43 -27
@@ -1659,8 +1659,9 @@ impl PlaybackSession {
16591659 /// nothing playable, so there is nothing for [`undo`](Self::undo) to take
16601660 /// back, and nothing reseeks.
16611661 ///
1662- /// Refused unless it can join the timeline -- same codec, same audio
1663- /// parameters or both silent; the `Err` names the property that disagrees,
1662+ /// Refused unless it can join the timeline -- a decoder this machine can
1663+ /// open, and audio parameters that agree or none at all; the `Err` names
1664+ /// the property that disagrees,
16641665 /// for a caller to show. Nothing is changed by a refusal. A *resolution* of
16651666 /// its own is not a refusal: the clip is placed on the project canvas by its
16661667 /// fit policy ([`PlaybackSession::set_fit`]) -- and neither is a *frame
@@ -2018,8 +2019,9 @@ impl Drop for PlaybackSession {
20182019 }
20192020
20202021 /// Whether `path`, already demuxed to `meta`, may join a timeline whose
2021-/// parameters are `timeline` and whose audio probes as `first`: same codec,
2022-/// same audio parameters or both silent, and a frame rate that can be named
2022+/// parameters are `timeline` and whose audio probes as `first`: a decoder this
2023+/// machine can open, audio parameters that agree (or no audio at all), and a
2024+/// frame rate that can be named
20232025 /// against the timeline's. The [`Rate`] it will be read at comes back with the
20242026 /// answer, so the number the check was decided on is the number it plays by.
20252027 ///
@@ -2028,7 +2030,9 @@ impl Drop for PlaybackSession {
20282030 /// own fit policy, so a 640x360 file joining a 1920x1080 timeline is a
20292031 /// letterboxed clip rather than a refusal, and so is a frame rate of its own:
20302032 /// the timeline keeps its own rate and the file is read at [`Rate`] against it
2031-/// ([`PlaybackSession::import`] notes how long it is *here*).
2033+/// ([`PlaybackSession::import`] notes how long it is *here*). Nor the same
2034+/// codec: every clip opens its own decoder, so a mixed-codec timeline is a
2035+/// decoder each rather than a refusal.
20322036 ///
20332037 /// The `Err` names the property that disagrees, and those strings are what a
20342038 /// front-end shows verbatim; [`PlaybackSession::import`] and
@@ -2040,18 +2044,22 @@ fn matches_timeline(
20402044 timeline: &VideoMeta,
20412045 first: &Option<crate::AudioProbe>,
20422046 ) -> crate::Result<Rate> {
2043- // Codec first: one timeline is one kind of source. Mixing them would decode
2044- // (every clip opens its own decoder) but on a machine without the VA-API
2045- // plugin the VP9 half would be black frames with the refusal only on
2046- // stderr, which is exactly what a front-end cannot show.
2047- if meta.codec != timeline.codec {
2048- return Err(format!(
2049- "{} does not match the timeline's {}",
2050- meta.codec.name(),
2051- timeline.codec.name()
2052- )
2053- .into());
2054- }
2047+ // The codec is *not* held to the timeline's -- every clip opens its own
2048+ // decoder, so an H.264 take and an HEVC one play on one timeline. What the
2049+ // codec gate was really protecting against stays, in the one place that can
2050+ // actually answer it: on a machine without the VA-API plugin an HEVC or VP9
2051+ // clip would be black frames with the refusal on stderr alone, so the file
2052+ // is asked for a decoder *here*, at the door, where the `Err` is still
2053+ // something a front-end can show. A zero-length range probes and starts no
2054+ // worker, and H.264 costs nothing at all -- [`DecodeSession::open_worker`]
2055+ // only enters VA-API off that path.
2056+ DecodeSession::open_worker(
2057+ &source.path,
2058+ 0,
2059+ 0,
2060+ ColorParams::default(),
2061+ Composer::passthrough(),
2062+ )?;
20552063 // The frame rate is *not* a refusal any more: a file shot at another rate is
20562064 // placed for the seconds it lasts and read through [`Rate`] at the
20572065 // decoder's door, so it plays at the speed it was shot at on a timeline
@@ -2069,8 +2077,9 @@ fn matches_timeline(
20692077 }
20702078
20712079 /// Whether a candidate's audio may join a timeline whose first source probes as
2072-/// `first`: same rate, same layout, or both silent. One output device and one
2073-/// exported track is all there is, and no resampler.
2080+/// `first`: same rate, same layout -- or no audio of its own at all, which is
2081+/// silence over the clip's span and agrees with everything. One output device
2082+/// and one exported track is all there is, and no resampler.
20742083 ///
20752084 /// The audio half of [`matches_timeline`], which a stream placed on its own
20762085 /// ([`PlaybackSession::place_stream_at`]) has to pass while the picture it
@@ -2088,9 +2097,9 @@ fn matches_timeline(
20882097 /// `Ok(None)` for a timeline whose first such source is silent, and for one of
20892098 /// nothing but stills. That is a silent timeline, and a file with sound is
20902099 /// still refused by [`audio_matches`] in the words it always used ("the file
2091-/// has audio, the timeline is silent") -- the same answer a silent *video* as
2092-/// source 0 has always given. This function widens which source is asked, not
2093-/// what the answer means.
2100+/// has audio, the timeline is silent") -- the device was opened on source 0's
2101+/// track and there is none to open. This function widens which source is asked,
2102+/// not what the answer means.
20942103 fn first_audio_of(sources: &[Source]) -> crate::Result<Option<crate::AudioProbe>> {
20952104 match audio_source_of(sources) {
20962105 Some(first) => AudioSession::probe(&first.path, first.audio_stream),
@@ -2119,12 +2128,19 @@ fn audio_matches(source: &Source, first: &Option<crate::AudioProbe>) -> crate::R
21192128 if probe == *first {
21202129 return Ok(());
21212130 }
2122- Err(match (probe, first) {
2123- (None, _) => "the file is silent, the timeline has audio".to_string(),
2124- (_, None) => "the file has audio, the timeline is silent".to_string(),
2125- (Some(a), Some(b)) => format!(
2131+ // ...and a *silent* file joins whatever the timeline is: it contributes
2132+ // silence over its span, which is the very thing both audio paths already
2133+ // synthesise for a gap ([`AudioSession::open_multi_streams_speed`] plays
2134+ // it, `AudioSession::copy_multi_streams` writes it). There is no rate and
2135+ // no layout to disagree about, so there is nothing left to refuse.
2136+ let Some(probe) = probe else {
2137+ return Ok(());
2138+ };
2139+ Err(match first {
2140+ None => "the file has audio, the timeline is silent".to_string(),
2141+ Some(b) => format!(
21262142 "audio {} Hz {} ch does not match the timeline's {} Hz {} ch",
2127- a.sample_rate, a.channels, b.sample_rate, b.channels
2143+ probe.sample_rate, probe.channels, b.sample_rate, b.channels
21282144 ),
21292145 }
21302146 .into())
crates/engine/tests/audio_decode.rsmodified+37 -0
@@ -272,3 +272,40 @@ fn an_ac3_source_refuses_an_mp4_audio_copy() {
272272 "unhelpful refusal: {err}"
273273 );
274274 }
275+
276+/// The two things a Matroska file with no *readable* sound can be, told apart:
277+/// a file with no audio track is the silent source it says it is, and a file
278+/// whose audio will not open at all is an error. They used to be the same
279+/// answer -- silence -- so a broken track played and exported as a hole with
280+/// nothing but an `eprintln` to say why.
281+#[test]
282+fn a_matroska_with_no_track_is_silent_and_a_broken_one_is_an_error() {
283+ // No audio track at all: a picture and two subtitle tracks. Silent, and the
284+ // stream picker offers nothing rather than refusing the file.
285+ let subs = asset("test_subs.mkv");
286+ assert!(
287+ AudioSession::probe(&subs, 0)
288+ .expect("no audio is not an error")
289+ .is_none(),
290+ "an mkv with no audio track is a silent source"
291+ );
292+ assert!(AudioSession::probe_streams(&subs).expect("list").is_empty());
293+ assert!(
294+ AudioSession::open(&subs).expect("open").is_none(),
295+ "no sound"
296+ );
297+
298+ // ...and a file that will not parse at all, under the same extension: an
299+ // `Err` a front-end can show, not a silent import.
300+ let broken = std::env::temp_dir().join(format!("ve_broken_{}.mkv", std::process::id()));
301+ std::fs::write(&broken, b"\x1a\x45\xdf\xa3not a matroska file at all").expect("write");
302+ let err = AudioSession::probe(&broken, 0)
303+ .expect_err("a broken file must not pass for a silent one")
304+ .to_string();
305+ assert!(!err.is_empty(), "the refusal says something");
306+ assert!(
307+ AudioSession::probe_streams(&broken).is_err(),
308+ "and so does the listing"
309+ );
310+ std::fs::remove_file(&broken).unwrap();
311+}
crates/engine/tests/audio_export.rsmodified+61 -0
@@ -511,6 +511,67 @@ fn a_cancelled_audio_export_leaves_no_file() {
511511 assert!(!part_path(&out).exists(), "no half-written .part either");
512512 }
513513
514+/// The samples a silent take contributes: a clip of a file with no audio track
515+/// is silence for exactly its span, between two clips that are heard. This is
516+/// what makes `PlaybackSession::import` letting such a file in honest -- the
517+/// export reads the same play list playback does, so a hole here is a hole in
518+/// the ear too.
519+#[test]
520+fn a_silent_clip_exports_as_silence_over_its_own_span() {
521+ let clip = |start, source| Clip {
522+ start,
523+ in_frame: 0,
524+ out_frame: 30,
525+ source,
526+ link: None,
527+ eq: None,
528+ color: None,
529+ fit: FitPolicy::default(),
530+ speed: Speed::NORMAL,
531+ };
532+ let project = Project::from_parts(
533+ vec![
534+ Source::new(asset("test_av.mp4"), 0),
535+ // Video only, no audio track at all: the silent take.
536+ Source::new(asset("test_mismatch.mp4"), 0),
537+ ],
538+ vec![
539+ (LaneKind::Video, vec![clip(0, 0), clip(30, 1), clip(60, 0)]),
540+ (LaneKind::Audio, vec![clip(0, 0), clip(30, 1), clip(60, 0)]),
541+ ],
542+ Vec::new(),
543+ Vec::new(),
544+ )
545+ .expect("a project whose middle take is silent");
546+
547+ let out = out_path("silent_clip", "wav");
548+ let handle = engine::export::start(
549+ project,
550+ meta(),
551+ &out,
552+ &ExportSettings {
553+ format: Format::Wav,
554+ ..Default::default()
555+ },
556+ );
557+ wait(&handle, Duration::from_secs(60)).expect("wav export");
558+ let (audio, samples) = decode(&out);
559+ let channels = usize::from(audio.channels);
560+ assert_eq!(
561+ samples.len(),
562+ (3.0 * f64::from(RATE)) as usize * channels,
563+ "three seconds of timeline, silent take included"
564+ );
565+ let heard = rms(&samples, channels, 0.05, 0.95);
566+ let quiet = rms(&samples, channels, 1.0, 2.0);
567+ let again = rms(&samples, channels, 2.05, 2.95);
568+ println!("rms: heard {heard:.4} silent take {quiet:.6} heard {again:.4}");
569+ assert!(heard > 0.01, "the first take is audible");
570+ assert!(again > 0.01, "the third take is audible");
571+ assert_eq!(quiet, 0.0, "the silent take is exact silence, not a stall");
572+ std::fs::remove_file(&out).unwrap();
573+}
574+
514575 /// A silent timeline cannot become an audio file, and says so rather than
515576 /// writing zero samples that a user would take for a broken microphone.
516577 #[test]
crates/engine/tests/audio_multi.rsmodified+67 -7
@@ -250,18 +250,19 @@ fn the_join_carries_no_second_priming_packet() {
250250 }
251251
252252 #[test]
253-fn a_source_without_the_timeline_audio_is_refused() {
254- // Import refuses these up front (same rate, same layout, or both silent);
253+fn a_source_that_disagrees_on_rate_or_layout_is_refused() {
254+ // Import refuses these up front (one output device, one set of parameters);
255255 // the copy and the decode paths refuse them again rather than mislabel one
256- // esds for two different tracks.
257- let mixed = [asset("test_av.mp4"), asset("test_mismatch.mp4")];
256+ // esds for two different tracks. Stream 1 of the multi-audio fixture is
257+ // 22.05 kHz mono against the timeline's 44.1 kHz stereo.
258+ let mixed = [(asset("test_av.mp4"), 0), (asset("test_multiaudio.mp4"), 1)];
258259 let segs = [(Some(0), 0.0, 1.0), (Some(1), 0.0, 1.0)];
259260 // (`.err()`, not `unwrap_err`: neither Ok payload is `Debug`.)
260261 for e in [
261- AudioSession::copy_multi_segments(&mixed, &segs).err(),
262- AudioSession::open_multi_segments(&mixed, &segs).err(),
262+ AudioSession::copy_multi_streams(&mixed, &segs).err(),
263+ AudioSession::open_multi_streams(&mixed, &segs).err(),
263264 ]
264- .map(|e| e.expect("a source with no audio track must be refused"))
265+ .map(|e| e.expect("a source at another rate must be refused"))
265266 {
266267 let msg = e.to_string();
267268 assert!(msg.contains("source 1"), "{msg}");
@@ -270,3 +271,62 @@ fn a_source_without_the_timeline_audio_is_refused() {
270271 assert!(AudioSession::copy_multi_segments(&sources(), &[(Some(2), 0.0, 1.0)]).is_err());
271272 assert!(AudioSession::open_multi_segments(&sources(), &[(Some(2), 0.0, 1.0)]).is_err());
272273 }
274+
275+/// A source with **no** track is not a refusal at all: its segments are the
276+/// same silence a gap is, in both paths. That is what a silent clip on an audio
277+/// lane is -- a picture over a hole -- and the timeline lets one in
278+/// (`PlaybackSession::import`) precisely because these two agree here.
279+#[test]
280+fn a_silent_source_is_silence_and_not_a_refusal() {
281+ let mixed = [asset("test_av.mp4"), asset("test_mismatch.mp4")];
282+ let segs = [
283+ (Some(0), 0.0, 1.0),
284+ (Some(1), 0.0, 1.0),
285+ (Some(0), 0.0, 1.0),
286+ ];
287+
288+ // Decoded: three seconds, the middle one exact zero, and the chunks still
289+ // arrive contiguous (`drain` asserts that), so the clock is fed through it.
290+ let (_, rx) = AudioSession::open_multi_segments(&mixed, &segs)
291+ .expect("a silent source opens")
292+ .expect("the first source has an audio track");
293+ let (samples, _, _) = drain(rx);
294+ let frames = samples.len() / CHANNELS;
295+ assert!(
296+ (frames as i64 - 3 * RATE as i64).unsigned_abs() < PACKET,
297+ "{frames} frames for three seconds"
298+ );
299+ let second = |n: usize| {
300+ let at = |s: usize| (s * RATE as usize * CHANNELS).min(samples.len());
301+ &samples[at(n)..at(n + 1)]
302+ };
303+ assert!(
304+ second(0).iter().any(|s| *s != 0.0),
305+ "the first second plays"
306+ );
307+ assert!(
308+ second(1).iter().all(|s| *s == 0.0),
309+ "the silent source is exact silence"
310+ );
311+ assert!(second(2).iter().any(|s| *s != 0.0), "and it comes back");
312+
313+ // Copied: the same shape in packets, so an mp4 export of that timeline is
314+ // as long as the timeline and quiet where the silent clip is.
315+ let (params, packets) = AudioSession::copy_multi_segments(&mixed, &segs)
316+ .expect("a silent source copies")
317+ .expect("the timeline has an audible source");
318+ let copied = packets.len() as u64 * PACKET;
319+ assert!(
320+ (copied as i64 - 3 * RATE as i64).unsigned_abs() < 2 * PACKET,
321+ "{copied} samples for three seconds, priming included"
322+ );
323+ assert_eq!(
324+ params.sample_rate, RATE as u32,
325+ "the audible source's track"
326+ );
327+ let silence: Vec<_> = packets[44..44 + 43].iter().map(|p| &p.bytes).collect();
328+ assert!(
329+ silence.iter().all(|b| b.len() <= 7),
330+ "the hole is written as the hand-made silent packet, not as audio"
331+ );
332+}
crates/engine/tests/av1.rsmodified+16 -6
@@ -155,17 +155,27 @@ fn the_software_path_refuses_av1_by_name() {
155155 assert!(refused.contains("plugin"), "{refused}");
156156 }
157157
158-/// A timeline is refused a source coded differently, in the same words a
159-/// resolution mismatch is refused in: a front-end shows the string as it is.
158+/// A timeline is *not* refused a source coded differently -- every clip opens
159+/// its own decoder. What survives is the reason the codec gate existed: on a
160+/// machine that cannot decode AV1 the file is refused at the door, by the
161+/// decoder's own name, rather than becoming a clip of black frames.
160162 #[test]
161-fn a_timeline_refuses_the_other_codec() {
163+fn a_timeline_takes_the_other_codec_or_names_the_missing_decoder() {
162164 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av.mp4");
165+ // The no-plugin machine, forced.
166+ // SAFETY: the suite is documented to run with --test-threads=1.
167+ unsafe { std::env::set_var("VE_SW", "1") };
163168 let refused = session
164169 .import(&asset("test_av1.mkv"))
165- .expect_err("AV1 must not join an H.264 timeline")
170+ .expect_err("no AV1 decoder means no AV1 clip")
166171 .to_string();
167- assert!(refused.contains("AV1"), "{refused}");
168- assert!(refused.contains("H.264"), "{refused}");
172+ unsafe { std::env::remove_var("VE_SW") };
173+ assert_eq!(refused, Codec::Av1.needs_plugin());
174+ assert!(
175+ !refused.contains("H.264"),
176+ "the timeline's own codec is no longer a reason: {refused}"
177+ );
178+ assert_eq!(session.sources().len(), 1, "a refusal left no row");
169179 }
170180
171181 /// The end-to-end user path: opening the file yields pictures, all of them,
crates/engine/tests/hevc.rsmodified+83 -6
@@ -112,17 +112,35 @@ fn the_software_path_refuses_hevc_by_name() {
112112 assert!(h264, "software H.264 decode still opens");
113113 }
114114
115-/// A timeline is refused a source coded differently, in the same words a
116-/// resolution mismatch is refused in: a front-end shows the string as it is.
115+/// A timeline is *not* refused a source coded differently -- every clip opens
116+/// its own decoder, so H.264 and HEVC share one timeline. What survives is the
117+/// reason the codec gate existed: on a machine that cannot decode HEVC the file
118+/// is refused at the door, by the decoder's own name, rather than becoming a
119+/// clip of black frames with the complaint on stderr.
117120 #[test]
118-fn a_timeline_refuses_the_other_codec() {
121+fn a_timeline_takes_the_other_codec_or_names_the_missing_decoder() {
119122 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av.mp4");
123+ // The no-plugin machine, forced: the refusal must still arrive, and it must
124+ // be the decoder's words and not the timeline's.
125+ // SAFETY: the suite is documented to run with --test-threads=1.
126+ unsafe { std::env::set_var("VE_SW", "1") };
120127 let refused = session
121128 .import(&asset("test_hevc.mp4"))
122- .expect_err("HEVC must not join an H.264 timeline")
129+ .expect_err("no HEVC decoder means no HEVC clip")
123130 .to_string();
124- assert!(refused.contains("HEVC"), "{refused}");
125- assert!(refused.contains("H.264"), "{refused}");
131+ unsafe { std::env::remove_var("VE_SW") };
132+ assert_eq!(refused, Codec::Hevc.needs_plugin());
133+ assert!(
134+ !refused.contains("H.264"),
135+ "the timeline's own codec is no longer a reason: {refused}"
136+ );
137+ assert_eq!(session.sources().len(), 1, "a refusal left no row");
138+
139+ // ...and where a decoder exists, it simply joins.
140+ match session.import(&asset("test_hevc.mp4")) {
141+ Ok(_) => assert_eq!(session.sources().len(), 2, "HEVC beside H.264"),
142+ Err(e) => assert_eq!(e.to_string(), Codec::Hevc.needs_plugin()),
143+ }
126144 }
127145
128146 /// The end-to-end user path: opening the file yields pictures, all of them,
@@ -155,6 +173,65 @@ fn the_plugin_decodes_every_hevc_frame() {
155173 );
156174 }
157175
176+/// The mixed-codec timeline, end to end: an H.264 take joins an HEVC one, both
177+/// spans really decode (a decoder each, opened at the span), and the export --
178+/// which re-encodes -- writes every frame of both. The refusal that used to
179+/// stand here would have made this whole timeline impossible.
180+#[test]
181+#[ignore = "needs libengine_hw.so and a VA-API driver with HEVC decode"]
182+fn an_h264_take_plays_and_exports_on_an_hevc_timeline() {
183+ let hevc = asset("test_hevc.mp4");
184+ let h264 = asset("test_av.mp4");
185+ let mut session = PlaybackSession::open(&hevc).expect("open test_hevc.mp4");
186+ session.set_gain(0.0);
187+ session.import(&h264).expect("H.264 joins an HEVC timeline");
188+ let end = session.timeline_duration();
189+ assert!(
190+ session
191+ .place_stream_at(end, &h264, 0, None)
192+ .expect("a file just imported is on this timeline"),
193+ "drag it onto the end"
194+ );
195+ assert_eq!(session.clip_spans().len(), 2, "two takes, two codecs");
196+
197+ // One picture out of each span, which is one decoder each: the HEVC clip
198+ // through the plugin, the H.264 one through either backend.
199+ for (at, what) in [(1.0, "the HEVC take"), (end + 1.0, "the H.264 take")] {
200+ session.seek(at);
201+ let deadline = Instant::now() + Duration::from_secs(10);
202+ let frame = loop {
203+ if let Some(frame) = session.try_frame() {
204+ break frame;
205+ }
206+ assert!(Instant::now() < deadline, "no frame from {what}");
207+ std::thread::sleep(Duration::from_millis(4));
208+ };
209+ assert_eq!(
210+ (frame.width, frame.height),
211+ session.resolution(),
212+ "{what} came out at the project size"
213+ );
214+ }
215+
216+ // ...and the export -- the one a front-end starts, off the session itself --
217+ // re-encodes both to one H.264 track.
218+ let frames =
219+ (session.timeline_duration() * f64::from(session.meta().frame_rate as f32)).round() as u32;
220+ let out = std::env::temp_dir().join(format!("ve_export_mixed_{}.mp4", std::process::id()));
221+ let _ = std::fs::remove_file(&out);
222+ let handle = session.export_to_with(&out, &ExportSettings::default());
223+ let started = Instant::now();
224+ while !handle.is_finished() {
225+ assert!(started.elapsed() < Duration::from_secs(240), "export hung");
226+ std::thread::sleep(Duration::from_millis(20));
227+ }
228+ handle.result().expect("outcome").expect("the mixed export");
229+ let (written, _) = Demuxer::open(&out).expect("reopen the export");
230+ assert_eq!(written.codec, Codec::H264, "exports are always H.264");
231+ assert_eq!(written.frame_count, frames, "both takes were written");
232+ let _ = std::fs::remove_file(&out);
233+}
234+
158235 /// Export re-encodes to H.264 whatever the source was coded with: the packet
159236 /// copy path is audio-only, so no HEVC byte can reach an `avc1` track.
160237 #[test]
crates/engine/tests/lanes.rsmodified+9 -4
@@ -52,8 +52,13 @@ fn out_path(name: &str, ext: &str) -> PathBuf {
5252 /// A hand-written v4 project: `V1` the whole of `test_av`, `V2` the middle
5353 /// third playing `test_av2` from its own frame 0, `A1` the whole of `test_av`.
5454 /// Exactly the file a user would write by hand, parsed by the real loader.
55-fn three_lane_file() -> PathBuf {
56- let path = out_path("project", "edith");
55+///
56+/// `name` is the caller's own, because [`out_path`] is unique per *run* and not
57+/// per test: two tests sharing one name run in parallel over one file, and the
58+/// first to finish deletes it out from under the second -- which then fails on
59+/// a file that is simply not there any more.
60+fn three_lane_file(name: &str) -> PathBuf {
61+ let path = out_path(name, "edith");
5762 // `source <audio stream> <path>`: the number is which audio track of the
5863 // file plays, not the source index -- both of these are on their first.
5964 let text = format!(
@@ -143,7 +148,7 @@ fn frame_of(session: &mut PlaybackSession, timeline: u32) -> Vec<u8> {
143148 #[test]
144149 fn playback_shows_the_topmost_video_lane() {
145150 pin_software();
146- let project = three_lane_file();
151+ let project = three_lane_file("playback");
147152 let mut session = PlaybackSession::open_project(&project).expect("open the project");
148153 session.set_gain(0.0);
149154 assert_eq!(session.timeline_duration(), f64::from(TOTAL) / FPS);
@@ -164,7 +169,7 @@ fn playback_shows_the_topmost_video_lane() {
164169 #[test]
165170 fn export_writes_the_same_composite() {
166171 pin_software();
167- let file = three_lane_file();
172+ let file = three_lane_file("export");
168173 let session = PlaybackSession::open_project(&file).expect("open the project");
169174 let out = out_path("composite", "mp4");
170175
crates/engine/tests/playback.rsmodified+60 -25
@@ -13,7 +13,7 @@ use std::time::{Duration, Instant};
1313
1414 use engine::export::{ExportSettings, Format};
1515 use engine::project::Lane;
16-use engine::{DecodeSession, Frame, PlaybackSession};
16+use engine::{Codec, DecodeSession, Frame, PlaybackSession};
1717
1818 fn asset(name: &str) -> PathBuf {
1919 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
@@ -788,30 +788,31 @@ fn the_first_import_opens_a_library_over_an_empty_timeline() {
788788 assert_eq!(session.sources().len(), 1, "the row survives the undo");
789789 }
790790
791-/// One timeline, one set of parameters: everything else is refused by name and
792-/// changes nothing.
791+/// One timeline, one frame rate and one set of audio parameters: what is left
792+/// is refused by name and changes nothing.
793793 #[test]
794794 fn import_refuses_what_does_not_match() {
795795 let mut session = open(asset("test_av.mp4"));
796796
797- // A different *codec* cannot join: one timeline is one kind of source.
798- let err = session
799- .import(&asset("test_vp9.mp4"))
800- .expect_err("VP9 must be refused")
801- .to_string();
802- assert!(err.contains("VP9"), "refusal must name the codec: {err}");
797+ // A different *codec* is not among them any more -- every clip opens its
798+ // own decoder. The only refusal left on that axis is a decoder this machine
799+ // cannot open, and it is the plugin's own words, not the timeline's.
800+ match session.import(&asset("test_vp9.mp4")) {
801+ Ok(_) => assert_eq!(session.sources().len(), 2, "VP9 joined the H.264 timeline"),
802+ Err(e) => assert_eq!(
803+ e.to_string(),
804+ Codec::Vp9.needs_plugin(),
805+ "the only codec refusal left is the missing decoder"
806+ ),
807+ }
808+ let rows = session.sources().len();
803809
804810 // A different resolution is no longer among the refusals -- it is placed on
805- // the project canvas instead -- but this file is also silent, and that is.
806- let err = session
811+ // the project canvas instead -- and neither is a file with no sound: it
812+ // contributes silence over its span.
813+ session
807814 .import(&asset("test_mismatch.mp4"))
808- .expect_err("a silent file must be refused")
809- .to_string();
810- assert!(err.contains("audio"), "refusal must name the audio: {err}");
811- assert!(
812- !err.contains("640x360"),
813- "a resolution of its own is not a refusal any more: {err}"
814- );
815+ .expect("a silent 640x360 file joins a timeline with sound");
815816
816817 // A frame rate of its own is no longer a refusal either: 25 fps joins a
817818 // 30 fps timeline and is read at `Rate` against it -- see
@@ -823,22 +824,32 @@ fn import_refuses_what_does_not_match() {
823824 .remove_source(&asset("test_25fps.mp4"), 0)
824825 .expect("...and the row it made comes back off");
825826
826- // Same size and rate, no audio track: the timeline has one.
827+ // What is still refused, and all that is: one output device means one rate
828+ // and one layout, and there is no resampler to make two into one.
827829 let err = session
828- .import(&asset("test_baseline.mp4"))
829- .expect_err("a silent file must be refused")
830+ .import(&asset("test_ac3.mp4"))
831+ .expect_err("a mono track cannot join a stereo timeline")
830832 .to_string();
831- assert!(err.contains("audio"), "refusal must name the audio: {err}");
833+ assert_eq!(
834+ err,
835+ "audio 44100 Hz 1 ch does not match the timeline's 44100 Hz 2 ch"
836+ );
832837
833838 assert!(
834839 session.import(&asset("no_such_file.mp4")).is_err(),
835840 "a missing file is an error, not a panic"
836841 );
837- assert_eq!(session.clip_spans().len(), 1, "a refusal changes nothing");
838- assert_eq!(session.sources().len(), 1, "a refusal left a library row");
842+ assert_eq!(session.clip_spans().len(), 1, "an import places nothing");
843+ assert_eq!(
844+ session.sources().len(),
845+ rows + 1,
846+ "only the silent file was taken in"
847+ );
839848 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);
840849
841- // The mirror: audio into a silent timeline is refused just as loudly.
850+ // The mirror is still refused: the device was opened on source 0's track
851+ // and a silent timeline has none to open, so a file with sound cannot be
852+ // heard on one.
842853 let mut silent = open(asset("test_baseline.mp4"));
843854 let err = silent
844855 .import(&asset("test_av.mp4"))
@@ -847,6 +858,30 @@ fn import_refuses_what_does_not_match() {
847858 assert!(err.contains("audio"), "refusal must name the audio: {err}");
848859 }
849860
861+/// The user path a silent take goes down: a file with no audio track lands on a
862+/// timeline that has one, is placed as the grouped take every video file is,
863+/// and plays -- pictures over its span, silence under them. The sound itself is
864+/// asserted on the samples in `tests/audio_export.rs`; what is asserted here is
865+/// that nothing about the *timeline* is refused or lost.
866+#[test]
867+fn a_silent_file_joins_a_timeline_with_sound_and_plays() {
868+ let mut session = open(asset("test_av.mp4"));
869+ import_and_place(&mut session, &asset("test_mismatch.mp4"));
870+ // 150 frames of test_av, then 60 of the silent file, at 30 fps.
871+ assert_eq!(session.clip_spans().len(), 2, "the silent take landed");
872+ assert!((session.timeline_duration() - 7.0).abs() < 1e-9);
873+ // Both lanes carry it: a silent file is a normal grouped take, and its
874+ // audio clip is the span the worker fills with silence.
875+ assert_eq!(session.lane_clips(Lane::V1).len(), 2);
876+ assert_eq!(session.lane_clips(Lane::A1).len(), 2);
877+
878+ // ...and it decodes: a picture from inside the silent clip's span, at the
879+ // project's resolution like every other clip.
880+ session.seek(6.0);
881+ let frame = next_frame(&mut session, "the silent clip");
882+ assert_eq!((frame.width, frame.height), session.resolution());
883+}
884+
850885 /// The user-facing point of a project resolution: media of two sizes on one
851886 /// timeline, each composed onto the project's own canvas.
852887 ///
crates/engine/tests/saveload.rsmodified+7 -4
@@ -733,7 +733,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() {
733733 fn a_source_that_no_longer_matches_the_timeline_is_refused_in_import_words() {
734734 let dir = scratch("mismatch");
735735 copy_in(&dir, "test_av.mp4");
736- std::fs::copy(asset("test_mismatch.mp4"), dir.join("test_av2.mp4")).expect("substitute");
736+ std::fs::copy(asset("test_ac3.mp4"), dir.join("test_av2.mp4")).expect("substitute");
737737 let path = dir.join("swapped.edith");
738738 std::fs::write(
739739 &path,
@@ -745,12 +745,15 @@ fn a_source_that_no_longer_matches_the_timeline_is_refused_in_import_words() {
745745 .expect("a source that stopped matching must not open")
746746 .to_string();
747747 // The suffix is `import`'s own refusal, word for word. The substitute is
748- // 640x360 *and* silent; only the second of those is a refusal now -- a
749- // resolution of its own is placed on the project canvas.
748+ // mono, which is the shape of what is left: one output device means one
749+ // rate and one layout. A resolution of its own is placed on the project
750+ // canvas, a rate of its own is read through `Rate`, a codec of its own
751+ // opens its own decoder and a file with no sound plays silence -- none of
752+ // those is a refusal any more.
750753 assert_eq!(
751754 err,
752755 format!(
753- "source {}: the file is silent, the timeline has audio",
756+ "source {}: audio 44100 Hz 1 ch does not match the timeline's 44100 Hz 2 ch",
754757 dir.join("test_av2.mp4").display()
755758 )
756759 );
crates/engine/tests/vp9.rsmodified+22 -6
@@ -76,17 +76,33 @@ fn the_software_path_refuses_vp9_by_name() {
7676 assert!(h264, "software H.264 decode still opens");
7777 }
7878
79-/// A VP9 timeline is refused a source coded differently, in the same words a
80-/// resolution mismatch is refused in: a front-end shows the string as it is.
79+/// A timeline is *not* refused a source coded differently -- every clip opens
80+/// its own decoder. What survives is the reason the codec gate existed: on a
81+/// machine that cannot decode VP9 the file is refused at the door, by the
82+/// decoder's own name, rather than becoming a clip of black frames.
8183 #[test]
82-fn a_timeline_refuses_the_other_codec() {
84+fn a_timeline_takes_the_other_codec_or_names_the_missing_decoder() {
8385 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av.mp4");
86+ // The no-plugin machine, forced.
87+ // SAFETY: the suite is documented to run with --test-threads=1.
88+ unsafe { std::env::set_var("VE_SW", "1") };
8489 let refused = session
8590 .import(&asset("test_vp9.mp4"))
86- .expect_err("VP9 must not join an H.264 timeline")
91+ .expect_err("no VP9 decoder means no VP9 clip")
8792 .to_string();
88- assert!(refused.contains("VP9"), "{refused}");
89- assert!(refused.contains("H.264"), "{refused}");
93+ unsafe { std::env::remove_var("VE_SW") };
94+ assert_eq!(refused, Codec::Vp9.needs_plugin());
95+ assert!(
96+ !refused.contains("H.264"),
97+ "the timeline's own codec is no longer a reason: {refused}"
98+ );
99+ assert_eq!(session.sources().len(), 1, "a refusal left no row");
100+
101+ // ...and where a decoder exists, it simply joins.
102+ match session.import(&asset("test_vp9.mp4")) {
103+ Ok(_) => assert_eq!(session.sources().len(), 2, "VP9 beside H.264"),
104+ Err(e) => assert_eq!(e.to_string(), Codec::Vp9.needs_plugin()),
105+ }
90106 }
91107
92108 /// The end-to-end user path: opening the file yields pictures, all of them,