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