objc2-replay-kit 0.3.2

Bindings to the ReplayKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
use objc2_app_kit::*;
#[cfg(feature = "objc2-core-media")]
use objc2_core_media::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/replaykit/rpcameraposition?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct RPCameraPosition(pub NSInteger);
impl RPCameraPosition {
    #[doc(alias = "RPCameraPositionFront")]
    pub const Front: Self = Self(1);
    #[doc(alias = "RPCameraPositionBack")]
    pub const Back: Self = Self(2);
}

unsafe impl Encode for RPCameraPosition {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for RPCameraPosition {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Singleton class used to control app recording.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/replaykit/rpscreenrecorder?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct RPScreenRecorder;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for RPScreenRecorder {}
);

impl RPScreenRecorder {
    extern_methods!(
        #[unsafe(method(sharedRecorder))]
        #[unsafe(method_family = none)]
        pub unsafe fn sharedRecorder() -> Retained<RPScreenRecorder>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(feature = "block2")]
        /// Deprecated. Use startRecordingWithHandler: instead.
        ///
        ///
        /// Starts app recording with a completion handler. Note that before recording actually starts, the user may be prompted with UI to confirm recording.
        ///
        /// Parameter `microphoneEnabled`: Determines whether the microphone input should be included in the recorded movie audio.
        ///
        /// 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.
        #[deprecated = "Use microphoneEnabled property"]
        #[unsafe(method(startRecordingWithMicrophoneEnabled:handler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn startRecordingWithMicrophoneEnabled_handler(
            &self,
            microphone_enabled: bool,
            handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Starts app recording with a completion handler. Note that before recording actually starts, the user may be prompted with UI to confirm recording.
        ///
        /// 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.
        #[unsafe(method(startRecordingWithHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn startRecordingWithHandler(
            &self,
            handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(all(
            feature = "RPPreviewViewController",
            feature = "block2",
            feature = "objc2-app-kit"
        ))]
        #[cfg(target_os = "macos")]
        /// Stops app recording with a completion handler.
        ///
        /// 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.
        #[unsafe(method(stopRecordingWithHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn stopRecordingWithHandler(
            &self,
            handler: Option<&block2::DynBlock<dyn Fn(*mut RPPreviewViewController, *mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Stops app recording with output URL and completion handler.
        ///
        /// Parameter `url`: Output URL for app recording movie.
        ///
        /// 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.
        #[unsafe(method(stopRecordingWithOutputURL:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn stopRecordingWithOutputURL_completionHandler(
            &self,
            url: &NSURL,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Discards the current recording. This can only be called after the handler block in stopRecordingWithHandler: is executed.
        #[unsafe(method(discardRecordingWithHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn discardRecordingWithHandler(&self, handler: &block2::DynBlock<dyn Fn()>);

        #[cfg(all(
            feature = "RPBroadcastExtension",
            feature = "block2",
            feature = "objc2-core-media"
        ))]
        /// 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.
        ///
        /// 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.
        #[unsafe(method(startCaptureWithHandler:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn startCaptureWithHandler_completionHandler(
            &self,
            capture_handler: Option<
                &block2::DynBlock<
                    dyn Fn(NonNull<CMSampleBuffer>, RPSampleBufferType, *mut NSError),
                >,
            >,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Stops screen capture with a completion handler
        ///
        /// 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
        #[unsafe(method(stopCaptureWithHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn stopCaptureWithHandler(
            &self,
            handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Start clip recording buffering with a completion handler. Note that before recording actually starts, the user may be prompted with UI to confirm recording.
        ///
        /// 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.
        #[unsafe(method(startClipBufferingWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn startClipBufferingWithCompletionHandler(
            &self,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Stop clip recording buffering with a completion handler.
        ///
        /// 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.
        #[unsafe(method(stopClipBufferingWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn stopClipBufferingWithCompletionHandler(
            &self,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Exports clip recording
        ///
        /// Parameter `url`: URL containing absolute path for where to save the clip
        ///
        /// 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
        ///
        /// 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.
        #[unsafe(method(exportClipToURL:duration:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn exportClipToURL_duration_completionHandler(
            &self,
            url: &NSURL,
            duration: NSTimeInterval,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn RPScreenRecorderDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn RPScreenRecorderDelegate>>,
        );

        #[unsafe(method(isAvailable))]
        #[unsafe(method_family = none)]
        pub unsafe fn isAvailable(&self) -> bool;

        #[unsafe(method(isRecording))]
        #[unsafe(method_family = none)]
        pub unsafe fn isRecording(&self) -> bool;

        #[unsafe(method(isMicrophoneEnabled))]
        #[unsafe(method_family = none)]
        pub unsafe fn isMicrophoneEnabled(&self) -> bool;

        /// Setter for [`isMicrophoneEnabled`][Self::isMicrophoneEnabled].
        #[unsafe(method(setMicrophoneEnabled:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMicrophoneEnabled(&self, microphone_enabled: bool);

        #[unsafe(method(isCameraEnabled))]
        #[unsafe(method_family = none)]
        pub unsafe fn isCameraEnabled(&self) -> bool;

        /// Setter for [`isCameraEnabled`][Self::isCameraEnabled].
        #[unsafe(method(setCameraEnabled:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCameraEnabled(&self, camera_enabled: bool);

        #[unsafe(method(cameraPosition))]
        #[unsafe(method_family = none)]
        pub unsafe fn cameraPosition(&self) -> RPCameraPosition;

        /// Setter for [`cameraPosition`][Self::cameraPosition].
        #[unsafe(method(setCameraPosition:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCameraPosition(&self, camera_position: RPCameraPosition);

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        #[unsafe(method(cameraPreviewView))]
        #[unsafe(method_family = none)]
        pub unsafe fn cameraPreviewView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
    );
}

