objc2_ar_kit/generated/ARSession.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9#[cfg(feature = "objc2-core-media")]
10use objc2_core_media::*;
11#[cfg(feature = "objc2-foundation")]
12use objc2_foundation::*;
13
14use crate::*;
15
16/// Set of options for running the session.
17///
18/// These options alter the behavior of calling run on a session.
19/// Providing no options will result in the default behavior of resuming tracking
20/// from the last known position and keeping all existing anchors.
21///
22/// See also [Apple's documentation](https://developer.apple.com/documentation/arkit/arsessionrunoptions?language=objc)
23// NS_OPTIONS
24#[cfg(feature = "objc2")]
25#[repr(transparent)]
26#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
27pub struct ARSessionRunOptions(pub NSUInteger);
28#[cfg(feature = "objc2")]
29bitflags::bitflags! {
30 impl ARSessionRunOptions: NSUInteger {
31/// The session will reset tracking.
32 #[doc(alias = "ARSessionRunOptionResetTracking")]
33 const ResetTracking = 1<<0;
34/// The session will remove existing anchors.
35 #[doc(alias = "ARSessionRunOptionRemoveExistingAnchors")]
36 const RemoveExistingAnchors = 1<<1;
37/// The session will stop currently active tracked raycasts.
38 #[doc(alias = "ARSessionRunOptionStopTrackedRaycasts")]
39 const StopTrackedRaycasts = 1<<2;
40/// The session will reset scene reconstruction.
41 #[doc(alias = "ARSessionRunOptionResetSceneReconstruction")]
42 const ResetSceneReconstruction = 1<<3;
43 }
44}
45
46#[cfg(feature = "objc2")]
47unsafe impl Encode for ARSessionRunOptions {
48 const ENCODING: Encoding = NSUInteger::ENCODING;
49}
50
51#[cfg(feature = "objc2")]
52unsafe impl RefEncode for ARSessionRunOptions {
53 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
54}
55
56#[cfg(feature = "objc2")]
57extern_class!(
58 /// The ARSession class configures and runs different Augmented Reality techniques on a device.
59 ///
60 /// See also [Apple's documentation](https://developer.apple.com/documentation/arkit/arsession?language=objc)
61 #[unsafe(super(NSObject))]
62 #[derive(Debug, PartialEq, Eq, Hash)]
63 #[cfg(feature = "objc2")]
64 pub struct ARSession;
65);
66
67#[cfg(feature = "objc2")]
68extern_conformance!(
69 unsafe impl NSObjectProtocol for ARSession {}
70);
71
72#[cfg(feature = "objc2")]
73impl ARSession {
74 extern_methods!(
75 #[cfg(feature = "objc2-foundation")]
76 /// Unique identifier of the running session.
77 ///
78 ///
79 /// The identifier may change after calling runWithConfiguration.
80 #[unsafe(method(identifier))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn identifier(&self) -> Retained<NSUUID>;
83
84 /// A delegate for receiving ARSession updates.
85 #[unsafe(method(delegate))]
86 #[unsafe(method_family = none)]
87 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn ARSessionDelegate>>>;
88
89 /// This is a [weak property][objc2::topics::weak_property].
90 /// Setter for [`delegate`][Self::delegate].
91 #[unsafe(method(setDelegate:))]
92 #[unsafe(method_family = none)]
93 pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn ARSessionDelegate>>);
94
95 #[cfg(feature = "dispatch2")]
96 /// The dispatch queue on which the delegate calls are performed.
97 ///
98 /// If not provided or nil, delegate calls will be performed on the main queue.
99 #[unsafe(method(delegateQueue))]
100 #[unsafe(method_family = none)]
101 pub unsafe fn delegateQueue(&self) -> Option<Retained<DispatchQueue>>;
102
103 #[cfg(feature = "dispatch2")]
104 /// Setter for [`delegateQueue`][Self::delegateQueue].
105 #[unsafe(method(setDelegateQueue:))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn setDelegateQueue(&self, delegate_queue: Option<&DispatchQueue>);
108
109 #[cfg(feature = "ARFrame")]
110 /// The current frame of the session.
111 #[unsafe(method(currentFrame))]
112 #[unsafe(method_family = none)]
113 pub unsafe fn currentFrame(&self) -> Option<Retained<ARFrame>>;
114
115 #[cfg(feature = "ARConfiguration")]
116 /// The configuration currently being used by the session.
117 #[unsafe(method(configuration))]
118 #[unsafe(method_family = none)]
119 pub unsafe fn configuration(&self) -> Option<Retained<ARConfiguration>>;
120
121 #[cfg(feature = "ARConfiguration")]
122 /// Runs the session with the provided configuration.
123 ///
124 /// Calling run on a session that has already started will
125 /// transition immediately to using the new configuration.
126 ///
127 /// Parameter `configuration`: The configuration to use.
128 #[unsafe(method(runWithConfiguration:))]
129 #[unsafe(method_family = none)]
130 pub unsafe fn runWithConfiguration(&self, configuration: &ARConfiguration);
131
132 #[cfg(feature = "ARConfiguration")]
133 /// Runs the session with the provided configuration and options.
134 ///
135 /// Calling run on a session that has already started will
136 /// transition immediately to using the new configuration. Options
137 /// can be used to alter the default behavior when transitioning configurations.
138 ///
139 /// Parameter `configuration`: The configuration to use.
140 ///
141 /// Parameter `options`: The run options to use.
142 #[unsafe(method(runWithConfiguration:options:))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn runWithConfiguration_options(
145 &self,
146 configuration: &ARConfiguration,
147 options: ARSessionRunOptions,
148 );
149
150 /// Pauses the session.
151 ///
152 /// Once paused, no more updates will be received from the
153 /// session until run is called again.
154 #[unsafe(method(pause))]
155 #[unsafe(method_family = none)]
156 pub unsafe fn pause(&self);
157
158 #[cfg(feature = "ARAnchor")]
159 /// Adds an anchor to the session.
160 ///
161 /// The anchor will be added in the next frame update.
162 ///
163 /// Parameter `anchor`: The anchor to add.
164 #[unsafe(method(addAnchor:))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn addAnchor(&self, anchor: &ARAnchor);
167
168 #[cfg(feature = "ARAnchor")]
169 /// Removes an anchor from the session.
170 ///
171 /// The anchor will be removed from subsequent frame updates.
172 ///
173 /// Parameter `anchor`: The anchor to remove.
174 #[unsafe(method(removeAnchor:))]
175 #[unsafe(method_family = none)]
176 pub unsafe fn removeAnchor(&self, anchor: &ARAnchor);
177
178 #[cfg(all(
179 feature = "ARWorldMap",
180 feature = "block2",
181 feature = "objc2-foundation"
182 ))]
183 /// Copies the current state of the world being tracked by the session.
184 ///
185 /// A world map is only provided when running an ARWorldTrackingConfiguration.
186 ///
187 /// Parameter `completionHandler`: The completion handler to call when the get has completed. This handler is executed
188 /// on the session's delegate queue. The completion handler takes the following parameters:
189 /// worldMap - The current world map or nil if unavailable.
190 /// error - An error that indicates why the world map is unavailable, or nil if a world map was provided.
191 #[unsafe(method(getCurrentWorldMapWithCompletionHandler:))]
192 #[unsafe(method_family = none)]
193 pub unsafe fn getCurrentWorldMapWithCompletionHandler(
194 &self,
195 completion_handler: &block2::DynBlock<dyn Fn(*mut ARWorldMap, *mut NSError)>,
196 );
197
198 #[cfg(all(
199 feature = "ARRaycastQuery",
200 feature = "ARRaycastResult",
201 feature = "objc2-foundation"
202 ))]
203 /// Perform a raycast.
204 ///
205 /// Parameter `query`: Raycast query used for raycasting.
206 ///
207 /// Returns: List of raycast results, sorted from nearest to farthest (in distance from the camera). The results could be empty if raycast fails.
208 #[unsafe(method(raycast:))]
209 #[unsafe(method_family = none)]
210 pub unsafe fn raycast(&self, query: &ARRaycastQuery) -> Retained<NSArray<ARRaycastResult>>;
211
212 #[cfg(all(
213 feature = "ARRaycastQuery",
214 feature = "ARRaycastResult",
215 feature = "ARTrackedRaycast",
216 feature = "block2",
217 feature = "objc2-foundation"
218 ))]
219 /// Perform a tracked raycast.
220 ///
221 /// The session performs continuous raycasting and calls the update handler with the updated results.
222 /// The ARTrackedRaycast object returned can be used to update the raycast with a new raycast query or stop raycasting.
223 ///
224 /// Parameter `query`: Raycast query used for raycasting.
225 ///
226 /// Parameter `updateHandler`: update handler where updated list of results, sorted from nearest to farthest (in distance from
227 /// the camera) are delivered. updateHandler will be called on session's delegate queue.
228 ///
229 /// Returns: Tracked raycast object used to update or stop raycasting. This could be nil if the raycast fails or if the
230 /// configuration is not `ARWorldTrackingConfiguration` or its subclasses.
231 #[unsafe(method(trackedRaycast:updateHandler:))]
232 #[unsafe(method_family = none)]
233 pub unsafe fn trackedRaycast_updateHandler(
234 &self,
235 query: &ARRaycastQuery,
236 update_handler: &block2::DynBlock<dyn Fn(NonNull<NSArray<ARRaycastResult>>)>,
237 ) -> Option<Retained<ARTrackedRaycast>>;
238
239 #[cfg(feature = "ARCollaborationData")]
240 /// Update session with collaboration data.
241 ///
242 ///
243 /// Use this to update the session with collaboration data received from other participants.
244 ///
245 ///
246 /// Parameter `collaborationData`: Collaboration data for updating the session.
247 ///
248 /// See: ARCollaborationData
249 #[unsafe(method(updateWithCollaborationData:))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn updateWithCollaborationData(&self, collaboration_data: &ARCollaborationData);
252
253 #[cfg(all(feature = "ARFrame", feature = "block2", feature = "objc2-foundation"))]
254 /// Requests a single, high resolution frame be captured at that moment in time.
255 ///
256 /// Some video formats do not support a significantly higher resolution than the streaming camera resolution. Use the
257 /// `isRecommendedForHighResolutionFrameCapturing`method on the video format to check if the format is recommended.
258 ///
259 /// See: -[ARVideoFormat isRecommendedForHighResolutionFrameCapturing]
260 ///
261 /// Parameter `completion`: Block being called when the call completes.
262 #[unsafe(method(captureHighResolutionFrameWithCompletion:))]
263 #[unsafe(method_family = none)]
264 pub unsafe fn captureHighResolutionFrameWithCompletion(
265 &self,
266 completion: &block2::DynBlock<dyn Fn(*mut ARFrame, *mut NSError)>,
267 );
268 );
269}
270
271/// Methods declared on superclass `NSObject`.
272#[cfg(feature = "objc2")]
273impl ARSession {
274 extern_methods!(
275 #[unsafe(method(init))]
276 #[unsafe(method_family = init)]
277 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
278
279 #[unsafe(method(new))]
280 #[unsafe(method_family = new)]
281 pub unsafe fn new() -> Retained<Self>;
282 );
283}
284
285#[cfg(feature = "objc2")]
286extern_protocol!(
287 /// [Apple's documentation](https://developer.apple.com/documentation/arkit/arsessionobserver?language=objc)
288 #[cfg(feature = "objc2")]
289 pub unsafe trait ARSessionObserver: NSObjectProtocol {
290 #[cfg(feature = "objc2-foundation")]
291 /// This is called when a session fails.
292 ///
293 ///
294 /// On failure the session will be paused.
295 ///
296 /// Parameter `session`: The session that failed.
297 ///
298 /// Parameter `error`: The error being reported (see ARError.h).
299 #[optional]
300 #[unsafe(method(session:didFailWithError:))]
301 #[unsafe(method_family = none)]
302 unsafe fn session_didFailWithError(&self, session: &ARSession, error: &NSError);
303
304 #[cfg(feature = "ARCamera")]
305 /// This is called when the camera’s tracking state has changed.
306 ///
307 ///
308 /// Parameter `session`: The session being run.
309 ///
310 /// Parameter `camera`: The camera that changed tracking states.
311 #[optional]
312 #[unsafe(method(session:cameraDidChangeTrackingState:))]
313 #[unsafe(method_family = none)]
314 unsafe fn session_cameraDidChangeTrackingState(
315 &self,
316 session: &ARSession,
317 camera: &ARCamera,
318 );
319
320 /// This is called when a session is interrupted.
321 ///
322 ///
323 /// A session will be interrupted and no longer able to track when
324 /// it fails to receive required sensor data. This happens when video capture is interrupted,
325 /// for example when the application is sent to the background or when there are
326 /// multiple foreground applications (see AVCaptureSessionInterruptionReason).
327 /// No additional frame updates will be delivered until the interruption has ended.
328 ///
329 /// Parameter `session`: The session that was interrupted.
330 #[optional]
331 #[unsafe(method(sessionWasInterrupted:))]
332 #[unsafe(method_family = none)]
333 unsafe fn sessionWasInterrupted(&self, session: &ARSession);
334
335 /// This is called when a session interruption has ended.
336 ///
337 ///
338 /// A session will continue running from the last known state once
339 /// the interruption has ended. If the device has moved, anchors will be misaligned.
340 /// To avoid this, some applications may want to reset tracking (see ARSessionRunOptions)
341 /// or attempt to relocalize (see `-[ARSessionObserver sessionShouldAttemptRelocalization:]`).
342 ///
343 /// Parameter `session`: The session that was interrupted.
344 #[optional]
345 #[unsafe(method(sessionInterruptionEnded:))]
346 #[unsafe(method_family = none)]
347 unsafe fn sessionInterruptionEnded(&self, session: &ARSession);
348
349 /// This is called after a session resumes from a pause or interruption to determine
350 /// whether or not the session should attempt to relocalize.
351 ///
352 ///
353 /// To avoid misaligned anchors, apps may wish to attempt a relocalization after
354 /// a session pause or interruption. If YES is returned: the session will begin relocalizing
355 /// and tracking state will switch to limited with reason relocalizing. If successful, the
356 /// session's tracking state will return to normal. Because relocalization depends on
357 /// the user's location, it can run indefinitely. Apps that wish to give up on relocalization
358 /// may call run with `ARSessionRunOptionResetTracking` at any time.
359 ///
360 /// Parameter `session`: The session to relocalize.
361 ///
362 /// Returns: Return YES to begin relocalizing.
363 #[optional]
364 #[unsafe(method(sessionShouldAttemptRelocalization:))]
365 #[unsafe(method_family = none)]
366 unsafe fn sessionShouldAttemptRelocalization(&self, session: &ARSession) -> bool;
367
368 #[cfg(feature = "objc2-core-media")]
369 /// This is called when the session outputs a new audio sample buffer.
370 ///
371 ///
372 /// Parameter `session`: The session being run.
373 ///
374 /// Parameter `audioSampleBuffer`: The captured audio sample buffer.
375 #[optional]
376 #[unsafe(method(session:didOutputAudioSampleBuffer:))]
377 #[unsafe(method_family = none)]
378 unsafe fn session_didOutputAudioSampleBuffer(
379 &self,
380 session: &ARSession,
381 audio_sample_buffer: &CMSampleBuffer,
382 );
383
384 #[cfg(feature = "ARCollaborationData")]
385 /// This is called when the session generated new collaboration data.
386 ///
387 ///
388 /// This data should be sent to all participants.
389 ///
390 ///
391 /// Parameter `session`: The session that produced world tracking collaboration data.
392 ///
393 /// Parameter `data`: Collaboration data to be sent to participants.
394 ///
395 /// See: ARCollaborationData
396 #[optional]
397 #[unsafe(method(session:didOutputCollaborationData:))]
398 #[unsafe(method_family = none)]
399 unsafe fn session_didOutputCollaborationData(
400 &self,
401 session: &ARSession,
402 data: &ARCollaborationData,
403 );
404
405 #[cfg(feature = "ARGeoTrackingTypes")]
406 /// This is called when geo tracking status changes.
407 ///
408 ///
409 /// Parameter `session`: The session being run.
410 ///
411 /// Parameter `geoTrackingStatus`: Latest geo tracking status.
412 #[optional]
413 #[unsafe(method(session:didChangeGeoTrackingStatus:))]
414 #[unsafe(method_family = none)]
415 unsafe fn session_didChangeGeoTrackingStatus(
416 &self,
417 session: &ARSession,
418 geo_tracking_status: &ARGeoTrackingStatus,
419 );
420 }
421);
422
423#[cfg(feature = "objc2")]
424extern_protocol!(
425 /// [Apple's documentation](https://developer.apple.com/documentation/arkit/arsessiondelegate?language=objc)
426 #[cfg(feature = "objc2")]
427 pub unsafe trait ARSessionDelegate: ARSessionObserver {
428 #[cfg(feature = "ARFrame")]
429 /// This is called when a new frame has been updated.
430 ///
431 ///
432 /// Parameter `session`: The session being run.
433 ///
434 /// Parameter `frame`: The frame that has been updated.
435 #[optional]
436 #[unsafe(method(session:didUpdateFrame:))]
437 #[unsafe(method_family = none)]
438 unsafe fn session_didUpdateFrame(&self, session: &ARSession, frame: &ARFrame);
439
440 #[cfg(all(feature = "ARAnchor", feature = "objc2-foundation"))]
441 /// This is called when new anchors are added to the session.
442 ///
443 ///
444 /// Parameter `session`: The session being run.
445 ///
446 /// Parameter `anchors`: An array of added anchors.
447 #[optional]
448 #[unsafe(method(session:didAddAnchors:))]
449 #[unsafe(method_family = none)]
450 unsafe fn session_didAddAnchors(&self, session: &ARSession, anchors: &NSArray<ARAnchor>);
451
452 #[cfg(all(feature = "ARAnchor", feature = "objc2-foundation"))]
453 /// This is called when anchors are updated.
454 ///
455 ///
456 /// Parameter `session`: The session being run.
457 ///
458 /// Parameter `anchors`: An array of updated anchors.
459 #[optional]
460 #[unsafe(method(session:didUpdateAnchors:))]
461 #[unsafe(method_family = none)]
462 unsafe fn session_didUpdateAnchors(&self, session: &ARSession, anchors: &NSArray<ARAnchor>);
463
464 #[cfg(all(feature = "ARAnchor", feature = "objc2-foundation"))]
465 /// This is called when anchors are removed from the session.
466 ///
467 ///
468 /// Parameter `session`: The session being run.
469 ///
470 /// Parameter `anchors`: An array of removed anchors.
471 #[optional]
472 #[unsafe(method(session:didRemoveAnchors:))]
473 #[unsafe(method_family = none)]
474 unsafe fn session_didRemoveAnchors(&self, session: &ARSession, anchors: &NSArray<ARAnchor>);
475 }
476);
477
478#[cfg(feature = "objc2")]
479extern_protocol!(
480 /// A data source for an ARSession
481 ///
482 /// See also [Apple's documentation](https://developer.apple.com/documentation/arkit/arsessionproviding?language=objc)
483 #[cfg(feature = "objc2")]
484 pub unsafe trait ARSessionProviding: NSObjectProtocol {
485 /// To ensure session changes are detected, Swift classes should mark this property as `
486 /// ` and `dynamic`
487 #[unsafe(method(session))]
488 #[unsafe(method_family = none)]
489 unsafe fn session(&self) -> Retained<ARSession>;
490 }
491);