screencapturekit/stream/configuration/
stream_properties.rs

1//! Stream identification and HDR configuration
2//!
3//! This module provides methods to configure stream identification and HDR capture settings.
4
5use super::internal::SCStreamConfiguration;
6use crate::utils::ffi_string::{ffi_string_from_buffer, SMALL_BUFFER_SIZE};
7
8/// Dynamic range mode for capture (macOS 15.0+)
9#[repr(i32)]
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
11pub enum SCCaptureDynamicRange {
12    /// Standard Dynamic Range (SDR) - default mode
13    #[default]
14    SDR = 0,
15    /// HDR with local display tone mapping
16    HDRLocalDisplay = 1,
17    /// HDR with canonical display tone mapping
18    HDRCanonicalDisplay = 2,
19}
20
21impl SCStreamConfiguration {
22    /// Set the stream name for identification
23    ///
24    /// Assigns a name to the stream that can be used for debugging and identification
25    /// purposes. The name appears in system logs and debugging tools.
26    ///
27    /// # Examples
28    ///
29    /// ```rust,no_run
30    /// use screencapturekit::prelude::*;
31    ///
32    /// let mut config = SCStreamConfiguration::default();
33    /// config.set_stream_name(Some("MyApp-MainCapture"));
34    /// ```
35    pub fn set_stream_name(&mut self, name: Option<&str>) {
36        unsafe {
37            if let Some(stream_name) = name {
38                if let Ok(c_name) = std::ffi::CString::new(stream_name) {
39                    crate::ffi::sc_stream_configuration_set_stream_name(
40                        self.as_ptr(),
41                        c_name.as_ptr(),
42                    );
43                }
44            } else {
45                crate::ffi::sc_stream_configuration_set_stream_name(
46                    self.as_ptr(),
47                    std::ptr::null(),
48                );
49            }
50        }
51    }
52
53    /// Get the configured stream name
54    ///
55    /// Returns the name assigned to this stream, if any.
56    pub fn get_stream_name(&self) -> Option<String> {
57        unsafe {
58            ffi_string_from_buffer(SMALL_BUFFER_SIZE, |buf, len| {
59                crate::ffi::sc_stream_configuration_get_stream_name(self.as_ptr(), buf, len)
60            })
61        }
62    }
63
64    /// Set the dynamic range mode for capture (macOS 15.0+)
65    ///
66    /// Controls whether to capture in SDR or HDR mode and how HDR content
67    /// should be tone-mapped for display.
68    ///
69    /// # Availability
70    /// macOS 15.0+. Requires the `macos_15_0` feature flag to be enabled.
71    ///
72    /// # Modes
73    /// - `SDR`: Standard dynamic range capture (default)
74    /// - `HDRLocalDisplay`: HDR with tone mapping optimized for the local display
75    /// - `HDRCanonicalDisplay`: HDR with canonical tone mapping for portability
76    ///
77    /// # Examples
78    ///
79    /// ```rust,no_run
80    /// use screencapturekit::prelude::*;
81    /// use screencapturekit::stream::configuration::stream_properties::SCCaptureDynamicRange;
82    ///
83    /// let mut config = SCStreamConfiguration::default();
84    /// config.set_width(1920)
85    /// config.set_height(1080)
86    /// config.set_capture_dynamic_range(SCCaptureDynamicRange::HDRLocalDisplay);
87    /// ```
88    #[cfg(feature = "macos_15_0")]
89    pub fn set_capture_dynamic_range(&mut self, dynamic_range: SCCaptureDynamicRange) {
90        unsafe {
91            crate::ffi::sc_stream_configuration_set_capture_dynamic_range(
92                self.as_ptr(),
93                dynamic_range as i32,
94            );
95        }
96    }
97
98    /// Get the configured dynamic range mode (macOS 15.0+)
99    ///
100    /// Returns the current HDR capture mode setting.
101    ///
102    /// Requires the `macos_15_0` feature flag to be enabled.
103    #[cfg(feature = "macos_15_0")]
104    pub fn get_capture_dynamic_range(&self) -> SCCaptureDynamicRange {
105        let value =
106            unsafe { crate::ffi::sc_stream_configuration_get_capture_dynamic_range(self.as_ptr()) };
107        match value {
108            1 => SCCaptureDynamicRange::HDRLocalDisplay,
109            2 => SCCaptureDynamicRange::HDRCanonicalDisplay,
110            _ => SCCaptureDynamicRange::SDR,
111        }
112    }
113}