pub struct RawFrameCache { /* private fields */ }Expand description
A cache that stores raw pixel byte buffers (e.g. decoded video frames) keyed by frame number.
When the cache reaches RAW_FRAME_CACHE_CAPACITY entries the least-recently
used frame is evicted before inserting the new one.
§Example
use oximedia_edit::render::RawFrameCache;
let mut cache = RawFrameCache::new(4);
let data = cache.get_or_render(0, || vec![0u8; 1024]);
assert_eq!(data.len(), 1024);Implementations§
Source§impl RawFrameCache
impl RawFrameCache
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new cache with the given capacity (clamped to at least 1).
Sourcepub fn get_or_render(
&mut self,
frame_num: u64,
render_fn: impl FnOnce() -> Vec<u8>,
) -> &[u8] ⓘ
pub fn get_or_render( &mut self, frame_num: u64, render_fn: impl FnOnce() -> Vec<u8>, ) -> &[u8] ⓘ
Return a reference to the cached bytes for frame_num, rendering and
inserting them via render_fn if not already present.
The rendered bytes are stored in the cache; on subsequent calls the same
reference is returned without invoking render_fn.
When the cache is full the oldest frame is evicted first (LRU by insertion order).
Sourcepub fn get(&self, frame_num: u64) -> Option<&[u8]>
pub fn get(&self, frame_num: u64) -> Option<&[u8]>
Return a reference to the cached bytes for frame_num without rendering.
Returns None if the frame is not in the cache.
Sourcepub fn insert(&mut self, frame_num: u64, data: Vec<u8>)
pub fn insert(&mut self, frame_num: u64, data: Vec<u8>)
Explicitly insert pre-rendered bytes for frame_num.
If the frame already exists it is replaced. If the cache is full the oldest frame is evicted.
Sourcepub fn invalidate(&mut self, frame_num: u64)
pub fn invalidate(&mut self, frame_num: u64)
Invalidate (remove) the cache entry for frame_num, if present.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RawFrameCache
impl RefUnwindSafe for RawFrameCache
impl Send for RawFrameCache
impl Sync for RawFrameCache
impl Unpin for RawFrameCache
impl UnsafeUnpin for RawFrameCache
impl UnwindSafe for RawFrameCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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