/* * 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 "decoder/shard_accumulator.h" #include "scene.h" #include "stream_reprojection.h" #include "utils/sync_queue.h" #include "wivrn_client.h" #include "wivrn_packets.h" #include #include #include #include "audio/audio.h" #include "render/imgui_impl.h" namespace scenes { class stream : public scene_impl, public std::enable_shared_from_this { public: enum class state { initializing, streaming, stalled }; private: static const size_t view_count = 2; using stream_description = xrt::drivers::wivrn::to_headset::video_stream_description::item; struct accumulator_images { std::unique_ptr decoder; vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr; vk::DescriptorSet descriptor_set = nullptr; vk::raii::PipelineLayout blit_pipeline_layout = nullptr; vk::raii::Pipeline blit_pipeline = nullptr; // latest frames from oldest to most recent std::array, 3> latest_frames; static std::optional common_frame(const std::vector &, uint64_t preferred_index); std::shared_ptr frame(std::optional id); std::vector frames() const; }; struct renderpass_output { vk::Extent2D size; vk::Format format; image_allocation image; vk::raii::ImageView image_view = nullptr; vk::raii::Framebuffer frame_buffer = nullptr; }; std::unique_ptr network_session; std::atomic exiting = false; std::thread network_thread; std::optional tracking_thread; std::thread video_thread; utils::sync_queue shard_queue; std::mutex decoder_mutex; std::optional video_stream_description; uint64_t next_frame; // Preferred index for next frame std::vector decoders; // Locked by decoder_mutex vk::raii::DescriptorPool blit_descriptor_pool = nullptr; vk::raii::RenderPass blit_render_pass = nullptr; std::array decoder_output{}; std::optional reprojector; vk::raii::Fence fence = nullptr; vk::raii::CommandBuffer command_buffer = nullptr; std::array, 2> haptics_actions; std::vector> input_actions; state state_ = state::initializing; XrTime first_frame_time{}; const float dbrightness = 2; bool show_performance_metrics = false; std::vector swapchains; xr::swapchain swapchain_imgui; vk::Format swapchain_format; std::optional