/// Methods declared on superclass `NSObject`.
impl RPScreenRecorder {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/replaykit/rpscreenrecorderdelegate?language=objc)
    pub unsafe trait RPScreenRecorderDelegate: NSObjectProtocol {
        #[cfg(all(feature = "RPPreviewViewController", feature = "objc2-app-kit"))]
        #[cfg(target_os = "macos")]
        /// Called when recording has stopped due to an error.
        ///
        /// Parameter `screenRecorder`: The instance of the screen recorder.
        ///
        /// Parameter `error`: An NSError describing why recording has stopped in the RPRecordingErrorDomain.
        ///
        /// Parameter `previewViewController`: If a partial movie is available before it was stopped, an instance of RPPreviewViewController will be returned.
        #[deprecated = "No longer supported"]
        #[optional]
        #[unsafe(method(screenRecorder:didStopRecordingWithError:previewViewController:))]
        #[unsafe(method_family = none)]
        unsafe fn screenRecorder_didStopRecordingWithError_previewViewController(
            &self,
            screen_recorder: &RPScreenRecorder,
            error: &NSError,
            preview_view_controller: Option<&RPPreviewViewController>,
        );

        #[cfg(all(feature = "RPPreviewViewController", feature = "objc2-app-kit"))]
        #[cfg(target_os = "macos")]
        #[optional]
        #[unsafe(method(screenRecorder:didStopRecordingWithPreviewViewController:error:))]
        #[unsafe(method_family = none)]
        unsafe fn screenRecorder_didStopRecordingWithPreviewViewController_error(
            &self,
            screen_recorder: &RPScreenRecorder,
            preview_view_controller: Option<&RPPreviewViewController>,
            error: Option<&NSError>,
        );

        /// 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.
        ///
        /// Parameter `screenRecorder`: The instance of the screen recorder.
        #[optional]
        #[unsafe(method(screenRecorderDidChangeAvailability:))]
        #[unsafe(method_family = none)]
        unsafe fn screenRecorderDidChangeAvailability(&self, screen_recorder: &RPScreenRecorder);
    }
);