Skip to main content

CMSampleBuffer

Struct CMSampleBuffer 

Source
pub struct CMSampleBuffer(/* private fields */);
Available on crate feature cm only.
Expand description

Owned reference to a CoreMedia CMSampleBufferRef.

Cloning increments the underlying refcount via CFRetain; dropping releases via CFRelease. The pointer is opaque to safe Rust — accessor methods on this type are the only sanctioned way to inspect it.

Implementations§

Source§

impl CMSampleBuffer

Source

pub const unsafe fn from_ptr(ptr: *mut c_void) -> Self

Wrap a raw CMSampleBufferRef without bumping its refcount or checking for NULL.

§Safety

The caller must ensure ptr is a valid CMSampleBufferRef retained at +1 (the wrapper will release on drop). For NULL-tolerant construction prefer Self::from_raw.

Source

pub fn from_raw(ptr: *mut c_void) -> Option<Self>

Wrap a raw CMSampleBufferRef without bumping its refcount.

Use this when the caller has just received a +1 retained pointer (e.g. a Swift Unmanaged.passRetained(...).toOpaque()). The returned CMSampleBuffer will release the pointer when dropped.

Returns None for a NULL pointer.

Source

pub unsafe fn from_raw_retained(ptr: *mut c_void) -> Option<Self>

Wrap a raw CMSampleBufferRef, calling CFRetain to bump its refcount before taking ownership.

Use this when the caller holds a borrowed (non-owning) reference and wants to take ownership without affecting the source.

§Safety

ptr must be a valid CMSampleBufferRef (or NULL). Passing a dangling or wrong-type pointer is undefined behaviour.

Source

pub const fn as_ptr(&self) -> *mut c_void

Borrow the underlying CMSampleBufferRef for hand-off to other Apple bindings without changing its refcount. The pointer remains valid for the lifetime of self.

Source

pub fn is_valid(&self) -> bool

Whether the sample buffer is in a valid state.

Source

pub fn data_is_ready(&self) -> bool

Whether the sample buffer’s data is ready for consumption.

Source

pub fn num_samples(&self) -> i64

Number of samples carried by this buffer (1 for video, N for audio).

Source

pub fn presentation_timestamp(&self) -> CMTime

Presentation timestamp of the first sample.

Returns CMTime::INVALID if the buffer has no PTS.

Source

pub fn decode_timestamp(&self) -> CMTime

Decode timestamp of the first sample (matters when there’s B-frame reordering between PTS and DTS).

Source

pub fn duration(&self) -> CMTime

Total duration of all samples in this buffer.

Source

pub fn data_buffer(&self) -> Option<CMBlockBuffer>

The attached CMBlockBuffer holding the encoded sample data, if the sample buffer is data-bearing (as opposed to image-bearing).

Video frames from VTCompressionSession always have a data buffer (the encoded NAL units / ProRes frame data). Decoded video frames from a capture pipeline typically use an image buffer instead — see Self::image_buffer_ptr.

Source

pub fn format_description(&self) -> Option<CMFormatDescription>

Format description (codec, dimensions, audio params, …) attached to this sample buffer.

Source

pub fn image_buffer_ptr(&self) -> *mut c_void

Raw CVImageBufferRef if the sample is image-bearing (decoded video frames from a capture pipeline). Use a CV crate’s wrapper to turn this into a safe CVPixelBuffer.

Returns NULL for sample buffers that don’t carry an image buffer (e.g. compressed video from VideoToolbox, audio samples).

Trait Implementations§

Source§

impl Clone for CMSampleBuffer

Source§

fn clone(&self) -> Self

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 CMSampleBuffer

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for CMSampleBuffer

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 Hash for CMSampleBuffer

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 CMSampleBuffer

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CMSampleBuffer

Source§

impl Send for CMSampleBuffer

Source§

impl Sync for CMSampleBuffer

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<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, 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> 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 = 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.