forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB03dc6e9Tahinli3 months ago178 commits

lib.rs60 lines, 2.2 KiBHistoryRawDownload
1//! Stateless VA-API video decoding and encoding.
2//!
3//! "Stateless" is the VA-API decode model, not a description of this crate: the
4//! driver decodes one picture at a time and knows nothing between pictures, so
5//! everything a codec spreads across frames — the decoded picture buffer,
6//! reference lists, picture order counts, reference slot updates — is kept
7//! here, in Rust, and handed to the driver per picture. That is the whole job.
8//!
9//! ```no_run
10//! use ec_hw::{Codec, Decoder};
11//!
12//! let display = ec_va::Display::open()?;
13//! let mut decoder = Decoder::new(&display, Codec::H264)?;
14//! # let annex_b_access_unit: &[u8] = &[];
15//! decoder.decode(annex_b_access_unit, 0)?;
16//! while let Some(frame) = decoder.next_frame() {
17//! let planes = frame.to_i420()?; // or frame.export_prime() for zero copy
18//! }
19//! # Ok::<(), ec_hw::Error>(())
20//! ```
21//!
22//! # Shape
23//!
24//! * [`params`] — the `#[repr(C)]` codec parameter buffers, each checked
25//! against the system headers by a `const` assertion.
26//! * [`dec`] — one stateless decoder per codec behind [`Decoder`].
27//! * [`enc`] — H.264 and HEVC encoders, and an opt-in AV1 one.
28//! * [`SurfacePool`] / [`Frame`] — surface recycling and pixel access.
29//!
30//! # Unsafe
31//!
32//! This crate is not `forbid(unsafe_code)`: handing a parameter struct to the
33//! driver and walking a coded-buffer segment list are both pointer work that
34//! `ec-va` cannot type for us. Both are confined to two functions —
35//! [`params::param_buffer`] and `enc::coded_bytes` — and everything else,
36//! including every codec's parameter derivation, is safe Rust.
37//!
38//! # Panics
39//!
40//! None by contract. Every driver and bitstream fault is an [`Error`], because
41//! edith loads this path as a `dlopen`ed plugin whose fall back to software is
42//! only as good as that promise.
43
44#![deny(missing_docs)]
45#![deny(unsafe_op_in_unsafe_fn)]
46
47pub mod dec;
48pub mod enc;
49pub mod error;
50pub mod frame;
51pub mod params;
52pub mod pool;
53
54pub use dec::{Codec, Decoder, StreamInfo};
55pub use enc::{
56 CodedFrame, EncCodec, Encoder, EncoderConfig, FrameMetadata, RateControlMode, Tunings,
57};
58pub use error::{Error, Result};
59pub use frame::{Frame, I420, I420_16, i420_to_nv12, nv12_to_i420};
60pub use pool::{PooledSurface, SurfacePool};