Skip to main content

CabacEncoder

Struct CabacEncoder 

Source
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

Source

pub fn new() -> Self

A freshly initialized engine (§9.3.2.5): range 510, low 0.

Source

pub fn encode_bin(&mut self, ctx: &mut CtxModel, bin: u32)

Encode one context-modeled decision (§9.3.4.3.2), updating ctx.

Source

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.

Source

pub fn encode_bypass_bits(&mut self, value: u32, n: u32)

Encode n equiprobable bins from the low bits of value, MSB-first.

Source

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.

Source

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.

Source

pub fn bit_len(&self) -> usize

Number of bits emitted so far (for rate estimation / debugging).

Source

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).

Source

pub fn reinit(&mut self)

Re-initialize the arithmetic engine (range 510, low 0), keeping the already-emitted bytes. The decoder does the same after reading an I_PCM CU’s samples, so the two stay in lockstep across the PCM interruption.

Source

pub fn finish(self) -> Vec<u8> ⓘ

Finish and return the byte-aligned coded bytes. Call after the terminating encode_terminate(1).

Trait Implementations§

Source§

impl Clone for CabacEncoder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for CabacEncoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.