use std::path::PathBuf;
#[derive(Debug)]
#[non_exhaustive]
pub enum VideoError {
Open {
path: PathBuf,
source: std::io::Error,
},
NothingPlayable,
V4l2 {
what: &'static str,
source: rustix::io::Errno,
},
UnsupportedFormat(u32),
NoFrames,
Drm {
what: &'static str,
source: std::io::Error,
},
NoPlane,
}
impl std::fmt::Display for VideoError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Open { path, source } => {
write!(f, "could not open {}: {source}", path.display())
}
Self::NothingPlayable => f.write_str("no hardware decoder accepts any offered asset"),
Self::V4l2 { what, source } => write!(f, "V4L2 {what} failed: {source}"),
Self::UnsupportedFormat(format) => write!(
f,
"decoder produced unsupported pixel format {format:#010x}"
),
Self::NoFrames => f.write_str(
"the stream produced no decoded frames — not an Annex-B elementary stream?",
),
Self::Drm { what, source } => write!(f, "DRM {what} failed: {source}"),
Self::NoPlane => f.write_str("no DRM plane accepts the decoded format on this CRTC"),
}
}
}
impl std::error::Error for VideoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Open { source, .. } | Self::Drm { source, .. } => Some(source),
Self::V4l2 { source, .. } => Some(source),
Self::NothingPlayable | Self::UnsupportedFormat(_) | Self::NoFrames | Self::NoPlane => {
None
}
}
}
}
impl VideoError {
pub(crate) fn v4l2(what: &'static str, source: rustix::io::Errno) -> Self {
Self::V4l2 { what, source }
}
pub(crate) fn drm(what: &'static str, source: impl Into<std::io::Error>) -> Self {
Self::Drm {
what,
source: source.into(),
}
}
}