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