1#![allow(
11 dead_code,
12 unused_imports,
13 unexpected_cfgs,
14 mismatched_lifetime_syntaxes,
15 clippy::all,
16 reason = "vendored from discord/cros-libva and discord/cros-codecs; kept close to upstream so fixes port cleanly"
17)]
18#![cfg_attr(
21 not(target_os = "linux"),
22 allow(
23 rustdoc::broken_intra_doc_links,
24 reason = "the items these docs link to are Linux-only"
25 )
26)]
27#![cfg(target_os = "linux")]
28
29mod bindings;
30mod buffer;
31mod config;
32mod context;
33mod display;
34mod generic_value;
35mod image;
36mod picture;
37mod pool;
38mod surface;
39mod usage_hint;
40
41mod codec;
45pub mod decode;
46pub mod encode;
47
48mod color;
52pub mod dmabuf;
53pub mod vpp;
54
55#[cfg(test)]
56mod testing;
57
58use bindings::*;
61use buffer::*;
62use config::*;
63use context::*;
64use generic_value::*;
65use picture::*;
66use surface::*;
67
68pub use bindings::{
69 VAEntrypoint, VAImage, VAImageFormat, VAProfile, VA_FOURCC_BGRA, VA_FOURCC_BGRX, VA_FOURCC_I420, VA_FOURCC_NV12,
70 VA_FOURCC_RGBA, VA_FOURCC_RGBX, VA_RT_FORMAT_RGB32, VA_RT_FORMAT_YUV420,
71};
72pub use codec::Codec;
73pub use color::{Color, Matrix};
74pub use display::{Display, DrmDeviceIterator, OpenDrmDisplayError};
75pub use image::{Image, ImageMut};
76pub use surface::{
77 DrmPrimeSurfaceDescriptor, DrmPrimeSurfaceDescriptorLayer, DrmPrimeSurfaceDescriptorObject, Surface,
78};
79pub use usage_hint::UsageHint;
80
81use std::num::NonZeroI32;
82
83#[derive(Debug)]
85pub struct VaError(NonZeroI32);
86
87impl VaError {
88 fn status(status: u32) -> Self {
91 Self(NonZeroI32::new(status as i32).expect("a failure status"))
92 }
93
94 pub fn va_status(&self) -> VAStatus {
96 self.0.get() as VAStatus
97 }
98}
99
100impl std::fmt::Display for VaError {
101 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
102 use std::ffi::CStr;
103
104 let err_str = unsafe { CStr::from_ptr(bindings::va().vaErrorStr(self.0.get())) }
107 .to_str()
108 .unwrap();
109 f.write_str(err_str)
110 }
111}
112
113impl std::error::Error for VaError {}
114
115fn va_check(code: VAStatus) -> Result<(), VaError> {
120 match code as u32 {
121 bindings::VA_STATUS_SUCCESS => Ok(()),
122 _ => Err(VaError(unsafe { NonZeroI32::new_unchecked(code) })),
123 }
124}