/* * 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 "vk/device_memory.h" #include "vk/renderpass.h" #include "wivrn_client.h" #include "wivrn_packets.h" #include #include #include #include #include #include #include "audio/audio.h" namespace scenes { class stream : public scene, public std::enable_shared_from_this { 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; // latest frames from oldest to most recent std::array, 2> latest_frames; static std::optional common_frame(const std::vector &); std::shared_ptr frame(std::optional id); std::vector frames() const; }; struct renderpass_output { VkExtent2D size; VkFormat format; VkImage image; VkDeviceMemory memory; VkImageView image_view; }; 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::vector decoders; // Locked by decoder_mutex std::array decoder_output{}; stream_reprojection reprojector; VkFence fence; VkCommandBuffer command_buffer; std::array, 2> haptics_actions; std::vector> input_actions; bool ready_ = false; bool video_started_ = false; XrTime first_frame_time{}; const float dbrightness = 2; std::optional