objc2_replay_kit/generated/
RPScreenRecorder.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-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9#[cfg(feature = "objc2-core-media")]
10use objc2_core_media::*;
11use objc2_foundation::*;
12
13use crate::*;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/replaykit/rpcameraposition?language=objc)
16// NS_ENUM
17#[repr(transparent)]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
19pub struct RPCameraPosition(pub NSInteger);
20impl RPCameraPosition {
21    #[doc(alias = "RPCameraPositionFront")]
22    pub const Front: Self = Self(1);
23    #[doc(alias = "RPCameraPositionBack")]
24    pub const Back: Self = Self(2);
25}
26
27unsafe impl Encode for RPCameraPosition {
28    const ENCODING: Encoding = NSInteger::ENCODING;
29}
30
31unsafe impl RefEncode for RPCameraPosition {
32    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35extern_class!(
36    /// Singleton class used to control app recording.
37    ///
38    /// See also [Apple's documentation](https://developer.apple.com/documentation/replaykit/rpscreenrecorder?language=objc)
39    #[unsafe(super(NSObject))]
40    #[derive(Debug, PartialEq, Eq, Hash)]
41    pub struct RPScreenRecorder;
42);
43
44extern_conformance!(
45    unsafe impl NSObjectProtocol for RPScreenRecorder {}
46);
47
48impl RPScreenRecorder {
49    extern_methods!(
50        #[unsafe(method(sharedRecorder))]
51        #[unsafe(method_family = none)]
52        pub unsafe fn sharedRecorder() -> Retained<RPScreenRecorder>;
53
54        #[unsafe(method(init))]
55        #[unsafe(method_family = init)]
56        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
57
58        #[cfg(feature = "block2")]
59        /// Deprecated. Use startRecordingWithHandler: instead.
60        ///
61        ///
62        /// Starts app recording with a completion handler. Note that before recording actually starts, the user may be prompted with UI to confirm recording.
63        ///
64        /// Parameter `microphoneEnabled`: Determines whether the microphone input should be included in the recorded movie audio.
65        ///
66        /// handler Called after user interactions are complete. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue starting the recording.
67        #[deprecated = "Use microphoneEnabled property"]
68        #[unsafe(method(startRecordingWithMicrophoneEnabled:handler:))]
69        #[unsafe(method_family = none)]
70        pub unsafe fn startRecordingWithMicrophoneEnabled_handler(
71            &self,
72            microphone_enabled: bool,
73            handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
74        );
75
76        #[cfg(feature = "block2")]
77        /// Starts app recording with a completion handler. Note that before recording actually starts, the user may be prompted with UI to confirm recording.
78        ///
79        /// handler Called after user interactions are complete. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue starting the recording.
80        #[unsafe(method(startRecordingWithHandler:))]
81        #[unsafe(method_family = none)]
82        pub unsafe fn startRecordingWithHandler(
83            &self,
84            handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
85        );
86
87        #[cfg(all(
88            feature = "RPPreviewViewController",
89            feature = "block2",
90            feature = "objc2-app-kit"
91        ))]
92        #[cfg(target_os = "macos")]
93        /// Stops app recording with a completion handler.
94        ///
95        /// handler Called when the movie is ready. Will return an instance of RPPreviewViewController on success which should be presented using [UIViewController presentViewController:animated:completion:]. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue stopping the recording.
96        #[unsafe(method(stopRecordingWithHandler:))]
97        #[unsafe(method_family = none)]
98        pub unsafe fn stopRecordingWithHandler(
99            &self,
100            handler: Option<&block2::DynBlock<dyn Fn(*mut RPPreviewViewController, *mut NSError)>>,
101        );
102
103        #[cfg(feature = "block2")]
104        /// Stops app recording with output URL and completion handler.
105        ///
106        /// Parameter `url`: Output URL for app recording movie.
107        ///
108        /// handler Called when  movie is written to specified output URL. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue stopping the recording and writing the output URL.
109        #[unsafe(method(stopRecordingWithOutputURL:completionHandler:))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn stopRecordingWithOutputURL_completionHandler(
112            &self,
113            url: &NSURL,
114            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
115        );
116
117        #[cfg(feature = "block2")]
118        /// Discards the current recording. This can only be called after the handler block in stopRecordingWithHandler: is executed.
119        #[unsafe(method(discardRecordingWithHandler:))]
120        #[unsafe(method_family = none)]
121        pub unsafe fn discardRecordingWithHandler(&self, handler: &block2::DynBlock<dyn Fn()>);
122
123        #[cfg(all(
124            feature = "RPBroadcastExtension",
125            feature = "block2",
126            feature = "objc2-core-media"
127        ))]
128        /// Starts screen and audio capture and continually calls the supplied handler with the current sampleBuffer and bufferType and passed it back to the application. Note that before recording actually starts, the user may be prompted with UI to confirm recording.
129        ///
130        /// handler Called continually with sampleBuffers and the bufferType. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue starting the capture.
131        #[unsafe(method(startCaptureWithHandler:completionHandler:))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn startCaptureWithHandler_completionHandler(
134            &self,
135            capture_handler: Option<
136                &block2::DynBlock<
137                    dyn Fn(NonNull<CMSampleBuffer>, RPSampleBufferType, *mut NSError),
138                >,
139            >,
140            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
141        );
142
143        #[cfg(feature = "block2")]
144        /// Stops screen capture with a completion handler
145        ///
146        /// handler Called after the screen capture has stopped. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue stopping the capture
147        #[unsafe(method(stopCaptureWithHandler:))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn stopCaptureWithHandler(
150            &self,
151            handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
152        );
153
154        #[cfg(feature = "block2")]
155        /// Start clip recording buffering with a completion handler. Note that before recording actually starts, the user may be prompted with UI to confirm recording.
156        ///
157        /// handler Called after clip recording is started. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue starting clip record buffering.
158        #[unsafe(method(startClipBufferingWithCompletionHandler:))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn startClipBufferingWithCompletionHandler(
161            &self,
162            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
163        );
164
165        #[cfg(feature = "block2")]
166        /// Stop clip recording buffering with a completion handler.
167        ///
168        /// handler Called after clip recording session is stopped. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue stopping clip record buffering.
169        #[unsafe(method(stopClipBufferingWithCompletionHandler:))]
170        #[unsafe(method_family = none)]
171        pub unsafe fn stopClipBufferingWithCompletionHandler(
172            &self,
173            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
174        );
175
176        #[cfg(feature = "block2")]
177        /// Exports clip recording
178        ///
179        /// Parameter `url`: URL containing absolute path for where to save the clip
180        ///
181        /// Parameter `duration`: Length of time in seconds for clip recording, capped at either the elapsed time, or a maximum of 15 seconds, depending on which is the shorter amount of time
182        ///
183        /// Must be called after startClipBufferingWithCompletionHandler:, otherwise this will return an error. Exports clip recording from newest samples in buffer for duration. handler Will be called after asset is finished writing to output path. Will be passed an optional NSError in the RPRecordingErrorDomain domain if there was an issue generating the clip recording.
184        #[unsafe(method(exportClipToURL:duration:completionHandler:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn exportClipToURL_duration_completionHandler(
187            &self,
188            url: &NSURL,
189            duration: NSTimeInterval,
190            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
191        );
192
193        #[unsafe(method(delegate))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn delegate(
196            &self,
197        ) -> Option<Retained<ProtocolObject<dyn RPScreenRecorderDelegate>>>;
198
199        /// Setter for [`delegate`][Self::delegate].
200        ///
201        /// This is a [weak property][objc2::topics::weak_property].
202        #[unsafe(method(setDelegate:))]
203        #[unsafe(method_family = none)]
204        pub unsafe fn setDelegate(
205            &self,
206            delegate: Option<&ProtocolObject<dyn RPScreenRecorderDelegate>>,
207        );
208
209        #[unsafe(method(isAvailable))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn isAvailable(&self) -> bool;
212
213        #[unsafe(method(isRecording))]
214        #[unsafe(method_family = none)]
215        pub unsafe fn isRecording(&self) -> bool;
216
217        #[unsafe(method(isMicrophoneEnabled))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn isMicrophoneEnabled(&self) -> bool;
220
221        /// Setter for [`isMicrophoneEnabled`][Self::isMicrophoneEnabled].
222        #[unsafe(method(setMicrophoneEnabled:))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn setMicrophoneEnabled(&self, microphone_enabled: bool);
225
226        #[unsafe(method(isCameraEnabled))]
227        #[unsafe(method_family = none)]
228        pub unsafe fn isCameraEnabled(&self) -> bool;
229
230        /// Setter for [`isCameraEnabled`][Self::isCameraEnabled].
231        #[unsafe(method(setCameraEnabled:))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn setCameraEnabled(&self, camera_enabled: bool);
234
235        #[unsafe(method(cameraPosition))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn cameraPosition(&self) -> RPCameraPosition;
238
239        /// Setter for [`cameraPosition`][Self::cameraPosition].
240        #[unsafe(method(setCameraPosition:))]
241        #[unsafe(method_family = none)]
242        pub unsafe fn setCameraPosition(&self, camera_position: RPCameraPosition);
243
244        #[cfg(feature = "objc2-app-kit")]
245        #[cfg(target_os = "macos")]
246        #[unsafe(method(cameraPreviewView))]
247        #[unsafe(method_family = none)]
248        pub unsafe fn cameraPreviewView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
249    );
250}
251
252/// Methods declared on superclass `NSObject`.
253impl RPScreenRecorder {
254    extern_methods!(
255        #[unsafe(method(new))]
256        #[unsafe(method_family = new)]
257        pub unsafe fn new() -> Retained<Self>;
258    );
259}
260
261extern_protocol!(
262    /// [Apple's documentation](https://developer.apple.com/documentation/replaykit/rpscreenrecorderdelegate?language=objc)
263    pub unsafe trait RPScreenRecorderDelegate: NSObjectProtocol {
264        #[cfg(all(feature = "RPPreviewViewController", feature = "objc2-app-kit"))]
265        #[cfg(target_os = "macos")]
266        /// Called when recording has stopped due to an error.
267        ///
268        /// Parameter `screenRecorder`: The instance of the screen recorder.
269        ///
270        /// Parameter `error`: An NSError describing why recording has stopped in the RPRecordingErrorDomain.
271        ///
272        /// Parameter `previewViewController`: If a partial movie is available before it was stopped, an instance of RPPreviewViewController will be returned.
273        #[deprecated = "No longer supported"]
274        #[optional]
275        #[unsafe(method(screenRecorder:didStopRecordingWithError:previewViewController:))]
276        #[unsafe(method_family = none)]
277        unsafe fn screenRecorder_didStopRecordingWithError_previewViewController(
278            &self,
279            screen_recorder: &RPScreenRecorder,
280            error: &NSError,
281            preview_view_controller: Option<&RPPreviewViewController>,
282        );
283
284        #[cfg(all(feature = "RPPreviewViewController", feature = "objc2-app-kit"))]
285        #[cfg(target_os = "macos")]
286        #[optional]
287        #[unsafe(method(screenRecorder:didStopRecordingWithPreviewViewController:error:))]
288        #[unsafe(method_family = none)]
289        unsafe fn screenRecorder_didStopRecordingWithPreviewViewController_error(
290            &self,
291            screen_recorder: &RPScreenRecorder,
292            preview_view_controller: Option<&RPPreviewViewController>,
293            error: Option<&NSError>,
294        );
295
296        /// Called when the recorder becomes available or stops being available. Check the screen recorder's availability property to check the current availability state. Possible reasons for the recorder to be unavailable include an in-progress Airplay/TVOut session or unsupported hardware.
297        ///
298        /// Parameter `screenRecorder`: The instance of the screen recorder.
299        #[optional]
300        #[unsafe(method(screenRecorderDidChangeAvailability:))]
301        #[unsafe(method_family = none)]
302        unsafe fn screenRecorderDidChangeAvailability(&self, screen_recorder: &RPScreenRecorder);
303    }
304);