1#![allow(dead_code, unused_imports, unexpected_cfgs, mismatched_lifetime_syntaxes)]
14#![allow(clippy::all)]
15
16mod bindings;
17pub mod buffer;
18mod config;
19mod context;
20mod display;
21mod generic_value;
22mod image;
23mod picture;
24mod surface;
25mod usage_hint;
26
27pub mod bitstream_utils;
30pub mod codec;
31pub mod decode;
32pub mod encode;
33
34pub mod color;
38pub mod dmabuf;
39pub mod vpp;
40
41pub use bindings::_VADRMPRIMESurfaceDescriptor__bindgen_ty_1 as VADRMPRIMESurfaceDescriptorObject;
42pub use bindings::_VADRMPRIMESurfaceDescriptor__bindgen_ty_2 as VADRMPRIMESurfaceDescriptorLayer;
43pub use bindings::*;
44pub use buffer::*;
45pub use color::{Color, Matrix};
46pub use config::*;
47pub use context::*;
48pub use display::*;
49pub use generic_value::*;
50pub use image::*;
51pub use picture::*;
52pub use surface::*;
53pub use usage_hint::*;
54
55#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
57pub struct Resolution {
58 pub width: u32,
59 pub height: u32,
60}
61
62impl Resolution {
63 pub fn can_contain(&self, other: Self) -> bool {
65 self.width >= other.width && self.height >= other.height
66 }
67
68 pub fn get_area(&self) -> usize {
69 (self.width as usize) * (self.height as usize)
70 }
71}
72
73impl From<(u32, u32)> for Resolution {
74 fn from(value: (u32, u32)) -> Self {
75 Self {
76 width: value.0,
77 height: value.1,
78 }
79 }
80}
81
82impl From<Resolution> for (u32, u32) {
83 fn from(value: Resolution) -> Self {
84 (value.width, value.height)
85 }
86}
87
88use std::num::NonZeroI32;
89
90#[derive(Debug)]
92pub struct VaError(NonZeroI32);
93
94impl VaError {
95 pub fn va_status(&self) -> VAStatus {
97 self.0.get() as VAStatus
98 }
99}
100
101impl std::fmt::Display for VaError {
102 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
103 use std::ffi::CStr;
104
105 let err_str = unsafe { CStr::from_ptr(bindings::va().vaErrorStr(self.0.get())) }
108 .to_str()
109 .unwrap();
110 f.write_str(err_str)
111 }
112}
113
114impl std::error::Error for VaError {}
115
116fn va_check(code: VAStatus) -> Result<(), VaError> {
121 match code as u32 {
122 bindings::VA_STATUS_SUCCESS => Ok(()),
123 _ => Err(VaError(unsafe { NonZeroI32::new_unchecked(code) })),
124 }
125}