forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB214cdf2Tahinli3 months ago821 commits

lib.rs44 lines, 1.8 KiBHistoryRawDownload
1//! H.264 (ITU-T Rec. H.264 / ISO 14496-10) bitstream syntax.
2//!
3//! Parsing only — no reconstruction. Shared by the software decoder
4//! (`ec-h264`) and the stateless hardware path, so every struct is a plain
5//! value type whose derived geometry (macroblock counts, crop rectangle,
6//! bit depths) is computed once at parse time; a decoder feeds these fields
7//! straight into flat per-picture arrays without re-deriving anything per
8//! macroblock.
9//!
10//! Layout of the crate follows the spec's own structure:
11//! - [`nal`]: Annex B framing + emulation-prevention removal (7.3.1, 7.4.1)
12//! - [`sps`]: sequence parameter set incl. VUI and HRD (7.3.2.1, E.1)
13//! - [`pps`]: picture parameter set incl. the High-profile tail (7.3.2.2)
14//! - [`slice`]: slice header for I/SI/P/SP/B (7.3.3)
15
16#![forbid(unsafe_code)]
17
18pub mod nal;
19pub mod pps;
20pub mod slice;
21pub mod sps;
22
23pub use nal::{AnnexBIter, NalHeader, NalUnitType, escape_rbsp, unescape_rbsp};
24pub use pps::Pps;
25pub use slice::{
26 DeblockControl, DecRefPicMarking, Mmco, PredWeightTable, RefPicListMod, SliceHeader, SliceType,
27 WeightEntry,
28};
29pub use sps::{BitstreamRestriction, Hrd, ScalingLists, Sps, Vui};
30
31/// True when there is at least one more RBSP syntax element before the
32/// `rbsp_stop_one_bit` (spec 7.2 `more_rbsp_data()`).
33///
34/// `data` is the full unescaped RBSP the reader walks; the stop bit is the
35/// last set bit of the last non-zero byte.
36pub fn more_rbsp_data(reader: &ec_core::BitReader<'_>, data: &[u8]) -> bool {
37 // Find the rbsp_stop_one_bit from the tail.
38 let Some(last_nonzero) = data.iter().rposition(|&b| b != 0) else {
39 return false; // all zero: corrupt, but by definition nothing left
40 };
41 let byte = data[last_nonzero];
42 let stop_bit_index = last_nonzero as u64 * 8 + (7 - byte.trailing_zeros() as u64);
43 reader.bit_position() < stop_bit_index
44}