The open source OpenXR runtime
0
fork

Configure Feed

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

st/prober: Implement xrt_builder functionallity

+233 -7
+217 -7
src/xrt/state_trackers/prober/p_prober.c
··· 14 14 #include "util/u_misc.h" 15 15 #include "util/u_config_json.h" 16 16 #include "util/u_debug.h" 17 + #include "util/u_pretty_print.h" 17 18 #include "util/u_trace_marker.h" 18 19 19 20 #include "os/os_hid.h" ··· 81 82 static int 82 83 p_probe(struct xrt_prober *xp); 83 84 85 + static xrt_result_t 86 + p_lock_list(struct xrt_prober *xp, struct xrt_prober_device ***out_devices, size_t *out_device_count); 87 + 88 + static xrt_result_t 89 + p_unlock_list(struct xrt_prober *xp, struct xrt_prober_device ***devices); 90 + 84 91 static int 85 92 p_dump(struct xrt_prober *xp); 93 + 94 + static xrt_result_t 95 + p_create_system(struct xrt_prober *xp, struct xrt_system_devices **out_xsysd); 86 96 87 97 static int 88 98 p_select_device(struct xrt_prober *xp, struct xrt_device **xdevs, size_t xdev_count); ··· 277 287 p->entries[p->num_entries++] = entry; 278 288 } 279 289 290 + static void 291 + add_builder(struct prober *p, struct xrt_builder *xb) 292 + { 293 + U_ARRAY_REALLOC_OR_FREE(p->builders, struct xrt_builder *, (p->builder_count + 1)); 294 + p->builders[p->builder_count++] = xb; 295 + 296 + P_TRACE(p, "%s: %s", xb->identifier, xb->name); 297 + } 298 + 280 299 static int 281 300 collect_entries(struct prober *p) 282 301 { 283 302 struct xrt_prober_entry_lists *lists = p->lists; 284 303 while (lists) { 304 + for (size_t i = 0; lists->builders[i] != NULL; i++) { 305 + struct xrt_builder *xb = lists->builders[i](); 306 + if (xb == NULL) { 307 + continue; 308 + } 309 + 310 + add_builder(p, xb); 311 + } 312 + 285 313 for (size_t j = 0; lists->entries != NULL && lists->entries[j]; j++) { 286 314 struct xrt_prober_entry *entry = lists->entries[j]; 287 315 for (size_t k = 0; entry[k].found != NULL; k++) { ··· 406 434 XRT_TRACE_MARKER(); 407 435 408 436 p->base.probe = p_probe; 437 + p->base.lock_list = p_lock_list; 438 + p->base.unlock_list = p_unlock_list; 409 439 p->base.dump = p_dump; 440 + p->base.create_system = p_create_system; 410 441 p->base.select = p_select_device; 411 442 p->base.open_hid_interface = p_open_hid_interface; 412 443 p->base.open_video_device = p_open_video_device; ··· 553 584 // First remove the variable tracking. 554 585 u_var_remove_root((void *)p); 555 586 587 + // Clean up all setter uppers. 588 + for (size_t i = 0; i < p->builder_count; i++) { 589 + xrt_builder_destroy(&p->builders[i]); 590 + } 591 + p->builder_count = 0; 592 + 556 593 // Clean up all auto_probers. 557 594 for (int i = 0; i < XRT_MAX_AUTO_PROBERS && p->auto_probers[i]; i++) { 558 595 p->auto_probers[i]->destroy(p->auto_probers[i]); ··· 618 655 static void 619 656 add_from_devices(struct prober *p, struct xrt_device **xdevs, size_t xdev_count, bool *have_hmd) 620 657 { 621 - // Build a list of all current probed devices. 622 - struct xrt_prober_device **dev_list = U_TYPED_ARRAY_CALLOC(struct xrt_prober_device *, p->device_count); 623 - for (size_t i = 0; i < p->device_count; i++) { 624 - dev_list[i] = &p->devices[i].base; 625 - } 658 + struct xrt_prober_device **dev_list = NULL; 659 + size_t dev_count = 0; 660 + 661 + xrt_prober_lock_list(&p->base, &dev_list, &dev_count); 626 662 627 663 // Loop over all devices and entries that might match them. 628 664 for (size_t i = 0; i < p->device_count; i++) { ··· 666 702 } 667 703 } 668 704 669 - // Free the temporary list. 670 - free(dev_list); 705 + xrt_prober_unlock_list(&p->base, &dev_list); 671 706 } 672 707 673 708 static void ··· 780 815 } 781 816 } 782 817 818 + struct xrt_builder * 819 + find_builder_by_identifier(struct prober *p, const char *ident) 820 + { 821 + for (size_t i = 0; i < p->builder_count; i++) { 822 + if (strcmp(p->builders[i]->identifier, ident) != 0) { 823 + continue; 824 + } 825 + 826 + // This is what we want. 827 + return p->builders[i]; 828 + } 829 + 830 + struct u_pp_sink_stack_only sink; 831 + u_pp_delegate_t dg = u_pp_sink_stack_only_init(&sink); 832 + 833 + u_pp(dg, "Could not find builder with identifier '%s' among %u supported builders:", ident, 834 + (uint32_t)p->builder_count); 835 + 836 + for (size_t i = 0; i < p->builder_count; i++) { 837 + struct xrt_builder *xb = p->builders[i]; 838 + u_pp(dg, "\n\t%s: %s", xb->identifier, xb->name); 839 + } 840 + 841 + P_WARN(p, "%s", sink.buffer); 842 + 843 + return NULL; 844 + } 845 + 783 846 784 847 /* 785 848 * ··· 825 888 return 0; 826 889 } 827 890 891 + static xrt_result_t 892 + p_lock_list(struct xrt_prober *xp, struct xrt_prober_device ***out_devices, size_t *out_device_count) 893 + { 894 + struct prober *p = (struct prober *)xp; 895 + 896 + assert(!p->list_locked); 897 + assert(out_devices != NULL); 898 + assert(*out_devices == NULL); 899 + 900 + // Build a list of all current probed devices. 901 + struct xrt_prober_device **dev_list = U_TYPED_ARRAY_CALLOC(struct xrt_prober_device *, p->device_count); 902 + for (size_t i = 0; i < p->device_count; i++) { 903 + dev_list[i] = &p->devices[i].base; 904 + } 905 + 906 + p->list_locked = true; 907 + 908 + *out_devices = dev_list; 909 + *out_device_count = p->device_count; 910 + 911 + return XRT_SUCCESS; 912 + } 913 + 914 + static xrt_result_t 915 + p_unlock_list(struct xrt_prober *xp, struct xrt_prober_device ***devices) 916 + { 917 + struct prober *p = (struct prober *)xp; 918 + 919 + assert(p->list_locked); 920 + assert(devices != NULL); 921 + 922 + p->list_locked = false; 923 + free(*devices); 924 + *devices = NULL; 925 + 926 + return XRT_SUCCESS; 927 + } 928 + 828 929 static int 829 930 p_dump(struct xrt_prober *xp) 830 931 { ··· 840 941 } 841 942 842 943 return 0; 944 + } 945 + 946 + static xrt_result_t 947 + p_create_system(struct xrt_prober *xp, struct xrt_system_devices **out_xsysd) 948 + { 949 + XRT_TRACE_MARKER(); 950 + 951 + struct prober *p = (struct prober *)xp; 952 + struct xrt_builder *select = NULL; 953 + enum u_config_json_active_config active; 954 + xrt_result_t xret = XRT_SUCCESS; 955 + struct u_pp_sink_stack_only sink; // Not inited, very large. 956 + u_pp_delegate_t dg = u_pp_sink_stack_only_init(&sink); 957 + 958 + 959 + /* 960 + * Logging. 961 + */ 962 + 963 + u_pp(dg, "Creating system:"); 964 + u_pp(dg, "\n\tBuilders:"); 965 + for (size_t i = 0; i < p->builder_count; i++) { 966 + u_pp(dg, "\n\t\t%s: %s", p->builders[i]->identifier, p->builders[i]->name); 967 + } 968 + 969 + 970 + /* 971 + * Config. 972 + */ 973 + 974 + u_config_json_get_active(&p->json, &active); 975 + 976 + switch (active) { 977 + case U_ACTIVE_CONFIG_NONE: break; 978 + case U_ACTIVE_CONFIG_REMOTE: select = find_builder_by_identifier(p, "remote"); break; 979 + case U_ACTIVE_CONFIG_TRACKING: select = find_builder_by_identifier(p, "rgb_tracking"); break; 980 + default: assert(false); 981 + } 982 + 983 + if (select != NULL) { 984 + u_pp(dg, "\n\tConfig selected %s", select->identifier); 985 + } else { 986 + u_pp(dg, "\n\tNo builder selected in config (or wasn't compiled in)"); 987 + } 988 + 989 + 990 + /* 991 + * Estimate. 992 + */ 993 + 994 + //! @todo Improve estimation selection logic. 995 + if (select == NULL) { 996 + for (size_t i = 0; i < p->builder_count; i++) { 997 + struct xrt_builder *xb = p->builders[i]; 998 + 999 + if (xb->exclude_from_automatic_discovery) { 1000 + continue; 1001 + } 1002 + 1003 + struct xrt_builder_estimate estimate = {0}; 1004 + xrt_builder_estimate_system(xb, p->json.root, xp, &estimate); 1005 + 1006 + if (estimate.certain.head) { 1007 + select = xb; 1008 + break; 1009 + } 1010 + } 1011 + 1012 + if (select != NULL) { 1013 + u_pp(dg, "\n\tSelected %s because it was certain it could create a head", select->identifier); 1014 + } else { 1015 + u_pp(dg, "\n\tNo builder was certain that it could create a head device"); 1016 + } 1017 + } 1018 + 1019 + if (select == NULL) { 1020 + for (size_t i = 0; i < p->builder_count; i++) { 1021 + struct xrt_builder *xb = p->builders[i]; 1022 + 1023 + if (xb->exclude_from_automatic_discovery) { 1024 + continue; 1025 + } 1026 + 1027 + struct xrt_builder_estimate estimate = {0}; 1028 + xrt_builder_estimate_system(xb, p->json.root, xp, &estimate); 1029 + 1030 + if (estimate.maybe.head) { 1031 + select = xb; 1032 + break; 1033 + } 1034 + } 1035 + 1036 + if (select != NULL) { 1037 + u_pp(dg, "\n\tSelected %s because it maybe could create a head", select->identifier); 1038 + } else { 1039 + u_pp(dg, "\n\tNo builder could maybe create a head device"); 1040 + } 1041 + } 1042 + 1043 + if (select != NULL) { 1044 + u_pp(dg, "\n\tUsing builder %s: %s", select->identifier, select->name); 1045 + xret = xrt_builder_open_system(select, p->json.root, xp, out_xsysd); 1046 + u_pp(dg, "\n\tResult: "); 1047 + u_pp_xrt_result(dg, xret); 1048 + } 1049 + 1050 + P_INFO(p, "%s", sink.buffer); 1051 + 1052 + return xret; 843 1053 } 844 1054 845 1055 static int
+16
src/xrt/state_trackers/prober/p_prober.h
··· 124 124 125 125 struct u_config_json json; 126 126 127 + /*! 128 + * List of created builder. 129 + */ 130 + struct xrt_builder **builders; 131 + 132 + /*! 133 + * The number of created builders. 134 + */ 135 + size_t builder_count; 136 + 137 + /*! 138 + * Has the list been locked. 139 + */ 140 + bool list_locked; 141 + 127 142 #ifdef XRT_HAVE_LIBUSB 128 143 struct 129 144 { ··· 141 156 ssize_t count; 142 157 } uvc; 143 158 #endif 159 + 144 160 145 161 struct xrt_auto_prober *auto_probers[XRT_MAX_AUTO_PROBERS]; 146 162