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        /// This is a [weak property][objc2::topics::weak_property].
200        /// Setter for [`delegate`][Self::delegate].
201        #[unsafe(method(setDelegate:))]
202        #[unsafe(method_family = none)]
203        pub unsafe fn setDelegate(
204            &self,
205            delegate: Option<&ProtocolObject<dyn RPScreenRecorderDelegate>>,
206        );
207
208        #[unsafe(method(isAvailable))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn isAvailable(&self) -> bool;
211
212        #[unsafe(method(isRecording))]
213        #[unsafe(method_family = none)]
214        pub unsafe fn isRecording(&self) -> bool;
215
216        #[unsafe(method(isMicrophoneEnabled))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn isMicrophoneEnabled(&self) -> bool;
219
220        /// Setter for [`isMicrophoneEnabled`][Self::isMicrophoneEnabled].
221        #[unsafe(method(setMicrophoneEnabled:))]
222        #[unsafe(method_family = none)]
223        pub unsafe fn setMicrophoneEnabled(&self, microphone_enabled: bool);
224
225        #[unsafe(method(isCameraEnabled))]
226        #[unsafe(method_family = none)]
227        pub unsafe fn isCameraEnabled(&self) -> bool;
228
229        /// Setter for [`isCameraEnabled`][Self::isCameraEnabled].
230        #[unsafe(method(setCameraEnabled:))]
231        #[unsafe(method_family = none)]
232        pub unsafe fn setCameraEnabled(&self, camera_enabled: bool);
233
234        #[unsafe(method(cameraPosition))]
235        #[unsafe(method_family = none)]
236        pub unsafe fn cameraPosition(&self) -> RPCameraPosition;
237
238        /// Setter for [`cameraPosition`][Self::cameraPosition].
239        #[unsafe(method(setCameraPosition:))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn setCameraPosition(&self, camera_position: RPCameraPosition);
242
243        #[cfg(feature = "objc2-app-kit")]
244        #[cfg(target_os = "macos")]
245        #[unsafe(method(cameraPreviewView))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn cameraPreviewView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
248    );
249}
250
251/// Methods declared on superclass `NSObject`.
252impl RPScreenRecorder {
253    extern_methods!(
254        #[unsafe(method(new))]
255        #[unsafe(method_family = new)]
256        pub unsafe fn new() -> Retained<Self>;
257    );
258}
259
260extern_protocol!(
261    /// [Apple's documentation](https://developer.apple.com/documentation/replaykit/rpscreenrecorderdelegate?language=objc)
262    pub unsafe trait RPScreenRecorderDelegate: NSObjectProtocol {
263        #[cfg(all(feature = "RPPreviewViewController", feature = "objc2-app-kit"))]
264        #[cfg(target_os = "macos")]
265        /// Called when recording has stopped due to an error.
266        ///
267        /// Parameter `screenRecorder`: The instance of the screen recorder.
268        ///
269        /// Parameter `error`: An NSError describing why recording has stopped in the RPRecordingErrorDomain.
270        ///
271        /// Parameter `previewViewController`: If a partial movie is available before it was stopped, an instance of RPPreviewViewController will be returned.
272        #[deprecated = "No longer supported"]
273        #[optional]
274        #[unsafe(method(screenRecorder:didStopRecordingWithError:previewViewController:))]
275        #[unsafe(method_family = none)]
276        unsafe fn screenRecorder_didStopRecordingWithError_previewViewController(
277            &self,
278            screen_recorder: &RPScreenRecorder,
279            error: &NSError,
280            preview_view_controller: Option<&RPPreviewViewController>,
281        );
282
283        #[cfg(all(feature = "RPPreviewViewController", feature = "objc2-app-kit"))]
284        #[cfg(target_os = "macos")]
285        #[optional]
286        #[unsafe(method(screenRecorder:didStopRecordingWithPreviewViewController:error:))]
287        #[unsafe(method_family = none)]
288        unsafe fn screenRecorder_didStopRecordingWithPreviewViewController_error(
289            &self,
290            screen_recorder: &RPScreenRecorder,
291            preview_view_controller: Option<&RPPreviewViewController>,
292            error: Option<&NSError>,
293        );
294
295        /// 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.
296        ///
297        /// Parameter `screenRecorder`: The instance of the screen recorder.
298        #[optional]
299        #[unsafe(method(screenRecorderDidChangeAvailability:))]
300        #[unsafe(method_family = none)]
301        unsafe fn screenRecorderDidChangeAvailability(&self, screen_recorder: &RPScreenRecorder);
302    }
303);