forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB11603ecTahinli3 months ago110 commits

lib.rs93 lines, 3.2 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 scale;
18pub mod waveform;
19
20pub use audio::{
21 AacPacket, AacTrackParams, AudioChunk, AudioMeta, AudioProbe, AudioSession, StreamInfo,
22};
23pub use clock::PlaybackClock;
24pub use decode::{DecodeSession, Frame};
25pub use demux::{Codec, VideoMeta};
26pub use export::ExportHandle;
27pub use mux::{AudioParams, Mp4Muxer, VideoParams};
28pub use playback::PlaybackSession;
29pub use project::{Clip, Project};
30
31/// Whether a path names a standalone audio file -- a source with no picture,
32/// which belongs on the audio lane and nowhere else. Extension only, lowercased:
33/// the decoder is what really decides, but a front-end has to know which lane a
34/// dropped file may land on *before* anything is opened, and so does
35/// [`PlaybackSession::import`](playback::PlaybackSession::import).
36///
37/// Exactly the containers the engine's audio path reads (`audio::AudioSession`):
38/// no opus, ac3 or dts, for which no pure-Rust decoder exists -- those are
39/// refused by the same door that refuses a `.txt`, which is the honest answer.
40pub fn is_audio(path: &std::path::Path) -> bool {
41 path.extension().and_then(|e| e.to_str()).is_some_and(|e| {
42 matches!(
43 e.to_ascii_lowercase().as_str(),
44 "mp3" | "wav" | "flac" | "ogg" | "oga" | "m4a" | "aac"
45 )
46 })
47}
48
49/// The largest picture this engine composes onto, either way: 8K, which is where
50/// a per-frame buffer stops being a sane thing to allocate.
51pub const MAX_RESOLUTION: u32 = 7680;
52
53/// Whether a project resolution is a picture at all: not zero either way, and
54/// not past [`MAX_RESOLUTION`]. Both doors ask -- the keystroke
55/// ([`PlaybackSession::set_resolution`](playback::PlaybackSession::set_resolution))
56/// and the file ([`edith::load`]) -- so a hand-written `resolution` line cannot
57/// reach an allocation a keypress could not, which is how `4294967295` used to
58/// panic the open with a capacity overflow.
59pub fn is_resolution(width: u32, height: u32) -> bool {
60 (1..=MAX_RESOLUTION).contains(&width) && (1..=MAX_RESOLUTION).contains(&height)
61}
62
63/// Boxed error; the engine has few failure modes and every one of them is fatal
64/// to the session, so a message is all a caller can act on.
65pub type Error = Box<dyn std::error::Error + Send + Sync>;
66pub type Result<T> = std::result::Result<T, Error>;
67
68#[cfg(test)]
69mod tests {
70 use std::path::Path;
71
72 #[test]
73 fn is_audio_admits_the_containers_the_decoder_reads() {
74 for name in [
75 "song.mp3", "a.WAV", "b.flac", "c.ogg", "d.oga", "e.m4a", "f.aac",
76 ] {
77 assert!(super::is_audio(Path::new(name)), "{name}");
78 }
79 // Video, projects, the formats with no pure-Rust decoder, and a file
80 // with no extension at all: all of them go elsewhere.
81 for name in [
82 "clip.mp4",
83 "take.MP4",
84 "cut.edith",
85 "x.opus",
86 "y.ac3",
87 "notes",
88 "mp3",
89 ] {
90 assert!(!super::is_audio(Path::new(name)), "{name}");
91 }
92 }
93}