pub struct RateBuffer { /* private fields */ }Expand description
Rate buffer using leaky bucket model.
The buffer simulates an encoder’s output buffer:
- Bits are added when frames are encoded
- Bits are removed at a constant rate (target bitrate)
Implementations§
Source§impl RateBuffer
impl RateBuffer
Sourcepub fn new(capacity: u64, initial_fullness: f32) -> Self
pub fn new(capacity: u64, initial_fullness: f32) -> Self
Create a new rate buffer.
§Arguments
capacity- Buffer size in bitsinitial_fullness- Initial fill level as fraction (0.0-1.0)
Sourcepub fn add_bits(&mut self, bits: u64) -> u64
pub fn add_bits(&mut self, bits: u64) -> u64
Add bits to the buffer (frame encoded).
Returns the number of bits that overflowed (couldn’t fit).
Sourcepub fn remove_bits(&mut self, bits: u64) -> u64
pub fn remove_bits(&mut self, bits: u64) -> u64
Remove bits from the buffer (drain at target bitrate).
Returns the number of bits that underflowed (buffer went negative).
Sourcepub fn available_space(&self) -> u64
pub fn available_space(&self) -> u64
Get available space in bits.
Trait Implementations§
Source§impl Clone for RateBuffer
impl Clone for RateBuffer
Source§fn clone(&self) -> RateBuffer
fn clone(&self) -> RateBuffer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RateBuffer
impl Debug for RateBuffer
Auto Trait Implementations§
impl Freeze for RateBuffer
impl RefUnwindSafe for RateBuffer
impl Send for RateBuffer
impl Sync for RateBuffer
impl Unpin for RateBuffer
impl UnsafeUnpin for RateBuffer
impl UnwindSafe for RateBuffer
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
Mutably borrows from an owned value. Read more
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>
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 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>
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