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 use bindings::_VADRMPRIMESurfaceDescriptor__bindgen_ty_1 as VADRMPRIMESurfaceDescriptorObject;
35pub use bindings::_VADRMPRIMESurfaceDescriptor__bindgen_ty_2 as VADRMPRIMESurfaceDescriptorLayer;
36pub use bindings::*;
37pub use buffer::*;
38pub use config::*;
39pub use context::*;
40pub use display::*;
41pub use generic_value::*;
42pub use image::*;
43pub use picture::*;
44pub use surface::*;
45pub use usage_hint::*;
46
47#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
49pub struct Resolution {
50 pub width: u32,
51 pub height: u32,
52}
53
54impl Resolution {
55 pub fn can_contain(&self, other: Self) -> bool {
57 self.width >= other.width && self.height >= other.height
58 }
59
60 pub fn get_area(&self) -> usize {
61 (self.width as usize) * (self.height as usize)
62 }
63}
64
65impl From<(u32, u32)> for Resolution {
66 fn from(value: (u32, u32)) -> Self {
67 Self {
68 width: value.0,
69 height: value.1,
70 }
71 }
72}
73
74impl From<Resolution> for (u32, u32) {
75 fn from(value: Resolution) -> Self {
76 (value.width, value.height)
77 }
78}
79
80use std::num::NonZeroI32;
81
82#[derive(Debug)]
84pub struct VaError(NonZeroI32);
85
86impl VaError {
87 pub fn va_status(&self) -> VAStatus {
89 self.0.get() as VAStatus
90 }
91}
92
93impl std::fmt::Display for VaError {
94 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 use std::ffi::CStr;
96
97 let err_str = unsafe { CStr::from_ptr(bindings::va().vaErrorStr(self.0.get())) }
100 .to_str()
101 .unwrap();
102 f.write_str(err_str)
103 }
104}
105
106impl std::error::Error for VaError {}
107
108fn va_check(code: VAStatus) -> Result<(), VaError> {
113 match code as u32 {
114 bindings::VA_STATUS_SUCCESS => Ok(()),
115 _ => Err(VaError(unsafe { NonZeroI32::new_unchecked(code) })),
116 }
117}