pub struct CMSampleBuffer(/* private fields */);Expand description
Opaque handle to CMSampleBuffer
Implementations§
Source§impl CMSampleBuffer
impl CMSampleBuffer
pub fn from_raw(ptr: *mut c_void) -> Option<Self>
Sourcepub unsafe fn from_ptr(ptr: *mut c_void) -> Self
pub unsafe fn from_ptr(ptr: *mut c_void) -> Self
§Safety
The caller must ensure the pointer is a valid CMSampleBuffer pointer.
pub fn as_ptr(&self) -> *mut c_void
Sourcepub fn create_for_image_buffer(
image_buffer: &CVPixelBuffer,
presentation_time: CMTime,
duration: CMTime,
) -> Result<Self, i32>
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 framepresentation_time- When the frame should be presentedduration- 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, CMTime};
use screencapturekit::cv::CVPixelBuffer;
// 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.presentation_timestamp().value, 0);
assert_eq!(sample.presentation_timestamp().timescale, 30);Sourcepub fn image_buffer(&self) -> Option<CVPixelBuffer>
pub fn image_buffer(&self) -> Option<CVPixelBuffer>
Get the image buffer (pixel buffer) from this sample
Sourcepub fn frame_status(&self) -> Option<SCFrameStatus>
pub fn 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.frame_status() {
match status {
SCFrameStatus::Complete => {
println!("Frame is complete, process it");
}
SCFrameStatus::Idle => {
println!("Frame is idle, no changes");
}
_ => {
println!("Frame status: {}", status);
}
}
}
}Sourcepub fn display_time(&self) -> Option<u64>
pub fn display_time(&self) -> Option<u64>
Get the display time (mach absolute time) from frame info
This is the time when the frame was displayed on screen.
Sourcepub fn scale_factor(&self) -> Option<f64>
pub fn scale_factor(&self) -> Option<f64>
Get the scale factor (point-to-pixel ratio) from frame info
This indicates the display’s scale factor (e.g., 2.0 for Retina displays).
Sourcepub fn content_scale(&self) -> Option<f64>
pub fn content_scale(&self) -> Option<f64>
Get the content scale from frame info
Sourcepub fn content_rect(&self) -> Option<CGRect>
pub fn content_rect(&self) -> Option<CGRect>
Get the content rectangle from frame info
This is the rectangle of the captured content within the frame.
Sourcepub fn bounding_rect(&self) -> Option<CGRect>
pub fn bounding_rect(&self) -> Option<CGRect>
Get the bounding rectangle from frame info
This is the bounding rectangle of all captured windows.
Sourcepub fn screen_rect(&self) -> Option<CGRect>
pub fn screen_rect(&self) -> Option<CGRect>
Get the screen rectangle from frame info
This is the rectangle of the screen being captured.
Sourcepub fn dirty_rects(&self) -> Option<Vec<CGRect>>
pub fn dirty_rects(&self) -> Option<Vec<CGRect>>
Get the dirty rectangles from frame info
Dirty rectangles indicate areas of the screen that have changed since the last frame. This can be used for efficient partial screen updates.
Sourcepub fn presentation_timestamp(&self) -> CMTime
pub fn presentation_timestamp(&self) -> CMTime
Get the presentation timestamp
pub fn is_valid(&self) -> bool
Sourcepub fn num_samples(&self) -> usize
pub fn num_samples(&self) -> usize
Get the number of samples in this buffer
Sourcepub fn audio_buffer_list(&self) -> Option<AudioBufferList>
pub fn audio_buffer_list(&self) -> Option<AudioBufferList>
Get the audio buffer list from this sample
Sourcepub fn data_buffer(&self) -> Option<CMBlockBuffer>
pub fn data_buffer(&self) -> Option<CMBlockBuffer>
Get the data buffer (for compressed data)
Sourcepub fn decode_timestamp(&self) -> CMTime
pub fn decode_timestamp(&self) -> CMTime
Get the decode timestamp of the sample buffer
Sourcepub fn output_presentation_timestamp(&self) -> CMTime
pub fn output_presentation_timestamp(&self) -> CMTime
Get the output presentation timestamp
Sourcepub fn set_output_presentation_timestamp(&self, time: CMTime) -> Result<(), i32>
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.
Sourcepub fn sample_size(&self, index: usize) -> usize
pub fn sample_size(&self, index: usize) -> usize
Get the size of a specific sample
Sourcepub fn total_sample_size(&self) -> usize
pub fn total_sample_size(&self) -> usize
Get the total size of all samples
Sourcepub fn is_data_ready(&self) -> bool
pub fn is_data_ready(&self) -> bool
Check if the sample buffer data is ready for access
Sourcepub fn make_data_ready(&self) -> Result<(), i32>
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.
Sourcepub fn format_description(&self) -> Option<CMFormatDescription>
pub fn format_description(&self) -> Option<CMFormatDescription>
Get the format description
Sourcepub fn sample_timing_info(
&self,
index: usize,
) -> Result<CMSampleTimingInfo, i32>
pub fn 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.
Sourcepub fn sample_timing_info_array(&self) -> Result<Vec<CMSampleTimingInfo>, i32>
pub fn 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.
Sourcepub fn invalidate(&self) -> Result<(), i32>
pub fn invalidate(&self) -> Result<(), i32>
Sourcepub fn create_copy_with_new_timing(
&self,
timing_info: &[CMSampleTimingInfo],
) -> Result<Self, i32>
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.
Sourcepub fn copy_pcm_data_into_audio_buffer_list(
&self,
frame_offset: i32,
num_frames: i32,
buffer_list: &mut AudioBufferList,
) -> Result<(), i32>
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.