screencapturekit/stream/configuration/
mod.rs1mod internal;
2
3pub mod advanced;
4pub mod audio;
5pub mod captured_elements;
6pub mod captured_frames;
7pub mod colors;
8pub mod dimensions;
9pub mod pixel_format;
10pub mod stream_properties;
11
12pub use advanced::SCPresenterOverlayAlertSetting;
13pub use audio::{AudioChannelCount, AudioSampleRate};
14pub use captured_frames::{MAX_QUEUE_DEPTH, MIN_QUEUE_DEPTH};
15pub use colors::{color_matrix, color_space, InteriorNulError};
16pub use internal::SCStreamConfiguration;
17pub use pixel_format::PixelFormat;
18pub use stream_properties::SCCaptureDynamicRange;
19
20#[repr(i32)]
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
25#[cfg(feature = "macos_14_0")]
26pub enum SCCaptureResolutionType {
27 #[default]
29 Automatic = 0,
30 Best = 1,
32 Nominal = 2,
34}
35
36#[cfg(feature = "macos_14_0")]
37impl SCCaptureResolutionType {
38 pub const fn from_raw(raw: i32) -> Option<Self> {
39 match raw {
40 0 => Some(Self::Automatic),
41 1 => Some(Self::Best),
42 2 => Some(Self::Nominal),
43 _ => None,
44 }
45 }
46}
47
48#[cfg(feature = "macos_14_0")]
49impl std::fmt::Display for SCCaptureResolutionType {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 match self {
52 Self::Automatic => write!(f, "Automatic"),
53 Self::Best => write!(f, "Best"),
54 Self::Nominal => write!(f, "Nominal"),
55 }
56 }
57}
58
59impl Default for SCStreamConfiguration {
60 fn default() -> Self {
61 Self::internal_init()
62 }
63}
64
65#[repr(i32)]
70#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
71#[cfg(feature = "macos_15_0")]
72pub enum SCStreamConfigurationPreset {
73 CaptureHDRStreamLocalDisplay = 0,
75 CaptureHDRStreamCanonicalDisplay = 1,
77 CaptureHDRScreenshotLocalDisplay = 2,
79 CaptureHDRScreenshotCanonicalDisplay = 3,
81 #[cfg(feature = "macos_26_0")]
88 CaptureHDRRecordingPreservedSDRHDR10 = 4,
89}
90
91impl SCStreamConfiguration {
92 #[must_use]
106 pub fn new() -> Self {
107 Self::default()
108 }
109
110 #[cfg(feature = "macos_15_0")]
124 #[allow(clippy::missing_errors_doc)]
125 pub fn from_preset(preset: SCStreamConfigurationPreset) -> crate::error::SCResult<Self> {
126 let ptr = unsafe { crate::ffi::sc_stream_configuration_create_with_preset(preset as i32) };
127 if ptr.is_null() {
128 #[cfg(feature = "macos_26_0")]
129 let required_version = match preset {
130 SCStreamConfigurationPreset::CaptureHDRRecordingPreservedSDRHDR10 => "26.0",
131 _ => "15.0",
132 };
133 #[cfg(not(feature = "macos_26_0"))]
134 let required_version = "15.0";
135 return Err(crate::error::SCError::feature_not_available(
136 format!("SCStreamConfiguration preset {preset:?}"),
137 required_version,
138 ));
139 }
140 Ok(unsafe { Self::from_ptr(ptr) })
141 }
142
143 #[cfg(feature = "macos_15_0")]
144 pub(crate) unsafe fn from_ptr(ptr: *const std::ffi::c_void) -> Self {
145 Self(ptr)
146 }
147}
148
149#[cfg(all(test, feature = "macos_15_0"))]
150mod tests {
151 #[test]
152 fn bridge_refuses_unknown_presets() {
153 for raw in [5, -1, i32::MAX, i32::MIN] {
154 let ptr = unsafe { crate::ffi::sc_stream_configuration_create_with_preset(raw) };
155 assert!(
156 ptr.is_null(),
157 "the bridge built a configuration for preset {raw}"
158 );
159 }
160 }
161}