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
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.
Sourcepub fn from_raw(ptr: *mut c_void) -> Option<Self>
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.
Sourcepub unsafe fn from_raw_retained(ptr: *mut c_void) -> Option<Self>
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.
Sourcepub const fn as_ptr(&self) -> *mut c_void
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.
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.
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(&self) -> *mut c_void
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).