mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
aux/tracking: introduce VIT loader
This commit is contained in:
parent
c6e629b4e7
commit
66027fc989
|
@ -62,8 +62,17 @@ if(XRT_HAVE_OPENCV)
|
|||
endif()
|
||||
|
||||
if(XRT_FEATURE_SLAM)
|
||||
target_sources(aux_tracking PRIVATE t_tracker_slam.cpp)
|
||||
target_link_libraries(aux_tracking PRIVATE xrt-external-slam)
|
||||
target_sources(aux_tracking
|
||||
PRIVATE
|
||||
t_vit_loader.c
|
||||
t_tracker_slam.cpp
|
||||
)
|
||||
target_link_libraries(aux_tracking
|
||||
PRIVATE
|
||||
xrt-external-slam
|
||||
xrt-external-vit
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(XRT_HAVE_OPENVR)
|
||||
|
|
101
src/xrt/auxiliary/tracking/t_vit_loader.c
Normal file
101
src/xrt/auxiliary/tracking/t_vit_loader.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
// Copyright 2023, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Visual-Intertial Tracking consumer helper.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
* @author Simon Zeni <simon.zeni@collabora.com>
|
||||
* @ingroup aux_tracking
|
||||
*/
|
||||
|
||||
#include "xrt/xrt_config_os.h"
|
||||
#include "tracking/t_vit_loader.h"
|
||||
#include "util/u_logging.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID)
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
vit_get_proc(void *handle, const char *name, void *proc_ptr)
|
||||
{
|
||||
#if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID)
|
||||
void *proc = dlsym(handle, name);
|
||||
char *err = dlerror();
|
||||
if (err != NULL) {
|
||||
U_LOG_E("Failed to load symbol %s", err);
|
||||
return;
|
||||
}
|
||||
|
||||
*(void **)proc_ptr = proc;
|
||||
#else
|
||||
#error "Unknown platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
t_vit_bundle_load(struct t_vit_bundle *vit, const char *path)
|
||||
{
|
||||
#if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID)
|
||||
vit->handle = dlopen(path, RTLD_LAZY);
|
||||
if (vit->handle == NULL) {
|
||||
U_LOG_E("Failed to open VIT library: %s", dlerror());
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
#error "Unknown platform"
|
||||
#endif
|
||||
|
||||
#define GET_PROC(SYM) \
|
||||
do { \
|
||||
vit_get_proc(vit->handle, "vit_" #SYM, &vit->SYM); \
|
||||
} while (0)
|
||||
|
||||
// Get the version first.
|
||||
GET_PROC(api_get_version);
|
||||
vit->api_get_version(&vit->version.major, &vit->version.minor, &vit->version.patch);
|
||||
|
||||
// Check major version.
|
||||
if (vit->version.major != VIT_HEADER_VERSION_MAJOR) {
|
||||
U_LOG_E("Incompatible major version (supports %u) was: %u.%u.%u", VIT_HEADER_VERSION_MAJOR,
|
||||
vit->version.major, vit->version.minor, vit->version.patch);
|
||||
dlclose(vit->handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
GET_PROC(tracker_create);
|
||||
GET_PROC(tracker_destroy);
|
||||
GET_PROC(tracker_has_image_format);
|
||||
GET_PROC(tracker_get_capabilities);
|
||||
GET_PROC(tracker_get_pose_capabilities);
|
||||
GET_PROC(tracker_set_pose_capabilities);
|
||||
GET_PROC(tracker_start);
|
||||
GET_PROC(tracker_stop);
|
||||
GET_PROC(tracker_reset);
|
||||
GET_PROC(tracker_is_running);
|
||||
GET_PROC(tracker_push_imu_sample);
|
||||
GET_PROC(tracker_push_img_sample);
|
||||
GET_PROC(tracker_add_imu_calibration);
|
||||
GET_PROC(tracker_add_camera_calibration);
|
||||
GET_PROC(tracker_pop_pose);
|
||||
GET_PROC(tracker_get_timing_titles);
|
||||
GET_PROC(pose_destroy);
|
||||
GET_PROC(pose_get_data);
|
||||
GET_PROC(pose_get_timing);
|
||||
GET_PROC(pose_get_features);
|
||||
#undef GET_PROC
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
t_vit_bundle_unload(struct t_vit_bundle *vit)
|
||||
{
|
||||
#if defined(XRT_OS_LINUX) || defined(XRT_OS_ANDROID)
|
||||
dlclose(vit->handle);
|
||||
#else
|
||||
#error "Unknown platform"
|
||||
#endif
|
||||
}
|
77
src/xrt/auxiliary/tracking/t_vit_loader.h
Normal file
77
src/xrt/auxiliary/tracking/t_vit_loader.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
// Copyright 2023, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Visual-Intertial Tracking consumer helper.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
* @author Simon Zeni <simon.zeni@collabora.com>
|
||||
* @ingroup aux_tracking
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "vit/vit_interface.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* A bundle of VIT interface functions, used by the tracking interface loader.
|
||||
*
|
||||
* @ingroup aux_tracking
|
||||
*/
|
||||
struct t_vit_bundle
|
||||
{
|
||||
void *handle;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t major;
|
||||
uint32_t minor;
|
||||
uint32_t patch;
|
||||
} version;
|
||||
|
||||
PFN_vit_api_get_version api_get_version;
|
||||
PFN_vit_tracker_create tracker_create;
|
||||
PFN_vit_tracker_destroy tracker_destroy;
|
||||
PFN_vit_tracker_has_image_format tracker_has_image_format;
|
||||
PFN_vit_tracker_get_capabilities tracker_get_capabilities;
|
||||
PFN_vit_tracker_get_pose_capabilities tracker_get_pose_capabilities;
|
||||
PFN_vit_tracker_set_pose_capabilities tracker_set_pose_capabilities;
|
||||
PFN_vit_tracker_start tracker_start;
|
||||
PFN_vit_tracker_stop tracker_stop;
|
||||
PFN_vit_tracker_reset tracker_reset;
|
||||
PFN_vit_tracker_is_running tracker_is_running;
|
||||
PFN_vit_tracker_push_imu_sample tracker_push_imu_sample;
|
||||
PFN_vit_tracker_push_img_sample tracker_push_img_sample;
|
||||
PFN_vit_tracker_add_imu_calibration tracker_add_imu_calibration;
|
||||
PFN_vit_tracker_add_camera_calibration tracker_add_camera_calibration;
|
||||
PFN_vit_tracker_pop_pose tracker_pop_pose;
|
||||
PFN_vit_tracker_get_timing_titles tracker_get_timing_titles;
|
||||
PFN_vit_pose_destroy pose_destroy;
|
||||
PFN_vit_pose_get_data pose_get_data;
|
||||
PFN_vit_pose_get_timing pose_get_timing;
|
||||
PFN_vit_pose_get_features pose_get_features;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Load the tracker.
|
||||
*
|
||||
* @ingroup aux_tracking
|
||||
*/
|
||||
bool
|
||||
t_vit_bundle_load(struct t_vit_bundle *vit, const char *path);
|
||||
|
||||
/*!
|
||||
* Unload the tracker.
|
||||
*
|
||||
* @ingroup aux_tracking
|
||||
*/
|
||||
void
|
||||
t_vit_bundle_unload(struct t_vit_bundle *vit);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue