Skip to main content

UnboundObjectPool

Struct UnboundObjectPool 

Source
pub struct UnboundObjectPool<T: Send> { /* private fields */ }
Expand description

A growable pool of reusable Ts — lets a frame-producing element (see crate::elements::SwDecoder, crate::elements::Scaler) hand out the same buffers over and over instead of allocating a fresh one (and freeing the old one) every single frame. Reusing an already-allocated ffmpeg_next::frame::Video also lets ffmpeg’s own avcodec_receive_frame/sws_scale skip their internal buffer allocation when the reused frame already matches — not just savings on this crate’s side.

Has no capacity wait or “pool exhausted” result: UnboundObjectPool::get pops a previously-returned item if one’s available, or calls init to build a fresh one on the spot otherwise. The pool therefore grows to whatever depth turns out to be needed (e.g. however many frames a downstream Queue lets pile up at once). As with any caller-provided closure, a panic inside init still propagates.

Deliberately a private implementation detail owned by whichever element produces the frames (a struct field, initialized once in that element’s own constructor) — not something the Pipeline holds or passes around. Nothing outside that one element needs to know a pool is involved at all; sharing the frames themselves downstream still goes through the ordinary Arc<UnboundObjectPoolRef<T>> in crate::buffer::MediaBuffer::Video.

Implementations§

Source§

impl<T: Send + Sync> UnboundObjectPool<T>

Source

pub fn new( size: usize, init: impl Fn() -> T + Send + Sync + 'static, release: impl Fn(&mut T) + Send + Sync + 'static, ) -> UnboundObjectPool<T>

Pre-fills with size items built via init (0 is fine — the pool still grows on demand, it just starts out empty and pays for the first size-ish get() calls up front instead of amortized over the stream). release runs on an item right before it goes back into the pool (e.g. to reset state) — a no-op closure is fine if there’s nothing to reset, which is the common case for a video frame: the next consume overwrites every pixel (and every piece of metadata it cares about, like pts) before anyone downstream sees it again.

Source

pub fn get(&self) -> UnboundObjectPoolRef<T>

Never waits for a pooled item and has no exhaustion error — see the type docs. If the pool is empty, this calls the supplied init closure directly.

Source

pub fn size(&self) -> usize

How many items are currently sitting in the pool, unused. Mainly for tests/diagnostics — nothing in this crate depends on this number for correctness.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more