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, 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);pub fn get_image_buffer(&self) -> Option<CVPixelBuffer>
Sourcepub fn get_frame_status(&self) -> Option<SCFrameStatus>
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);
}
}
}
}pub fn get_presentation_timestamp(&self) -> CMTime
pub fn get_duration(&self) -> CMTime
pub fn is_valid(&self) -> bool
pub fn get_num_samples(&self) -> usize
pub fn get_audio_buffer_list(&self) -> Option<AudioBufferList>
pub fn get_data_buffer(&self) -> Option<CMBlockBuffer>
Sourcepub fn get_decode_timestamp(&self) -> CMTime
pub fn get_decode_timestamp(&self) -> CMTime
Get the decode timestamp of the sample buffer
Sourcepub fn get_output_presentation_timestamp(&self) -> CMTime
pub fn get_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 get_sample_size(&self, index: usize) -> usize
pub fn get_sample_size(&self, index: usize) -> usize
Get the size of a specific sample
Sourcepub fn get_total_sample_size(&self) -> usize
pub fn get_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 get_format_description(&self) -> Option<CMFormatDescription>
pub fn get_format_description(&self) -> Option<CMFormatDescription>
Get the format description
Sourcepub fn get_sample_timing_info(
&self,
index: usize,
) -> Result<CMSampleTimingInfo, i32>
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.
Sourcepub fn get_sample_timing_info_array(
&self,
) -> Result<Vec<CMSampleTimingInfo>, i32>
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.
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.