CMSampleBuffer

Struct CMSampleBuffer 

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

Opaque handle to CMSampleBuffer

Implementations§

Source§

impl CMSampleBuffer

Source

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

Source

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

§Safety

The caller must ensure the pointer is a valid CMSampleBuffer pointer.

Source

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

Source

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

Create a sample buffer for an image buffer (video frame)

§Arguments
  • image_buffer - The pixel buffer containing the video frame
  • presentation_time - When the frame should be presented
  • duration - How long the frame should be displayed
§Errors

Returns a Core Media error code if the sample buffer creation fails.

§Examples
use screencapturekit::cm::{CMSampleBuffer, CVPixelBuffer, CMTime};

// Create a pixel buffer
let pixel_buffer = CVPixelBuffer::create(1920, 1080, 0x42475241)
    .expect("Failed to create pixel buffer");

// Create timing information (30fps video)
let presentation_time = CMTime::new(0, 30); // Frame 0 at 30 fps
let duration = CMTime::new(1, 30);          // 1/30th of a second

// Create sample buffer
let sample = CMSampleBuffer::create_for_image_buffer(
    &pixel_buffer,
    presentation_time,
    duration,
).expect("Failed to create sample buffer");

assert!(sample.is_valid());
assert_eq!(sample.get_presentation_timestamp().value, 0);
assert_eq!(sample.get_presentation_timestamp().timescale, 30);
Source

pub fn get_image_buffer(&self) -> Option<CVPixelBuffer>

Source

pub fn get_frame_status(&self) -> Option<SCFrameStatus>

Get the frame status from a sample buffer

Returns the SCFrameStatus attachment from the sample buffer, indicating whether the frame is complete, idle, blank, etc.

§Examples
use screencapturekit::cm::{CMSampleBuffer, SCFrameStatus};

fn handle_frame(sample: CMSampleBuffer) {
    if let Some(status) = sample.get_frame_status() {
        match status {
            SCFrameStatus::Complete => {
                println!("Frame is complete, process it");
            }
            SCFrameStatus::Idle => {
                println!("Frame is idle, no changes");
            }
            _ => {
                println!("Frame status: {}", status);
            }
        }
    }
}
Source

pub fn get_presentation_timestamp(&self) -> CMTime

Source

pub fn get_duration(&self) -> CMTime

Source

pub fn is_valid(&self) -> bool

Source

pub fn get_num_samples(&self) -> usize

Source

pub fn get_audio_buffer_list(&self) -> Option<AudioBufferList>

Source

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

Source

pub fn get_decode_timestamp(&self) -> CMTime

Get the decode timestamp of the sample buffer

Source

pub fn get_output_presentation_timestamp(&self) -> CMTime

Get the output presentation timestamp

Source

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

Set the output presentation timestamp

§Errors

Returns a Core Media error code if the operation fails.

Source

pub fn get_sample_size(&self, index: usize) -> usize

Get the size of a specific sample

Source

pub fn get_total_sample_size(&self) -> usize

Get the total size of all samples

Source

pub fn is_data_ready(&self) -> bool

Check if the sample buffer data is ready for access

Source

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

Make the sample buffer data ready for access

§Errors

Returns a Core Media error code if the operation fails.

Source

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

Get the format description

Source

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

Get sample timing info for a specific sample

§Errors

Returns a Core Media error code if the timing info cannot be retrieved.

Source

pub fn get_sample_timing_info_array( &self, ) -> Result<Vec<CMSampleTimingInfo>, i32>

Get all sample timing info as a vector

§Errors

Returns a Core Media error code if any timing info cannot be retrieved.

Source

pub fn invalidate(&self) -> Result<(), i32>

Invalidate the sample buffer

§Errors

Returns a Core Media error code if the invalidation fails.

Source

pub fn create_copy_with_new_timing( &self, timing_info: &[CMSampleTimingInfo], ) -> Result<Self, i32>

Create a copy with new timing information

§Errors

Returns a Core Media error code if the copy cannot be created.

Source

pub fn copy_pcm_data_into_audio_buffer_list( &self, frame_offset: i32, num_frames: i32, buffer_list: &mut AudioBufferList, ) -> Result<(), i32>

Copy PCM audio data into an audio buffer list

§Errors

Returns a Core Media error code if the copy operation fails.

Trait Implementations§

Source§

impl Debug for CMSampleBuffer

Source§

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

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

impl Display 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§

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 · 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.