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