/* * WiVRn VR streaming * Copyright (C) 2022 Guillaume Meunier * Copyright (C) 2022 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 "app_launcher.h" #include "application.h" #include "audio/audio.h" #include "configuration.h" #include "decoder/shard_accumulator.h" #include "render/imgui_impl.h" #include "scene.h" #include "scenes/input_profile.h" #include "stream_defoveator.h" #include "utils/thread_safe.h" #include "wifi_lock.h" #include "wivrn_client.h" #include "wivrn_packets.h" #include "xr/space.h" #include #include #include #include #include #include namespace scenes { class stream : public scene_impl, public std::enable_shared_from_this { public: enum class state { initializing, streaming, stalled, shutdown, }; static const size_t image_buffer_size = 3; app_launcher apps; private: static const size_t view_count = 2; static const size_t decoder_count = view_count + 1; struct accumulator_images { std::unique_ptr decoder; // latest frames, rolling buffer std::array, image_buffer_size> latest_frames; std::shared_ptr frame(uint64_t id) const; bool empty() const; }; wifi_lock::wifi wifi; // for frames inside accumulator images std::mutex frames_mutex; std::array, decoder_count> common_frame(XrTime display_time); std::unique_ptr network_session; std::thread network_thread; thread_safe tracking_control{}; std::array, 3> interaction_profiles; // left hand, right hand, gamepad std::atomic interaction_profile_changed = false; std::atomic scheduled_derived_pose = 0; // Tracking thread will compute derived pose when time is reached std::atomic recenter_requested = false; std::atomic hid_forwarding = false; std::atomic display_time_phase = 0; std::atomic display_time_period = 0; XrTime last_display_time = 0; std::atomic real_display_period = 0; std::optional tracking_thread; std::shared_mutex decoder_mutex; std::optional video_stream_description; std::array decoders; // Locked by decoder_mutex std::optional defoveator; vk::raii::Fence fence = nullptr; vk::raii::CommandBuffer command_buffer = nullptr; struct haptics_action { XrAction action; XrPath path; float amplitude; }; std::unordered_multimap haptics_actions; std::vector> input_actions; std::atomic state_ = state::initializing; void set_state(state new_state) { state prev = state_; if (prev == state::shutdown) return; state_.compare_exchange_strong(prev, new_state); } xr::swapchain swapchain; std::optional