To go from XrTime to MLTime:
MLTime:xrConvertTimeToTimespecTimeKHR
MLTime to XrTime:
MLTimeConvertMLTimeToSystemTime
As I can't find any reference to XrTime in the above links (only MLTime and system time), I'm not sure I got your point correctly. What I did:
- retrieve the camera MLTime timestamp to pass to
MLCVCameraGetFramePose
;
- convert this MLTime timestamp to timespec time with
MLTimeConvertMLTimeToSystemTime
;
- convert the resulting timespec time to XrTime with
xrConvertTimespecTimeToTimeKHR
to pass to xrLocateSpace
.
Is this correct?
In the following logs, I'm recording the original camera MLTime (MLTime = lines), converted to timespec (timespec = lines) and converted to XrTime (XrTime = lines) timestamps as well as the locations returned by MLCVCameraGetFramePose (MLCVCameraGetFramePose = lines) and xrLocateSpace (xrLocateSpace = lines). I'm however occasionally getting the following exception in MLCVCameraGetFramePose
:
2023-12-18 15:00:27.058 1031-2560 ml_camera_client com.mycompany.myapp D Ready for raw video frame callback
2023-12-18 15:00:27.058 1031-2560 utility com.mycompany.myapp I MLTime = 1050517926488000
2023-12-18 15:00:27.058 1031-2560 utility com.mycompany.myapp I MLCVCameraGetFramePose: orientation = (-0.250627, 0.489080, 0.121367, 0.826594), position = (-0.214779, 0.067654, 0.024862)
2023-12-18 15:00:27.058 1031-2560 utility com.mycompany.myapp I timespec = 1050473273482136
2023-12-18 15:00:27.058 1031-2560 utility com.mycompany.myapp I XrTime = 1050473273482136
2023-12-18 15:00:27.058 1031-2560 utility com.mycompany.myapp I xrLocateSpace: orientation = (-0.245247, 0.491186, 0.121783, 0.826897), position = (-0.173523, 0.066953, 0.041910)
2023-12-18 15:00:27.266 1031-2560 ml_camera_client com.mycompany.myapp D released video buffer 558 timestamp = 1050473323618816
2023-12-18 15:00:27.269 1031-1049 ml_camera_client com.mycompany.myapp D got video buffer 559 timestamp = 1050473349627761
2023-12-18 15:00:27.269 1031-1054 ml_camera_client com.mycompany.myapp D capturecompletecount = 562 timestamp = 1050473806111016
2023-12-18 15:00:27.270 1031-1054 ml_camera_client com.mycompany.myapp D capture complete for 1050473806111016
2023-12-18 15:00:27.273 1031-2563 ml_camera_client com.mycompany.myapp D Ready for raw video frame callback
2023-12-18 15:00:27.273 1031-2563 utility com.mycompany.myapp I MLTime = 1050517959812000
2023-12-18 15:00:29.230 1031-2563 com.mycompany.myapp com.mycompany.myapp E leapcore/frameworks/perception/data_sources/include/pad/xpad_data_source.h(107) GetClosestTimestampedData():
ERR: exception: Data Not Found for timestamp: 1050517959812us
2023-12-18 15:00:29.239 1031-2563 com.mycompany.myapp com.mycompany.myapp E leapcore/frameworks/perception/data_sources/include/pad/xpad_data_source.h(107) GetClosestTimestampedData():
ERR: [stack trace begin]
#00 pc 0000000000020432 /system/lib64/libml_perception_head_tracking.so (_ZNK2ml10perception11datasources14XPadDataSourceINS_3pil2ss17world_pose_resultEE25GetClosestTimestampedDataERKNSt3__16chrono8durationIxNS7_5ratioILl1ELl1000000000EEEEE+3026)
#01 pc 0000000000017942 /system/lib64/libml_perception_head_tracking.so (_ZNK2ml10perception10components13head_tracking12HeadTracking7GetPoseERKNSt3__16chrono8durationIxNS4_5ratioILl1ELl1000000000EEEEE+834)
#02 pc 000000000002cbe0 /system/lib64/libperception.magicleap.so (_ZZ22MLCVCameraGetFramePoseENK3$_2clEv+368)
#03 pc 000000000002c70e /system/lib64/libperception.magicleap.so (MLCVCameraGetFramePose+222)
From the native API documentation (CV Camera | MagicLeap Developer Documentation), The camera tracker only caches a limited set of poses. Retrieve the camera pose as soon as the timestamp is available else the API may return MLResult_PoseNotFound. Nowhere is it stated that an exception can occur. Should I guard against it?
Similarly, it sometimes happens in xrLocateSpace
:
2023-12-18 15:58:17.115 25492-25844 ml_camera_client com.mycompany.myapp D Ready for raw video frame callback
2023-12-18 15:58:17.115 25492-25844 utility com.mycompany.myapp I MLTime = 1053987885382000
2023-12-18 15:58:17.115 25492-25844 utility com.mycompany.myapp I timespec = 1053943138692888
2023-12-18 15:58:17.115 25492-25844 utility com.mycompany.myapp I XrTime = 1053943138692888
2023-12-18 15:58:17.118 25492-25844 com.mycompany.myapp com.mycompany.myapp E leapcore/frameworks/perception/data_sources/include/pad/xpad_data_source.h(107) GetClosestTimestampedData():
ERR: exception: Data Not Found for timestamp: 1053987885260us
2023-12-18 15:58:17.135 25492-25844 com.mycompany.myapp com.mycompany.myapp E leapcore/frameworks/perception/data_sources/include/pad/xpad_data_source.h(107) GetClosestTimestampedData():
ERR: [stack trace begin]
#00 pc 0000000000020432 /system/lib64/libml_perception_head_tracking.so (_ZNK2ml10perception11datasources14XPadDataSourceINS_3pil2ss17world_pose_resultEE25GetClosestTimestampedDataERKNSt3__16chrono8durationIxNS7_5ratioILl1ELl1000000000EEEEE+3026)
#01 pc 0000000000017942 /system/lib64/libml_perception_head_tracking.so (_ZNK2ml10perception10components13head_tracking12HeadTracking7GetPoseERKNSt3__16chrono8durationIxNS4_5ratioILl1ELl1000000000EEEEE+834)
#02 pc 000000000001a229 /system/lib64/libml_perception_head_tracking.so (_ZNSt3__110__function6__funcIZNK2ml10perception10components13head_tracking8internal4$_12clERNS5_12HeadTrackingEEUlNS_6chrono8durationIxNS_5ratioILl1ELl1000000000EEEEEE_NS_9allocatorISF_EEFNS3_10pose_query15NodeQueryResultI9MLPoseExtEESE_EEclEOSE_+41)
#03 pc 0000000000011f4f /system/lib64/libml_perception_session.so (_ZNK2ml10perception10pose_query9PoseQueryINS_2IdE9MLPoseExtKNS1_19ml_pose_identity_fnMUlRKS3_E_EKNS1_18ml_pose_combine_fnMUlRKS4_SA_E_EKNS1_17ml_pose_invert_fnMUlSA_E_EE7GetPoseES6_S6_NSt3__16chrono8durationIxNSG_5ratioILl1ELl1000000000EEEEE+431)
#04 pc 000000000000e6e1 /system/lib64/libml_perception_session.so (_ZNK2ml10perception10components7session7Session7GetPoseERKNS_2IdES6_NSt3__16chrono8durationIxNS7_5ratioILl1ELl1000000000EEEEE+273)
#05 pc 00000000001a2882 /system/lib64/libopenxr_runtime.magicleap.so (_ZN2ml3oxr5space17OXR_xrLocateSpaceINS_8PlatformILNS_14TargetPlatformE2EEEEE8XrResultP9XrSpace_TS8_lP15XrSpaceLocation+834)
#06 pc 00000000000b67dd /data/app/com.mycompany.myapp-8QHNA-tW_b-zWAd-Mx0vWQ==/base.apk!libopenxr_loaderd.so (offset 0x42d000) (xrLocateSpace+173)
Any idea what's going wrong?