pub struct CMSampleBuffer(/* private fields */);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
impl CMSampleBuffer
Sourcepub const unsafe fn from_ptr(ptr: *mut c_void) -> Self
pub const unsafe fn from_ptr(ptr: *mut c_void) -> Self
Wrap a raw CMSampleBufferRef without bumping its refcount or
checking for NULL.
§Safety
ptr must be a non-null, live CMSampleBufferRef of the exact type
carrying one retain transferred to this wrapper. The caller must not
release or separately adopt that retain. For NULL-tolerant construction
prefer Self::from_raw.
Sourcepub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self>
pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self>
Adopt 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.
§Safety
A non-null ptr must be a live CMSampleBufferRef of the exact type
carrying one retain transferred to this wrapper. The caller must not
release or separately adopt that transferred retain.
Sourcepub unsafe fn from_raw_borrowed(ptr: *mut c_void) -> Option<Self>
pub unsafe fn from_raw_borrowed(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
A non-null ptr must be a live CMSampleBufferRef of the exact type for
the duration of the retain call.
Sourcepub const fn as_ptr(&self) -> *mut c_void
pub const fn as_ptr(&self) -> *mut c_void
Borrow the underlying +0 CMSampleBufferRef without changing its
refcount. The pointer remains valid for the lifetime of self.
Sourcepub fn data_is_ready(&self) -> bool
pub fn data_is_ready(&self) -> bool
Whether the sample buffer’s data is ready for consumption.
Sourcepub fn num_samples(&self) -> i64
pub fn num_samples(&self) -> i64
Number of samples carried by this buffer (1 for video, N for audio).
Sourcepub fn presentation_timestamp(&self) -> CMTime
pub fn presentation_timestamp(&self) -> CMTime
Presentation timestamp of the first sample.
Returns CMTime::INVALID if the buffer has no PTS.
Sourcepub fn decode_timestamp(&self) -> CMTime
pub fn decode_timestamp(&self) -> CMTime
Decode timestamp of the first sample (matters when there’s B-frame reordering between PTS and DTS).
Sourcepub fn data_buffer(&self) -> Option<CMBlockBuffer>
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_borrowed.
Sourcepub fn format_description(&self) -> Option<CMFormatDescription>
pub fn format_description(&self) -> Option<CMFormatDescription>
Format description (codec, dimensions, audio params, …) attached to this sample buffer.
Sourcepub fn image_buffer_ptr_borrowed(&self) -> *mut c_void
pub fn image_buffer_ptr_borrowed(&self) -> *mut c_void
Borrowed +0 CVImageBufferRef if the sample is image-bearing.
Returns NULL for sample buffers that don’t carry an image buffer
(for example, compressed video or audio samples). The pointer remains
valid only while self and the sample buffer’s image association remain
alive. Retain it before storing or adopting it.
Sourcepub fn image_buffer(&self) -> Option<CVImageBuffer>
Available on crate feature cv only.
pub fn image_buffer(&self) -> Option<CVImageBuffer>
cv only.Copy the sample buffer’s image buffer into an independently owned wrapper.