1use crate::vp9::bits::BitError;
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Error {
6 Bitstream(BitError),
7 Invalid(String),
8 Unsupported(String),
9 MissingReference(String),
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Error::Bitstream(e) => write!(f, "bitstream error: {e}"),
16 Error::Invalid(s) => write!(f, "invalid bitstream: {s}"),
17 Error::Unsupported(s) => write!(f, "unsupported: {s}"),
18 Error::MissingReference(s) => write!(f, "missing reference frame: {s}"),
19 }
20 }
21}
22
23impl std::error::Error for Error {}
24
25impl From<BitError> for Error {
26 fn from(e: BitError) -> Self {
27 Error::Bitstream(e)
28 }
29}
30
31impl From<Error> for crate::media::Error {
32 fn from(e: Error) -> Self {
33 match e {
34 Error::Unsupported(s) => crate::media::Error::Unsupported(format!("vp9: {s}")),
35 other => crate::media::Error::Invalid(format!("vp9: {other}")),
36 }
37 }
38}
39
40pub type Result<T> = std::result::Result<T, Error>;
41
42macro_rules! ensure {
43 ($cond:expr, $($arg:tt)+) => {
44 if !$cond {
45 return Err($crate::vp9::error::Error::Invalid(format!($($arg)+)));
46 }
47 };
48}
49pub(crate) use ensure;