//! Stateless VA-API video decoding and encoding. //! //! "Stateless" is the VA-API decode model, not a description of this crate: the //! driver decodes one picture at a time and knows nothing between pictures, so //! everything a codec spreads across frames — the decoded picture buffer, //! reference lists, picture order counts, reference slot updates — is kept //! here, in Rust, and handed to the driver per picture. That is the whole job. //! //! ```no_run //! use ec_hw::{Codec, Decoder}; //! //! let display = ec_va::open()?; //! let mut decoder = Decoder::new(&display, Codec::H264)?; //! # let annex_b_access_unit: &[u8] = &[]; //! decoder.decode(annex_b_access_unit, 0)?; //! while let Some(frame) = decoder.next_frame() { //! let planes = frame.to_i420()?; // or frame.export_prime() for zero copy //! } //! # Ok::<(), ec_hw::Error>(()) //! ``` //! # Bit depth //! //! [`Frame::to_i420`] truncates a 10-bit (P010) surface to 8 bits, because a //! byte per sample is what the software path speaks. A 10-bit consumer must //! call [`Frame::to_i420_16`] instead — that is the lossless path that keeps //! all ten bits. //! //! Encoding is 10-bit too, for H.265 (Main10) and AV1: `EncoderConfig::ten_bit()` allocates P010 //! surfaces and takes its pixels through [`Encoder::encode_16`] (or straight //! from a 10-bit [`Frame`], with no conversion at all). H.264 stays //! 8-bit here, because the profiles this crate configures for it //! are 8-bit. //! //! # Shape //! //! * [`params`] — the codec parameter buffers, converted to cros-libva's typed //! buffers. //! * [`dec`] — one stateless decoder per codec behind [`Decoder`]: H.264, //! HEVC, VP9 and AV1. //! * [`enc`] — H.264, HEVC and AV1 encoders: IDR + P GOPs, CQP/CBR/VBR/QVBR. //! * [`SurfacePool`] / [`Frame`] — surface recycling and pixel access. //! //! # Unsafe //! //! None. Every libva call goes through `ec-va`, which goes through cros-libva's //! safe wrappers, so this crate is `forbid(unsafe_code)`. //! //! # Panics //! //! None by contract. Every driver and bitstream fault is an [`Error`], because //! edith loads this path as a `dlopen`ed plugin whose fall back to software is //! only as good as that promise. #![forbid(unsafe_code)] #![deny(missing_docs)] #[cfg(target_os = "linux")] pub mod dec; #[cfg(target_os = "linux")] pub mod enc; pub mod error; #[cfg_attr(not(target_os = "linux"), allow(dead_code))] pub(crate) mod dpb264; #[cfg_attr(not(target_os = "linux"), allow(dead_code))] pub(crate) mod h264_common; pub(crate) mod level; pub(crate) mod rate; pub(crate) mod ref_slots; pub(crate) mod vkdec_vp9; pub(crate) mod hevc_dpb; pub mod hw; #[cfg(target_os = "linux")] pub mod frame; pub(crate) mod output; pub mod picture; #[cfg(target_os = "linux")] pub mod params; #[cfg(target_os = "linux")] pub mod pool; pub mod reset; pub mod types; pub(crate) mod vkdec264; pub(crate) mod vkdec265; pub(crate) mod vkdec_av1; #[cfg(target_os = "linux")] pub use dec::{Decoder, StreamInfo}; #[cfg(target_os = "linux")] pub use enc::Encoder; pub use error::{Error, Result}; #[cfg(target_os = "linux")] pub use ec_vk::{DmaBufFormat, DmaBufPlane}; #[cfg(target_os = "linux")] pub use hw::{DmaBufFrame, DmaBufYuvFrame, dmabuf_modifiers, dup_fd}; #[cfg(windows)] pub use hw::{D3d11Frame, D3d11Pool, d3d11_supported}; pub use hw::{ Backend, Capability, CodecProfile, Direction, EncodeInput, HwDecoder, HwEncoder, RgbFrame, RgbOrder, RgbOutput, capabilities, }; #[cfg(target_os = "linux")] pub use frame::Frame; pub use output::HwPicture; pub use picture::{Colour, I420, I420_16, RgbPicture, i420_to_nv12, nv12_to_i420}; #[cfg(target_os = "linux")] pub use picture::DmaBufPicture; #[cfg(target_os = "linux")] pub use pool::{PooledSurface, SurfacePool}; pub use reset::{gpu_recently_reset, gpu_reset_epoch, report_gpu_reset}; pub use types::{ Codec, CodedFrame, EncCodec, EncoderConfig, FrameMetadata, H264Profile, RateControlMode, Tunings, };