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
55use bindings::*;
58use buffer::*;
59use config::*;
60use context::*;
61use generic_value::*;
62use picture::*;
63use surface::*;
64
65pub use bindings::{
66 VAEntrypoint, VAImage, VAImageFormat, VAProfile, VA_FOURCC_BGRA, VA_FOURCC_BGRX, VA_FOURCC_I420, VA_FOURCC_NV12,
67 VA_FOURCC_RGBA, VA_FOURCC_RGBX, VA_RT_FORMAT_RGB32, VA_RT_FORMAT_YUV420,
68};
69pub use codec::Codec;
70pub use color::{Color, Matrix};
71pub use display::{Display, DrmDeviceIterator, OpenDrmDisplayError};
72pub use image::{Image, ImageMut};
73pub use surface::{
74 DrmPrimeSurfaceDescriptor, DrmPrimeSurfaceDescriptorLayer, DrmPrimeSurfaceDescriptorObject, Surface,
75};
76pub use usage_hint::UsageHint;
77
78use std::num::NonZeroI32;
79
80#[derive(Debug)]
82pub struct VaError(NonZeroI32);
83
84impl VaError {
85 fn status(status: u32) -> Self {
88 Self(NonZeroI32::new(status as i32).expect("a failure status"))
89 }
90
91 pub fn va_status(&self) -> VAStatus {
93 self.0.get() as VAStatus
94 }
95}
96
97impl std::fmt::Display for VaError {
98 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99 use std::ffi::CStr;
100
101 let err_str = unsafe { CStr::from_ptr(bindings::va().vaErrorStr(self.0.get())) }
104 .to_str()
105 .unwrap();
106 f.write_str(err_str)
107 }
108}
109
110impl std::error::Error for VaError {}
111
112fn va_check(code: VAStatus) -> Result<(), VaError> {
117 match code as u32 {
118 bindings::VA_STATUS_SUCCESS => Ok(()),
119 _ => Err(VaError(unsafe { NonZeroI32::new_unchecked(code) })),
120 }
121}