Skip to main content

FfmpegBuffer

Struct FfmpegBuffer 

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

Refcounted view onto a contiguous byte range inside an AVBufferRef.

Holds one reference to the buffer. The view (offset + length) carves out a sub-region, which is what lets several planes of one allocation — NV12’s data[1] == data[0] + y_size — each be their own carrier at their own offset, every one bumping the same refcount.

§Lifetime, stated plainly

This carrier keeps FFmpeg’s buffer alive, which is the point and also the catch: a frame held is a pool slot held. A decoder whose pool is exhausted blocks or fails, so a consumer that parks view frames in a queue is a consumer that stalls its own decoder. Read in place, drop, decode on. See the contract for the tradeoff table and for why graph traffic belongs on the owned lane.

Implementations§

Source§

impl FfmpegBuffer

Source

pub fn copy_from_slice(bytes: &[u8]) -> Option<Self>

Allocates a fresh refcounted buffer and copies bytes into it.

The view lane copies here, and it has to. Not every byte FFmpeg hands over lives in an AVBufferRef: subtitle rect text, AVFrameSideData payloads and a palette plane are plain allocations with no refcount to share. A carrier over them has to own something, so it owns a copy — and the lane stays honest by saying so rather than pretending the whole road is zero-copy.

None when the allocation fails.

Source

pub const fn empty() -> Self

The empty carrier: no buffer, no bytes, no allocation.

Infallible and const, which is the point — it is what an unpopulated plane slot holds, and eight of them per frame is not a place to put an allocator.

Source

pub const fn len(&self) -> usize

Bytes visible through this view.

Source

pub const fn is_empty(&self) -> bool

Whether the view is zero bytes long.

Source

pub const fn offset(&self) -> usize

Byte offset of this view’s start inside the underlying buffer.

Source

pub fn as_ptr(&self) -> *const u8

Start of the view. Valid for Self::len bytes while self lives.

A dangling-but-aligned pointer when the view is empty, so a caller must consult len before reading — the same contract NonNull::dangling keeps.

Source

pub const fn as_av_buffer_ref(&self) -> *const AVBufferRef

The underlying AVBufferRef, borrowed — null for the empty carrier.

Points at the whole buffer, not this view’s sub-region, and is *const on purpose: a shared borrow must not become an aliased write. Do not av_buffer_unref it — self still owns that reference.

Source

pub fn ptr_eq(&self, other: &Self) -> bool

Whether two carriers view the same underlying allocation.

The proof a clone shared rather than copied, and the proof two planes of one frame really do share one buffer.

Compares the AVBuffer behind the reference, not the reference itself: av_buffer_ref mints a new AVBufferRef around the same shared object, so two carriers that genuinely share have different AVBufferRef pointers and the same buffer.

Source

pub fn try_clone(&self) -> Option<Self>

Fallible Clone::clone: None on allocation failure instead of a panic.

Trait Implementations§

Source§

impl AsRef<[u8]> for FfmpegBuffer

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for FfmpegBuffer

Source§

fn clone(&self) -> Self

One refcount bump. Panics on allocation failure; see FfmpegBuffer::try_clone for the fallible road.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FfmpegBuffer

Source§

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

Shape, not contents: a carrier can be megabytes, and a Debug that prints them is a Debug nobody can use.

Source§

impl Drop for FfmpegBuffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for FfmpegBuffer

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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