Skip to main content

CMSampleBuffer

Struct CMSampleBuffer 

pub struct CMSampleBuffer(/* private fields */);
Expand description

Re-exported CMSampleBuffer — same opaque-pointer wrapper used across the doom-fish suite. 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§

§

impl CMSampleBuffer

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

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.

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

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.

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

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.

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.

pub fn is_valid(&self) -> bool

Whether the sample buffer is in a valid state.

pub fn data_is_ready(&self) -> bool

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

pub fn num_samples(&self) -> i64

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

pub fn presentation_timestamp(&self) -> CMTime

Presentation timestamp of the first sample.

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

pub fn decode_timestamp(&self) -> CMTime

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

pub fn duration(&self) -> CMTime

Total duration of all samples in this buffer.

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.

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

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

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

Source§

impl CMSampleBufferExt for CMSampleBuffer

Source§

fn create_for_image_buffer( image_buffer: &CVPixelBuffer, presentation_time: CMTime, duration: CMTime, ) -> Result<Self, i32>

Construct a sample buffer wrapping a CVPixelBuffer. Read more
Source§

fn image_buffer(&self) -> Option<CVPixelBuffer>

Borrow the attached CVPixelBuffer, if any.
Source§

fn audio_buffer_list(&self) -> Option<AudioBufferList>

Read the audio sample buffer’s underlying AudioBufferList, if any.
Source§

fn output_presentation_timestamp(&self) -> CMTime

Output presentation timestamp (after timing adjustments).
Source§

fn set_output_presentation_timestamp(&self, time: CMTime) -> Result<(), i32>

Override the output presentation timestamp. Read more
Source§

fn sample_size(&self, index: usize) -> usize

Size of one sample at index in bytes.
Source§

fn total_sample_size(&self) -> usize

Sum of all sample sizes in this buffer.
Source§

fn is_data_ready(&self) -> bool

Whether the underlying data is ready for reading.
Source§

fn make_data_ready(&self) -> Result<(), i32>

Mark the underlying data as ready (flushes any pending make-data-ready callbacks). Read more
Source§

fn sample_timing_info(&self, index: usize) -> Result<CMSampleTimingInfo, i32>

Read the timing info for the sample at index. Read more
Source§

fn cg_image(&self) -> Result<CGImage, i32>

Build an apple_cf::cg::CGImage from the buffer’s attached CVImageBuffer. Read more
Source§

impl CMSampleBufferSCExt for CMSampleBuffer

Source§

fn frame_status(&self) -> Option<SCFrameStatus>

SCStreamFrameInfo.status attachment.
Source§

fn display_time(&self) -> Option<u64>

SCStreamFrameInfo.displayTime attachment.
Source§

fn scale_factor(&self) -> Option<f64>

SCStreamFrameInfo.scaleFactor attachment.
Source§

fn content_scale(&self) -> Option<f64>

SCStreamFrameInfo.contentScale attachment.
Source§

fn content_rect(&self) -> Option<CGRect>

SCStreamFrameInfo.contentRect attachment.
Source§

fn bounding_rect(&self) -> Option<CGRect>

SCStreamFrameInfo.boundingRect attachment.
Source§

fn screen_rect(&self) -> Option<CGRect>

SCStreamFrameInfo.screenRect attachment.
Source§

fn presenter_overlay_content_rect(&self) -> Option<CGRect>

SCStreamFrameInfo.presenterOverlayContentRect attachment.
Source§

fn dirty_rects(&self) -> Option<Vec<CGRect>>

SCStreamFrameInfo.dirtyRects attachment.
Source§

fn frame_info(&self) -> Option<FrameInfo>

Read every populated SCStreamFrameInfo attachment in a single FFI round-trip.
§

impl Clone for CMSampleBuffer

§

fn clone(&self) -> CMSampleBuffer

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for CMSampleBuffer

§

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

Formats the value using the given formatter. Read more
§

impl Drop for CMSampleBuffer

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl Hash for CMSampleBuffer

§

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

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
§

impl PartialEq for CMSampleBuffer

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
§

impl Eq for CMSampleBuffer

§

impl Send for CMSampleBuffer

§

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.