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 while encoding or decoding. 6 7 use std::fmt; 8 9 use crate::virtio::resource_bridge::ResourceBridgeError; 10 use crate::virtio::video::control::CtrlType; 11 use crate::virtio::video::encoder::EncoderError; 12 13 /// An error indicating something went wrong while encoding or decoding. 14 /// Unlike `virtio::video::Error`, `VideoError` is not fatal for `Worker`. 15 #[derive(Debug)] 16 pub enum VideoError { 17 /// The encoder implementation returned an error. 18 EncoderImpl(EncoderError), 19 /// Invalid argument. 20 InvalidArgument, 21 /// Invalid operation 22 InvalidOperation, 23 /// Invalid stream ID is specified. 24 InvalidStreamId(u32), 25 /// Invalid resource ID is specified. 26 InvalidResourceId { stream_id: u32, resource_id: u32 }, 27 /// Invalid parameters are specified. 28 InvalidParameter, 29 /// Failed to get a resource FD via resource_bridge. 30 ResourceBridgeFailure(ResourceBridgeError), 31 /// Unsupported control type is specified. 32 UnsupportedControl(CtrlType), 33 /// `libvda` returned an error. 34 VdaError(libvda::Error), 35 /// `libvda` returned a failure response. 36 VdaFailure(libvda::decode::Response), 37 } 38 39 impl fmt::Display for VideoError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result40 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 41 use self::VideoError::*; 42 match self { 43 InvalidArgument => write!(f, "invalid argument"), 44 InvalidOperation => write!(f, "invalid operation"), 45 InvalidStreamId(id) => write!(f, "invalid stream ID {}", id), 46 InvalidResourceId { 47 stream_id, 48 resource_id, 49 } => write!( 50 f, 51 "invalid resource ID {} for stream {}", 52 resource_id, stream_id 53 ), 54 InvalidParameter => write!(f, "invalid parameter"), 55 ResourceBridgeFailure(id) => write!(f, "failed to get resource FD for id {}", id), 56 UnsupportedControl(ctrl_type) => write!(f, "unsupported control: {:?}", ctrl_type), 57 VdaError(e) => write!(f, "error occurred in libvda: {}", e), 58 VdaFailure(r) => write!(f, "failed while processing a requst in VDA: {}", r), 59 EncoderImpl(e) => write!(f, "error occurred in the encoder implementation: {}", e), 60 } 61 } 62 } 63 64 impl From<libvda::Error> for VideoError { from(error: libvda::Error) -> Self65 fn from(error: libvda::Error) -> Self { 66 VideoError::VdaError(error) 67 } 68 } 69 70 impl std::error::Error for VideoError {} 71 72 pub type VideoResult<T> = Result<T, VideoError>; 73