• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //! Errors that can happen in LibVDA.
6 
7 use std::error;
8 use std::fmt;
9 use std::fmt::Display;
10 
11 use super::format;
12 use crate::decode;
13 use crate::encode;
14 
15 #[derive(Debug)]
16 pub enum Error {
17     // Encode session error. The error code provided is specific
18     // to the implementation type (`VeaImplType`).
19     EncodeSessionFailure(i32),
20     EncodeSessionInitFailure(encode::Config),
21     GetCapabilitiesFailure,
22     InstanceInitFailure,
23     InvalidCapabilities(String),
24     LibVdaFailure(decode::Response),
25     ReadEventFailure(std::io::Error),
26     SessionIdAlreadyUsed(u32),
27     SessionInitFailure(format::Profile),
28     SessionNotFound(u32),
29     UnknownPixelFormat(u32),
30     UnknownProfile(i32),
31 }
32 
33 pub type Result<T> = std::result::Result<T, Error>;
34 
35 impl error::Error for Error {}
36 
37 impl Display for Error {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result38     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39         use self::Error::*;
40 
41         match self {
42             EncodeSessionFailure(e) => write!(f, "encode session error: {}", e),
43             EncodeSessionInitFailure(c) => {
44                 write!(f, "failed to initialize encode session with config {:?}", c)
45             }
46             GetCapabilitiesFailure => write!(f, "failed to get capabilities"),
47             InstanceInitFailure => write!(f, "failed to initialize VDA instance"),
48             InvalidCapabilities(e) => write!(f, "obtained capabilities are invalid: {}", e),
49             LibVdaFailure(e) => write!(f, "error happened in libvda: {}", e),
50             ReadEventFailure(e) => write!(f, "failed to read event: {}", e),
51             SessionInitFailure(p) => write!(f, "failed to initialize decode session with {:?}", p),
52             SessionIdAlreadyUsed(id) => write!(f, "session_id {} is already used", id),
53             SessionNotFound(id) => write!(f, "no session has session_id {}", id),
54             UnknownPixelFormat(p) => write!(f, "unknown pixel format: {}", p),
55             UnknownProfile(p) => write!(f, "unknown profile: {}", p),
56         }
57     }
58 }
59