Skip to main content

SimpleRateController

Struct SimpleRateController 

Source
pub struct SimpleRateController { /* private fields */ }
Expand description

A simplified, self-contained rate controller.

§Usage

use oximedia_codec::rate_control::{SimpleRateControlConfig, SimpleRateController};

let cfg = SimpleRateControlConfig::abr(4000, 30.0, (1920, 1080));
let mut rc = SimpleRateController::new(cfg);

for i in 0..300_u32 {
    let complexity = 0.5_f32;                     // supplied by analyser
    let bits = rc.allocate_frame_bits(complexity);
    rc.record_frame(bits, complexity);
}

let stats = rc.stats();
assert!(stats.frames_encoded == 300);

Implementations§

Source§

impl SimpleRateController

Source

pub fn new(config: SimpleRateControlConfig) -> Self

Create a new controller from config.

The VBV buffer starts at 50 % fullness for CBR mode and at 0 for all other modes.

Source

pub fn target_bits_per_frame(&self) -> u64

Return the pre-computed target bits-per-frame for the current mode.

CRF mode always returns 0 because bit budget is implicitly derived from the QP rather than a bitrate target.

Source

pub fn allocate_frame_bits(&mut self, complexity: f32) -> u32

Decide how many bits to allocate for the next frame given its complexity estimate (any non-negative float, relative scale).

The return value is a recommendation in bits; the caller feeds the actual encoded size back via record_frame.

Source

pub fn record_frame(&mut self, actual_bits: u32, complexity: f32)

Record the outcome of encoding a frame.

  • actual_bits: real encoded size in bits.
  • complexity: the same complexity estimate passed to allocate_frame_bits for this frame.

This updates internal accounting (VBV fullness, bit budget, complexity history) so that subsequent allocations are informed by history.

Source

pub fn vbv_status(&self) -> f64

Current VBV buffer fullness: 0.0 = empty, 1.0 = full.

For non-CBR modes this always returns 0.0.

Source

pub fn is_keyframe(&self) -> bool

Return true if the current frame index is a keyframe position.

Uses the keyframe_interval from the configuration. Frame index 0 (the very first frame) is always considered a keyframe.

Source

pub fn stats(&self) -> SimpleRateControlStats

Snapshot of accumulated statistics.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.