objc2_sensitive_content_analysis/generated/
SCVideoStreamAnalyzer.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-av-foundation")]
7use objc2_av_foundation::*;
8#[cfg(feature = "objc2-core-video")]
9use objc2_core_video::*;
10use objc2_foundation::*;
11#[cfg(feature = "objc2-video-toolbox")]
12use objc2_video_toolbox::*;
13
14use crate::*;
15
16/// Options for the different types of analyzed video streams.
17///
18/// Pass this enum into the ``SCVideoStreamAnalyzer/init(participantUUID:streamDirection:)`` initializer when creating an ``SCVideoStreamAnalyzer`` to analyze video streams.
19///
20/// See also [Apple's documentation](https://developer.apple.com/documentation/sensitivecontentanalysis/scvideostreamanalyzerstreamdirection?language=objc)
21// NS_ENUM
22#[repr(transparent)]
23#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
24pub struct SCVideoStreamAnalyzerStreamDirection(pub NSInteger);
25impl SCVideoStreamAnalyzerStreamDirection {
26    /// An option that refers to a video stream sent to another device.
27    ///
28    /// This option refers to the stream that originates from the device's camera.
29    #[doc(alias = "SCVideoStreamAnalyzerStreamDirectionOutgoing")]
30    pub const Outgoing: Self = Self(1);
31    /// An option that indicates a video stream from another device.
32    ///
33    /// This option refers to a video stream that the device receives over the network from another device's camera.
34    #[doc(alias = "SCVideoStreamAnalyzerStreamDirectionIncoming")]
35    pub const Incoming: Self = Self(2);
36}
37
38unsafe impl Encode for SCVideoStreamAnalyzerStreamDirection {
39    const ENCODING: Encoding = NSInteger::ENCODING;
40}
41
42unsafe impl RefEncode for SCVideoStreamAnalyzerStreamDirection {
43    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
44}
45
46/// A handler your app provides to receive video-stream analysis results.
47///
48/// Your app implements this handler and the framework calls it when the analyzer's video stream detects sensitive content, or an error providing corresponding analysis, or error as input parameters.
49///
50/// This handler receives an instance of ``SCSensitivityAnalysis``, and an
51/// <doc
52/// ://com.apple.documentation/documentation/swift/error>, for example:
53///
54/// ```swift
55/// analyzer.analysisChangedHandler = { analysis, error in
56/// self.analysis = analysis
57/// if analysis.shouldInterruptVideo {
58/// // ...
59/// }
60/// if analysis.shouldIndicateSensitivity {
61/// // ...
62/// }
63/// if analysis.shouldMuteAudio {
64/// // ...
65/// }
66/// }
67/// ```
68///
69/// See also [Apple's documentation](https://developer.apple.com/documentation/sensitivecontentanalysis/scvideostreamanalysischangehandler?language=objc)
70#[cfg(all(feature = "SCSensitivityAnalysis", feature = "block2"))]
71pub type SCVideoStreamAnalysisChangeHandler =
72    *mut block2::DynBlock<dyn Fn(*mut SCSensitivityAnalysis, *mut NSError)>;
73
74extern_class!(
75    /// Monitors a stream of video by analyzing frames for sensitive content.
76    ///
77    /// Use this class to detect senstive content in a video stream, such as on a conference call that your app implements. The class detects senstive content in the video stream from either the device's camera or the remote device(s) signed into the call, depending on how you configure the analyzer.
78    ///
79    /// Create an instance of this class for each video stream in the call.
80    ///
81    /// To begin analyzing the stream, pass it to either ``beginAnalysis(of:)-(AVCaptureDeviceInput)`` (
82    /// <doc
83    /// ://com.apple.documentation/documentation/avfoundation/avcapturedeviceinput>) or ``beginAnalysis(of:)-(VTDecompressionSession)`` (
84    /// <doc
85    /// ://com.apple.documentation/documentation/videotoolbox/vtdecompressionsession>), depending on your video playback implementation.
86    ///
87    /// - Important: This class works only when the Communication Safety parental control in Screen Time is enabled, or when Sensitive Content Warnings is on in Settings. The initializers of this class throw an error if both settings are off.
88    ///
89    /// ### React to sensitive content
90    ///
91    /// When the framework detects sensitive content in the stream, it calls ``analysisChangedHandler`` immediately with an ``SCSensitivityAnalysis`` object that includes information about the detection.
92    ///
93    /// You implement the ``analysisChangedHandler`` callback to inspect the detection results, which includes confirmation that content is sensitve as well as guidance on next steps your app can take. The framework offers your app suggestions in the handler, which include:
94    ///
95    /// - Alerting the person to the presence of sensitive content (``SCSensitivityAnalysis/shouldIndicateSensitivity``)
96    /// - Interrupting video playback (``SCSensitivityAnalysis/shouldInterruptVideo``)
97    /// - Muting audio (``SCSensitivityAnalysis/shouldMuteAudio``)
98    ///
99    /// To stop analyzing the stream, call ``endAnalysis()``. If your app implements a custom stream decoder, you can analyze individual frames by passing pixel buffers to ``analyze(_:)``.
100    ///
101    /// In the event of an error during analysis, the handler receives an error object that details what went wrong. For more information, see: ``SCVideoStreamAnalysisChangeHandler``.
102    ///
103    /// ### Add the app entitlement
104    ///
105    /// To use this class, the system requires the
106    /// <doc
107    /// ://com.apple.documentation/documentation/bundleresources/entitlements/com.apple.developer.sensitivecontentanalysis.client> entitlement in your app's code signature. Calls to the framework fail to return positive results without it. You can can add this entitlement to your app by enabling the Sensitive Content Analysis capability in Xcode; see
108    /// <doc
109    /// ://com.apple.documentation/documentation/xcode/adding-capabilities-to-your-app>.
110    ///
111    /// For more information, see
112    /// <doc
113    /// :detecting-nudity-in-media-and-providing-intervention-options>.
114    ///
115    /// See also [Apple's documentation](https://developer.apple.com/documentation/sensitivecontentanalysis/scvideostreamanalyzer?language=objc)
116    #[unsafe(super(NSObject))]
117    #[derive(Debug, PartialEq, Eq, Hash)]
118    pub struct SCVideoStreamAnalyzer;
119);
120
121extern_conformance!(
122    unsafe impl NSObjectProtocol for SCVideoStreamAnalyzer {}
123);
124
125impl SCVideoStreamAnalyzer {
126    extern_methods!(
127        #[cfg(feature = "SCSensitivityAnalysis")]
128        /// The results of the first detected sensitive video frame.
129        ///
130        /// The analysis also includes suggestions for the app based on the nature of the sensitive content, specifically: ``SCSensitivityAnalysis/shouldInterruptVideo``, ``SCSensitivityAnalysis/shouldIndicateSensitivity`` and ``SCSensitivityAnalysis/shouldMuteAudio``.
131        #[unsafe(method(analysis))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn analysis(&self) -> Option<Retained<SCSensitivityAnalysis>>;
134
135        #[cfg(all(feature = "SCSensitivityAnalysis", feature = "block2"))]
136        /// A handler that your app provides to react to sensitive content detection.
137        ///
138        /// The system invokes all analyzer handlers on the same conference call with the updated analysis or error.
139        ///
140        /// # Safety
141        ///
142        /// - The returned block's argument 1 must be a valid pointer or null.
143        /// - The returned block's argument 2 must be a valid pointer or null.
144        #[unsafe(method(analysisChangedHandler))]
145        #[unsafe(method_family = none)]
146        pub unsafe fn analysisChangedHandler(&self) -> SCVideoStreamAnalysisChangeHandler;
147
148        #[cfg(all(feature = "SCSensitivityAnalysis", feature = "block2"))]
149        /// Setter for [`analysisChangedHandler`][Self::analysisChangedHandler].
150        ///
151        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
152        ///
153        /// # Safety
154        ///
155        /// `analysis_changed_handler` must be a valid pointer or null.
156        #[unsafe(method(setAnalysisChangedHandler:))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn setAnalysisChangedHandler(
159            &self,
160            analysis_changed_handler: SCVideoStreamAnalysisChangeHandler,
161        );
162
163        /// Creates a video stream analyzer for the given call participant and stream option.
164        ///
165        /// - parameter participantUUID: A unique identifier that you provide to distinguish among multiple individuals on a conference call. Set this argument to the same value per person on the call, if your app supports multiple streams per person.
166        /// - parameter streamDirection: An option that indicates whether the stream comes from the device's camera or from a remote individual signed in to the call.
167        /// - parameter error: An error that occurs while intializing a video stream analyzer.
168        ///
169        /// - Important: This class works only when the Communication Safety parental control in Screen Time is enabled, or when Sensitive Content Warnings is on in Settings. This method throws an error if both settings are off, or if the device doesn't support analysis for the specified stream direction.
170        #[unsafe(method(initWithParticipantUUID:streamDirection:error:_))]
171        #[unsafe(method_family = init)]
172        pub unsafe fn initWithParticipantUUID_streamDirection_error(
173            this: Allocated<Self>,
174            participant_uuid: &NSString,
175            stream_direction: SCVideoStreamAnalyzerStreamDirection,
176        ) -> Result<Retained<Self>, Retained<NSError>>;
177
178        #[unsafe(method(init))]
179        #[unsafe(method_family = init)]
180        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
181
182        #[unsafe(method(new))]
183        #[unsafe(method_family = new)]
184        pub unsafe fn new(&self) -> Retained<Self>;
185
186        #[cfg(feature = "objc2-core-video")]
187        /// Analyzes individual video-stream frames for sensitive content.
188        ///
189        /// This method analyzes a specific video frame and updates ``analysis`` according to the results. If your app implements a custom stream decoder, you can call this method for each video frame.
190        #[unsafe(method(analyzePixelBuffer:))]
191        #[unsafe(method_family = none)]
192        pub unsafe fn analyzePixelBuffer(&self, pixel_buffer: &CVPixelBuffer);
193    );
194}
195
196/// Methods declared on superclass `NSObject`.
197impl SCVideoStreamAnalyzer {
198    extern_methods!(
199        #[unsafe(method(new))]
200        #[unsafe(method_family = new)]
201        pub unsafe fn new_class() -> Retained<Self>;
202    );
203}
204
205/// SessionManagement.
206impl SCVideoStreamAnalyzer {
207    extern_methods!(
208        #[cfg(feature = "objc2-video-toolbox")]
209        /// Analyzes video frames for the given decompression session.
210        ///
211        /// - parameter decompressionSession: An object that provides video frames for your app to analyze for sensitive content.
212        /// - parameter error: An error object that describes an issue that occurs while providing the video decompression session.
213        /// - returns: `YES` if the method succeeds; otherwise, `NO`.
214        ///
215        /// If the framework detects sensitive content in the video stream, the
216        /// <doc
217        /// ://com.apple.documentation/documentation/videotoolbox/vtdecompressionsession> produces blank frames to effectively censor the video stream on the person's behalf. When your app is ready to show the video stream again, resume analysis by calling ``continueStream``.
218        #[unsafe(method(beginAnalysisOfDecompressionSession:error:_))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn beginAnalysisOfDecompressionSession_error(
221            &self,
222            decompression_session: &VTDecompressionSession,
223        ) -> Result<(), Retained<NSError>>;
224
225        #[cfg(feature = "objc2-av-foundation")]
226        /// Analyzes video frames for the given capture device input.
227        ///
228        /// - parameter captureDeviceInput: An object that contains information about the specific camera and its captured content in the video stream.
229        /// - parameter error: An error object that describes an issue that occurs while processing the capture device input.
230        /// - returns: `YES` if the method succeeds; otherwise, `NO`.
231        ///
232        /// Call this method to begin analyzing a video stream from the given
233        /// <doc
234        /// ://com.apple.documentation/documentation/avfoundation/avcapturedeviceinput>. If the framework detects sensitive content in the video stream, the capture-device-input interrupts subsequent frames with the `AVCaptureSessionInterruptionReasonSensitiveContentMitigationActivated` interruption reason to effectively censor the video stream on the person's behalf. When your app is ready to show the video stream again, resume analysis by calling ``continueStream``.
235        #[unsafe(method(beginAnalysisOfCaptureDeviceInput:error:_))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn beginAnalysisOfCaptureDeviceInput_error(
238            &self,
239            capture_device_input: &AVCaptureDeviceInput,
240        ) -> Result<(), Retained<NSError>>;
241
242        /// Stops stream analysis.
243        ///
244        /// This method stops analyzing the video stream in reference to the most recent call to `beginAnalysis`.
245        #[unsafe(method(endAnalysis))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn endAnalysis(&self);
248
249        /// Indicates that your app is ready to resume video stream analysis.
250        ///
251        /// When the framework detects sensitive content in the video stream, it pauses analysis and begins censoring the stream's video frames. Call this method to resume analysis and stop censoring video frames when your app is ready to show the stream again.
252        #[unsafe(method(continueStream))]
253        #[unsafe(method_family = none)]
254        pub unsafe fn continueStream(&self);
255    );
256}
257
258/// VideoStreamAnalysis.
259///
260/// Intervention guidance that the framework recommends based on the nature of the detected sensitive content.
261#[cfg(feature = "SCSensitivityAnalysis")]
262impl SCSensitivityAnalysis {
263    extern_methods!(
264        /// Intervention guidance that suggests the app interrupt the video stream.
265        #[unsafe(method(shouldInterruptVideo))]
266        #[unsafe(method_family = none)]
267        pub unsafe fn shouldInterruptVideo(&self) -> bool;
268
269        /// Intervention guidance that suggests the app indicate the presence of sensitive content.
270        #[unsafe(method(shouldIndicateSensitivity))]
271        #[unsafe(method_family = none)]
272        pub unsafe fn shouldIndicateSensitivity(&self) -> bool;
273
274        /// Intervention guidance that suggests the app mute the audio of the current video stream.
275        #[unsafe(method(shouldMuteAudio))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn shouldMuteAudio(&self) -> bool;
278    );
279}