forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBfbbacfbTahinli3 months ago81 commits

lib.rs78 lines, 2.5 KiBHistoryRawDownload
1//! Video engine: demux -> decode -> pixel convert. No UI dependencies.
2
3pub mod ao;
4pub mod audio;
5pub mod clock;
6pub mod color;
7pub mod convert;
8pub mod decode;
9pub mod demux;
10pub mod edith;
11pub mod eq;
12pub mod export;
13pub mod hw;
14pub mod mux;
15pub mod playback;
16pub mod project;
17pub mod waveform;
18
19pub use audio::{
20 AacPacket, AacTrackParams, AudioChunk, AudioMeta, AudioProbe, AudioSession, StreamInfo,
21};
22pub use clock::PlaybackClock;
23pub use decode::{DecodeSession, Frame};
24pub use demux::{Codec, VideoMeta};
25pub use export::ExportHandle;
26pub use mux::{AudioParams, Mp4Muxer, VideoParams};
27pub use playback::PlaybackSession;
28pub use project::{Clip, Project};
29
30/// Whether a path names a standalone audio file -- a source with no picture,
31/// which belongs on the audio lane and nowhere else. Extension only, lowercased:
32/// the decoder is what really decides, but a front-end has to know which lane a
33/// dropped file may land on *before* anything is opened, and so does
34/// [`PlaybackSession::import`](playback::PlaybackSession::import).
35///
36/// Exactly the containers the engine's audio path reads (`audio::AudioSession`):
37/// no opus, ac3 or dts, for which no pure-Rust decoder exists -- those are
38/// refused by the same door that refuses a `.txt`, which is the honest answer.
39pub fn is_audio(path: &std::path::Path) -> bool {
40 path.extension().and_then(|e| e.to_str()).is_some_and(|e| {
41 matches!(
42 e.to_ascii_lowercase().as_str(),
43 "mp3" | "wav" | "flac" | "ogg" | "oga" | "m4a" | "aac"
44 )
45 })
46}
47
48/// Boxed error; the engine has few failure modes and every one of them is fatal
49/// to the session, so a message is all a caller can act on.
50pub type Error = Box<dyn std::error::Error + Send + Sync>;
51pub type Result<T> = std::result::Result<T, Error>;
52
53#[cfg(test)]
54mod tests {
55 use std::path::Path;
56
57 #[test]
58 fn is_audio_admits_the_containers_the_decoder_reads() {
59 for name in [
60 "song.mp3", "a.WAV", "b.flac", "c.ogg", "d.oga", "e.m4a", "f.aac",
61 ] {
62 assert!(super::is_audio(Path::new(name)), "{name}");
63 }
64 // Video, projects, the formats with no pure-Rust decoder, and a file
65 // with no extension at all: all of them go elsewhere.
66 for name in [
67 "clip.mp4",
68 "take.MP4",
69 "cut.edith",
70 "x.opus",
71 "y.ac3",
72 "notes",
73 "mp3",
74 ] {
75 assert!(!super::is_audio(Path::new(name)), "{name}");
76 }
77 }
78}