forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB7cdaf34Tahinli3 months ago29 commits

lib.rs41 lines, 1.7 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, unescape_rbsp};
24pub use pps::Pps;
25pub use slice::{DeblockControl, SliceHeader, SliceType};
26pub use sps::{Hrd, ScalingLists, Sps, Vui};
27
28/// True when there is at least one more RBSP syntax element before the
29/// `rbsp_stop_one_bit` (spec 7.2 `more_rbsp_data()`).
30///
31/// `data` is the full unescaped RBSP the reader walks; the stop bit is the
32/// last set bit of the last non-zero byte.
33pub fn more_rbsp_data(reader: &ec_core::BitReader<'_>, data: &[u8]) -> bool {
34 // Find the rbsp_stop_one_bit from the tail.
35 let Some(last_nonzero) = data.iter().rposition(|&b| b != 0) else {
36 return false; // all zero: corrupt, but by definition nothing left
37 };
38 let byte = data[last_nonzero];
39 let stop_bit_index = last_nonzero as u64 * 8 + (7 - byte.trailing_zeros() as u64);
40 reader.bit_position() < stop_bit_index
41}