Skip to main content

SimpleFramePool

Struct SimpleFramePool 

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

A simple frame pool implementation with fixed capacity.

This pool stores a fixed number of frame buffers and reuses them during video decoding. When the pool is empty, callers must allocate new buffers directly.

§Thread Safety

This implementation uses a Mutex internally, making it safe to share across threads.

§Examples

use ff_decode::{VideoDecoder, SimpleFramePool};

// Create a pool with capacity for 32 frames (automatically initialized)
let pool = SimpleFramePool::new(32);

let decoder = VideoDecoder::open("video.mp4")?
    .frame_pool(pool)
    .build()?;

// Frames are acquired from the pool during decoding
for frame in decoder.frames().take(100) {
    let frame = frame?;
    // Process frame...
}

Implementations§

Source§

impl SimpleFramePool

Source

pub fn new(max_capacity: usize) -> Arc<Self>

Creates a new frame pool with the specified maximum capacity.

This function uses RAII (Resource Acquisition Is Initialization) pattern and automatically initializes the pool’s self-reference, eliminating the need for a separate initialization step.

§Arguments
  • max_capacity - Maximum number of buffers to keep in the pool. When the pool is full, returned buffers are dropped instead of being stored.
§Examples
use ff_decode::SimpleFramePool;
use std::sync::Arc;

// Create a pool for 32 frames - automatically initialized
let pool = SimpleFramePool::new(32);

// Use with decoder
let decoder = VideoDecoder::open("video.mp4")?
    .frame_pool(pool)
    .build()?;
Source

pub fn max_capacity(&self) -> usize

Returns the maximum capacity of this pool.

Source

pub fn available(&self) -> usize

Returns the current number of buffers available in the pool.

§Examples
use ff_decode::SimpleFramePool;

let pool = SimpleFramePool::new(32);
assert_eq!(pool.available(), 0); // Pool starts empty

Trait Implementations§

Source§

impl Debug for SimpleFramePool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FramePool for SimpleFramePool

Source§

fn acquire(&self, size: usize) -> Option<PooledBuffer>

Acquires a buffer of at least the specified size from the pool. Read more
Source§

fn release(&self, buffer: Vec<u8>)

Returns a buffer to the pool. Read more

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, 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.