forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

lib.rs113 lines, 3.9 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::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//! # Bit depth
22//!
23//! [`Frame::to_i420`] truncates a 10-bit (P010) surface to 8 bits, because a
24//! byte per sample is what the software path speaks. A 10-bit consumer must
25//! call [`Frame::to_i420_16`] instead — that is the lossless path that keeps
26//! all ten bits.
27//!
28//! Encoding is 10-bit too, for H.265 (Main10) and AV1: `EncoderConfig::ten_bit()` allocates P010
29//! surfaces and takes its pixels through [`Encoder::encode_16`] (or straight
30//! from a 10-bit [`Frame`], with no conversion at all). H.264 stays
31//! 8-bit here, because the profiles this crate configures for it
32//! are 8-bit.
33//!
34//! # Shape
35//!
36//! * [`params`] — the codec parameter buffers, converted to cros-libva's typed
37//! buffers.
38//! * [`dec`] — one stateless decoder per codec behind [`Decoder`]: H.264,
39//! HEVC, VP9 and AV1.
40//! * [`enc`] — H.264, HEVC and AV1 encoders: IDR + P GOPs, CQP/CBR/VBR/QVBR.
41//! * [`SurfacePool`] / [`Frame`] — surface recycling and pixel access.
42//!
43//! # Unsafe
44//!
45//! None. Every libva call goes through `ec-va`, which goes through cros-libva's
46//! safe wrappers, so this crate is `forbid(unsafe_code)`.
47//!
48//! # Panics
49//!
50//! None by contract. Every driver and bitstream fault is an [`Error`], because
51//! edith loads this path as a `dlopen`ed plugin whose fall back to software is
52//! only as good as that promise.
53
54#![forbid(unsafe_code)]
55#![deny(missing_docs)]
56
57#[cfg(target_os = "linux")]
58pub mod dec;
59#[cfg(target_os = "linux")]
60pub mod enc;
61pub mod error;
62#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
63pub(crate) mod dpb264;
64#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
65pub(crate) mod h264_common;
66pub(crate) mod level;
67pub(crate) mod rate;
68pub(crate) mod ref_slots;
69pub(crate) mod vkdec_vp9;
70pub(crate) mod hevc_dpb;
71pub mod hw;
72#[cfg(target_os = "linux")]
73pub mod frame;
74pub(crate) mod output;
75pub mod picture;
76#[cfg(target_os = "linux")]
77pub mod params;
78#[cfg(target_os = "linux")]
79pub mod pool;
80pub mod reset;
81pub mod types;
82pub(crate) mod vkdec264;
83pub(crate) mod vkdec265;
84pub(crate) mod vkdec_av1;
85
86#[cfg(target_os = "linux")]
87pub use dec::{Decoder, StreamInfo};
88#[cfg(target_os = "linux")]
89pub use enc::Encoder;
90pub use error::{Error, Result};
91#[cfg(target_os = "linux")]
92pub use ec_vk::{DmaBufFormat, DmaBufPlane};
93#[cfg(target_os = "linux")]
94pub use hw::{DmaBufFrame, DmaBufYuvFrame, dmabuf_modifiers, dup_fd};
95#[cfg(windows)]
96pub use hw::{D3d11Frame, D3d11Pool, d3d11_supported};
97pub use hw::{
98 Backend, Capability, CodecProfile, Direction, EncodeInput, HwDecoder, HwEncoder, RgbFrame,
99 RgbOrder, RgbOutput, capabilities,
100};
101#[cfg(target_os = "linux")]
102pub use frame::Frame;
103pub use output::HwPicture;
104pub use picture::{Colour, I420, I420_16, RgbPicture, i420_to_nv12, nv12_to_i420};
105#[cfg(target_os = "linux")]
106pub use picture::DmaBufPicture;
107#[cfg(target_os = "linux")]
108pub use pool::{PooledSurface, SurfacePool};
109pub use reset::{gpu_recently_reset, gpu_reset_epoch, report_gpu_reset};
110pub use types::{
111 Codec, CodedFrame, EncCodec, EncoderConfig, FrameMetadata, H264Profile, RateControlMode,
112 Tunings,
113};