Skip to content

Commit d43d481

Browse files
committed
refactor!: simplify config setters to return Self
directly BREAKING CHANGE: All SCStreamConfiguration set_* methods now return Self
1 parent a47cab3 commit d43d481

34 files changed

Lines changed: 313 additions & 260 deletions

src/cg.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Core Graphics types for screen coordinates and dimensions
22
//!
33
//! This module provides Rust equivalents of Core Graphics types used in
4-
//! ScreenCaptureKit for representing screen coordinates, sizes, and rectangles.
4+
//! `ScreenCaptureKit` for representing screen coordinates, sizes, and rectangles.
55
66
use std::fmt;
77

8-
/// CGRect representation
8+
/// `CGRect` representation
99
///
1010
/// Represents a rectangle with origin (x, y) and dimensions (width, height).
1111
///
@@ -148,7 +148,7 @@ impl fmt::Display for CGRect {
148148
}
149149
}
150150

151-
/// CGSize representation
151+
/// `CGSize` representation
152152
///
153153
/// Represents a 2D size with width and height.
154154
///
@@ -249,7 +249,7 @@ impl fmt::Display for CGSize {
249249
}
250250
}
251251

252-
/// CGPoint representation
252+
/// `CGPoint` representation
253253
///
254254
/// Represents a point in 2D space.
255255
///
@@ -319,7 +319,7 @@ impl CGPoint {
319319
dx.hypot(dy)
320320
}
321321

322-
/// Calculate squared distance to another point (faster than distance_to)
322+
/// Calculate squared distance to another point (faster than `distance_to`)
323323
pub const fn distance_squared_to(&self, other: &Self) -> f64 {
324324
let dx = self.x - other.x;
325325
let dy = self.y - other.y;
@@ -339,5 +339,5 @@ impl fmt::Display for CGPoint {
339339
}
340340
}
341341

342-
/// CGDisplayID type alias
342+
/// `CGDisplayID` type alias
343343
pub type CGDisplayID = u32;

src/cm/block_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! CMBlockBuffer - Block of contiguous data
1+
//! `CMBlockBuffer` - Block of contiguous data
22
33
use super::ffi;
44

src/cm/format_description.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! CMFormatDescription - Media format description
1+
//! `CMFormatDescription` - Media format description
22
33
#![allow(dead_code)]
44

