From 368a3842fb2590ded7d489e530fcc0cd589af96e Mon Sep 17 00:00:00 2001 From: Meng Jiao Date: Mon, 4 Mar 2024 10:39:27 +0800 Subject: [PATCH] d/remote: Get view count from json config --- doc/example_configs/config_v0.mono_remote.json | 9 +++++++++ .../config_v0.mono_remote.json.license | 2 ++ src/xrt/auxiliary/util/u_config_json.c | 7 ++++++- src/xrt/auxiliary/util/u_config_json.h | 2 +- src/xrt/drivers/remote/r_hmd.c | 17 ++++++++++++++--- src/xrt/drivers/remote/r_hub.c | 2 ++ src/xrt/drivers/remote/r_interface.h | 1 + src/xrt/drivers/remote/r_internal.h | 1 + src/xrt/targets/common/target_builder_remote.c | 10 ++++++---- 9 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 doc/example_configs/config_v0.mono_remote.json create mode 100644 doc/example_configs/config_v0.mono_remote.json.license diff --git a/doc/example_configs/config_v0.mono_remote.json b/doc/example_configs/config_v0.mono_remote.json new file mode 100644 index 000000000..2af2d0a57 --- /dev/null +++ b/doc/example_configs/config_v0.mono_remote.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://monado.pages.freedesktop.org/monado/config_v0.schema.json", + "active": "remote", + "remote": { + "version": 0, + "port": 4242, + "view_count": 1 + } +} diff --git a/doc/example_configs/config_v0.mono_remote.json.license b/doc/example_configs/config_v0.mono_remote.json.license new file mode 100644 index 000000000..32c51300e --- /dev/null +++ b/doc/example_configs/config_v0.mono_remote.json.license @@ -0,0 +1,2 @@ +Copyright 2024, Collabora, Ltd. +SPDX-License-Identifier: CC0-1.0 diff --git a/src/xrt/auxiliary/util/u_config_json.c b/src/xrt/auxiliary/util/u_config_json.c index bfa91584d..e8dd818e1 100644 --- a/src/xrt/auxiliary/util/u_config_json.c +++ b/src/xrt/auxiliary/util/u_config_json.c @@ -238,7 +238,7 @@ u_config_json_get_active(struct u_config_json *json, enum u_config_json_active_c } bool -u_config_json_get_remote_port(struct u_config_json *json, int *out_port) +u_config_json_get_remote_settings(struct u_config_json *json, int *out_port, uint32_t *out_view_count) { cJSON *t = cJSON_GetObjectItemCaseSensitive(json->root, "remote"); if (t == NULL) { @@ -260,8 +260,13 @@ u_config_json_get_remote_port(struct u_config_json *json, int *out_port) if (!get_obj_int(t, "port", &port)) { return false; } + int view_count = 0; + if (!get_obj_int(t, "view_count", &view_count)) { + return false; + } *out_port = port; + *out_view_count = view_count; return true; } diff --git a/src/xrt/auxiliary/util/u_config_json.h b/src/xrt/auxiliary/util/u_config_json.h index a54982b1f..2fd8f0116 100644 --- a/src/xrt/auxiliary/util/u_config_json.h +++ b/src/xrt/auxiliary/util/u_config_json.h @@ -100,7 +100,7 @@ u_config_json_get_tracking_overrides(struct u_config_json *json, * @ingroup aux_util */ bool -u_config_json_get_remote_port(struct u_config_json *json, int *out_port); +u_config_json_get_remote_settings(struct u_config_json *json, int *out_port, uint32_t *out_view_count); enum u_gui_state_scene diff --git a/src/xrt/drivers/remote/r_hmd.c b/src/xrt/drivers/remote/r_hmd.c index 2a9bc5c13..317c51a8e 100644 --- a/src/xrt/drivers/remote/r_hmd.c +++ b/src/xrt/drivers/remote/r_hmd.c @@ -159,6 +159,7 @@ r_hmd_create(struct r_hub *r) rh->base.device_type = XRT_DEVICE_TYPE_HMD; rh->base.inputs[0].name = XRT_INPUT_GENERIC_HEAD_POSE; rh->base.inputs[0].active = true; + rh->base.hmd->view_count = r->view_count; rh->r = r; // Print name. @@ -166,6 +167,7 @@ r_hmd_create(struct r_hub *r) snprintf(rh->base.serial, sizeof(rh->base.serial), "Remote HMD"); // Setup info. + bool ret = true; struct u_device_simple_info info; info.display.w_pixels = 1920; info.display.h_pixels = 1080; @@ -173,10 +175,19 @@ r_hmd_create(struct r_hub *r) info.display.h_meters = 0.07f; info.lens_horizontal_separation_meters = 0.13f / 2.0f; info.lens_vertical_position_meters = 0.07f / 2.0f; - info.fov[0] = 85.0f * (M_PI / 180.0f); - info.fov[1] = 85.0f * (M_PI / 180.0f); - if (!u_device_setup_split_side_by_side(&rh->base, &info)) { + if (rh->r->view_count == 1) { + info.fov[0] = 120.0f * (M_PI / 180.0f); + ret = u_device_setup_one_eye(&rh->base, &info); + } else if (rh->r->view_count == 2) { + info.fov[0] = 85.0f * (M_PI / 180.0f); + info.fov[1] = 85.0f * (M_PI / 180.0f); + ret = u_device_setup_split_side_by_side(&rh->base, &info); + } else { + U_LOG_E("Invalid view count"); + ret = false; + } + if (!ret) { U_LOG_E("Failed to setup basic device info"); r_hmd_destroy(&rh->base); return NULL; diff --git a/src/xrt/drivers/remote/r_hub.c b/src/xrt/drivers/remote/r_hub.c index 33640c4f0..aaaf0b3c0 100644 --- a/src/xrt/drivers/remote/r_hub.c +++ b/src/xrt/drivers/remote/r_hub.c @@ -404,6 +404,7 @@ r_hub_system_devices_destroy(struct xrt_system_devices *xsysd) xrt_result_t r_create_devices(uint16_t port, + uint32_t view_count, struct xrt_session_event_sink *broadcast, struct xrt_system_devices **out_xsysd, struct xrt_space_overseer **out_xso) @@ -436,6 +437,7 @@ r_create_devices(uint16_t port, r->gui.left = true; r->gui.right = true; r->port = port; + r->view_count = view_count; r->accept_fd = -1; r->rc.fd = -1; diff --git a/src/xrt/drivers/remote/r_interface.h b/src/xrt/drivers/remote/r_interface.h index 2754bfea2..34324b271 100644 --- a/src/xrt/drivers/remote/r_interface.h +++ b/src/xrt/drivers/remote/r_interface.h @@ -165,6 +165,7 @@ struct r_remote_connection */ xrt_result_t r_create_devices(uint16_t port, + uint32_t view_count, struct xrt_session_event_sink *broadcast, struct xrt_system_devices **out_xsysd, struct xrt_space_overseer **out_xso); diff --git a/src/xrt/drivers/remote/r_internal.h b/src/xrt/drivers/remote/r_internal.h index f16c4f90b..b8970d160 100644 --- a/src/xrt/drivers/remote/r_internal.h +++ b/src/xrt/drivers/remote/r_internal.h @@ -50,6 +50,7 @@ struct r_hub r_socket_t accept_fd; uint16_t port; + uint32_t view_count; struct os_thread_helper oth; diff --git a/src/xrt/targets/common/target_builder_remote.c b/src/xrt/targets/common/target_builder_remote.c index 210d7fa8e..fe99d2ba9 100644 --- a/src/xrt/targets/common/target_builder_remote.c +++ b/src/xrt/targets/common/target_builder_remote.c @@ -34,12 +34,12 @@ */ static bool -get_settings(cJSON *json, int *port) +get_settings(cJSON *json, int *port, uint32_t *view_count) { struct u_config_json config_json = {0}; u_config_json_open_or_create_main_file(&config_json); - bool bret = u_config_json_get_remote_port(&config_json, port); + bool bret = u_config_json_get_remote_settings(&config_json, port, view_count); u_config_json_close(&config_json); @@ -84,11 +84,13 @@ remote_open_system(struct xrt_builder *xb, int port = 4242; - if (!get_settings(config, &port)) { + uint32_t view_count = 1; + if (!get_settings(config, &port, &view_count)) { port = 4242; + view_count = 1; } - return r_create_devices(port, broadcast, out_xsysd, out_xso); + return r_create_devices(port, view_count, broadcast, out_xsysd, out_xso); } static void