forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits

lib.rs77 lines, 2.6 KiBHistoryRawDownload
1//! Compatibility shim: the `symphonia-core` 0.6 surface edith consumes, over
2//! [`ec_core`] and (through the `symphonia` shim) [`ec_probe`].
3//!
4//! This is the vocabulary half — parameters, packets, units, the reader and
5//! decoder traits. The registries that build them live in the `symphonia`
6//! shim, and the AAC decoder seat in `symphonia-codec-aac`, exactly as the
7//! incumbent splits them.
8//!
9//! Written from the signatures edith calls (`crates/engine/src/audio.rs`
10//! lines 36-53 and their call sites) and the crate's published documentation.
11//! No symphonia source was read: the incumbent is MPL-2.0 and this family is
12//! MIT OR Apache-2.0.
13//!
14//! **Not the whole crate.** What edith does not call is not here: metadata
15//! revisions, the sample-buffer zoo, `Signal`/`AudioBuffer` generics, the
16//! `CodecRegistry` builder API. Each is a small addition when something needs
17//! it; none is a silent omission.
18
19#![forbid(unsafe_code)]
20
21pub mod codecs;
22pub mod formats;
23pub mod io;
24pub mod meta;
25pub mod packet;
26pub mod units;
27
28use std::fmt;
29
30/// The incumbent's error type, in the shape callers match on.
31#[derive(Debug)]
32pub enum Error {
33 /// Underlying I/O failure.
34 IoError(std::io::Error),
35 /// The bitstream is malformed.
36 DecodeError(String),
37 /// A capability this build does not have, naming what and why.
38 Unsupported(String),
39 /// A seek that could not be served.
40 SeekError(String),
41 /// End of stream.
42 ResetRequired,
43}
44
45/// `Result` with this crate's [`Error`].
46pub type Result<T> = std::result::Result<T, Error>;
47
48impl fmt::Display for Error {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 match self {
51 Error::IoError(e) => write!(f, "io error: {e}"),
52 Error::DecodeError(e) => write!(f, "decode error: {e}"),
53 Error::Unsupported(e) => write!(f, "unsupported: {e}"),
54 Error::SeekError(e) => write!(f, "seek error: {e}"),
55 Error::ResetRequired => write!(f, "decoder reset required"),
56 }
57 }
58}
59
60impl std::error::Error for Error {}
61
62impl From<std::io::Error> for Error {
63 fn from(e: std::io::Error) -> Error {
64 Error::IoError(e)
65 }
66}
67
68impl From<ec_core::Error> for Error {
69 fn from(e: ec_core::Error) -> Error {
70 match e {
71 ec_core::Error::Io(io) => Error::IoError(io),
72 ec_core::Error::Eof | ec_core::Error::NeedMore => Error::ResetRequired,
73 ec_core::Error::Unsupported { .. } => Error::Unsupported(e.to_string()),
74 ec_core::Error::Corrupt { .. } => Error::DecodeError(e.to_string()),
75 }
76 }
77}