The open source OpenXR runtime

t/common: Add a few builders

+885 -2
+8 -1
src/xrt/targets/common/CMakeLists.txt
··· 5 5 # Lists 6 6 # 7 7 8 - add_library(target_lists STATIC target_lists.c) 8 + add_library(target_lists STATIC 9 + target_builder_interface.h 10 + target_builder_legacy.c 11 + target_builder_remote.c 12 + target_builder_rgb_tracking.c 13 + target_lists.c 14 + target_lists.h 15 + ) 9 16 target_link_libraries( 10 17 target_lists 11 18 PRIVATE
+59
src/xrt/targets/common/target_builder_interface.h
··· 1 + // Copyright 2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief List of all @ref xrt_builder creation functions. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + */ 8 + 9 + #include "xrt/xrt_config_build.h" 10 + #include "xrt/xrt_config_drivers.h" 11 + 12 + 13 + /* 14 + * 15 + * Config checking. 16 + * 17 + */ 18 + 19 + #if defined(XRT_BUILD_DRIVER_PSMV) || defined(XRT_BUILD_DRIVER_PSVR) || defined(XRT_DOXYGEN) 20 + #define T_BUILDER_RGB_TRACKING 21 + #endif 22 + 23 + #if defined(XRT_BUILD_DRIVER_REMOTE) || defined(XRT_DOXYGEN) 24 + #define T_BUILDER_REMOTE 25 + #endif 26 + 27 + // Always enabled. 28 + #define T_BUILDER_LEGACY 29 + 30 + 31 + /* 32 + * 33 + * Setter upper creation functions. 34 + * 35 + */ 36 + 37 + #ifdef T_BUILDER_RGB_TRACKING 38 + /*! 39 + * RGB tracking based drivers, like @ref drv_psmv and @ref drv_psvr. 40 + */ 41 + struct xrt_builder * 42 + t_builder_rgb_tracking_create(void); 43 + #endif 44 + 45 + #ifdef T_BUILDER_REMOTE 46 + /*! 47 + * The remote driver builder. 48 + */ 49 + struct xrt_builder * 50 + t_builder_remote_create(void); 51 + #endif 52 + 53 + #ifdef T_BUILDER_LEGACY 54 + /*! 55 + * Builder used as a fallback for drivers not converted to builders yet. 56 + */ 57 + struct xrt_builder * 58 + t_builder_legacy_create(void); 59 + #endif
+231
src/xrt/targets/common/target_builder_legacy.c
··· 1 + // Copyright 2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Fallback builder the old method of probing devices. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup xrt_iface 8 + */ 9 + 10 + #include "xrt/xrt_config_drivers.h" 11 + #include "xrt/xrt_prober.h" 12 + 13 + #include "util/u_misc.h" 14 + #include "util/u_device.h" 15 + #include "util/u_system_helpers.h" 16 + 17 + #include "target_builder_interface.h" 18 + 19 + #include <assert.h> 20 + 21 + 22 + /* 23 + * 24 + * Helper functions. 25 + * 26 + */ 27 + 28 + static struct xrt_device * 29 + get_ht_device(struct u_system_devices *usysd, enum xrt_input_name name) 30 + { 31 + for (uint32_t i = 0; i < usysd->base.xdev_count; i++) { 32 + struct xrt_device *xdev = usysd->base.xdevs[i]; 33 + 34 + if (xdev == NULL || !xdev->hand_tracking_supported) { 35 + continue; 36 + } 37 + 38 + for (uint32_t j = 0; j < xdev->input_count; j++) { 39 + struct xrt_input *input = &xdev->inputs[j]; 40 + 41 + if (input->name == name) { 42 + return xdev; 43 + } 44 + } 45 + } 46 + 47 + return NULL; 48 + } 49 + 50 + static const char *driver_list[] = { 51 + #ifdef XRT_BUILD_DRIVER_HYDRA 52 + "hydra", 53 + #endif 54 + 55 + #ifdef XRT_BUILD_DRIVER_HDK 56 + "hdk", 57 + #endif 58 + 59 + #ifdef XRT_BUILD_DRIVER_VIVE 60 + "vive", 61 + #endif 62 + 63 + #ifdef XRT_BUILD_DRIVER_ULV2 64 + "ulv2", 65 + #endif 66 + 67 + #ifdef XRT_BUILD_DRIVER_DEPTHAI 68 + "depthai", 69 + #endif 70 + 71 + #ifdef XRT_BUILD_DRIVER_WMR 72 + "wmr", 73 + #endif 74 + 75 + #ifdef XRT_BUILD_DRIVER_ARDUINO 76 + "arduino", 77 + #endif 78 + 79 + #ifdef XRT_BUILD_DRIVER_DAYDREAM 80 + "daydream", 81 + #endif 82 + 83 + #ifdef XRT_BUILD_DRIVER_SURVIVE 84 + "survive", 85 + #endif 86 + 87 + #ifdef XRT_BUILD_DRIVER_OHMD 88 + "oh", 89 + #endif 90 + 91 + #ifdef XRT_BUILD_DRIVER_NS 92 + "ns", 93 + #endif 94 + 95 + #ifdef XRT_BUILD_DRIVER_ANDROID 96 + "android", 97 + #endif 98 + 99 + #ifdef XRT_BUILD_DRIVER_ILLIXR 100 + "illixr", 101 + #endif 102 + 103 + #ifdef XRT_BUILD_DRIVER_REALSENSE 104 + "rs", 105 + #endif 106 + 107 + #ifdef XRT_BUILD_DRIVER_EUROC 108 + "euroc", 109 + #endif 110 + 111 + #ifdef XRT_BUILD_DRIVER_QWERTY 112 + "qwerty", 113 + #endif 114 + 115 + #if defined(XRT_BUILD_DRIVER_HANDTRACKING) && defined(XRT_BUILD_DRIVER_DEPTHAI) 116 + "ht", 117 + #endif 118 + }; 119 + 120 + /* 121 + * 122 + * Member functions. 123 + * 124 + */ 125 + 126 + static xrt_result_t 127 + legacy_estimate_system(struct xrt_builder *xb, 128 + cJSON *config, 129 + struct xrt_prober *xp, 130 + struct xrt_builder_estimate *estimate) 131 + { 132 + estimate->maybe.head = true; 133 + estimate->maybe.left = true; 134 + estimate->maybe.right = true; 135 + estimate->priority = -20; 136 + 137 + return XRT_SUCCESS; 138 + } 139 + 140 + static xrt_result_t 141 + legacy_open_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, struct xrt_system_devices **out_xsysd) 142 + { 143 + struct u_system_devices *usysd = u_system_devices_allocate(); 144 + int ret = 0; 145 + 146 + assert(out_xsysd != NULL); 147 + assert(*out_xsysd == NULL); 148 + 149 + 150 + /* 151 + * Create the devices. 152 + */ 153 + 154 + ret = xrt_prober_probe(xp); 155 + if (ret < 0) { 156 + return XRT_ERROR_ALLOCATION; 157 + } 158 + 159 + ret = xrt_prober_select(xp, usysd->base.xdevs, ARRAY_SIZE(usysd->base.xdevs)); 160 + if (ret < 0) { 161 + u_system_devices_destroy(&usysd); 162 + } 163 + 164 + // Count the xdevs. 165 + for (uint32_t i = 0; i < ARRAY_SIZE(usysd->base.xdevs); i++) { 166 + if (usysd->base.xdevs[i] == NULL) { 167 + break; 168 + } 169 + 170 + usysd->base.xdev_count++; 171 + } 172 + 173 + 174 + /* 175 + * Setup the roles. 176 + */ 177 + 178 + int head, left, right; 179 + u_device_assign_xdev_roles(usysd->base.xdevs, usysd->base.xdev_count, &head, &left, &right); 180 + 181 + if (head >= 0) { 182 + usysd->base.roles.head = usysd->base.xdevs[head]; 183 + } 184 + if (left >= 0) { 185 + usysd->base.roles.left = usysd->base.xdevs[left]; 186 + } 187 + if (right >= 0) { 188 + usysd->base.roles.right = usysd->base.xdevs[right]; 189 + } 190 + 191 + // Find hand tracking devices. 192 + usysd->base.roles.hand_tracking.left = get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_LEFT); 193 + usysd->base.roles.hand_tracking.right = get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT); 194 + 195 + 196 + /* 197 + * Done. 198 + */ 199 + 200 + *out_xsysd = &usysd->base; 201 + 202 + return XRT_SUCCESS; 203 + } 204 + 205 + static void 206 + legacy_destroy(struct xrt_builder *xb) 207 + { 208 + free(xb); 209 + } 210 + 211 + 212 + /* 213 + * 214 + * 'Exported' functions. 215 + * 216 + */ 217 + 218 + struct xrt_builder * 219 + t_builder_legacy_create(void) 220 + { 221 + struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 222 + xb->estimate_system = legacy_estimate_system; 223 + xb->open_system = legacy_open_system; 224 + xb->destroy = legacy_destroy; 225 + xb->identifier = "legacy"; 226 + xb->name = "Legacy probing system"; 227 + xb->driver_identifiers = driver_list; 228 + xb->driver_identifier_count = ARRAY_SIZE(driver_list); 229 + 230 + return xb; 231 + }
+140
src/xrt/targets/common/target_builder_remote.c
··· 1 + // Copyright 2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Remote driver builder. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup xrt_iface 8 + */ 9 + 10 + #include "xrt/xrt_config_drivers.h" 11 + #include "xrt/xrt_prober.h" 12 + 13 + #include "util/u_builders.h" 14 + #include "util/u_config_json.h" 15 + #include "util/u_system_helpers.h" 16 + 17 + #include "target_builder_interface.h" 18 + 19 + #ifdef XRT_BUILD_DRIVER_REMOTE 20 + #include "remote/r_interface.h" 21 + #endif 22 + 23 + #include <assert.h> 24 + 25 + 26 + /* 27 + * 28 + * Helper functions. 29 + * 30 + */ 31 + 32 + static bool 33 + get_settings(cJSON *json, int *port) 34 + { 35 + struct u_config_json config_json = {0}; 36 + u_config_json_open_or_create_main_file(&config_json); 37 + 38 + bool bret = u_config_json_get_remote_port(&config_json, port); 39 + 40 + u_config_json_close(&config_json); 41 + 42 + return bret; 43 + } 44 + 45 + static const char *driver_list[] = { 46 + "remote", 47 + }; 48 + 49 + 50 + /* 51 + * 52 + * Member functions. 53 + * 54 + */ 55 + 56 + static xrt_result_t 57 + remote_estimate_system(struct xrt_builder *xb, 58 + cJSON *config, 59 + struct xrt_prober *xp, 60 + struct xrt_builder_estimate *estimate) 61 + { 62 + estimate->certain.head = true; 63 + estimate->certain.left = true; 64 + estimate->certain.right = true; 65 + estimate->priority = -50; 66 + 67 + return XRT_SUCCESS; 68 + } 69 + 70 + static xrt_result_t 71 + remote_open_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, struct xrt_system_devices **out_xsysd) 72 + { 73 + struct u_system_devices *usysd = u_system_devices_allocate(); 74 + 75 + assert(out_xsysd != NULL); 76 + assert(*out_xsysd == NULL); 77 + 78 + 79 + int port = 4242; 80 + if (!get_settings(config, &port)) { 81 + port = 4242; 82 + } 83 + 84 + struct xrt_device *head = NULL, *left = NULL, *right = NULL; 85 + r_create_devices(port, &head, &left, &right); 86 + 87 + if (head == NULL) { 88 + u_system_devices_destroy(&usysd); 89 + xrt_device_destroy(&left); 90 + xrt_device_destroy(&right); 91 + return XRT_ERROR_ALLOCATION; 92 + } 93 + 94 + usysd->base.xdevs[usysd->base.xdev_count++] = head; 95 + if (left != NULL) { 96 + usysd->base.xdevs[usysd->base.xdev_count++] = left; 97 + } 98 + if (right != NULL) { 99 + usysd->base.xdevs[usysd->base.xdev_count++] = right; 100 + } 101 + 102 + usysd->base.roles.head = head; 103 + usysd->base.roles.left = left; 104 + usysd->base.roles.right = right; 105 + usysd->base.roles.hand_tracking.left = left; 106 + usysd->base.roles.hand_tracking.right = right; 107 + 108 + *out_xsysd = &usysd->base; 109 + 110 + return XRT_SUCCESS; 111 + } 112 + 113 + static void 114 + remote_destroy(struct xrt_builder *xb) 115 + { 116 + free(xb); 117 + } 118 + 119 + 120 + /* 121 + * 122 + * 'Exported' functions. 123 + * 124 + */ 125 + 126 + struct xrt_builder * 127 + t_builder_remote_create(void) 128 + { 129 + struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 130 + xb->estimate_system = remote_estimate_system; 131 + xb->open_system = remote_open_system; 132 + xb->destroy = remote_destroy; 133 + xb->identifier = "remote"; 134 + xb->name = "Remote simulation devices builder"; 135 + xb->driver_identifiers = driver_list; 136 + xb->driver_identifier_count = ARRAY_SIZE(driver_list); 137 + xb->exclude_from_automatic_discovery = true; 138 + 139 + return xb; 140 + }
+423
src/xrt/targets/common/target_builder_rgb_tracking.c
··· 1 + // Copyright 2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Builder to setup rgb tracking devices into a system. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup xrt_iface 8 + */ 9 + 10 + #include "xrt/xrt_config_have.h" 11 + #include "xrt/xrt_config_drivers.h" 12 + 13 + #include "xrt/xrt_prober.h" 14 + #include "xrt/xrt_settings.h" 15 + #include "xrt/xrt_frameserver.h" 16 + 17 + #include "util/u_sink.h" 18 + #include "util/u_misc.h" 19 + #include "util/u_device.h" 20 + #include "util/u_logging.h" 21 + #include "util/u_builders.h" 22 + #include "util/u_config_json.h" 23 + #include "util/u_system_helpers.h" 24 + 25 + #include "target_builder_interface.h" 26 + 27 + #include "dummy/dummy_interface.h" 28 + 29 + #ifdef XRT_HAVE_OPENCV 30 + #include "tracking/t_tracking.h" 31 + #endif 32 + 33 + #ifdef XRT_BUILD_DRIVER_PSVR 34 + #include "psvr/psvr_interface.h" 35 + #endif 36 + 37 + #ifdef XRT_BUILD_DRIVER_PSMV 38 + #include "psmv/psmv_interface.h" 39 + #endif 40 + 41 + #include <assert.h> 42 + 43 + 44 + /* 45 + * 46 + * Helper functions. 47 + * 48 + */ 49 + 50 + static const char *driver_list[] = { 51 + #ifdef XRT_BUILD_DRIVER_PSVR 52 + "psvr", 53 + #endif 54 + 55 + #ifdef XRT_BUILD_DRIVER_PSMV 56 + "psmv", 57 + #endif 58 + }; 59 + 60 + static bool 61 + get_settings(cJSON *json, struct xrt_settings_tracking *settings) 62 + { 63 + struct u_config_json config_json = {0}; 64 + u_config_json_open_or_create_main_file(&config_json); 65 + 66 + bool bret = u_config_json_get_tracking_settings(&config_json, settings); 67 + 68 + u_config_json_close(&config_json); 69 + 70 + return bret; 71 + } 72 + 73 + struct build_state 74 + { 75 + struct xrt_settings_tracking settings; 76 + 77 + struct xrt_frame_context *xfctx; 78 + struct xrt_tracking_origin *origin; 79 + struct xrt_fs *xfs; 80 + struct xrt_tracked_psvr *psvr; 81 + struct xrt_tracked_psmv *psmv_red; 82 + struct xrt_tracked_psmv *psmv_purple; 83 + }; 84 + 85 + #ifdef XRT_HAVE_OPENCV 86 + static void 87 + on_video_device(struct xrt_prober *xp, 88 + struct xrt_prober_device *pdev, 89 + const char *product, 90 + const char *manufacturer, 91 + const char *serial, 92 + void *ptr) 93 + { 94 + struct build_state *build = (struct build_state *)ptr; 95 + 96 + if (build->xfs != NULL || product == NULL) { 97 + return; 98 + } 99 + 100 + if (strcmp(product, build->settings.camera_name) != 0) { 101 + return; 102 + } 103 + 104 + xrt_prober_open_video_device(xp, pdev, build->xfctx, &build->xfs); 105 + } 106 + 107 + static void 108 + setup_pipeline(struct xrt_prober *xp, struct build_state *build) 109 + { 110 + struct t_stereo_camera_calibration *data = NULL; 111 + 112 + xrt_prober_list_video_devices(xp, on_video_device, build); 113 + 114 + if (build->xfs == NULL) { 115 + return; 116 + } 117 + 118 + // Parse the calibration data from the file. 119 + if (!t_stereo_camera_calibration_load(build->settings.calibration_path, &data)) { 120 + return; 121 + } 122 + 123 + struct xrt_frame_sink *xsink = NULL; 124 + struct xrt_frame_sink *xsinks[4] = {0}; 125 + struct xrt_colour_rgb_f32 rgb[2] = {{1.f, 0.f, 0.f}, {1.f, 0.f, 1.f}}; 126 + 127 + // We create the two psmv trackers up front, but don't start them. 128 + // clang-format off 129 + t_psmv_create(build->xfctx, &rgb[0], data, &build->psmv_red, &xsinks[0]); 130 + t_psmv_create(build->xfctx, &rgb[1], data, &build->psmv_purple, &xsinks[1]); 131 + t_psvr_create(build->xfctx, data, &build->psvr, &xsinks[2]); 132 + // clang-format on 133 + 134 + // Setup origin to the common one. 135 + build->psvr->origin = build->origin; 136 + build->psmv_red->origin = build->origin; 137 + build->psmv_purple->origin = build->origin; 138 + 139 + // We create the default multi-channel hsv filter. 140 + struct t_hsv_filter_params params = T_HSV_DEFAULT_PARAMS(); 141 + t_hsv_filter_create(build->xfctx, &params, xsinks, &xsink); 142 + 143 + // The filter only supports yuv or yuyv formats. 144 + u_sink_create_to_yuv_or_yuyv(build->xfctx, xsink, &xsink); 145 + 146 + // Put a queue before it to multi-thread the filter. 147 + u_sink_simple_queue_create(build->xfctx, xsink, &xsink); 148 + 149 + // Hardcoded quirk sink. 150 + struct u_sink_quirk_params qp; 151 + U_ZERO(&qp); 152 + 153 + switch (build->settings.camera_type) { 154 + case XRT_SETTINGS_CAMERA_TYPE_REGULAR_MONO: 155 + qp.stereo_sbs = false; 156 + qp.ps4_cam = false; 157 + qp.leap_motion = false; 158 + break; 159 + case XRT_SETTINGS_CAMERA_TYPE_REGULAR_SBS: 160 + qp.stereo_sbs = true; 161 + qp.ps4_cam = false; 162 + qp.leap_motion = false; 163 + break; 164 + case XRT_SETTINGS_CAMERA_TYPE_SLAM: 165 + qp.stereo_sbs = true; 166 + qp.ps4_cam = false; 167 + qp.leap_motion = false; 168 + break; 169 + case XRT_SETTINGS_CAMERA_TYPE_PS4: 170 + qp.stereo_sbs = true; 171 + qp.ps4_cam = true; 172 + qp.leap_motion = false; 173 + break; 174 + case XRT_SETTINGS_CAMERA_TYPE_LEAP_MOTION: 175 + qp.stereo_sbs = true; 176 + qp.ps4_cam = false; 177 + qp.leap_motion = true; 178 + break; 179 + } 180 + 181 + u_sink_quirk_create(build->xfctx, xsink, &qp, &xsink); 182 + 183 + // Start the stream now. 184 + xrt_fs_stream_start(build->xfs, xsink, XRT_FS_CAPTURE_TYPE_TRACKING, build->settings.camera_mode); 185 + } 186 + #endif 187 + 188 + 189 + /* 190 + * 191 + * Member functions. 192 + * 193 + */ 194 + 195 + static xrt_result_t 196 + rgb_estimate_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, struct xrt_builder_estimate *estimate) 197 + { 198 + U_ZERO(estimate); 199 + 200 + struct u_builder_search_results results = {0}; 201 + struct xrt_prober_device **xpdevs = NULL; 202 + size_t xpdev_count = 0; 203 + xrt_result_t xret = XRT_SUCCESS; 204 + struct xrt_settings_tracking settings = {0}; 205 + 206 + 207 + /* 208 + * Pre device looking stuff. 209 + */ 210 + 211 + // Lock the device list 212 + xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); 213 + if (xret != XRT_SUCCESS) { 214 + return xret; 215 + } 216 + 217 + // Is tracking setup? 218 + if (get_settings(config, &settings)) { 219 + estimate->certain.dof6 = true; 220 + } 221 + 222 + 223 + /* 224 + * Can we find PSVR HND? 225 + */ 226 + 227 + #ifdef XRT_BUILD_DRIVER_PSVR 228 + struct xrt_prober_device *psvr = u_builder_find_prober_device(xpdevs, xpdev_count, PSVR_VID, PSVR_PID); 229 + if (psvr != NULL) { 230 + estimate->certain.head = true; 231 + } 232 + #endif 233 + 234 + 235 + /* 236 + * Can we find any PSMV controllers? 237 + */ 238 + 239 + #ifdef XRT_BUILD_DRIVER_PSMV 240 + static struct u_builder_search_filter move_filters[2] = { 241 + {PSMV_VID, PSMV_PID_ZCM1, XRT_BUS_TYPE_BLUETOOTH}, 242 + {PSMV_VID, PSMV_PID_ZCM2, XRT_BUS_TYPE_BLUETOOTH}, 243 + }; 244 + 245 + u_builder_search(xp, xpdevs, xpdev_count, move_filters, ARRAY_SIZE(move_filters), &results); 246 + 247 + if (results.xpdev_count >= 1) { 248 + estimate->certain.right = true; 249 + } 250 + 251 + if (results.xpdev_count >= 2) { 252 + estimate->certain.left = true; 253 + } 254 + #endif 255 + 256 + 257 + /* 258 + * Tidy. 259 + */ 260 + 261 + xret = xrt_prober_unlock_list(xp, &xpdevs); 262 + assert(xret == XRT_SUCCESS); 263 + 264 + return XRT_SUCCESS; 265 + } 266 + 267 + static xrt_result_t 268 + rgb_open_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, struct xrt_system_devices **out_xsysd) 269 + { 270 + struct u_builder_search_results results = {0}; 271 + struct xrt_prober_device **xpdevs = NULL; 272 + size_t xpdev_count = 0; 273 + xrt_result_t xret = XRT_SUCCESS; 274 + 275 + assert(out_xsysd != NULL); 276 + assert(*out_xsysd == NULL); 277 + 278 + struct u_system_devices *usysd = u_system_devices_allocate(); 279 + 280 + 281 + /* 282 + * Tracking. 283 + */ 284 + 285 + struct build_state build = {0}; 286 + if (get_settings(config, &build.settings)) { 287 + #ifdef XRT_HAVE_OPENCV 288 + build.xfctx = &usysd->xfctx; 289 + build.origin = &usysd->origin; 290 + build.origin->type = XRT_TRACKING_TYPE_RGB; 291 + build.origin->offset.orientation.y = 1.0f; 292 + build.origin->offset.position.z = -2.0f; 293 + build.origin->offset.position.y = 1.0f; 294 + 295 + setup_pipeline(xp, &build); 296 + #else 297 + U_LOG_W("Tracking setup but not built with OpenCV/Tracking!"); 298 + #endif 299 + } else { 300 + U_LOG_I("Not tracking setup in config file, only in 3dof mode available"); 301 + } 302 + 303 + 304 + /* 305 + * Devices. 306 + */ 307 + 308 + // Lock the device list 309 + xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); 310 + if (xret != XRT_SUCCESS) { 311 + u_system_devices_destroy(&usysd); 312 + return xret; 313 + } 314 + 315 + struct xrt_device *head = NULL; 316 + struct xrt_device *psmv_red = NULL; 317 + struct xrt_device *psmv_purple = NULL; 318 + 319 + #ifdef XRT_BUILD_DRIVER_PSVR 320 + struct xrt_prober_device *psvr = u_builder_find_prober_device(xpdevs, xpdev_count, PSVR_VID, PSVR_PID); 321 + if (psvr != NULL) { 322 + head = psvr_device_create(build.psvr); 323 + } 324 + #endif 325 + 326 + if (head != NULL) { 327 + #ifdef XRT_HAVE_OPENCV 328 + if (build.psvr != NULL) { 329 + t_psvr_start(build.psvr); 330 + } 331 + #endif 332 + } else { 333 + head = dummy_hmd_create(); 334 + } 335 + 336 + 337 + #ifdef XRT_BUILD_DRIVER_PSMV 338 + static struct u_builder_search_filter move_filters[2] = { 339 + {PSMV_VID, PSMV_PID_ZCM1, XRT_BUS_TYPE_BLUETOOTH}, 340 + {PSMV_VID, PSMV_PID_ZCM2, XRT_BUS_TYPE_BLUETOOTH}, 341 + }; 342 + 343 + u_builder_search(xp, xpdevs, xpdev_count, move_filters, ARRAY_SIZE(move_filters), &results); 344 + 345 + if (results.xpdev_count >= 1) { 346 + psmv_red = psmv_device_create(xp, results.xpdevs[0], build.psmv_red); 347 + 348 + #ifdef XRT_HAVE_OPENCV 349 + if (psmv_red != NULL && build.psmv_red != NULL) { 350 + t_psmv_start(build.psmv_red); 351 + } 352 + #endif 353 + } 354 + 355 + if (results.xpdev_count >= 2) { 356 + psmv_purple = psmv_device_create(xp, results.xpdevs[1], build.psmv_purple); 357 + 358 + #ifdef XRT_HAVE_OPENCV 359 + if (psmv_purple != NULL && build.psmv_purple != NULL) { 360 + t_psmv_start(build.psmv_purple); 361 + } 362 + #endif 363 + } 364 + #endif 365 + 366 + // Unlock the device list 367 + xret = xrt_prober_unlock_list(xp, &xpdevs); 368 + if (xret != XRT_SUCCESS) { 369 + u_system_devices_destroy(&usysd); 370 + return xret; 371 + } 372 + 373 + 374 + usysd->base.xdevs[usysd->base.xdev_count++] = head; 375 + usysd->base.roles.head = head; 376 + 377 + if (psmv_red != NULL) { 378 + usysd->base.xdevs[usysd->base.xdev_count++] = psmv_red; 379 + usysd->base.roles.right = psmv_red; 380 + } 381 + 382 + if (psmv_purple != NULL) { 383 + usysd->base.xdevs[usysd->base.xdev_count++] = psmv_purple; 384 + usysd->base.roles.left = psmv_purple; 385 + } 386 + 387 + 388 + /* 389 + * Done. 390 + */ 391 + 392 + *out_xsysd = &usysd->base; 393 + 394 + return XRT_SUCCESS; 395 + } 396 + 397 + static void 398 + rgb_destroy(struct xrt_builder *xb) 399 + { 400 + free(xb); 401 + } 402 + 403 + 404 + /* 405 + * 406 + * 'Exported' functions. 407 + * 408 + */ 409 + 410 + struct xrt_builder * 411 + t_builder_rgb_tracking_create(void) 412 + { 413 + struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 414 + xb->estimate_system = rgb_estimate_system; 415 + xb->open_system = rgb_open_system; 416 + xb->destroy = rgb_destroy; 417 + xb->identifier = "rgb_tracking"; 418 + xb->name = "RGB tracking based devices (PSVR, PSMV, ...)"; 419 + xb->driver_identifiers = driver_list; 420 + xb->driver_identifier_count = ARRAY_SIZE(driver_list); 421 + 422 + return xb; 423 + }
+23 -1
src/xrt/targets/common/target_lists.c
··· 9 9 #include "xrt/xrt_config_drivers.h" 10 10 11 11 #include "target_lists.h" 12 + #include "target_builder_interface.h" 13 + 12 14 13 15 #ifdef XRT_BUILD_DRIVER_ARDUINO 14 16 #include "arduino/arduino_interface.h" ··· 92 94 #include "ht/ht_interface.h" 93 95 #endif 94 96 #endif 97 + 98 + 99 + /*! 100 + * Builders 101 + */ 102 + xrt_builder_create_func_t target_builder_list[] = { 103 + #ifdef T_BUILDER_RGB_TRACKING 104 + t_builder_rgb_tracking_create, 105 + #endif // T_BUILDER_RGB_TRACKING 106 + 107 + #ifdef T_BUILDER_REMOTE 108 + t_builder_remote_create, 109 + #endif // T_BUILDER_REMOTE 110 + 111 + #ifdef T_BUILDER_LEGACY 112 + t_builder_legacy_create, 113 + #endif // T_BUILDER_LEGACY 114 + 115 + NULL, 116 + }; 95 117 96 118 97 119 /*! ··· 220 242 }; 221 243 222 244 struct xrt_prober_entry_lists target_lists = { 223 - NULL, 245 + target_builder_list, 224 246 target_entry_lists, 225 247 target_auto_list, 226 248 NULL,
+1
src/xrt/targets/common/target_lists.h
··· 13 13 extern struct xrt_prober_entry target_entry_list[]; 14 14 extern struct xrt_prober_entry *target_entry_lists[]; 15 15 extern xrt_auto_prober_create_func_t target_auto_list[]; 16 + extern xrt_builder_create_func_t target_builder_list[]; 16 17 extern struct xrt_prober_entry_lists target_lists;