screencapturekit/stream/configuration/
internal.rs

1use std::ffi::c_void;
2use std::fmt;
3
4/// Opaque wrapper around `SCStreamConfiguration`
5///
6/// Configuration for a screen capture stream, including dimensions,
7/// pixel format, audio settings, and other capture parameters.
8///
9/// # Examples
10///
11/// ```
12/// use screencapturekit::stream::configuration::SCStreamConfiguration;
13///
14/// let mut config = SCStreamConfiguration::default();
15/// config.set_width(1920);
16/// config.set_height(1080);
17/// ```
18#[repr(transparent)]
19pub struct SCStreamConfiguration(*const c_void);
20
21impl PartialEq for SCStreamConfiguration {
22    fn eq(&self, other: &Self) -> bool {
23        self.0 == other.0
24    }
25}
26
27impl Eq for SCStreamConfiguration {}
28
29impl std::hash::Hash for SCStreamConfiguration {
30    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
31        self.0.hash(state);
32    }
33}
34
35impl SCStreamConfiguration {
36    pub(crate) fn internal_init() -> Self {
37        unsafe {
38            let ptr = crate::ffi::sc_stream_configuration_create();
39            Self(ptr)
40        }
41    }
42
43    pub(crate) fn as_ptr(&self) -> *const c_void {
44        self.0
45    }
46}
47
48impl Drop for SCStreamConfiguration {
49    fn drop(&mut self) {
50        if !self.0.is_null() {
51            unsafe {
52                crate::ffi::sc_stream_configuration_release(self.0);
53            }
54        }
55    }
56}
57
58impl Clone for SCStreamConfiguration {
59    fn clone(&self) -> Self {
60        unsafe { Self(crate::ffi::sc_stream_configuration_retain(self.0)) }
61    }
62}
63
64unsafe impl Send for SCStreamConfiguration {}
65unsafe impl Sync for SCStreamConfiguration {}
66
67impl fmt::Debug for SCStreamConfiguration {
68    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69        f.debug_struct("SCStreamConfiguration")
70            .field("ptr", &self.0)
71            .finish()
72    }
73}
74
75impl fmt::Display for SCStreamConfiguration {
76    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77        write!(f, "SCStreamConfiguration")
78    }
79}