pub struct CabacEncoder { /* private fields */ }Expand description
CABAC arithmetic encoder (H.265 §9.3.4.3).
Feed bins via encode_bin (context-modeled),
encode_bypass, and encode_terminate.
The final encode_terminate(1) (i.e. end_of_slice_segment_flag = 1) flushes
the engine; finish then returns the byte-aligned slice data.
Clone is what makes rate estimation possible: an encoder can copy the live
engine and contexts, code a candidate into the copy, read bit_len,
and throw it away without disturbing the real bitstream.
Implementations§
Source§impl CabacEncoder
impl CabacEncoder
Sourcepub fn encode_bin(&mut self, ctx: &mut CtxModel, bin: u32)
pub fn encode_bin(&mut self, ctx: &mut CtxModel, bin: u32)
Encode one context-modeled decision (§9.3.4.3.2), updating ctx.
Sourcepub fn encode_bypass(&mut self, bin: u32)
pub fn encode_bypass(&mut self, bin: u32)
Encode one equiprobable bin with no context (§9.3.4.3.4). Faster and used for sign bits, high-order coefficient bits, etc.
Sourcepub fn encode_bypass_bits(&mut self, value: u32, n: u32)
pub fn encode_bypass_bits(&mut self, value: u32, n: u32)
Encode n equiprobable bins from the low bits of value, MSB-first.
Sourcepub fn encode_terminate(&mut self, bin: u32)
pub fn encode_terminate(&mut self, bin: u32)
Encode a termination decision (§9.3.4.3.5). bin = 1 ends the slice and
flushes the engine; bin = 0 just renormalizes and coding continues.
Sourcepub fn probe(&self) -> Self
pub fn probe(&self) -> Self
The arithmetic state with an empty output buffer.
Rate-distortion decisions need to know what a candidate would cost, so
they encode it into a copy and read bit_len. Cloning
the whole encoder would copy every byte written so far, once per
candidate per level — quadratic in picture size. The bit count is a
difference, so the buffer can start empty as long as low, range and
the outstanding-bit count carry over.
Sourcepub fn bit_len(&self) -> usize
pub fn bit_len(&self) -> usize
Number of bits emitted so far (for rate estimation / debugging).
Sourcepub fn writer_mut(&mut self) -> &mut BitWriter
pub fn writer_mut(&mut self) -> &mut BitWriter
Direct access to the underlying bit writer. Only valid to use between a
flush (encode_terminate(1), as I_PCM does) and reinit
— e.g. to emit pcm_alignment_zero_bits and raw PCM samples that bypass
the arithmetic coder (H.265 §7.3.8.5 / §9.3.1).
Trait Implementations§
Source§impl Clone for CabacEncoder
impl Clone for CabacEncoder
Auto Trait Implementations§
impl Forget for CabacEncoder
impl Freeze for CabacEncoder
impl Move for CabacEncoder
impl RefUnwindSafe for CabacEncoder
impl Send for CabacEncoder
impl Sync for CabacEncoder
impl Unpin for CabacEncoder
impl UnsafeUnpin for CabacEncoder
impl UnwindSafe for CabacEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more