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
impl SimpleRateController
Sourcepub fn new(config: SimpleRateControlConfig) -> Self
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.
Sourcepub fn target_bits_per_frame(&self) -> u64
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.
Sourcepub fn allocate_frame_bits(&mut self, complexity: f32) -> u32
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.
Sourcepub fn record_frame(&mut self, actual_bits: u32, complexity: f32)
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 toallocate_frame_bitsfor this frame.
This updates internal accounting (VBV fullness, bit budget, complexity history) so that subsequent allocations are informed by history.
Sourcepub fn vbv_status(&self) -> f64
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.
Sourcepub fn is_keyframe(&self) -> bool
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.
Sourcepub fn stats(&self) -> SimpleRateControlStats
pub fn stats(&self) -> SimpleRateControlStats
Snapshot of accumulated statistics.
Auto Trait Implementations§
impl Freeze for SimpleRateController
impl RefUnwindSafe for SimpleRateController
impl Send for SimpleRateController
impl Sync for SimpleRateController
impl Unpin for SimpleRateController
impl UnsafeUnpin for SimpleRateController
impl UnwindSafe for SimpleRateController
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> 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