@@ -57,9 +57,9 @@ pub mod codec_types {
5757
pub const HEVC_2: FourCharCode = FourCharCode::from_bytes(*b"hev1");
5858
/// JPEG ('jpeg')
5959
pub const JPEG: FourCharCode = FourCharCode::from_bytes(*b"jpeg");
60-
/// Apple ProRes 422 ('apcn')
60+
/// Apple `ProRes` 422 ('apcn')
6161
pub const PRORES_422: FourCharCode = FourCharCode::from_bytes(*b"apcn");
62-
/// Apple ProRes 4444 ('ap4h')
62+
/// Apple `ProRes` 4444 ('ap4h')
6363
pub const PRORES_4444: FourCharCode = FourCharCode::from_bytes(*b"ap4h");
6464

6565
// Audio codecs
@@ -99,7 +99,7 @@ impl CMFormatDescription {
9999
unsafe { ffi::cm_format_description_get_media_type(self.0) }
100100
}
101101

102-
/// Get the media type as FourCharCode
102+
/// Get the media type as `FourCharCode`
103103
pub fn media_type(&self) -> crate::utils::four_char_code::FourCharCode {
104104
crate::utils::four_char_code::FourCharCode::from(self.get_media_type())
105105
}
@@ -109,7 +109,7 @@ impl CMFormatDescription {
109109
unsafe { ffi::cm_format_description_get_media_subtype(self.0) }
110110
}
111111

112-
/// Get the media subtype as FourCharCode
112+
/// Get the media subtype as `FourCharCode`
113113
pub fn media_subtype(&self) -> crate::utils::four_char_code::FourCharCode {
114114
crate::utils::four_char_code::FourCharCode::from(self.get_media_subtype())
115115
}
@@ -192,7 +192,7 @@ impl CMFormatDescription {
192192
self.media_subtype() == codec_types::LPCM
193193
}
194194

195-
/// Check if the codec is ProRes
195+
/// Check if the codec is `ProRes`
196196
pub fn is_prores(&self) -> bool {
197197
let subtype = self.media_subtype();
198198
subtype == codec_types::PRORES_422 || subtype == codec_types::PRORES_4444

src/cm/frame_status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt;
44

55
/// Frame status for captured screen content
66
///
7-
/// Indicates the state of a frame captured by ScreenCaptureKit.
7+
/// Indicates the state of a frame captured by `ScreenCaptureKit`.
88
/// This maps to Apple's `SCFrameStatus` enum.
99
#[repr(i32)]
1010
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]

src/cm/iosurface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! IOSurface - Hardware-accelerated surface
1+
//! `IOSurface` - Hardware-accelerated surface
22
33
use std::fmt;
44
use super::ffi;

src/cm/pixel_buffer.rs

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! CVPixelBuffer - Video pixel buffer
1+
//! `CVPixelBuffer` - Video pixel buffer
22
33
use std::fmt;
44
use super::ffi;
@@ -50,6 +50,10 @@ impl CVPixelBuffer {
5050
/// * `height` - Height of the pixel buffer in pixels
5151
/// * `pixel_format` - Pixel format type (e.g., 0x42475241 for BGRA)
5252
///
53+
/// # Errors
54+
///
55+
/// Returns a Core Video error code if the pixel buffer creation fails.
56+
///
5357
/// # Examples
5458
///
5559
/// ```
@@ -98,6 +102,10 @@ impl CVPixelBuffer {
98102
/// - Memory remains valid for the lifetime of the pixel buffer
99103
/// - `bytes_per_row` correctly represents the memory layout
100104
///
105+
/// # Errors
106+
///
107+
/// Returns a Core Video error code if the pixel buffer creation fails.
108+
///
101109
/// # Examples
102110
///
103111
/// ```
@@ -163,6 +171,10 @@ impl CVPixelBuffer {
163171
///
164172
/// This is useful for pixel buffers that have been created with extended pixels
165173
/// enabled, to ensure proper edge handling for effects and filters.
174+
///
175+
/// # Errors
176+
///
177+
/// Returns a Core Video error code if the operation fails.
166178
pub fn fill_extended_pixels(&self) -> Result<(), i32> {
167179
unsafe {
168180
let status = ffi::cv_pixel_buffer_fill_extended_pixels(self.0);
@@ -182,6 +194,10 @@ impl CVPixelBuffer {
182194
/// - `plane_base_addresses` points to valid memory for each plane
183195
/// - Memory remains valid for the lifetime of the pixel buffer
184196
/// - All plane parameters correctly represent the memory layout
197+
///
198+
/// # Errors
199+
///
200+
/// Returns a Core Video error code if the pixel buffer creation fails.
185201
pub unsafe fn create_with_planar_bytes(
186202
width: usize,
187203
height: usize,
@@ -218,7 +234,11 @@ impl CVPixelBuffer {
218234
}
219235
}
220236

221-
/// Create a pixel buffer from an IOSurface
237+
/// Create a pixel buffer from an `IOSurface`
238+
///
239+
/// # Errors
240+
///
241+
/// Returns a Core Video error code if the pixel buffer creation fails.
222242
pub fn create_with_io_surface(surface: &IOSurface) -> Result<Self, i32> {
223243
unsafe {
224244
let mut pixel_buffer_ptr: *mut std::ffi::c_void = std::ptr::null_mut();
@@ -235,7 +255,7 @@ impl CVPixelBuffer {
235255
}
236256
}
237257

238-
/// Get the Core Foundation type ID for CVPixelBuffer
258+
/// Get the Core Foundation type ID for `CVPixelBuffer`
239259
pub fn get_type_id() -> usize {
240260
unsafe { ffi::cv_pixel_buffer_get_type_id() }
241261
}
@@ -300,7 +320,7 @@ impl CVPixelBuffer {
300320
}
301321
}
302322

303-
/// Check if the pixel buffer is backed by an IOSurface
323+
/// Check if the pixel buffer is backed by an `IOSurface`
304324
pub fn is_backed_by_io_surface(&self) -> bool {
305325
self.get_io_surface().is_some()
306326
}
@@ -345,6 +365,11 @@ impl CVPixelBuffer {
345365
unsafe { ffi::cv_pixel_buffer_get_bytes_per_row(self.0) }
346366
}
347367

368+
/// Lock the base address for raw access
369+
///
370+
/// # Errors
371+
///
372+
/// Returns a Core Video error code if the lock operation fails.
348373
pub fn lock_raw(&self, flags: u32) -> Result<(), i32> {
349374
unsafe {
350375
let result = ffi::cv_pixel_buffer_lock_base_address(self.0, flags);
@@ -356,6 +381,11 @@ impl CVPixelBuffer {
356381
}
357382
}
358383

384+
/// Unlock the base address after raw access
385+
///
386+
/// # Errors
387+
///
388+
/// Returns a Core Video error code if the unlock operation fails.
359389
pub fn unlock_raw(&self, flags: u32) -> Result<(), i32> {
360390
unsafe {
361391
let result = ffi::cv_pixel_buffer_unlock_base_address(self.0, flags);
@@ -385,14 +415,19 @@ impl CVPixelBuffer {
385415
}
386416
}
387417

418+
/// Lock the base address and return a guard for RAII-style access
419+
///
420+
/// # Errors
421+
///
422+
/// Returns a Core Video error code if the lock operation fails.
388423
pub fn lock_base_address(&self, read_only: bool) -> Result<CVPixelBufferLockGuard<'_>, i32> {
389424
let flags = u32::from(read_only);
390425
self.lock_raw(flags)?;
391426
Ok(CVPixelBufferLockGuard { buffer: self, read_only })
392427
}
393428
}
394429

395-
/// RAII guard for locked CVPixelBuffer base address
430+
/// RAII guard for locked `CVPixelBuffer` base address
396431
pub struct CVPixelBufferLockGuard<'a> {
397432
buffer: &'a CVPixelBuffer,
398433
read_only: bool,
@@ -451,7 +486,7 @@ impl fmt::Display for CVPixelBuffer {
451486
}
452487
}
453488

454-
/// Opaque handle to CVPixelBufferPool
489+
/// Opaque handle to `CVPixelBufferPool`
455490
#[repr(transparent)]
456491
#[derive(Debug)]
457492
pub struct CVPixelBufferPool(*mut std::ffi::c_void);
@@ -500,6 +535,10 @@ impl CVPixelBufferPool {
500535
/// * `height` - Height of pixel buffers in the pool
501536
/// * `pixel_format` - Pixel format type
502537
/// * `max_buffers` - Maximum number of buffers in the pool (0 for unlimited)
538+
///
539+
/// # Errors
540+
///
541+
/// Returns a Core Video error code if the pool creation fails.
503542
pub fn create(
504543
width: usize,
505544
height: usize,
@@ -525,6 +564,10 @@ impl CVPixelBufferPool {
525564
}
526565

527566
/// Create a pixel buffer from the pool
567+
///
568+
/// # Errors
569+
///
570+
/// Returns a Core Video error code if the buffer creation fails.
528571
pub fn create_pixel_buffer(&self) -> Result<CVPixelBuffer, i32> {
529572
unsafe {
530573
let mut pixel_buffer_ptr: *mut std::ffi::c_void = std::ptr::null_mut();
@@ -550,14 +593,18 @@ impl CVPixelBufferPool {
550593
}
551594
}
552595

553-
/// Get the Core Foundation type ID for CVPixelBufferPool
596+
/// Get the Core Foundation type ID for `CVPixelBufferPool`
554597
pub fn get_type_id() -> usize {
555598
unsafe { ffi::cv_pixel_buffer_pool_get_type_id() }
556599
}
557600

558601
/// Create a pixel buffer from the pool with auxiliary attributes
559602
///
560603
/// This allows specifying additional attributes for the created buffer
604+
///
605+
/// # Errors
606+
///
607+
/// Returns a Core Video error code if the buffer creation fails.
561608
pub fn create_pixel_buffer_with_aux_attributes(
562609
&self,
563610
aux_attributes: Option<&std::collections::HashMap<String, u32>>,
@@ -593,7 +640,7 @@ impl CVPixelBufferPool {
593640

594641
/// Get the pool attributes
595642
///
596-
/// Returns the raw pointer to the CFDictionary containing pool attributes
643+
/// Returns the raw pointer to the `CFDictionary` containing pool attributes
597644
pub fn get_attributes(&self) -> Option<*const std::ffi::c_void> {
598645
unsafe {
599646
let ptr = ffi::cv_pixel_buffer_pool_get_attributes(self.0);
@@ -607,7 +654,7 @@ impl CVPixelBufferPool {
607654

608655
/// Get the pixel buffer attributes
609656
///
610-
/// Returns the raw pointer to the CFDictionary containing pixel buffer attributes
657+
/// Returns the raw pointer to the `CFDictionary` containing pixel buffer attributes
611658
pub fn get_pixel_buffer_attributes(&self) -> Option<*const std::ffi::c_void> {
612659
unsafe {
613660
let ptr = ffi::cv_pixel_buffer_pool_get_pixel_buffer_attributes(self.0);

0 commit comments

Comments
 (0)