/* * 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 "audio/audio.h" #include "decoder/shard_accumulator.h" #include "render/imgui_impl.h" #include "scene.h" #include "scenes/blitter.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 namespace scenes { class stream : public scene_impl, public std::enable_shared_from_this { public: enum class state { initializing, streaming, stalled }; static const size_t image_buffer_size = 3; app_launcher apps; private: static const size_t view_count = 2; using stream_description = wivrn::to_headset::video_stream_description::item; 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 alpha() const; bool empty() const; }; wifi_lock::wifi wifi; // for frames inside accumulator images std::mutex frames_mutex; std::vector> common_frame(XrTime display_time); std::unique_ptr network_session; std::atomic exiting = false; std::thread network_thread; thread_safe tracking_control{}; std::array, 2> interaction_profiles; // left and right hand std::atomic interaction_profile_changed = false; 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::vector decoders; // Locked by decoder_mutex std::array blitters; 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; state state_ = state::initializing; xr::swapchain swapchain; std::optional