pub struct FramePool { /* private fields */ }Expand description
Frame pool for reusing frame allocations.
Supports both typed VideoFrame/AudioFrame recycling and a raw
byte-buffer free-list that can be pre-allocated via FramePoolConfig.
Implementations§
Source§impl FramePool
impl FramePool
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new frame pool with the given capacity for typed frames.
Sourcepub fn with_config(config: FramePoolConfig) -> Self
pub fn with_config(config: FramePoolConfig) -> Self
Create a pool pre-populated according to config.
config.pre_allocate zeroed buffers of config.frame_bytes bytes are
placed in the internal free-list immediately, so the first
pre_allocate calls to Self::acquire_raw return without any heap
allocation.
Sourcepub fn acquire_raw(&mut self) -> Vec<u8> ⓘ
pub fn acquire_raw(&mut self) -> Vec<u8> ⓘ
Acquire a raw byte buffer from the free-list, or allocate a new one.
If frame_bytes was set in the config, the returned buffer is exactly
that size. Otherwise a zero-length buffer is returned for newly
allocated entries — callers should resize as needed.
Sourcepub fn release_raw(&mut self, buf: Vec<u8>)
pub fn release_raw(&mut self, buf: Vec<u8>)
Return a raw byte buffer to the free-list for reuse.
Silently drops the buffer when the free-list is at capacity.
Sourcepub fn pre_allocated_count(&self) -> usize
pub fn pre_allocated_count(&self) -> usize
Number of raw buffers currently available in the free-list.
Sourcepub fn get_video_frame(
&mut self,
format: PixelFormat,
width: u32,
height: u32,
) -> VideoFrame
pub fn get_video_frame( &mut self, format: PixelFormat, width: u32, height: u32, ) -> VideoFrame
Get a video frame from the pool or create a new one.
Sourcepub fn return_video_frame(&mut self, frame: VideoFrame)
pub fn return_video_frame(&mut self, frame: VideoFrame)
Return a video frame to the pool.
Sourcepub fn get_audio_frame(
&mut self,
format: SampleFormat,
sample_rate: u32,
channels: ChannelLayout,
) -> AudioFrame
pub fn get_audio_frame( &mut self, format: SampleFormat, sample_rate: u32, channels: ChannelLayout, ) -> AudioFrame
Get an audio frame from the pool or create a new one.
Sourcepub fn return_audio_frame(&mut self, frame: AudioFrame)
pub fn return_audio_frame(&mut self, frame: AudioFrame)
Return an audio frame to the pool.
Sourcepub fn video_frame_count(&self) -> usize
pub fn video_frame_count(&self) -> usize
Get the number of video frames in the pool.
Sourcepub fn audio_frame_count(&self) -> usize
pub fn audio_frame_count(&self) -> usize
Get the number of audio frames in the pool.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FramePool
impl RefUnwindSafe for FramePool
impl Send for FramePool
impl Sync for FramePool
impl Unpin for FramePool
impl UnsafeUnpin for FramePool
impl UnwindSafe for FramePool
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