pub trait CMSampleBufferExt {
// Required methods
fn create_for_image_buffer(
image_buffer: &CVPixelBuffer,
presentation_time: CMTime,
duration: CMTime,
) -> Result<Self, i32>
where Self: Sized;
fn image_buffer(&self) -> Option<CVPixelBuffer>;
fn audio_buffer_list(&self) -> Option<AudioBufferList>;
fn output_presentation_timestamp(&self) -> CMTime;
fn set_output_presentation_timestamp(&self, time: CMTime) -> Result<(), i32>;
fn sample_size(&self, index: usize) -> usize;
fn total_sample_size(&self) -> usize;
fn is_data_ready(&self) -> bool;
fn make_data_ready(&self) -> Result<(), i32>;
fn sample_timing_info(
&self,
index: usize,
) -> Result<CMSampleTimingInfo, i32>;
fn cg_image(&self) -> Result<CGImage, i32>;
}Expand description
Extension trait carrying generic CMSampleBuffer accessors that aren’t
available on apple_cf::cm::CMSampleBuffer yet (planned for an
apple-cf v0.2 release).
Required Methods§
Sourcefn create_for_image_buffer(
image_buffer: &CVPixelBuffer,
presentation_time: CMTime,
duration: CMTime,
) -> Result<Self, i32>where
Self: Sized,
fn create_for_image_buffer(
image_buffer: &CVPixelBuffer,
presentation_time: CMTime,
duration: CMTime,
) -> Result<Self, i32>where
Self: Sized,
Construct a sample buffer wrapping a CVPixelBuffer.
§Errors
Returns the underlying OSStatus if CoreMedia fails to create the
sample buffer.
Sourcefn image_buffer(&self) -> Option<CVPixelBuffer>
fn image_buffer(&self) -> Option<CVPixelBuffer>
Borrow the attached CVPixelBuffer, if any.
Sourcefn audio_buffer_list(&self) -> Option<AudioBufferList>
fn audio_buffer_list(&self) -> Option<AudioBufferList>
Read the audio sample buffer’s underlying AudioBufferList, if any.
Sourcefn output_presentation_timestamp(&self) -> CMTime
fn output_presentation_timestamp(&self) -> CMTime
Output presentation timestamp (after timing adjustments).
Sourcefn set_output_presentation_timestamp(&self, time: CMTime) -> Result<(), i32>
fn set_output_presentation_timestamp(&self, time: CMTime) -> Result<(), i32>
Override the output presentation timestamp.
§Errors
Returns the underlying OSStatus if CoreMedia rejects the new value.
Sourcefn sample_size(&self, index: usize) -> usize
fn sample_size(&self, index: usize) -> usize
Size of one sample at index in bytes.
Sourcefn total_sample_size(&self) -> usize
fn total_sample_size(&self) -> usize
Sum of all sample sizes in this buffer.
Sourcefn is_data_ready(&self) -> bool
fn is_data_ready(&self) -> bool
Whether the underlying data is ready for reading.
Sourcefn make_data_ready(&self) -> Result<(), i32>
fn make_data_ready(&self) -> Result<(), i32>
Mark the underlying data as ready (flushes any pending make-data-ready callbacks).
§Errors
Returns the underlying OSStatus if CoreMedia reports failure.
Sourcefn sample_timing_info(&self, index: usize) -> Result<CMSampleTimingInfo, i32>
fn sample_timing_info(&self, index: usize) -> Result<CMSampleTimingInfo, i32>
Read the timing info for the sample at index.
§Errors
Returns the underlying OSStatus if index is out of range.
Sourcefn cg_image(&self) -> Result<CGImage, i32>
fn cg_image(&self) -> Result<CGImage, i32>
Build an apple_cf::cg::CGImage from the buffer’s attached
CVImageBuffer.
Backed by VTCreateCGImageFromCVPixelBuffer, which understands every
pixel format ScreenCaptureKit (or any other CoreMedia producer) can
emit — BGRA, 420v YCbCr 8-bit bi-planar video range, l10r 10-bit ARGB,
etc. — and uses Apple’s hardware path when one exists. The resulting
CGImage is IOSurface-backed when the source was, so passing it
straight into ImageIO (CGImageDestinationAddImage / imageio-rs
ImageDestination::add_cg_image) or into Metal sampling avoids any
host-side pixel copy.
Returns the canonical apple_cf::cg::CGImage (the same type used by
imageio-rs and every other doom-fish suite crate that consumes
CGImages), so the result flows straight into safe APIs with no
pointer juggling at the callsite.
§Errors
Returns the underlying OSStatus from VTCreateCGImageFromCVPixelBuffer
(or -12731 kCMSampleBufferError_NoSampleBufferContent when the
buffer has no image buffer attached — typical for audio-only or
timing-metadata-only samples).