diff --git a/client/application.cpp b/client/application.cpp index da0dd723..cfbc4d59 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -18,15 +18,13 @@ */ #include "application.h" +#include "hardware.h" #include "magic_enum.hpp" #include "scene.h" #include "spdlog/common.h" #include "spdlog/spdlog.h" #include "utils/ranges.h" -#include "utils/strings.h" #include "vk/details/enumerate.h" -#include "vk/pipeline.h" -#include "vk/shader.h" #include "vk/vk.h" #include "xr/xr.h" #include @@ -42,8 +40,8 @@ #endif #ifdef XR_USE_PLATFORM_ANDROID -#include #include +#include #endif using namespace std::chrono_literals; @@ -398,8 +396,9 @@ void application::initialize() auto views = xr_system_id.view_configuration_views(app_info.viewconfig); xr_swapchains.reserve(views.size()); - for (auto & view: views) + for (auto view: views) { + view = override_view(view, guess_model()); xr_swapchains.emplace_back(xr_session, vk_device, swapchain_format, view.recommendedImageRectWidth, view.recommendedImageRectHeight); spdlog::info("Created swapchain {}: {}x{}", xr_swapchains.size(), xr_swapchains.back().width(), xr_swapchains.back().height()); @@ -410,34 +409,22 @@ void application::initialize() // TODO get it from application info xr_actionset = xr::actionset(xr_instance, "actions", "Actions"); - // TODO better way to handle bindings for different vendors/flavors of vendor -#ifdef XR_USE_PLATFORM_ANDROID - char property_chararr[PROP_VALUE_MAX + 1]; - __system_property_get("ro.product.manufacturer", property_chararr); -#else - char property_chararr[93]; -#endif - std::string manufacturer_string(property_chararr); - - if (manufacturer_string == "Oculus" || manufacturer_string == "Meta") + switch (guess_model()) { - spdlog::info("Suggesting Oculus Quest 2 bindings"); - std::vector touch_controller_bindings; - for (const auto & [name, type]: oculus_touch) - { - process_binding_action(touch_controller_bindings, name, type); + case model::oculus_quest: + case model::oculus_quest_2: + case model::meta_quest_3: { + spdlog::info("Suggesting oculus/touch_controller bindings"); + std::vector touch_controller_bindings; + for (const auto & [name, type]: oculus_touch) + { + process_binding_action(touch_controller_bindings, name, type); + } + xr_instance.suggest_bindings("/interaction_profiles/oculus/touch_controller", touch_controller_bindings); } - xr_instance.suggest_bindings("/interaction_profiles/oculus/touch_controller", touch_controller_bindings); - } - else if (manufacturer_string == "Pico") - { -#ifdef XR_USE_PLATFORM_ANDROID - __system_property_get("ro.product.model", property_chararr); -#endif - std::string model_string(property_chararr); + break; - if (model_string == "Pico Neo 3") - { + case model::pico_neo_3: { spdlog::info("Suggesting Pico Neo 3 bindings"); std::vector pico_neo_3_bindings; for (const auto & [name, type]: pico_neo_3) @@ -446,8 +433,9 @@ void application::initialize() } xr_instance.suggest_bindings("/interaction_profiles/bytedance/pico_neo3_controller", pico_neo_3_bindings); } - else - { + break; + + case model::pico_4: { spdlog::info("Suggesting Pico 4 bindings"); std::vector pico_4_bindings; for (const auto & [name, type]: pico_4) @@ -456,9 +444,8 @@ void application::initialize() } xr_instance.suggest_bindings("/interaction_profiles/bytedance/pico4_controller", pico_4_bindings); } - } - else - { + + case model::unknown: { spdlog::info("Suggesting Khronos simple controller bindings"); std::vector simple_controller_bindings; for (const auto & [name, type]: simple_controller) @@ -466,6 +453,8 @@ void application::initialize() process_binding_action(simple_controller_bindings, name, type); } xr_instance.suggest_bindings("/interaction_profiles/khr/simple_controller", simple_controller_bindings); + } + break; } xr_session.attach_actionsets({xr_actionset}); @@ -581,7 +570,7 @@ application::application(application_info info) : jobject intent = Env->CallObjectMethod(activity->clazz, jtmID); jtmID = Env->GetMethodID(Env->GetObjectClass(intent), "getDataString", "()Ljava/lang/String;"); - jstring dataString_jni = (jstring)Env->CallObjectMethod(intent, jtmID); + jstring dataString_jni = (jstring)Env->CallObjectMethod(intent, jtmID); std::string dataString; if (dataString_jni) { @@ -787,7 +776,7 @@ void application::poll_actions() instance_->xr_session.sync_actions(instance_->xr_actionset); } -bool application::read_action(XrAction action, bool & value, XrTime& last_change_time) +bool application::read_action(XrAction action, bool & value, XrTime & last_change_time) { if (!is_focused()) return false; @@ -808,7 +797,7 @@ bool application::read_action(XrAction action, bool & value, XrTime& last_change return true; } -bool application::read_action(XrAction action, float & value, XrTime& last_change_time) +bool application::read_action(XrAction action, float & value, XrTime & last_change_time) { if (!is_focused()) return false; @@ -829,7 +818,7 @@ bool application::read_action(XrAction action, float & value, XrTime& last_chang return true; } -bool application::read_action(XrAction action, XrVector2f & value, XrTime& last_change_time) +bool application::read_action(XrAction action, XrVector2f & value, XrTime & last_change_time) { if (!is_focused()) return false; diff --git a/client/hardware.cpp b/client/hardware.cpp new file mode 100644 index 00000000..363117c6 --- /dev/null +++ b/client/hardware.cpp @@ -0,0 +1,103 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2023 Guillaume Meunier + * Copyright (C) 2023 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "hardware.h" + +#include +#include + +#include + +#ifdef XR_USE_PLATFORM_ANDROID +#include "utils/wrap_lambda.h" + +#include + +static std::string get_property(const char * property) +{ + auto info = __system_property_find(property); + std::string result; + wrap_lambda cb = [&result](const char * name, const char * value, uint32_t serial) { + result = value; + }; + + __system_property_read_callback(info, cb.userdata_first(), cb); + return result; +} +#endif + +model guess_model() +{ +#ifdef XR_USE_PLATFORM_ANDROID + const auto device = get_property("ro.product.device"); + if (device == "monterey") + return model::oculus_quest; + if (device == "hollywood") + return model::oculus_quest_2; + + const auto manufacturer = get_property("ro.product.manufacturer"); + const auto model = get_property("ro.product.model"); + if (manufacturer == "Pico") + { + if (model == "Pico Neo 3") + return model::pico_neo_3; + + spdlog::info("manufacturer={}, model={}, device={} assuming Pico 4", manufacturer, model, device); + return model::pico_4; + } + + spdlog::info("Unknown model, manufacturer={}, model={}, device={}", manufacturer, model, device); +#endif + return model::unknown; +} + +XrViewConfigurationView override_view(XrViewConfigurationView view, model m) +{ + // Standalone headsets tend to report a lower resolution + // as the GPU can't handle full res. + // Return the panel resolution instead. + switch (m) + { + case model::oculus_quest: + spdlog::info("Using panel resolution 1440x1600 for Quest"); + view.recommendedImageRectWidth = 1440; + view.recommendedImageRectHeight = 1600; + return view; + case model::oculus_quest_2: + spdlog::info("Using panel resolution 1832x1920 for Quest 2"); + view.recommendedImageRectWidth = 1832; + view.recommendedImageRectHeight = 1920; + return view; + case model::meta_quest_3: + spdlog::info("Using panel resolution 2064x2208 for Quest 3"); + view.recommendedImageRectWidth = 2064; + view.recommendedImageRectHeight = 2208; + return view; + case model::pico_neo_3: + return view; + case model::pico_4: + spdlog::info("Using panel resolution 2160x2160 for Pico 4"); + view.recommendedImageRectWidth = 2160; + view.recommendedImageRectHeight = 2160; + return view; + case model::unknown: + return view; + } + throw std::range_error("invalid model " + std::to_string((int)m)); +} diff --git a/client/hardware.h b/client/hardware.h new file mode 100644 index 00000000..b663f8be --- /dev/null +++ b/client/hardware.h @@ -0,0 +1,35 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2023 Guillaume Meunier + * Copyright (C) 2023 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include + +enum class model +{ + oculus_quest, + oculus_quest_2, + meta_quest_3, + pico_neo_3, + pico_4, + unknown +}; + +model guess_model(); + +XrViewConfigurationView override_view(XrViewConfigurationView, model); diff --git a/common/utils/wrap_lambda.h b/common/utils/wrap_lambda.h new file mode 100644 index 00000000..3851946d --- /dev/null +++ b/common/utils/wrap_lambda.h @@ -0,0 +1,73 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2023 Guillaume Meunier + * Copyright (C) 2023 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +namespace details +{ +template +struct add_void; + +template +struct add_void> +{ + template + static T fn_0(void * userdata, Args... a) + { + L * f = (L *)userdata; + return (*f)(a...); + } + + template + static T fn(Args... a, void * userdata) + { + L * f = (L *)userdata; + return (*f)(a...); + } +}; +} // namespace details + +template +class wrap_lambda +{ + T impl; + +public: + wrap_lambda(T && l) : + impl(l) {} + + auto userdata_first() + { + using F = decltype(std::function(impl)); + return details::add_void::template fn_0; + } + + operator auto() + { + using F = decltype(std::function(impl)); + return details::add_void::template fn; + } + + operator void *() + { + return this; + } +}; diff --git a/server/driver/audio_pulse.cpp b/server/driver/audio_pulse.cpp index c7abf2b4..7fb37c6b 100644 --- a/server/driver/audio_pulse.cpp +++ b/server/driver/audio_pulse.cpp @@ -4,6 +4,7 @@ #include "os/os_time.h" #include "util/u_logging.h" #include "utils/sync_queue.h" +#include "utils/wrap_lambda.h" #include "wivrn_session.h" #include @@ -15,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -49,41 +49,6 @@ void wait_connected(std::atomic & state) } } -template -struct add_void; - -template -struct add_void> -{ - template - static T fn(Args... a, void * userdata) - { - L * f = (L *)userdata; - return (*f)(a...); - } -}; - -template -class wrap_lambda -{ - T impl; - -public: - wrap_lambda(T && l) : - impl(l) {} - - operator auto() - { - using F = decltype(std::function(impl)); - return add_void::template fn; - } - - operator void *() - { - return this; - } -}; - void unload_module(uintptr_t id); void unload_module(pa_context * ctx, uint32_t id)