]>
Commit | Line | Data |
---|---|---|
1 | // Copyright 2022 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 | use crate::bindings; | |
6 | ||
7 | /// Return status. | |
8 | pub type VAResult<T> = Result<T, VAError>; | |
9 | ||
10 | /// Non-successful return values of `VAStatus`. | |
11 | #[derive(Clone, Copy, Debug, PartialEq)] | |
12 | #[repr(u32)] | |
13 | pub enum VAError { | |
14 | /// Current operation has failed. | |
15 | OperationFailed = bindings::constants::VA_STATUS_ERROR_OPERATION_FAILED, | |
16 | /// Allocation failed. | |
17 | AllocationFailed = bindings::constants::VA_STATUS_ERROR_ALLOCATION_FAILED, | |
18 | /// Invalid display ID. | |
19 | InvalidDisplay = bindings::constants::VA_STATUS_ERROR_INVALID_DISPLAY, | |
20 | /// Invalid configuration. | |
21 | InvalidConfig = bindings::constants::VA_STATUS_ERROR_INVALID_CONFIG, | |
22 | /// Invalid context. | |
23 | InvalidContext = bindings::constants::VA_STATUS_ERROR_INVALID_CONTEXT, | |
24 | /// Invalid surface ID. | |
25 | InvalidSurface = bindings::constants::VA_STATUS_ERROR_INVALID_SURFACE, | |
26 | /// Invalid buffer. | |
27 | InvalidBuffer = bindings::constants::VA_STATUS_ERROR_INVALID_BUFFER, | |
28 | /// Invalid image. | |
29 | InvalidImage = bindings::constants::VA_STATUS_ERROR_INVALID_IMAGE, | |
30 | /// Invalid subpicture. | |
31 | InvalidSubpicture = bindings::constants::VA_STATUS_ERROR_INVALID_SUBPICTURE, | |
32 | /// Requested attribute is not supported. | |
33 | AttrNotSupported = bindings::constants::VA_STATUS_ERROR_ATTR_NOT_SUPPORTED, | |
34 | /// Maximum number of allowed elements has been exceeded. | |
35 | MaxNumExceeded = bindings::constants::VA_STATUS_ERROR_MAX_NUM_EXCEEDED, | |
36 | /// Unsupported codec profile. | |
37 | UnsupportedProfile = bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_PROFILE, | |
38 | /// Unsupported entrypoint. | |
39 | UnsupportedEntrypoint = bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT, | |
40 | /// Unsupported RT format. | |
41 | UnsupportedRTFormat = bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT, | |
42 | /// Unsupported buffer type. | |
43 | UnsupportedBuffertype = bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE, | |
44 | /// Surface is still being worked on. | |
45 | SurfaceBusy = bindings::constants::VA_STATUS_ERROR_SURFACE_BUSY, | |
46 | /// Requested flag is not supported. | |
47 | FlagNotSupported = bindings::constants::VA_STATUS_ERROR_FLAG_NOT_SUPPORTED, | |
48 | /// Invalid parameter. | |
49 | InvalidParameter = bindings::constants::VA_STATUS_ERROR_INVALID_PARAMETER, | |
50 | /// Requested resolution is not supported. | |
51 | ResolutionNotSupported = bindings::constants::VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED, | |
52 | /// Unimplemented feature. | |
53 | Unimplemented = bindings::constants::VA_STATUS_ERROR_UNIMPLEMENTED, | |
54 | /// Surface is still being displayed. | |
55 | SurfaceInDisplaying = bindings::constants::VA_STATUS_ERROR_SURFACE_IN_DISPLAYING, | |
56 | /// Invalid image format. | |
57 | InvalidImageFormat = bindings::constants::VA_STATUS_ERROR_INVALID_IMAGE_FORMAT, | |
58 | /// Generic decoding error. | |
59 | DecodingError = bindings::constants::VA_STATUS_ERROR_DECODING_ERROR, | |
60 | /// Generic encoding error. | |
61 | EncodingError = bindings::constants::VA_STATUS_ERROR_ENCODING_ERROR, | |
62 | /** | |
63 | * An invalid/unsupported value was supplied. | |
64 | * | |
65 | * This is a catch-all error code for invalid or unsupported values. | |
66 | * e.g. value exceeding the valid range, invalid type in the context | |
67 | * of generic attribute values. | |
68 | */ | |
69 | InvalidValue = bindings::constants::VA_STATUS_ERROR_INVALID_VALUE, | |
70 | /// An unsupported filter was supplied. | |
71 | UnsupportedFilter = bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_FILTER, | |
72 | /// An invalid filter chain was supplied. | |
73 | InvalidFilterChain = bindings::constants::VA_STATUS_ERROR_INVALID_FILTER_CHAIN, | |
74 | /// Indicate HW busy (e.g. run multiple encoding simultaneously). | |
75 | HWBusy = bindings::constants::VA_STATUS_ERROR_HW_BUSY, | |
76 | /// An unsupported memory type was supplied. | |
77 | UnsupportedMemoryType = bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE, | |
78 | /// Indicate allocated buffer size is not enough for input or output | |
79 | NotEnoughBuffer = bindings::constants::VA_STATUS_ERROR_NOT_ENOUGH_BUFFER, | |
80 | /// Operation has timed out. | |
81 | Timedout = bindings::constants::VA_STATUS_ERROR_TIMEDOUT, | |
82 | /// Unknown error. | |
83 | Unknown = bindings::constants::VA_STATUS_ERROR_UNKNOWN, | |
84 | } | |
85 | ||
86 | impl std::fmt::Display for VAError { | |
87 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
88 | write!(f, "{:?}", self) | |
89 | } | |
90 | } | |
91 | ||
92 | pub(crate) trait ConvertStatus { | |
93 | fn check(self) -> VAResult<()>; | |
94 | } | |
95 | ||
96 | impl ConvertStatus for bindings::VAStatus { | |
97 | fn check(self) -> VAResult<()> { | |
98 | match self as u32 { | |
99 | bindings::constants::VA_STATUS_SUCCESS => Ok(()), | |
100 | bindings::constants::VA_STATUS_ERROR_OPERATION_FAILED => Err(VAError::OperationFailed), | |
101 | bindings::constants::VA_STATUS_ERROR_ALLOCATION_FAILED => Err(VAError::AllocationFailed), | |
102 | bindings::constants::VA_STATUS_ERROR_INVALID_DISPLAY => Err(VAError::InvalidDisplay), | |
103 | bindings::constants::VA_STATUS_ERROR_INVALID_CONFIG => Err(VAError::InvalidConfig), | |
104 | bindings::constants::VA_STATUS_ERROR_INVALID_CONTEXT => Err(VAError::InvalidContext), | |
105 | bindings::constants::VA_STATUS_ERROR_INVALID_SURFACE => Err(VAError::InvalidSurface), | |
106 | bindings::constants::VA_STATUS_ERROR_INVALID_BUFFER => Err(VAError::InvalidBuffer), | |
107 | bindings::constants::VA_STATUS_ERROR_INVALID_IMAGE => Err(VAError::InvalidImage), | |
108 | bindings::constants::VA_STATUS_ERROR_INVALID_SUBPICTURE => Err(VAError::InvalidSubpicture), | |
109 | bindings::constants::VA_STATUS_ERROR_ATTR_NOT_SUPPORTED => Err(VAError::AttrNotSupported), | |
110 | bindings::constants::VA_STATUS_ERROR_MAX_NUM_EXCEEDED => Err(VAError::MaxNumExceeded), | |
111 | bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_PROFILE => Err(VAError::UnsupportedProfile), | |
112 | bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT => Err(VAError::UnsupportedEntrypoint), | |
113 | bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT => Err(VAError::UnsupportedRTFormat), | |
114 | bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE => Err(VAError::UnsupportedBuffertype), | |
115 | bindings::constants::VA_STATUS_ERROR_SURFACE_BUSY => Err(VAError::SurfaceBusy), | |
116 | bindings::constants::VA_STATUS_ERROR_FLAG_NOT_SUPPORTED => Err(VAError::FlagNotSupported), | |
117 | bindings::constants::VA_STATUS_ERROR_INVALID_PARAMETER => Err(VAError::InvalidParameter), | |
118 | bindings::constants::VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED => Err(VAError::ResolutionNotSupported), | |
119 | bindings::constants::VA_STATUS_ERROR_UNIMPLEMENTED => Err(VAError::Unimplemented), | |
120 | bindings::constants::VA_STATUS_ERROR_SURFACE_IN_DISPLAYING => Err(VAError::SurfaceInDisplaying), | |
121 | bindings::constants::VA_STATUS_ERROR_INVALID_IMAGE_FORMAT => Err(VAError::InvalidImageFormat), | |
122 | bindings::constants::VA_STATUS_ERROR_DECODING_ERROR => Err(VAError::DecodingError), | |
123 | bindings::constants::VA_STATUS_ERROR_ENCODING_ERROR => Err(VAError::EncodingError), | |
124 | bindings::constants::VA_STATUS_ERROR_INVALID_VALUE => Err(VAError::InvalidValue), | |
125 | bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_FILTER => Err(VAError::UnsupportedFilter), | |
126 | bindings::constants::VA_STATUS_ERROR_INVALID_FILTER_CHAIN => Err(VAError::InvalidFilterChain), | |
127 | bindings::constants::VA_STATUS_ERROR_HW_BUSY => Err(VAError::HWBusy), | |
128 | bindings::constants::VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE => Err(VAError::UnsupportedMemoryType), | |
129 | bindings::constants::VA_STATUS_ERROR_NOT_ENOUGH_BUFFER => Err(VAError::NotEnoughBuffer), | |
130 | bindings::constants::VA_STATUS_ERROR_TIMEDOUT => Err(VAError::Timedout), | |
131 | _ => Err(VAError::Unknown), | |
132 | } | |
133 | } | |
134 | } |