Skip to main content

FramePool

Trait FramePool 

Source
pub trait FramePool:
    Send
    + Sync
    + Debug {
    // Required method
    fn acquire(&self, size: usize) -> Option<PooledBuffer>;

    // Provided method
    fn release(&self, _buffer: Vec<u8>) { ... }
}
Expand description

A trait for frame buffer pooling.

Implementing this trait allows custom memory management strategies for decoded video frames. This is useful for reducing allocation pressure during real-time video playback.

§Thread Safety

Implementations must be Send + Sync to allow sharing across threads.

§Example Implementation

use ff_common::{FramePool, PooledBuffer};
use std::sync::{Arc, Mutex};

struct SimplePool {
    buffers: Mutex<Vec<Vec<u8>>>,
    buffer_size: usize,
}

impl FramePool for SimplePool {
    fn acquire(&self, size: usize) -> Option<PooledBuffer> {
        // Implementation...
        None
    }
}

Required Methods§

Source

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

Acquires a buffer of at least the specified size from the pool.

§Arguments
  • size - The minimum required buffer size in bytes.
§Returns

Returns Some(PooledBuffer) if a buffer is available, or None if the pool is exhausted. When None is returned, the decoder will allocate a new buffer directly.

§Thread Safety

This method may be called from multiple threads concurrently.

Provided Methods§

Source

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

Returns a buffer to the pool.

This method is called automatically when a PooledBuffer is dropped. The default implementation does nothing (the buffer is simply dropped).

§Arguments
  • buffer - The buffer data to return to the pool.

Implementors§