av_foundation/
capture_session.rs1use objc2::{extern_class, msg_send, msg_send_id, mutability::InteriorMutable, rc::Id, ClassType};
2use objc2_foundation::{NSArray, NSInteger, NSObject, NSObjectProtocol, NSString};
3
4use crate::{capture_input::AVCaptureInput, capture_output_base::AVCaptureOutput, capture_session_preset::AVCaptureSessionPreset};
5
6extern "C" {
7 pub static AVCaptureSessionRuntimeErrorNotification: &'static NSString;
8 pub static AVCaptureSessionErrorKey: &'static NSString;
9 pub static AVCaptureSessionDidStartRunningNotification: &'static NSString;
10 pub static AVCaptureSessionDidStopRunningNotification: &'static NSString;
11 pub static AVCaptureSessionWasInterruptedNotification: &'static NSString;
12 pub static AVCaptureSessionInterruptionReasonKey: &'static NSString;
13 pub static AVCaptureSessionInterruptionSystemPressureStateKey: &'static NSString;
14 pub static AVCaptureSessionInterruptionEndedNotification: &'static NSString;
15}
16
17pub type AVCaptureSessionInterruptionReason = NSInteger;
18
19pub const AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableInBackground: AVCaptureSessionInterruptionReason = 1;
20pub const AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient: AVCaptureSessionInterruptionReason = 2;
21pub const AVCaptureSessionInterruptionReasonVideoDeviceInUseByAnotherClient: AVCaptureSessionInterruptionReason = 3;
22pub const AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableWithMultipleForegroundApps: AVCaptureSessionInterruptionReason = 4;
23pub const AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableDueToSystemPressure: AVCaptureSessionInterruptionReason = 5;
24
25pub type AVCaptureVideoOrientation = NSInteger;
26
27pub const AVCaptureVideoOrientationPortrait: AVCaptureVideoOrientation = 1;
28pub const AVCaptureVideoOrientationPortraitUpsideDown: AVCaptureVideoOrientation = 2;
29pub const AVCaptureVideoOrientationLandscapeRight: AVCaptureVideoOrientation = 3;
30pub const AVCaptureVideoOrientationLandscapeLeft: AVCaptureVideoOrientation = 4;
31
32extern_class!(
33 #[derive(Debug, PartialEq, Eq, Hash)]
34 pub struct AVCaptureSession;
35
36 unsafe impl ClassType for AVCaptureSession {
37 type Super = NSObject;
38 type Mutability = InteriorMutable;
39 }
40);
41
42unsafe impl NSObjectProtocol for AVCaptureSession {}
43
44impl AVCaptureSession {
45 pub fn new() -> Id<Self> {
46 unsafe { msg_send_id![AVCaptureSession::class(), new] }
47 }
48 pub fn can_set_session_preset(&self, preset: &AVCaptureSessionPreset) -> bool {
49 unsafe { msg_send![self, canSetSessionPreset: preset] }
50 }
51
52 pub fn get_session_preset(&self) -> Id<AVCaptureSessionPreset> {
53 unsafe { msg_send_id![self, sessionPreset] }
54 }
55
56 pub fn set_session_preset(&self, preset: &AVCaptureSessionPreset) {
57 unsafe { msg_send![self, setSessionPreset: preset] }
58 }
59
60 pub fn inputs(&self) -> Id<NSArray<AVCaptureInput>> {
61 unsafe { msg_send_id![self, inputs] }
62 }
63
64 pub fn can_add_input(&self, input: &AVCaptureInput) -> bool {
65 unsafe { msg_send![self, canAddInput: input] }
66 }
67
68 pub fn add_input(&self, input: &AVCaptureInput) {
69 unsafe { msg_send![self, addInput: input] }
70 }
71
72 pub fn remove_input(&self, input: &AVCaptureInput) {
73 unsafe { msg_send![self, removeInput: input] }
74 }
75
76 pub fn outputs(&self) -> Id<NSArray<AVCaptureOutput>> {
77 unsafe { msg_send_id![self, outputs] }
78 }
79
80 pub fn can_add_output(&self, output: &AVCaptureOutput) -> bool {
81 unsafe { msg_send![self, canAddOutput: output] }
82 }
83
84 pub fn add_output(&self, output: &AVCaptureOutput) {
85 unsafe { msg_send![self, addOutput: output] }
86 }
87
88 pub fn remove_output(&self, output: &AVCaptureOutput) {
89 unsafe { msg_send![self, removeOutput: output] }
90 }
91
92 pub fn add_input_with_no_connections(&self, input: &AVCaptureInput) {
93 unsafe { msg_send![self, addInputWithNoConnections: input] }
94 }
95
96 pub fn add_output_with_no_connections(&self, output: &AVCaptureOutput) {
97 unsafe { msg_send![self, addOutputWithNoConnections: output] }
98 }
99
100 pub fn connections(&self) -> Id<NSArray<AVCaptureConnection>> {
101 unsafe { msg_send_id![self, connections] }
102 }
103
104 pub fn can_add_connection(&self, connection: &AVCaptureConnection) -> bool {
105 unsafe { msg_send![self, canAddConnection: connection] }
106 }
107
108 pub fn add_connection(&self, connection: &AVCaptureConnection) {
109 unsafe { msg_send![self, addConnection: connection] }
110 }
111
112 pub fn remove_connection(&self, connection: &AVCaptureConnection) {
113 unsafe { msg_send![self, removeConnection: connection] }
114 }
115
116 pub fn is_running(&self) -> bool {
117 unsafe { msg_send![self, isRunning] }
118 }
119
120 #[cfg(target_os = "ios")]
121 pub fn is_interrupted(&self) -> bool {
122 unsafe { msg_send![self, isInterrupted] }
123 }
124
125 #[cfg(target_os = "ios")]
126 pub fn is_multitasking_camera_access_supported(&self) -> bool {
127 unsafe { msg_send![self, isMultitaskingCameraAccessSupported] }
128 }
129
130 #[cfg(target_os = "ios")]
131 pub fn get_uses_application_audio_session(&self) -> bool {
132 unsafe { msg_send![self, usesApplicationAudioSession] }
133 }
134
135 #[cfg(target_os = "ios")]
136 pub fn set_uses_application_audio_session(&self, uses_application_audio_session: bool) {
137 unsafe { msg_send![self, setUsesApplicationAudioSession: uses_application_audio_session] }
138 }
139
140 pub fn begin_configuration(&self) {
141 unsafe { msg_send![self, beginConfiguration] }
142 }
143
144 pub fn commit_configuration(&self) {
145 unsafe { msg_send![self, commitConfiguration] }
146 }
147
148 pub fn start_running(&self) {
149 unsafe { msg_send![self, startRunning] }
150 }
151
152 pub fn stop_running(&self) {
153 unsafe { msg_send![self, stopRunning] }
154 }
155}
156
157extern_class!(
158 #[derive(Debug, PartialEq, Eq, Hash)]
159 pub struct AVCaptureConnection;
160
161 unsafe impl ClassType for AVCaptureConnection {
162 type Super = NSObject;
163 type Mutability = InteriorMutable;
164 }
165);
166
167unsafe impl NSObjectProtocol for AVCaptureConnection {}