forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust381.5 MiBb8521ccTahinli11 hours ago4437 commits

error.rs68 lines, 2.0 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 /// No usable `/dev/dri/renderD*` VA display exists.
25 NoDevice,
26 /// libva returned a value this crate cannot interpret.
27 Protocol(String),
28}
29
30impl Error {
31 /// Wrap a cros-libva error with the libva entry point it came from.
32 pub(crate) fn va(op: &'static str, e: &VaError) -> Self {
33 Error::Va {
34 op,
35 status: e.va_status(),
36 message: e.to_string(),
37 }
38 }
39
40 /// The raw `VAStatus`, if this error came from libva.
41 pub fn status(&self) -> Option<i32> {
42 match self {
43 Error::Va { status, .. } => Some(*status),
44 _ => None,
45 }
46 }
47}
48
49/// Turn a cros-libva result into ours, tagging the entry point.
50pub fn va_ok<T>(op: &'static str, r: std::result::Result<T, VaError>) -> Result<T> {
51 r.map_err(|e| Error::va(op, &e))
52}
53
54impl fmt::Display for Error {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 match self {
57 Error::Va {
58 op,
59 status,
60 message,
61 } => write!(f, "{op} failed: {message} (VAStatus 0x{status:08x})"),
62 Error::NoDevice => write!(f, "no usable /dev/dri/renderD* VA display"),
63 Error::Protocol(what) => write!(f, "libva returned an uninterpretable value: {what}"),
64 }
65 }
66}
67
68impl std::error::Error for Error {}