|
| 1 | +use std::error::Error; |
1 | 2 | use std::ffi::{c_int, c_uint};
|
| 3 | +use std::fmt::{self, Display, Formatter}; |
2 | 4 |
|
3 | 5 | use strum::FromRepr;
|
4 | 6 |
|
| 7 | +/// Error enum return by various `rav1d` operations. |
5 | 8 | #[derive(Clone, Copy, PartialEq, Eq, FromRepr, Debug)]
|
6 | 9 | #[repr(u8)]
|
7 | 10 | #[non_exhaustive]
|
8 | 11 | pub enum Rav1dError {
|
9 | 12 | /// This represents a generic `rav1d` error.
|
10 |
| - /// It has nothing to do with the other `errno`-based ones |
11 |
| - /// (and that's why it's not all caps like the other ones). |
| 13 | + /// It has nothing to do with the other `errno`-based ones. |
12 | 14 | ///
|
13 | 15 | /// Normally `EPERM = 1`, but `dav1d` never uses `EPERM`,
|
14 | 16 | /// but does use `-1`, as opposed to the normal `DAV1D_ERR(E*)`.
|
15 | 17 | ///
|
16 |
| - /// Also Note that this forces `0` to be the niche, |
| 18 | + /// Also note that this forces `0` to be the niche, |
17 | 19 | /// which is more optimal since `0` is no error for [`Dav1dResult`].
|
18 |
| - EGeneric = 1, |
19 |
| - |
20 |
| - ENOENT = libc::ENOENT as u8, |
21 |
| - EIO = libc::EIO as u8, |
22 |
| - EAGAIN = libc::EAGAIN as u8, |
23 |
| - ENOMEM = libc::ENOMEM as u8, |
24 |
| - EINVAL = libc::EINVAL as u8, |
25 |
| - ERANGE = libc::ERANGE as u8, |
26 |
| - ENOPROTOOPT = libc::ENOPROTOOPT as u8, |
| 20 | + Other = 1, |
| 21 | + |
| 22 | + /// No entity. |
| 23 | + /// |
| 24 | + /// No Sequence Header OBUs were found in the buffer. |
| 25 | + NoEntity = libc::ENOENT as u8, |
| 26 | + |
| 27 | + /// Try again. |
| 28 | + /// |
| 29 | + /// If this is returned by [`rav1d_send_data`], then there |
| 30 | + /// are decoded frames pending that first have to be retrieved via [`rav1d_get_picture`] |
| 31 | + /// before processing any further pending data. |
| 32 | + /// |
| 33 | + /// If this is returned by [`rav1d_get_picture`], then no decoded frames are pending |
| 34 | + /// currently and more data needs to be sent to the decoder. |
| 35 | + TryAgain = libc::EAGAIN as u8, |
| 36 | + |
| 37 | + /// Out of memory. |
| 38 | + /// |
| 39 | + /// Not enough memory is currently available for performing this operation. |
| 40 | + OutOfMemory = libc::ENOMEM as u8, |
| 41 | + |
| 42 | + /// Invalid argument. |
| 43 | + /// |
| 44 | + /// One of the arguments passed to the function, including the bitstream, is invalid. |
| 45 | + InvalidArgument = libc::EINVAL as u8, |
| 46 | + |
| 47 | + /// Out of range. |
| 48 | + /// |
| 49 | + /// The frame size is larger than the limit. |
| 50 | + OutOfRange = libc::ERANGE as u8, |
| 51 | + |
| 52 | + /// Unsupported bitstream. |
| 53 | + /// |
| 54 | + /// The provided bitstream is not supported by `rav1d`. |
| 55 | + UnsupportedBitstream = libc::ENOPROTOOPT as u8, |
| 56 | +} |
| 57 | + |
| 58 | +impl Rav1dError { |
| 59 | + pub const fn as_str(&self) -> &'static str { |
| 60 | + match self { |
| 61 | + Rav1dError::TryAgain => "Try again", |
| 62 | + Rav1dError::InvalidArgument => "Invalid argument", |
| 63 | + Rav1dError::OutOfMemory => "Not enough memory available", |
| 64 | + Rav1dError::UnsupportedBitstream => "Unsupported bitstream", |
| 65 | + Rav1dError::Other => "Other error", |
| 66 | + Rav1dError::NoEntity => "No sequence header found", |
| 67 | + Rav1dError::OutOfRange => "Out of range", |
| 68 | + } |
| 69 | + } |
27 | 70 | }
|
28 | 71 |
|
| 72 | +impl Display for Rav1dError { |
| 73 | + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { |
| 74 | + write!(fmt, "{}", self.as_str()) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +impl Error for Rav1dError {} |
| 79 | + |
29 | 80 | pub type Rav1dResult<T = ()> = Result<T, Rav1dError>;
|
30 | 81 |
|
31 | 82 | #[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
0 commit comments