The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

aux/tracking: introduce VIT loader

+189 -2
+11 -2
src/xrt/auxiliary/tracking/CMakeLists.txt
··· 62 62 endif() 63 63 64 64 if(XRT_FEATURE_SLAM) 65 - target_sources(aux_tracking PRIVATE t_tracker_slam.cpp) 66 - target_link_libraries(aux_tracking PRIVATE xrt-external-slam) 65 + target_sources(aux_tracking 66 + PRIVATE 67 + t_vit_loader.c 68 + t_tracker_slam.cpp 69 + ) 70 + target_link_libraries(aux_tracking 71 + PRIVATE 72 + xrt-external-slam 73 + xrt-external-vit 74 + ${CMAKE_DL_LIBS} 75 + ) 67 76 endif() 68 77 69 78 if(XRT_HAVE_OPENVR)
+101
src/xrt/auxiliary/tracking/t_vit_loader.c
··· 1 + // Copyright 2023, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Visual-Intertial Tracking consumer helper. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @author Simon Zeni <simon.zeni@collabora.com> 8 + * @ingroup aux_tracking 9 + */ 10 + 11 + #include "xrt/xrt_config_os.h" 12 + #include "tracking/t_vit_loader.h" 13 + #include "util/u_logging.h" 14 + 15 + #include <stdlib.h> 16 + 17 + #if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID) 18 + #include <dlfcn.h> 19 + #endif 20 + 21 + static inline void 22 + vit_get_proc(void *handle, const char *name, void *proc_ptr) 23 + { 24 + #if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID) 25 + void *proc = dlsym(handle, name); 26 + char *err = dlerror(); 27 + if (err != NULL) { 28 + U_LOG_E("Failed to load symbol %s", err); 29 + return; 30 + } 31 + 32 + *(void **)proc_ptr = proc; 33 + #else 34 + #error "Unknown platform" 35 + #endif 36 + } 37 + 38 + bool 39 + t_vit_bundle_load(struct t_vit_bundle *vit, const char *path) 40 + { 41 + #if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID) 42 + vit->handle = dlopen(path, RTLD_LAZY); 43 + if (vit->handle == NULL) { 44 + U_LOG_E("Failed to open VIT library: %s", dlerror()); 45 + return false; 46 + } 47 + #else 48 + #error "Unknown platform" 49 + #endif 50 + 51 + #define GET_PROC(SYM) \ 52 + do { \ 53 + vit_get_proc(vit->handle, "vit_" #SYM, &vit->SYM); \ 54 + } while (0) 55 + 56 + // Get the version first. 57 + GET_PROC(api_get_version); 58 + vit->api_get_version(&vit->version.major, &vit->version.minor, &vit->version.patch); 59 + 60 + // Check major version. 61 + if (vit->version.major != VIT_HEADER_VERSION_MAJOR) { 62 + U_LOG_E("Incompatible major version (supports %u) was: %u.%u.%u", VIT_HEADER_VERSION_MAJOR, 63 + vit->version.major, vit->version.minor, vit->version.patch); 64 + dlclose(vit->handle); 65 + return false; 66 + } 67 + 68 + GET_PROC(tracker_create); 69 + GET_PROC(tracker_destroy); 70 + GET_PROC(tracker_has_image_format); 71 + GET_PROC(tracker_get_capabilities); 72 + GET_PROC(tracker_get_pose_capabilities); 73 + GET_PROC(tracker_set_pose_capabilities); 74 + GET_PROC(tracker_start); 75 + GET_PROC(tracker_stop); 76 + GET_PROC(tracker_reset); 77 + GET_PROC(tracker_is_running); 78 + GET_PROC(tracker_push_imu_sample); 79 + GET_PROC(tracker_push_img_sample); 80 + GET_PROC(tracker_add_imu_calibration); 81 + GET_PROC(tracker_add_camera_calibration); 82 + GET_PROC(tracker_pop_pose); 83 + GET_PROC(tracker_get_timing_titles); 84 + GET_PROC(pose_destroy); 85 + GET_PROC(pose_get_data); 86 + GET_PROC(pose_get_timing); 87 + GET_PROC(pose_get_features); 88 + #undef GET_PROC 89 + 90 + return true; 91 + } 92 + 93 + void 94 + t_vit_bundle_unload(struct t_vit_bundle *vit) 95 + { 96 + #if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID) 97 + dlclose(vit->handle); 98 + #else 99 + #error "Unknown platform" 100 + #endif 101 + }
+77
src/xrt/auxiliary/tracking/t_vit_loader.h
··· 1 + // Copyright 2023, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Visual-Intertial Tracking consumer helper. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @author Simon Zeni <simon.zeni@collabora.com> 8 + * @ingroup aux_tracking 9 + */ 10 + 11 + #pragma once 12 + 13 + #include "vit/vit_interface.h" 14 + 15 + #ifdef __cplusplus 16 + extern "C" { 17 + #endif 18 + 19 + /*! 20 + * A bundle of VIT interface functions, used by the tracking interface loader. 21 + * 22 + * @ingroup aux_tracking 23 + */ 24 + struct t_vit_bundle 25 + { 26 + void *handle; 27 + 28 + struct 29 + { 30 + uint32_t major; 31 + uint32_t minor; 32 + uint32_t patch; 33 + } version; 34 + 35 + PFN_vit_api_get_version api_get_version; 36 + PFN_vit_tracker_create tracker_create; 37 + PFN_vit_tracker_destroy tracker_destroy; 38 + PFN_vit_tracker_has_image_format tracker_has_image_format; 39 + PFN_vit_tracker_get_capabilities tracker_get_capabilities; 40 + PFN_vit_tracker_get_pose_capabilities tracker_get_pose_capabilities; 41 + PFN_vit_tracker_set_pose_capabilities tracker_set_pose_capabilities; 42 + PFN_vit_tracker_start tracker_start; 43 + PFN_vit_tracker_stop tracker_stop; 44 + PFN_vit_tracker_reset tracker_reset; 45 + PFN_vit_tracker_is_running tracker_is_running; 46 + PFN_vit_tracker_push_imu_sample tracker_push_imu_sample; 47 + PFN_vit_tracker_push_img_sample tracker_push_img_sample; 48 + PFN_vit_tracker_add_imu_calibration tracker_add_imu_calibration; 49 + PFN_vit_tracker_add_camera_calibration tracker_add_camera_calibration; 50 + PFN_vit_tracker_pop_pose tracker_pop_pose; 51 + PFN_vit_tracker_get_timing_titles tracker_get_timing_titles; 52 + PFN_vit_pose_destroy pose_destroy; 53 + PFN_vit_pose_get_data pose_get_data; 54 + PFN_vit_pose_get_timing pose_get_timing; 55 + PFN_vit_pose_get_features pose_get_features; 56 + }; 57 + 58 + /*! 59 + * Load the tracker. 60 + * 61 + * @ingroup aux_tracking 62 + */ 63 + bool 64 + t_vit_bundle_load(struct t_vit_bundle *vit, const char *path); 65 + 66 + /*! 67 + * Unload the tracker. 68 + * 69 + * @ingroup aux_tracking 70 + */ 71 + void 72 + t_vit_bundle_unload(struct t_vit_bundle *vit); 73 + 74 + 75 + #ifdef __cplusplus 76 + } 77 + #endif