Skip to content

Commit

Permalink
Added event handling to AKDevice
Browse files Browse the repository at this point in the history
Summary: Just allowing to determine tracking states.

Reviewed By: enpe

Differential Revision: D67949270

fbshipit-source-id: 6824119c793c6d96491c83f2277a3d40bb328601
  • Loading branch information
janherling authored and facebook-github-bot committed Jan 9, 2025
1 parent e45014b commit 3b39086
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion impl/ocean/devices/arkit/AKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <ARKit/ARKit.h>

@interface AKTracker6DOFDelegate : NSObject<ARSessionDelegate>
@interface AKTracker6DOFDelegate : NSObject<ARSessionDelegate, ARSessionObserver>
@end

namespace Ocean
Expand Down Expand Up @@ -192,6 +192,13 @@ class OCEAN_DEVICES_ARKIT_EXPORT AKDevice : virtual public Device
*/
bool parameter(const std::string& parameter, Value& value) override;

/**
* Translates the value of an ARTrackingState to a readable string.
* @param state The state to translate
* @return The readable string
*/
static std::string translateTrackingState(const ARTrackingState& state);

/**
* Translates the value of an ARGeoTrackingState to a readable string.
* @param state The state to translate
Expand Down
40 changes: 40 additions & 0 deletions impl/ocean/devices/arkit/AKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,28 @@ - (void)session:(ARSession *)session didRemoveAnchors:(NSArray<__kindof ARAnchor
}
}

- (void)session:(ARSession*)session cameraDidChangeTrackingState:(ARCamera*)camera
{
Log::debug() << "ARKit camera tracking state changed: " << AKDevice::translateTrackingState(camera.trackingState);
}

- (void)sessionWasInterrupted:(ARSession*)session
{
Log::warning() << "ARKit session was interrupted";
}

- (void)sessionInterruptionEnded:(ARSession*)session
{
Log::debug() << "ARKit session interruption ended";
}

- (BOOL)sessionShouldAttemptRelocalization:(ARSession*)session
{
Log::debug() << "ARKit session should attempt relocalization";

return YES;
}

+ (ARVideoFormat*)determinePreferredVideoFormat:(NSArray<ARVideoFormat*>*)supportedVideoFormats withWidth:(unsigned int)preferredWidth withHeight:(unsigned int)preferredHeight withFps:(float)preferredFps withHDR:(int)preferredHDR
{
#ifdef OCEAN_DEBUG
Expand Down Expand Up @@ -1025,6 +1047,24 @@ + (ARVideoFormat*)determinePreferredVideoFormat:(NSArray<ARVideoFormat*>*)suppor
return true;
}

std::string AKDevice::translateTrackingState(const ARTrackingState& state)
{
switch (state)
{
case ARTrackingStateNotAvailable:
return std::string("ARTrackingStateNotAvailable");

case ARTrackingStateLimited:
return std::string("ARTrackingStateLimited");

case ARTrackingStateNormal:
return std::string("ARTrackingStateNormal");
}

ocean_assert(false && "Unknown");
return std::string("Unknown");
}

API_AVAILABLE(ios(14.0))
std::string AKDevice::translateGeoTrackingState(const ARGeoTrackingState& state)
{
Expand Down

0 comments on commit 3b39086

Please sign in to comment.