1use std::path::PathBuf;
4
5#[derive(Debug)]
7#[non_exhaustive]
8pub enum VideoError {
9 Open {
11 path: PathBuf,
13 source: std::io::Error,
15 },
16
17 NothingPlayable,
22
23 V4l2 {
25 what: &'static str,
27 source: rustix::io::Errno,
29 },
30
31 UnsupportedFormat(u32),
33
34 NoFrames,
36
37 Drm {
39 what: &'static str,
41 source: std::io::Error,
43 },
44
45 NoPlane,
47}
48
49impl std::fmt::Display for VideoError {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 match self {
52 Self::Open { path, source } => {
53 write!(f, "could not open {}: {source}", path.display())
54 }
55 Self::NothingPlayable => f.write_str("no hardware decoder accepts any offered asset"),
56 Self::V4l2 { what, source } => write!(f, "V4L2 {what} failed: {source}"),
57 Self::UnsupportedFormat(format) => write!(
58 f,
59 "decoder produced unsupported pixel format {format:#010x}"
60 ),
61 Self::NoFrames => f.write_str(
62 "the stream produced no decoded frames — not an Annex-B elementary stream?",
63 ),
64 Self::Drm { what, source } => write!(f, "DRM {what} failed: {source}"),
65 Self::NoPlane => f.write_str("no DRM plane accepts the decoded format on this CRTC"),
66 }
67 }
68}
69
70impl std::error::Error for VideoError {
71 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
72 match self {
73 Self::Open { source, .. } | Self::Drm { source, .. } => Some(source),
74 Self::V4l2 { source, .. } => Some(source),
75 Self::NothingPlayable | Self::UnsupportedFormat(_) | Self::NoFrames | Self::NoPlane => {
76 None
77 }
78 }
79 }
80}
81
82impl VideoError {
83 pub(crate) fn v4l2(what: &'static str, source: rustix::io::Errno) -> Self {
84 Self::V4l2 { what, source }
85 }
86
87 pub(crate) fn drm(what: &'static str, source: impl Into<std::io::Error>) -> Self {
88 Self::Drm {
89 what,
90 source: source.into(),
91 }
92 }
93}