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
impl FfmpegBuffer
Sourcepub fn copy_from_slice(bytes: &[u8]) -> Option<Self>
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.
Sourcepub const fn empty() -> Self
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.
Sourcepub const fn offset(&self) -> usize
pub const fn offset(&self) -> usize
Byte offset of this view’s start inside the underlying buffer.
Sourcepub fn as_ptr(&self) -> *const u8
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.
Sourcepub const fn as_av_buffer_ref(&self) -> *const AVBufferRef
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.
Sourcepub fn ptr_eq(&self, other: &Self) -> bool
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.
Sourcepub fn try_clone(&self) -> Option<Self>
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
impl AsRef<[u8]> for FfmpegBuffer
Source§impl Clone for FfmpegBuffer
impl Clone for FfmpegBuffer
Source§fn clone(&self) -> Self
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)
fn clone_from(&mut self, source: &Self)
source. Read more