forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

error.rs76 lines, 2.3 KiBHistoryRawDownload
1//! Typed errors. Every libva failure becomes an [`Error::Va`] carrying the
2//! failing entry point, the raw status and libva's own description of it.
3
4use std::fmt;
5
6use cros_libva::VaError;
7
8/// Result alias used throughout the crate.
9pub type Result<T> = std::result::Result<T, Error>;
10
11/// Everything this crate can fail with.
12#[derive(Debug)]
13#[non_exhaustive]
14pub enum Error {
15 /// A libva entry point returned something other than `VA_STATUS_SUCCESS`.
16 Va {
17 /// The libva entry point that failed, e.g. `"vaBeginPicture"`.
18 op: &'static str,
19 /// The raw `VAStatus`.
20 status: i32,
21 /// libva's description of `status`.
22 message: String,
23 },
24 /// A DRM render node could not be opened as a VA display.
25 Drm {
26 /// The node that was tried.
27 path: String,
28 /// Why it failed.
29 message: String,
30 },
31 /// No usable `/dev/dri/renderD*` VA display exists.
32 NoDevice,
33 /// libva returned a value this crate cannot interpret.
34 Protocol(String),
35}
36
37impl Error {
38 /// Wrap a cros-libva error with the libva entry point it came from.
39 pub(crate) fn va(op: &'static str, e: &VaError) -> Self {
40 Error::Va {
41 op,
42 status: e.va_status(),
43 message: e.to_string(),
44 }
45 }
46
47 /// The raw `VAStatus`, if this error came from libva.
48 pub fn status(&self) -> Option<i32> {
49 match self {
50 Error::Va { status, .. } => Some(*status),
51 _ => None,
52 }
53 }
54}
55
56/// Turn a cros-libva result into ours, tagging the entry point.
57pub fn va_ok<T>(op: &'static str, r: std::result::Result<T, VaError>) -> Result<T> {
58 r.map_err(|e| Error::va(op, &e))
59}
60
61impl fmt::Display for Error {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 match self {
64 Error::Va {
65 op,
66 status,
67 message,
68 } => write!(f, "{op} failed: {message} (VAStatus 0x{status:08x})"),
69 Error::Drm { path, message } => write!(f, "opening DRM node {path}: {message}"),
70 Error::NoDevice => write!(f, "no usable /dev/dri/renderD* VA display"),
71 Error::Protocol(what) => write!(f, "libva returned an uninterpretable value: {what}"),
72 }
73 }
74}
75
76impl std::error::Error for Error {}