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