pub struct BitReader<'a> { /* private fields */ }Expand description
MSB-first bit reader over a borrowed byte slice.
Implementations§
Source§impl<'a> BitReader<'a>
impl<'a> BitReader<'a>
Sourcepub fn total_bits(&self) -> usize
pub fn total_bits(&self) -> usize
Total number of payload bits in the reader.
Sourcepub fn bits_remaining(&self) -> usize
pub fn bits_remaining(&self) -> usize
Number of unread bits (saturating at zero).
Sourcepub fn byte_aligned(&self) -> bool
pub fn byte_aligned(&self) -> bool
True if the reader is currently byte-aligned.
Sourcepub fn align_to_byte(&mut self)
pub fn align_to_byte(&mut self)
Skip forward to the next byte boundary if not already aligned.
Sourcepub fn u(&mut self, n: u32) -> u32
pub fn u(&mut self, n: u32) -> u32
Read n bits MSB first into a u32. Past-the-end bits are 0.
n must be ≤ 32 (the upper limit covers every fixed-width
field used by H.264 / HEVC / AV1 OBU headers).
Sourcepub fn u64(&mut self, n: u32) -> u64
pub fn u64(&mut self, n: u32) -> u64
Read n bits MSB first into a u64 (for AV1’s 64-bit
reference_frame_id-class fields).
Sourcepub fn peek_bits(&self, n: u32) -> u32
pub fn peek_bits(&self, n: u32) -> u32
Peek the next n bits MSB-first without advancing bit_pos.
n must be ≤ 32. Past-the-end bits are zero, identical to
BitReader::u’s contract. Useful for codec parsers that need
to inspect a marker bit before deciding whether to commit to a
branch.
Sourcepub fn more_rbsp_data(&self) -> bool
pub fn more_rbsp_data(&self) -> bool
H.264 §7.2 / H.265 §7.2 / H.266 §7.2 more_rbsp_data().
Returns true if there is at least one more RBSP data bit
before the rbsp_trailing_bits() marker. The marker is a 1
bit (the rbsp_stop_one_bit) followed by zero or more 0
bits up to the next byte boundary, sitting at the end of the
RBSP. The algorithm: search forward from the current position
for any 1 bit after the next 1 — if we find one, the
next 1 was not the stop marker and there is more data.
Returns false once positioned at or past the stop bit, and
at end-of-stream.
Sourcepub fn read_rbsp_trailing_bits(&mut self) -> Result<(), BitstreamError>
pub fn read_rbsp_trailing_bits(&mut self) -> Result<(), BitstreamError>
H.264 §7.3.2.11 / H.265 §7.3.2.11 / H.266 §7.3.10
rbsp_trailing_bits(). Consumes a 1 (rbsp_stop_one_bit)
followed by zero or more 0 bits up to the next byte
boundary. Returns Err(InvalidData) if the next bit is not
1, if any of the padding bits before the boundary is not
0, or if the stream ends before the marker is found.
Sourcepub fn ue(&mut self) -> Result<u32, BitstreamError>
pub fn ue(&mut self) -> Result<u32, BitstreamError>
Unsigned Exp-Golomb (ue(v)). H.264 9.1 / H.265 9.2.
Returns an error if 32 or more leading zeros are seen: the
largest representable ue(v) value is u32::MAX - 1 (31 leading
zeros), so 32 leading zeros has no valid u32 value and the
1 << leadingZeros term would overflow.
Sourcepub fn se(&mut self) -> Result<i32, BitstreamError>
pub fn se(&mut self) -> Result<i32, BitstreamError>
Signed Exp-Golomb (se(v)). H.264 9.1.1 / H.265 9.2.2.