av_foundation/
capture_session.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use objc2::{extern_class, msg_send, msg_send_id, mutability::InteriorMutable, rc::Id, ClassType};
use objc2_foundation::{NSArray, NSInteger, NSObject, NSObjectProtocol, NSString};

use crate::{capture_input::AVCaptureInput, capture_output_base::AVCaptureOutput, capture_session_preset::AVCaptureSessionPreset};

extern "C" {
    pub static AVCaptureSessionRuntimeErrorNotification: &'static NSString;
    pub static AVCaptureSessionErrorKey: &'static NSString;
    pub static AVCaptureSessionDidStartRunningNotification: &'static NSString;
    pub static AVCaptureSessionDidStopRunningNotification: &'static NSString;
    pub static AVCaptureSessionWasInterruptedNotification: &'static NSString;
    pub static AVCaptureSessionInterruptionReasonKey: &'static NSString;
    pub static AVCaptureSessionInterruptionSystemPressureStateKey: &'static NSString;
    pub static AVCaptureSessionInterruptionEndedNotification: &'static NSString;
}

pub type AVCaptureSessionInterruptionReason = NSInteger;

pub const AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableInBackground: AVCaptureSessionInterruptionReason = 1;
pub const AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient: AVCaptureSessionInterruptionReason = 2;
pub const AVCaptureSessionInterruptionReasonVideoDeviceInUseByAnotherClient: AVCaptureSessionInterruptionReason = 3;
pub const AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableWithMultipleForegroundApps: AVCaptureSessionInterruptionReason = 4;
pub const AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableDueToSystemPressure: AVCaptureSessionInterruptionReason = 5;

pub type AVCaptureVideoOrientation = NSInteger;

pub const AVCaptureVideoOrientationPortrait: AVCaptureVideoOrientation = 1;
pub const AVCaptureVideoOrientationPortraitUpsideDown: AVCaptureVideoOrientation = 2;
pub const AVCaptureVideoOrientationLandscapeRight: AVCaptureVideoOrientation = 3;
pub const AVCaptureVideoOrientationLandscapeLeft: AVCaptureVideoOrientation = 4;

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVCaptureSession;

    unsafe impl ClassType for AVCaptureSession {
        type Super = NSObject;
        type Mutability = InteriorMutable;
    }
);

unsafe impl NSObjectProtocol for AVCaptureSession {}

impl AVCaptureSession {
    pub fn new() -> Id<Self> {
        unsafe { msg_send_id![AVCaptureSession::class(), new] }
    }
    pub fn can_set_session_preset(&self, preset: &AVCaptureSessionPreset) -> bool {
        unsafe { msg_send![self, canSetSessionPreset: preset] }
    }

    pub fn get_session_preset(&self) -> Id<AVCaptureSessionPreset> {
        unsafe { msg_send_id![self, sessionPreset] }
    }

    pub fn set_session_preset(&self, preset: &AVCaptureSessionPreset) {
        unsafe { msg_send![self, setSessionPreset: preset] }
    }

    pub fn inputs(&self) -> Id<NSArray<AVCaptureInput>> {
        unsafe { msg_send_id![self, inputs] }
    }

    pub fn can_add_input(&self, input: &AVCaptureInput) -> bool {
        unsafe { msg_send![self, canAddInput: input] }
    }

    pub fn add_input(&self, input: &AVCaptureInput) {
        unsafe { msg_send![self, addInput: input] }
    }

    pub fn remove_input(&self, input: &AVCaptureInput) {
        unsafe { msg_send![self, removeInput: input] }
    }

    pub fn outputs(&self) -> Id<NSArray<AVCaptureOutput>> {
        unsafe { msg_send_id![self, outputs] }
    }

    pub fn can_add_output(&self, output: &AVCaptureOutput) -> bool {
        unsafe { msg_send![self, canAddOutput: output] }
    }

    pub fn add_output(&self, output: &AVCaptureOutput) {
        unsafe { msg_send![self, addOutput: output] }
    }

    pub fn remove_output(&self, output: &AVCaptureOutput) {
        unsafe { msg_send![self, removeOutput: output] }
    }

    pub fn add_input_with_no_connections(&self, input: &AVCaptureInput) {
        unsafe { msg_send![self, addInputWithNoConnections: input] }
    }

    pub fn add_output_with_no_connections(&self, output: &AVCaptureOutput) {
        unsafe { msg_send![self, addOutputWithNoConnections: output] }
    }

    pub fn connections(&self) -> Id<NSArray<AVCaptureConnection>> {
        unsafe { msg_send_id![self, connections] }
    }

    pub fn can_add_connection(&self, connection: &AVCaptureConnection) -> bool {
        unsafe { msg_send![self, canAddConnection: connection] }
    }

    pub fn add_connection(&self, connection: &AVCaptureConnection) {
        unsafe { msg_send![self, addConnection: connection] }
    }

    pub fn remove_connection(&self, connection: &AVCaptureConnection) {
        unsafe { msg_send![self, removeConnection: connection] }
    }

    pub fn is_running(&self) -> bool {
        unsafe { msg_send![self, isRunning] }
    }

    #[cfg(target_os = "ios")]
    pub fn is_interrupted(&self) -> bool {
        unsafe { msg_send![self, isInterrupted] }
    }

    #[cfg(target_os = "ios")]
    pub fn is_multitasking_camera_access_supported(&self) -> bool {
        unsafe { msg_send![self, isMultitaskingCameraAccessSupported] }
    }

    #[cfg(target_os = "ios")]
    pub fn get_uses_application_audio_session(&self) -> bool {
        unsafe { msg_send![self, usesApplicationAudioSession] }
    }

    #[cfg(target_os = "ios")]
    pub fn set_uses_application_audio_session(&self, uses_application_audio_session: bool) {
        unsafe { msg_send![self, setUsesApplicationAudioSession: uses_application_audio_session] }
    }

    pub fn begin_configuration(&self) {
        unsafe { msg_send![self, beginConfiguration] }
    }

    pub fn commit_configuration(&self) {
        unsafe { msg_send![self, commitConfiguration] }
    }

    pub fn start_running(&self) {
        unsafe { msg_send![self, startRunning] }
    }

    pub fn stop_running(&self) {
        unsafe { msg_send![self, stopRunning] }
    }
}

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVCaptureConnection;

    unsafe impl ClassType for AVCaptureConnection {
        type Super = NSObject;
        type Mutability = InteriorMutable;
    }
);

unsafe impl NSObjectProtocol for AVCaptureConnection {}