🔀 merge(A5): import stops gatekeeping — silent files land as silence, mixed codecs play per-clip, refusals name the missing decoder
Browse files at this commit12 changed files +526 -154
- crates/app/src/main.rs +5 -4
- crates/engine/src/audio.rs +116 -65
- crates/engine/src/playback.rs +43 -27
- crates/engine/tests/audio_decode.rs +37 -0
- crates/engine/tests/audio_export.rs +61 -0
- crates/engine/tests/audio_multi.rs +67 -7
- crates/engine/tests/av1.rs +16 -6
- crates/engine/tests/hevc.rs +83 -6
- crates/engine/tests/lanes.rs +9 -4
- crates/engine/tests/playback.rs +60 -25
- crates/engine/tests/saveload.rs +7 -4
- crates/engine/tests/vp9.rs +22 -6
crates/app/src/main.rsmodified+5 -4
| @@ -10706,11 +10706,12 @@ mod tests { | |||
| 10706 | // Silent like the engine suite: this opens the real device. | 10706 | // Silent like the engine suite: this opens the real device. |
| 10707 | session.set_gain(0.0); | 10707 | session.set_gain(0.0); |
| 10708 | assert_eq!(session.sources().len(), 1); | 10708 | assert_eq!(session.sources().len(), 1); |
| 10709 | - // 640x360 would join now (the project canvas places it); this file is | 10709 | + // 640x360 joins now (the project canvas places it), and so does a file |
| 10710 | - // also silent, and a silent file cannot join a timeline with sound. | 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. | ||
| 10711 | let refusal = session | 10712 | let refusal = session |
| 10712 | - .import(&asset("test_mismatch.mp4")) | 10713 | + .import(&asset("test_ac3.mp4")) |
| 10713 | - .expect_err("a silent file must not join a timeline with audio") | 10714 | + .expect_err("a mono track must not join a stereo timeline") |
| 10714 | .to_string(); | 10715 | .to_string(); |
| 10715 | assert!(refusal.contains("audio"), "refusal must name it: {refusal}"); | 10716 | assert!(refusal.contains("audio"), "refusal must name it: {refusal}"); |
| 10716 | assert_eq!(session.sources().len(), 1, "a refusal added a row"); | 10717 | assert_eq!(session.sources().len(), 1, "a refusal added a row"); |
crates/engine/src/audio.rsmodified+116 -65
| @@ -203,10 +203,14 @@ impl AudioSession { | |||
| 203 | /// pause — the master clock counts what the device has been fed, so a hole | 203 | /// pause — the master clock counts what the device has been fed, so a hole |
| 204 | /// that fed nothing would stall the whole timeline on it. | 204 | /// that fed nothing would stall the whole timeline on it. |
| 205 | /// | 205 | /// |
| 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 | + /// | ||
| 206 | /// Only the sources some segment names are opened. `Ok(None)` when `sources` | 210 | /// 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 | 211 | + /// is empty or its first entry has no AAC track; a later source that |
| 208 | - /// missing audio or disagrees on rate/layout is an `Err` — import refuses | 212 | + /// disagrees on rate/layout is an `Err` — import refuses those up front (one |
| 209 | - /// those up front (one timeline, one output device), this is the backstop. | 213 | + /// timeline, one output device), this is the backstop. |
| 210 | pub fn open_multi_segments( | 214 | pub fn open_multi_segments( |
| 211 | sources: &[PathBuf], | 215 | sources: &[PathBuf], |
| 212 | segs: &[(Option<usize>, f64, f64)], | 216 | segs: &[(Option<usize>, f64, f64)], |
| @@ -294,11 +298,18 @@ impl AudioSession { | |||
| 294 | first.check_decoder()?; | 298 | first.check_decoder()?; |
| 295 | 299 | ||
| 296 | let mut tracks: Vec<Option<Track>> = sources.iter().map(|_| None).collect(); | 300 | 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(); | ||
| 297 | tracks[at] = Some(first); | 305 | tracks[at] = Some(first); |
| 298 | for &(source, ..) in segs { | 306 | for &(source, ..) in segs { |
| 299 | let Some(source) = source else { | 307 | let Some(source) = source else { |
| 300 | continue; // a gap opens no file | 308 | continue; // a gap opens no file |
| 301 | }; | 309 | }; |
| 310 | + if silent.get(source) == Some(&true) { | ||
| 311 | + continue; | ||
| 312 | + } | ||
| 302 | let slot = tracks | 313 | let slot = tracks |
| 303 | .get_mut(source) | 314 | .get_mut(source) |
| 304 | .ok_or_else(|| format!("segment names source {source} of {}", sources.len()))?; | 315 | .ok_or_else(|| format!("segment names source {source} of {}", sources.len()))?; |
| @@ -306,8 +317,14 @@ impl AudioSession { | |||
| 306 | continue; // already opened, and the checks below already ran | 317 | continue; // already opened, and the checks below already ran |
| 307 | } | 318 | } |
| 308 | let (path, stream) = &sources[source]; | 319 | let (path, stream) = &sources[source]; |
| 309 | - let track = Track::open(path, *stream)? | 320 | + // A source with no audio track at all is not a failure: its |
| 310 | - .ok_or_else(|| format!("source {source} has no audio track"))?; | 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 | + }; | ||
| 311 | if (track.sample_rate(), track.channels()?) != (meta.sample_rate, meta.channels) { | 328 | if (track.sample_rate(), track.channels()?) != (meta.sample_rate, meta.channels) { |
| 312 | return Err(format!( | 329 | return Err(format!( |
| 313 | "source {source} is {} Hz {} ch, the timeline is {} Hz {} ch", | 330 | "source {source} is {} Hz {} ch, the timeline is {} Hz {} ch", |
| @@ -324,14 +341,15 @@ impl AudioSession { | |||
| 324 | 341 | ||
| 325 | let segments: Vec<Segment> = segs | 342 | let segments: Vec<Segment> = segs |
| 326 | .iter() | 343 | .iter() |
| 327 | - .map(|&(source, start_secs, end_secs)| match source { | 344 | + // A gap, and a source with no track to decode, are the same stretch |
| 328 | - Some(source) => tracks[source] | 345 | + // of nothing: as many frames of silence as the window is long. |
| 329 | - .as_ref() | 346 | + .map(|&(source, start_secs, end_secs)| { |
| 330 | - .expect("opened above") | 347 | + match source.and_then(|source| Some((source, tracks[source].as_ref()?))) { |
| 331 | - .segment(source, start_secs, end_secs), | 348 | + Some((source, track)) => track.segment(source, start_secs, end_secs), |
| 332 | - None => Segment::silence( | 349 | + None => Segment::silence( |
| 333 | - ((end_secs - start_secs).max(0.0) * f64::from(meta.sample_rate)) as u64, | 350 | + ((end_secs - start_secs).max(0.0) * f64::from(meta.sample_rate)) as u64, |
| 334 | - ), | 351 | + ), |
| 352 | + } | ||
| 335 | }) | 353 | }) |
| 336 | .collect(); | 354 | .collect(); |
| 337 | // Chunk numbering is continuous across every join, counted from the first | 355 | // Chunk numbering is continuous across every join, counted from the first |
| @@ -622,7 +640,11 @@ impl AudioSession { | |||
| 622 | decodable: matches!(track.channels, 1 | 2), | 640 | decodable: matches!(track.channels, 1 | 2), |
| 623 | }]); | 641 | }]); |
| 624 | } | 642 | } |
| 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 { | ||
| 626 | return Ok(Vec::new()); | 648 | return Ok(Vec::new()); |
| 627 | }; | 649 | }; |
| 628 | return Ok(vec![StreamInfo { | 650 | return Ok(vec![StreamInfo { |
| @@ -635,7 +657,7 @@ impl AudioSession { | |||
| 635 | }]); | 657 | }]); |
| 636 | } | 658 | } |
| 637 | if crate::is_audio(path) { | 659 | if crate::is_audio(path) { |
| 638 | - let track = SymTrack::open(path)?; | 660 | + let track = SymTrack::open_required(path)?; |
| 639 | return Ok(vec![StreamInfo { | 661 | return Ok(vec![StreamInfo { |
| 640 | index: 0, | 662 | index: 0, |
| 641 | codec: track.codec.into(), | 663 | codec: track.codec.into(), |
| @@ -762,15 +784,18 @@ impl AudioSession { | |||
| 762 | /// half a packet over the whole list however many files it spans, and the | 784 | /// half a packet over the whole list however many files it spans, and the |
| 763 | /// extra priming packet is still the very first segment's alone. | 785 | /// extra priming packet is still the very first segment's alone. |
| 764 | /// | 786 | /// |
| 765 | - /// Every source must declare the same [`AacTrackParams`]: the copy becomes | 787 | + /// Every source that *has* a track must declare the same |
| 766 | - /// one output track with one esds. Import refuses a mismatch up front; the | 788 | + /// [`AacTrackParams`]: the copy becomes one output track with one esds. |
| 767 | - /// check here is the backstop, as is the missing-track `Err`. | 789 | + /// Import refuses a mismatch up front; the check here is the backstop. |
| 768 | /// | 790 | /// |
| 769 | /// A segment naming **no** source is a gap, and is copied as that many | 791 | /// A segment naming **no** source is a gap, and is copied as that many |
| 770 | /// packets of [`silent_packet`] silence — the rounding debt carried through | 792 | /// packets of [`silent_packet`] silence — the rounding debt carried through |
| 771 | /// it like any other, so the hole occupies its exact duration and the audio | 793 | /// it like any other, so the hole occupies its exact duration and the audio |
| 772 | /// after it stays in sync with the picture. A gap the track *opens* on gets | 794 | /// 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`]). | ||
| 774 | pub fn copy_multi_segments( | 799 | pub fn copy_multi_segments( |
| 775 | sources: &[PathBuf], | 800 | sources: &[PathBuf], |
| 776 | segs: &[(Option<usize>, f64, f64)], | 801 | segs: &[(Option<usize>, f64, f64)], |
| @@ -789,24 +814,34 @@ impl AudioSession { | |||
| 789 | sources: &[(PathBuf, usize)], | 814 | sources: &[(PathBuf, usize)], |
| 790 | segs: &[(Option<usize>, f64, f64)], | 815 | segs: &[(Option<usize>, f64, f64)], |
| 791 | ) -> crate::Result<Option<(AacTrackParams, Vec<AacPacket>)>> { | 816 | ) -> 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 { | ||
| 793 | return Ok(None); // no segments, or nothing but silence | 831 | return Ok(None); // no segments, or nothing but silence |
| 794 | }; | 832 | }; |
| 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); | ||
| 804 | 833 | ||
| 805 | let sample_rate = params.sample_rate; | 834 | let sample_rate = params.sample_rate; |
| 806 | let mut err = 0i64; | 835 | let mut err = 0i64; |
| 807 | let mut packets: Vec<AacPacket> = Vec::new(); | 836 | let mut packets: Vec<AacPacket> = Vec::new(); |
| 808 | for &(source, start_secs, end_secs) in segs { | 837 | 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 { | ||
| 810 | let ideal = ((end_secs - start_secs).max(0.0) * f64::from(sample_rate)) as i64; | 845 | let ideal = ((end_secs - start_secs).max(0.0) * f64::from(sample_rate)) as i64; |
| 811 | let bytes = silent_packet(params.chan_conf)?; | 846 | let bytes = silent_packet(params.chan_conf)?; |
| 812 | // A reader drops the first packet of an AAC track as the | 847 | // A reader drops the first packet of an AAC track as the |
| @@ -824,7 +859,6 @@ impl AudioSession { | |||
| 824 | } | 859 | } |
| 825 | continue; | 860 | continue; |
| 826 | }; | 861 | }; |
| 827 | - let track = source_at(&mut tracks, sources, source)?; | ||
| 828 | if track.track_params() != params { | 862 | if track.track_params() != params { |
| 829 | return Err(format!( | 863 | return Err(format!( |
| 830 | "source {source} audio is {:?}, the timeline's is {params:?}", | 864 | "source {source} audio is {:?}, the timeline's is {params:?}", |
| @@ -885,24 +919,25 @@ fn silent_packet(chan_conf: u8) -> crate::Result<Vec<u8>> { | |||
| 885 | } | 919 | } |
| 886 | } | 920 | } |
| 887 | 921 | ||
| 888 | -/// The source at `index`, on the stream it names, opened on first use. Sources | 922 | +/// The source at `index`, on the stream it names, opened on first use -- and |
| 889 | -/// a segment list never names are never touched: a project's list only grows. | 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. | ||
| 890 | fn source_at<'a>( | 928 | fn source_at<'a>( |
| 891 | - tracks: &'a mut [Option<AacTrack>], | 929 | + tracks: &'a mut [Option<Option<AacTrack>>], |
| 892 | sources: &[(PathBuf, usize)], | 930 | sources: &[(PathBuf, usize)], |
| 893 | index: usize, | 931 | index: usize, |
| 894 | -) -> crate::Result<&'a mut AacTrack> { | 932 | +) -> crate::Result<Option<&'a mut AacTrack>> { |
| 895 | let slot = tracks | 933 | let slot = tracks |
| 896 | .get_mut(index) | 934 | .get_mut(index) |
| 897 | .ok_or_else(|| format!("segment names source {index} of {}", sources.len()))?; | 935 | .ok_or_else(|| format!("segment names source {index} of {}", sources.len()))?; |
| 898 | if slot.is_none() { | 936 | if slot.is_none() { |
| 899 | let (path, stream) = &sources[index]; | 937 | let (path, stream) = &sources[index]; |
| 900 | - *slot = Some( | 938 | + *slot = Some(copy_track(path, *stream)?); |
| 901 | - copy_track(path, *stream)? | ||
| 902 | - .ok_or_else(|| format!("source {index} has no audio track"))?, | ||
| 903 | - ); | ||
| 904 | } | 939 | } |
| 905 | - Ok(slot.as_mut().expect("just opened")) | 940 | + Ok(slot.as_mut().expect("just opened").as_mut()) |
| 906 | } | 941 | } |
| 907 | 942 | ||
| 908 | /// A source's track for the *copy* path, which needs raw AAC access units. | 943 | /// A source's track for the *copy* path, which needs raw AAC access units. |
| @@ -994,8 +1029,8 @@ impl Track { | |||
| 994 | // decoder straight out of the blocks ([`MkvAc3Track`]). Sound neither | 1029 | // decoder straight out of the blocks ([`MkvAc3Track`]). Sound neither |
| 995 | // one can decode (Opus, DTS) leaves the source the silent one it always | 1030 | // one can decode (Opus, DTS) leaves the source the silent one it always |
| 996 | // was, which `AudioSession::unsupported` puts into words, rather than | 1031 | // was, which `AudioSession::unsupported` puts into words, rather than |
| 997 | - // failing the import of a file whose picture is fine -- and so does an | 1032 | + // failing the import of a file whose picture is fine. A track that will |
| 998 | - // AC-3 track that will not open, a laced block say. | 1033 | + // not open at all is *not* in that group: see below. |
| 999 | if crate::demux::is_matroska(path) { | 1034 | if crate::demux::is_matroska(path) { |
| 1000 | if stream > 0 { | 1035 | if stream > 0 { |
| 1001 | return Err(format!("{}: audio stream {stream} of 1 stream", path.display()).into()); | 1036 | return Err(format!("{}: audio stream {stream} of 1 stream", path.display()).into()); |
| @@ -1003,24 +1038,27 @@ impl Track { | |||
| 1003 | match MkvAc3Track::open(path) { | 1038 | match MkvAc3Track::open(path) { |
| 1004 | Ok(Some(track)) => return Ok(Some(Self::Mkv(track))), | 1039 | Ok(Some(track)) => return Ok(Some(Self::Mkv(track))), |
| 1005 | Ok(None) => {} | 1040 | Ok(None) => {} |
| 1006 | - // Named on the way past for the same reason symphonia's failure | 1041 | + // Named on the way past rather than returned: symphonia gets the |
| 1007 | - // is, below: an AC-3 track that broke is a bug, not a codec we | 1042 | + // same file next and may read the track perfectly well (a laced |
| 1008 | - // never had. | 1043 | + // block is [`MkvAc3Track`]'s limitation, not the file's), and |
| 1044 | + // if it cannot either, *its* `Err` is the one that comes back. | ||
| 1009 | Err(e) => eprintln!("matroska audio: {}: {e}", path.display()), | 1045 | Err(e) => eprintln!("matroska audio: {}: {e}", path.display()), |
| 1010 | } | 1046 | } |
| 1011 | - // Logged on the way past: "silent" here covers both a codec nothing | 1047 | + // Two things are silent here and no more: a file with no audio |
| 1012 | - // decodes and a track that genuinely broke, and only the second is a | 1048 | + // track at all, and a track whose codec nothing in this project |
| 1013 | - // bug -- with no trace at all it reaches the user as a lane that | 1049 | + // decodes (Opus, DTS -- [`AudioSession::unsupported`] is what puts |
| 1014 | - // drew no waveform and nothing else to go on. | 1050 | + // that into words). A track that will not *open* is an `Err`, the |
| 1015 | - return Ok(SymTrack::open(path) | 1051 | + // same answer the mp4 arm gives: turned into silence it would play |
| 1016 | - .inspect_err(|e| eprintln!("matroska audio: {}: {e}", path.display())) | 1052 | + // and export as a hole with only an eprintln to say why, which is a |
| 1017 | - .ok() | 1053 | + // bug wearing a feature's clothes. |
| 1018 | - .filter(|t| { | 1054 | + let Some(track) = SymTrack::open(path)? else { |
| 1019 | - t.decoder() | 1055 | + return Ok(None); |
| 1020 | - .inspect_err(|e| eprintln!("matroska audio: {}: {e}", path.display())) | 1056 | + }; |
| 1021 | - .is_ok() | 1057 | + if let Err(e) = track.decoder() { |
| 1022 | - }) | 1058 | + eprintln!("matroska audio: {}: {e}", path.display()); |
| 1023 | - .map(Self::Sym)); | 1059 | + return Ok(None); |
| 1060 | + } | ||
| 1061 | + return Ok(Some(Self::Sym(track))); | ||
| 1024 | } | 1062 | } |
| 1025 | let audio_file = crate::is_audio(path); | 1063 | let audio_file = crate::is_audio(path); |
| 1026 | // Ahead of the AAC reader, because that one answers "not AAC" for a | 1064 | // Ahead of the AAC reader, because that one answers "not AAC" for a |
| @@ -1041,7 +1079,7 @@ impl Track { | |||
| 1041 | if stream > 0 { | 1079 | if stream > 0 { |
| 1042 | return Err(format!("{}: audio stream {stream} of 1 stream", path.display()).into()); | 1080 | return Err(format!("{}: audio stream {stream} of 1 stream", path.display()).into()); |
| 1043 | } | 1081 | } |
| 1044 | - SymTrack::open(path).map(|track| Some(Self::Sym(track))) | 1082 | + SymTrack::open_required(path).map(|track| Some(Self::Sym(track))) |
| 1045 | } | 1083 | } |
| 1046 | 1084 | ||
| 1047 | fn sample_rate(&self) -> u32 { | 1085 | fn sample_rate(&self) -> u32 { |
| @@ -1166,7 +1204,13 @@ struct SymTrack { | |||
| 1166 | } | 1204 | } |
| 1167 | 1205 | ||
| 1168 | impl SymTrack { | 1206 | 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>> { | ||
| 1170 | let mss = MediaSourceStream::new(Box::new(File::open(path)?), Default::default()); | 1214 | let mss = MediaSourceStream::new(Box::new(File::open(path)?), Default::default()); |
| 1171 | // The extension is a hint, not a decision: the probe reads the magic and | 1215 | // The extension is a hint, not a decision: the probe reads the magic and |
| 1172 | // is free to disagree, which is what makes a mislabelled file work. | 1216 | // is free to disagree, which is what makes a mislabelled file work. |
| @@ -1180,9 +1224,9 @@ impl SymTrack { | |||
| 1180 | FormatOptions::default(), | 1224 | FormatOptions::default(), |
| 1181 | MetadataOptions::default(), | 1225 | MetadataOptions::default(), |
| 1182 | )?; | 1226 | )?; |
| 1183 | - let track = reader | 1227 | + let Some(track) = reader.default_track(SymKind::Audio) else { |
| 1184 | - .default_track(SymKind::Audio) | 1228 | + return Ok(None); |
| 1185 | - .ok_or_else(|| format!("{} has no audio track", path.display()))?; | 1229 | + }; |
| 1186 | let (track_id, num_frames, delay) = (track.id, track.num_frames, track.delay); | 1230 | let (track_id, num_frames, delay) = (track.id, track.num_frames, track.delay); |
| 1187 | let time_base = track | 1231 | let time_base = track |
| 1188 | .time_base | 1232 | .time_base |
| @@ -1203,7 +1247,7 @@ impl SymTrack { | |||
| 1203 | let codec = symphonia::default::get_codecs() | 1247 | let codec = symphonia::default::get_codecs() |
| 1204 | .get_audio_decoder(params.codec) | 1248 | .get_audio_decoder(params.codec) |
| 1205 | .map_or("an unsupported format", |d| d.codec.info.short_name); | 1249 | .map_or("an unsupported format", |d| d.codec.info.short_name); |
| 1206 | - Ok(Self { | 1250 | + Ok(Some(Self { |
| 1207 | reader, | 1251 | reader, |
| 1208 | track_id, | 1252 | track_id, |
| 1209 | sample_rate, | 1253 | sample_rate, |
| @@ -1217,7 +1261,14 @@ impl SymTrack { | |||
| 1217 | time_base, | 1261 | time_base, |
| 1218 | params, | 1262 | params, |
| 1219 | codec, | 1263 | 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()) | ||
| 1221 | } | 1272 | } |
| 1222 | 1273 | ||
| 1223 | /// A fresh decoder: seeking mid-stream leaves state that belongs to the | 1274 | /// 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 { | |||
| 1659 | /// nothing playable, so there is nothing for [`undo`](Self::undo) to take | 1659 | /// nothing playable, so there is nothing for [`undo`](Self::undo) to take |
| 1660 | /// back, and nothing reseeks. | 1660 | /// back, and nothing reseeks. |
| 1661 | /// | 1661 | /// |
| 1662 | - /// Refused unless it can join the timeline -- same codec, same audio | 1662 | + /// Refused unless it can join the timeline -- a decoder this machine can |
| 1663 | - /// parameters or both silent; the `Err` names the property that disagrees, | 1663 | + /// open, and audio parameters that agree or none at all; the `Err` names |
| 1664 | + /// the property that disagrees, | ||
| 1664 | /// for a caller to show. Nothing is changed by a refusal. A *resolution* of | 1665 | /// for a caller to show. Nothing is changed by a refusal. A *resolution* of |
| 1665 | /// its own is not a refusal: the clip is placed on the project canvas by its | 1666 | /// its own is not a refusal: the clip is placed on the project canvas by its |
| 1666 | /// fit policy ([`PlaybackSession::set_fit`]) -- and neither is a *frame | 1667 | /// fit policy ([`PlaybackSession::set_fit`]) -- and neither is a *frame |
| @@ -2018,8 +2019,9 @@ impl Drop for PlaybackSession { | |||
| 2018 | } | 2019 | } |
| 2019 | 2020 | ||
| 2020 | /// Whether `path`, already demuxed to `meta`, may join a timeline whose | 2021 | /// Whether `path`, already demuxed to `meta`, may join a timeline whose |
| 2021 | -/// parameters are `timeline` and whose audio probes as `first`: same codec, | 2022 | +/// parameters are `timeline` and whose audio probes as `first`: a decoder this |
| 2022 | -/// same audio parameters or both silent, and a frame rate that can be named | 2023 | +/// machine can open, audio parameters that agree (or no audio at all), and a |
| 2024 | +/// frame rate that can be named | ||
| 2023 | /// against the timeline's. The [`Rate`] it will be read at comes back with the | 2025 | /// against the timeline's. The [`Rate`] it will be read at comes back with the |
| 2024 | /// answer, so the number the check was decided on is the number it plays by. | 2026 | /// answer, so the number the check was decided on is the number it plays by. |
| 2025 | /// | 2027 | /// |
| @@ -2028,7 +2030,9 @@ impl Drop for PlaybackSession { | |||
| 2028 | /// own fit policy, so a 640x360 file joining a 1920x1080 timeline is a | 2030 | /// own fit policy, so a 640x360 file joining a 1920x1080 timeline is a |
| 2029 | /// letterboxed clip rather than a refusal, and so is a frame rate of its own: | 2031 | /// letterboxed clip rather than a refusal, and so is a frame rate of its own: |
| 2030 | /// the timeline keeps its own rate and the file is read at [`Rate`] against it | 2032 | /// 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. | ||
| 2032 | /// | 2036 | /// |
| 2033 | /// The `Err` names the property that disagrees, and those strings are what a | 2037 | /// The `Err` names the property that disagrees, and those strings are what a |
| 2034 | /// front-end shows verbatim; [`PlaybackSession::import`] and | 2038 | /// front-end shows verbatim; [`PlaybackSession::import`] and |
| @@ -2040,18 +2044,22 @@ fn matches_timeline( | |||
| 2040 | timeline: &VideoMeta, | 2044 | timeline: &VideoMeta, |
| 2041 | first: &Option<crate::AudioProbe>, | 2045 | first: &Option<crate::AudioProbe>, |
| 2042 | ) -> crate::Result<Rate> { | 2046 | ) -> crate::Result<Rate> { |
| 2043 | - // Codec first: one timeline is one kind of source. Mixing them would decode | 2047 | + // The codec is *not* held to the timeline's -- every clip opens its own |
| 2044 | - // (every clip opens its own decoder) but on a machine without the VA-API | 2048 | + // decoder, so an H.264 take and an HEVC one play on one timeline. What the |
| 2045 | - // plugin the VP9 half would be black frames with the refusal only on | 2049 | + // codec gate was really protecting against stays, in the one place that can |
| 2046 | - // stderr, which is exactly what a front-end cannot show. | 2050 | + // actually answer it: on a machine without the VA-API plugin an HEVC or VP9 |
| 2047 | - if meta.codec != timeline.codec { | 2051 | + // clip would be black frames with the refusal on stderr alone, so the file |
| 2048 | - return Err(format!( | 2052 | + // is asked for a decoder *here*, at the door, where the `Err` is still |
| 2049 | - "{} does not match the timeline's {}", | 2053 | + // something a front-end can show. A zero-length range probes and starts no |
| 2050 | - meta.codec.name(), | 2054 | + // worker, and H.264 costs nothing at all -- [`DecodeSession::open_worker`] |
| 2051 | - timeline.codec.name() | 2055 | + // only enters VA-API off that path. |
| 2052 | - ) | 2056 | + DecodeSession::open_worker( |
| 2053 | - .into()); | 2057 | + &source.path, |
| 2054 | - } | 2058 | + 0, |
| 2059 | + 0, | ||
| 2060 | + ColorParams::default(), | ||
| 2061 | + Composer::passthrough(), | ||
| 2062 | + )?; | ||
| 2055 | // The frame rate is *not* a refusal any more: a file shot at another rate is | 2063 | // The frame rate is *not* a refusal any more: a file shot at another rate is |
| 2056 | // placed for the seconds it lasts and read through [`Rate`] at the | 2064 | // placed for the seconds it lasts and read through [`Rate`] at the |
| 2057 | // decoder's door, so it plays at the speed it was shot at on a timeline | 2065 | // decoder's door, so it plays at the speed it was shot at on a timeline |
| @@ -2069,8 +2077,9 @@ fn matches_timeline( | |||
| 2069 | } | 2077 | } |
| 2070 | 2078 | ||
| 2071 | /// Whether a candidate's audio may join a timeline whose first source probes as | 2079 | /// 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 | 2080 | +/// `first`: same rate, same layout -- or no audio of its own at all, which is |
| 2073 | -/// exported track is all there is, and no resampler. | 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. | ||
| 2074 | /// | 2083 | /// |
| 2075 | /// The audio half of [`matches_timeline`], which a stream placed on its own | 2084 | /// The audio half of [`matches_timeline`], which a stream placed on its own |
| 2076 | /// ([`PlaybackSession::place_stream_at`]) has to pass while the picture it | 2085 | /// ([`PlaybackSession::place_stream_at`]) has to pass while the picture it |
| @@ -2088,9 +2097,9 @@ fn matches_timeline( | |||
| 2088 | /// `Ok(None)` for a timeline whose first such source is silent, and for one of | 2097 | /// `Ok(None)` for a timeline whose first such source is silent, and for one of |
| 2089 | /// nothing but stills. That is a silent timeline, and a file with sound is | 2098 | /// nothing but stills. That is a silent timeline, and a file with sound is |
| 2090 | /// still refused by [`audio_matches`] in the words it always used ("the file | 2099 | /// 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 | 2100 | +/// has audio, the timeline is silent") -- the device was opened on source 0's |
| 2092 | -/// source 0 has always given. This function widens which source is asked, not | 2101 | +/// track and there is none to open. This function widens which source is asked, |
| 2093 | -/// what the answer means. | 2102 | +/// not what the answer means. |
| 2094 | fn first_audio_of(sources: &[Source]) -> crate::Result<Option<crate::AudioProbe>> { | 2103 | fn first_audio_of(sources: &[Source]) -> crate::Result<Option<crate::AudioProbe>> { |
| 2095 | match audio_source_of(sources) { | 2104 | match audio_source_of(sources) { |
| 2096 | Some(first) => AudioSession::probe(&first.path, first.audio_stream), | 2105 | Some(first) => AudioSession::probe(&first.path, first.audio_stream), |
| @@ -2119,12 +2128,19 @@ fn audio_matches(source: &Source, first: &Option<crate::AudioProbe>) -> crate::R | |||
| 2119 | if probe == *first { | 2128 | if probe == *first { |
| 2120 | return Ok(()); | 2129 | return Ok(()); |
| 2121 | } | 2130 | } |
| 2122 | - Err(match (probe, first) { | 2131 | + // ...and a *silent* file joins whatever the timeline is: it contributes |
| 2123 | - (None, _) => "the file is silent, the timeline has audio".to_string(), | 2132 | + // silence over its span, which is the very thing both audio paths already |
| 2124 | - (_, None) => "the file has audio, the timeline is silent".to_string(), | 2133 | + // synthesise for a gap ([`AudioSession::open_multi_streams_speed`] plays |
| 2125 | - (Some(a), Some(b)) => format!( | 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!( | ||
| 2126 | "audio {} Hz {} ch does not match the timeline's {} Hz {} ch", | 2142 | "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 |
| 2128 | ), | 2144 | ), |
| 2129 | } | 2145 | } |
| 2130 | .into()) | 2146 | .into()) |
crates/engine/tests/audio_decode.rsmodified+37 -0
| @@ -272,3 +272,40 @@ fn an_ac3_source_refuses_an_mp4_audio_copy() { | |||
| 272 | "unhelpful refusal: {err}" | 272 | "unhelpful refusal: {err}" |
| 273 | ); | 273 | ); |
| 274 | } | 274 | } |
| 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() { | |||
| 511 | assert!(!part_path(&out).exists(), "no half-written .part either"); | 511 | assert!(!part_path(&out).exists(), "no half-written .part either"); |
| 512 | } | 512 | } |
| 513 | 513 | ||
| 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 | + | ||
| 514 | /// A silent timeline cannot become an audio file, and says so rather than | 575 | /// A silent timeline cannot become an audio file, and says so rather than |
| 515 | /// writing zero samples that a user would take for a broken microphone. | 576 | /// writing zero samples that a user would take for a broken microphone. |
| 516 | #[test] | 577 | #[test] |
crates/engine/tests/audio_multi.rsmodified+67 -7
| @@ -250,18 +250,19 @@ fn the_join_carries_no_second_priming_packet() { | |||
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | #[test] | 252 | #[test] |
| 253 | -fn a_source_without_the_timeline_audio_is_refused() { | 253 | +fn a_source_that_disagrees_on_rate_or_layout_is_refused() { |
| 254 | - // Import refuses these up front (same rate, same layout, or both silent); | 254 | + // Import refuses these up front (one output device, one set of parameters); |
| 255 | // the copy and the decode paths refuse them again rather than mislabel one | 255 | // the copy and the decode paths refuse them again rather than mislabel one |
| 256 | - // esds for two different tracks. | 256 | + // esds for two different tracks. Stream 1 of the multi-audio fixture is |
| 257 | - let mixed = [asset("test_av.mp4"), asset("test_mismatch.mp4")]; | 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)]; | ||
| 258 | let segs = [(Some(0), 0.0, 1.0), (Some(1), 0.0, 1.0)]; | 259 | let segs = [(Some(0), 0.0, 1.0), (Some(1), 0.0, 1.0)]; |
| 259 | // (`.err()`, not `unwrap_err`: neither Ok payload is `Debug`.) | 260 | // (`.err()`, not `unwrap_err`: neither Ok payload is `Debug`.) |
| 260 | for e in [ | 261 | for e in [ |
| 261 | - AudioSession::copy_multi_segments(&mixed, &segs).err(), | 262 | + AudioSession::copy_multi_streams(&mixed, &segs).err(), |
| 262 | - AudioSession::open_multi_segments(&mixed, &segs).err(), | 263 | + AudioSession::open_multi_streams(&mixed, &segs).err(), |
| 263 | ] | 264 | ] |
| 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")) |
| 265 | { | 266 | { |
| 266 | let msg = e.to_string(); | 267 | let msg = e.to_string(); |
| 267 | assert!(msg.contains("source 1"), "{msg}"); | 268 | assert!(msg.contains("source 1"), "{msg}"); |
| @@ -270,3 +271,62 @@ fn a_source_without_the_timeline_audio_is_refused() { | |||
| 270 | assert!(AudioSession::copy_multi_segments(&sources(), &[(Some(2), 0.0, 1.0)]).is_err()); | 271 | assert!(AudioSession::copy_multi_segments(&sources(), &[(Some(2), 0.0, 1.0)]).is_err()); |
| 271 | assert!(AudioSession::open_multi_segments(&sources(), &[(Some(2), 0.0, 1.0)]).is_err()); | 272 | assert!(AudioSession::open_multi_segments(&sources(), &[(Some(2), 0.0, 1.0)]).is_err()); |
| 272 | } | 273 | } |
| 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() { | |||
| 155 | assert!(refused.contains("plugin"), "{refused}"); | 155 | assert!(refused.contains("plugin"), "{refused}"); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | -/// A timeline is refused a source coded differently, in the same words a | 158 | +/// A timeline is *not* refused a source coded differently -- every clip opens |
| 159 | -/// resolution mismatch is refused in: a front-end shows the string as it is. | 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. | ||
| 160 | #[test] | 162 | #[test] |
| 161 | -fn a_timeline_refuses_the_other_codec() { | 163 | +fn a_timeline_takes_the_other_codec_or_names_the_missing_decoder() { |
| 162 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av.mp4"); | 164 | 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") }; | ||
| 163 | let refused = session | 168 | let refused = session |
| 164 | .import(&asset("test_av1.mkv")) | 169 | .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") |
| 166 | .to_string(); | 171 | .to_string(); |
| 167 | - assert!(refused.contains("AV1"), "{refused}"); | 172 | + unsafe { std::env::remove_var("VE_SW") }; |
| 168 | - assert!(refused.contains("H.264"), "{refused}"); | 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"); | ||
| 169 | } | 179 | } |
| 170 | 180 | ||
| 171 | /// The end-to-end user path: opening the file yields pictures, all of them, | 181 | /// 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() { | |||
| 112 | assert!(h264, "software H.264 decode still opens"); | 112 | assert!(h264, "software H.264 decode still opens"); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | -/// A timeline is refused a source coded differently, in the same words a | 115 | +/// A timeline is *not* refused a source coded differently -- every clip opens |
| 116 | -/// resolution mismatch is refused in: a front-end shows the string as it is. | 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. | ||
| 117 | #[test] | 120 | #[test] |
| 118 | -fn a_timeline_refuses_the_other_codec() { | 121 | +fn a_timeline_takes_the_other_codec_or_names_the_missing_decoder() { |
| 119 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av.mp4"); | 122 | 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") }; | ||
| 120 | let refused = session | 127 | let refused = session |
| 121 | .import(&asset("test_hevc.mp4")) | 128 | .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") |
| 123 | .to_string(); | 130 | .to_string(); |
| 124 | - assert!(refused.contains("HEVC"), "{refused}"); | 131 | + unsafe { std::env::remove_var("VE_SW") }; |
| 125 | - assert!(refused.contains("H.264"), "{refused}"); | 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 | + } | ||
| 126 | } | 144 | } |
| 127 | 145 | ||
| 128 | /// The end-to-end user path: opening the file yields pictures, all of them, | 146 | /// 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() { | |||
| 155 | ); | 173 | ); |
| 156 | } | 174 | } |
| 157 | 175 | ||
| 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 | + | ||
| 158 | /// Export re-encodes to H.264 whatever the source was coded with: the packet | 235 | /// Export re-encodes to H.264 whatever the source was coded with: the packet |
| 159 | /// copy path is audio-only, so no HEVC byte can reach an `avc1` track. | 236 | /// copy path is audio-only, so no HEVC byte can reach an `avc1` track. |
| 160 | #[test] | 237 | #[test] |
crates/engine/tests/lanes.rsmodified+9 -4
| @@ -52,8 +52,13 @@ fn out_path(name: &str, ext: &str) -> PathBuf { | |||
| 52 | /// A hand-written v4 project: `V1` the whole of `test_av`, `V2` the middle | 52 | /// A hand-written v4 project: `V1` the whole of `test_av`, `V2` the middle |
| 53 | /// third playing `test_av2` from its own frame 0, `A1` the whole of `test_av`. | 53 | /// third playing `test_av2` from its own frame 0, `A1` the whole of `test_av`. |
| 54 | /// Exactly the file a user would write by hand, parsed by the real loader. | 54 | /// Exactly the file a user would write by hand, parsed by the real loader. |
| 55 | -fn three_lane_file() -> PathBuf { | 55 | +/// |
| 56 | - let path = out_path("project", "edith"); | 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"); | ||
| 57 | // `source <audio stream> <path>`: the number is which audio track of the | 62 | // `source <audio stream> <path>`: the number is which audio track of the |
| 58 | // file plays, not the source index -- both of these are on their first. | 63 | // file plays, not the source index -- both of these are on their first. |
| 59 | let text = format!( | 64 | let text = format!( |
| @@ -143,7 +148,7 @@ fn frame_of(session: &mut PlaybackSession, timeline: u32) -> Vec<u8> { | |||
| 143 | #[test] | 148 | #[test] |
| 144 | fn playback_shows_the_topmost_video_lane() { | 149 | fn playback_shows_the_topmost_video_lane() { |
| 145 | pin_software(); | 150 | pin_software(); |
| 146 | - let project = three_lane_file(); | 151 | + let project = three_lane_file("playback"); |
| 147 | let mut session = PlaybackSession::open_project(&project).expect("open the project"); | 152 | let mut session = PlaybackSession::open_project(&project).expect("open the project"); |
| 148 | session.set_gain(0.0); | 153 | session.set_gain(0.0); |
| 149 | assert_eq!(session.timeline_duration(), f64::from(TOTAL) / FPS); | 154 | assert_eq!(session.timeline_duration(), f64::from(TOTAL) / FPS); |
| @@ -164,7 +169,7 @@ fn playback_shows_the_topmost_video_lane() { | |||
| 164 | #[test] | 169 | #[test] |
| 165 | fn export_writes_the_same_composite() { | 170 | fn export_writes_the_same_composite() { |
| 166 | pin_software(); | 171 | pin_software(); |
| 167 | - let file = three_lane_file(); | 172 | + let file = three_lane_file("export"); |
| 168 | let session = PlaybackSession::open_project(&file).expect("open the project"); | 173 | let session = PlaybackSession::open_project(&file).expect("open the project"); |
| 169 | let out = out_path("composite", "mp4"); | 174 | let out = out_path("composite", "mp4"); |
| 170 | 175 | ||
crates/engine/tests/playback.rsmodified+60 -25
| @@ -13,7 +13,7 @@ use std::time::{Duration, Instant}; | |||
| 13 | 13 | ||
| 14 | use engine::export::{ExportSettings, Format}; | 14 | use engine::export::{ExportSettings, Format}; |
| 15 | use engine::project::Lane; | 15 | use engine::project::Lane; |
| 16 | -use engine::{DecodeSession, Frame, PlaybackSession}; | 16 | +use engine::{Codec, DecodeSession, Frame, PlaybackSession}; |
| 17 | 17 | ||
| 18 | fn asset(name: &str) -> PathBuf { | 18 | fn asset(name: &str) -> PathBuf { |
| 19 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) | 19 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| @@ -788,30 +788,31 @@ fn the_first_import_opens_a_library_over_an_empty_timeline() { | |||
| 788 | assert_eq!(session.sources().len(), 1, "the row survives the undo"); | 788 | assert_eq!(session.sources().len(), 1, "the row survives the undo"); |
| 789 | } | 789 | } |
| 790 | 790 | ||
| 791 | -/// One timeline, one set of parameters: everything else is refused by name and | 791 | +/// One timeline, one frame rate and one set of audio parameters: what is left |
| 792 | -/// changes nothing. | 792 | +/// is refused by name and changes nothing. |
| 793 | #[test] | 793 | #[test] |
| 794 | fn import_refuses_what_does_not_match() { | 794 | fn import_refuses_what_does_not_match() { |
| 795 | let mut session = open(asset("test_av.mp4")); | 795 | let mut session = open(asset("test_av.mp4")); |
| 796 | 796 | ||
| 797 | - // A different *codec* cannot join: one timeline is one kind of source. | 797 | + // A different *codec* is not among them any more -- every clip opens its |
| 798 | - let err = session | 798 | + // own decoder. The only refusal left on that axis is a decoder this machine |
| 799 | - .import(&asset("test_vp9.mp4")) | 799 | + // cannot open, and it is the plugin's own words, not the timeline's. |
| 800 | - .expect_err("VP9 must be refused") | 800 | + match session.import(&asset("test_vp9.mp4")) { |
| 801 | - .to_string(); | 801 | + Ok(_) => assert_eq!(session.sources().len(), 2, "VP9 joined the H.264 timeline"), |
| 802 | - assert!(err.contains("VP9"), "refusal must name the codec: {err}"); | 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(); | ||
| 803 | 809 | ||
| 804 | // A different resolution is no longer among the refusals -- it is placed on | 810 | // 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. | 811 | + // the project canvas instead -- and neither is a file with no sound: it |
| 806 | - let err = session | 812 | + // contributes silence over its span. |
| 813 | + session | ||
| 807 | .import(&asset("test_mismatch.mp4")) | 814 | .import(&asset("test_mismatch.mp4")) |
| 808 | - .expect_err("a silent file must be refused") | 815 | + .expect("a silent 640x360 file joins a timeline with sound"); |
| 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 | 816 | ||
| 816 | // A frame rate of its own is no longer a refusal either: 25 fps joins a | 817 | // A frame rate of its own is no longer a refusal either: 25 fps joins a |
| 817 | // 30 fps timeline and is read at `Rate` against it -- see | 818 | // 30 fps timeline and is read at `Rate` against it -- see |
| @@ -823,22 +824,32 @@ fn import_refuses_what_does_not_match() { | |||
| 823 | .remove_source(&asset("test_25fps.mp4"), 0) | 824 | .remove_source(&asset("test_25fps.mp4"), 0) |
| 824 | .expect("...and the row it made comes back off"); | 825 | .expect("...and the row it made comes back off"); |
| 825 | 826 | ||
| 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. | ||
| 827 | let err = session | 829 | let err = session |
| 828 | - .import(&asset("test_baseline.mp4")) | 830 | + .import(&asset("test_ac3.mp4")) |
| 829 | - .expect_err("a silent file must be refused") | 831 | + .expect_err("a mono track cannot join a stereo timeline") |
| 830 | .to_string(); | 832 | .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 | + ); | ||
| 832 | 837 | ||
| 833 | assert!( | 838 | assert!( |
| 834 | session.import(&asset("no_such_file.mp4")).is_err(), | 839 | session.import(&asset("no_such_file.mp4")).is_err(), |
| 835 | "a missing file is an error, not a panic" | 840 | "a missing file is an error, not a panic" |
| 836 | ); | 841 | ); |
| 837 | - assert_eq!(session.clip_spans().len(), 1, "a refusal changes nothing"); | 842 | + assert_eq!(session.clip_spans().len(), 1, "an import places nothing"); |
| 838 | - assert_eq!(session.sources().len(), 1, "a refusal left a library row"); | 843 | + assert_eq!( |
| 844 | + session.sources().len(), | ||
| 845 | + rows + 1, | ||
| 846 | + "only the silent file was taken in" | ||
| 847 | + ); | ||
| 839 | assert!((session.timeline_duration() - 5.0).abs() < 1e-9); | 848 | assert!((session.timeline_duration() - 5.0).abs() < 1e-9); |
| 840 | 849 | ||
| 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. | ||
| 842 | let mut silent = open(asset("test_baseline.mp4")); | 853 | let mut silent = open(asset("test_baseline.mp4")); |
| 843 | let err = silent | 854 | let err = silent |
| 844 | .import(&asset("test_av.mp4")) | 855 | .import(&asset("test_av.mp4")) |
| @@ -847,6 +858,30 @@ fn import_refuses_what_does_not_match() { | |||
| 847 | assert!(err.contains("audio"), "refusal must name the audio: {err}"); | 858 | assert!(err.contains("audio"), "refusal must name the audio: {err}"); |
| 848 | } | 859 | } |
| 849 | 860 | ||
| 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 | + | ||
| 850 | /// The user-facing point of a project resolution: media of two sizes on one | 885 | /// The user-facing point of a project resolution: media of two sizes on one |
| 851 | /// timeline, each composed onto the project's own canvas. | 886 | /// timeline, each composed onto the project's own canvas. |
| 852 | /// | 887 | /// |
crates/engine/tests/saveload.rsmodified+7 -4
| @@ -733,7 +733,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() { | |||
| 733 | fn a_source_that_no_longer_matches_the_timeline_is_refused_in_import_words() { | 733 | fn a_source_that_no_longer_matches_the_timeline_is_refused_in_import_words() { |
| 734 | let dir = scratch("mismatch"); | 734 | let dir = scratch("mismatch"); |
| 735 | copy_in(&dir, "test_av.mp4"); | 735 | 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"); |
| 737 | let path = dir.join("swapped.edith"); | 737 | let path = dir.join("swapped.edith"); |
| 738 | std::fs::write( | 738 | std::fs::write( |
| 739 | &path, | 739 | &path, |
| @@ -745,12 +745,15 @@ fn a_source_that_no_longer_matches_the_timeline_is_refused_in_import_words() { | |||
| 745 | .expect("a source that stopped matching must not open") | 745 | .expect("a source that stopped matching must not open") |
| 746 | .to_string(); | 746 | .to_string(); |
| 747 | // The suffix is `import`'s own refusal, word for word. The substitute is | 747 | // 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 | 748 | + // mono, which is the shape of what is left: one output device means one |
| 749 | - // resolution of its own is placed on the project canvas. | 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. | ||
| 750 | assert_eq!( | 753 | assert_eq!( |
| 751 | err, | 754 | err, |
| 752 | format!( | 755 | 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", |
| 754 | dir.join("test_av2.mp4").display() | 757 | dir.join("test_av2.mp4").display() |
| 755 | ) | 758 | ) |
| 756 | ); | 759 | ); |
crates/engine/tests/vp9.rsmodified+22 -6
| @@ -76,17 +76,33 @@ fn the_software_path_refuses_vp9_by_name() { | |||
| 76 | assert!(h264, "software H.264 decode still opens"); | 76 | assert!(h264, "software H.264 decode still opens"); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | -/// A VP9 timeline is refused a source coded differently, in the same words a | 79 | +/// A timeline is *not* refused a source coded differently -- every clip opens |
| 80 | -/// resolution mismatch is refused in: a front-end shows the string as it is. | 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. | ||
| 81 | #[test] | 83 | #[test] |
| 82 | -fn a_timeline_refuses_the_other_codec() { | 84 | +fn a_timeline_takes_the_other_codec_or_names_the_missing_decoder() { |
| 83 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av.mp4"); | 85 | 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") }; | ||
| 84 | let refused = session | 89 | let refused = session |
| 85 | .import(&asset("test_vp9.mp4")) | 90 | .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") |
| 87 | .to_string(); | 92 | .to_string(); |
| 88 | - assert!(refused.contains("VP9"), "{refused}"); | 93 | + unsafe { std::env::remove_var("VE_SW") }; |
| 89 | - assert!(refused.contains("H.264"), "{refused}"); | 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 | + } | ||
| 90 | } | 106 | } |
| 91 | 107 | ||
| 92 | /// The end-to-end user path: opening the file yields pictures, all of them, | 108 | /// The end-to-end user path: opening the file yields pictures, all of them, |