Skip to main content

FfmpegBytes

Struct FfmpegBytes 

Source
pub struct FfmpegBytes(/* private fields */);
Expand description

The bytes every packet and frame this crate produces are carried in.

Owned, Send + Sync, 'static, and clone-is-a-refcount-bump: the core’s D-seat amputation contract, satisfied. Nothing inside reaches back into libavcodec.

§Why it is opaque

The obvious spelling was the bare Arc<[u8]> this type wraps, and 0.9.0’s first cut used it. It is opaque for one reason, and the reason is not aesthetics:

Arc<[u8]> is one storage strategy, and it is not going to be the only one. Every exit currently allocates, copies, and frees per frame; a decode loop at 4K is asking the global allocator for eight megabytes sixty times a second and handing it back. The recorded answer is a plane pool — reusable slabs handed out at the boundary and returned when the last consumer drops them (issue #35). A pooled slab is a different carrier with the same contract: still owned, still Send + Sync, still refcount-cloned, still holding no FFmpeg lifetime.

If the carrier were Arc<[u8]> in the public aliases, adding the pool would change the type of every frame and every packet in the crate — a breaking release for a change consumers cannot observe. Behind this newtype it is a new arm of a private enum: no signature moves, no consumer recompiles differently, and the AsRef<[u8]> a consumer actually programs against is unchanged. That extension point is this type’s justification for existing.

The enum has exactly one arm today. It gains the second when the pool is built and not before — this codebase does not carry members nothing can produce.

Implementations§

Source§

impl FfmpegBytes

Source

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

Copies bytes into a fresh carrier.

The copy site. Every exit in this crate lands here or on Self::empty, so “one copy at the boundary” is a property of one constructor rather than a promise thirty call sites keep — and it is the one place a future pooled arm has to be taught about.

Public because the reverse direction needs it: a consumer building a packet to feed back into a decoder has bytes and needs a carrier, and the alternative is an opaque type nobody outside this crate can construct.

A zero-length copy lands on the shared empty allocation rather than minting its own.

Source

pub fn empty() -> Self

The zero-length carrier, shared.

Placeholder plane slots and payload-less packets are frequent — a video frame allocates four slots and populates one to three of them — and each would otherwise be its own Arc header allocation. One empty allocation for the process, cloned by refcount, instead.

Source

pub fn as_slice(&self) -> &[u8]

The bytes, as a slice.

The same answer AsRef::as_ref gives; inherent so a caller reaching through a &FfmpegBytes does not have to name the trait.

Source

pub fn len(&self) -> usize

Number of bytes carried.

Source

pub fn is_empty(&self) -> bool

true when this carries no bytes.

Source

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

true when both handles name the same allocation — a clone of one another, rather than two copies that happen to be equal.

The property the amputation contract is really about: Clone on a message is a refcount bump. PartialEq answers a different question (do these hold the same bytes), and a test that wants to prove the clone did not copy has to ask this one.

Trait Implementations§

Source§

impl AsRef<[u8]> for FfmpegBytes

Source§

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

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

impl Clone for FfmpegBytes

Source§

fn clone(&self) -> FfmpegBytes

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FfmpegBytes

Source§

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

Length only, never the bytes.

A derived Debug would print a decoded 4K plane one integer at a time; this type is reached from the derived Debug of every packet, frame and side-data entry in the crate, so the terse form is the one that keeps those useful. Mirrors what FfmpegBuffer’s own hand-written Debug did through 0.8.

Source§

impl Default for FfmpegBytes

Source§

fn default() -> FfmpegBytes

Returns the “default value” for a type. Read more
Source§

impl Eq for FfmpegBytes

Source§

impl Hash for FfmpegBytes

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FfmpegBytes

Source§

fn eq(&self, other: &FfmpegBytes) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FfmpegBytes

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