/* * 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 "wivrn_connection.h" #include "wivrn_packets.h" #include "xrt/xrt_system.h" #include #include #include #include #include class wivrn_hmd; class wivrn_controller; namespace xrt::drivers::wivrn { struct clock_offset { std::chrono::nanoseconds epoch_offset{}; uint64_t from_headset(uint64_t) const; std::chrono::nanoseconds to_headset(uint64_t timestamp_ns) const; }; class wivrn_session : public std::enable_shared_from_this { wivrn_connection connection; std::atomic quit = false; std::thread thread; std::mutex mutex; std::unique_ptr hmd; std::unique_ptr left_hand; std::unique_ptr right_hand; clock_offset offset; std::chrono::steady_clock::time_point offset_age{}; std::ofstream feedback_csv; wivrn_session(TCP && tcp, in6_addr & address); public: static xrt_system_devices * create_session(TCP && tcp); clock_offset get_offset(); void operator()(from_headset::headset_info_packet &&); void operator()(from_headset::tracking &&); void operator()(from_headset::inputs &&); void operator()(from_headset::timesync_response &&); void operator()(from_headset::feedback &&); template void send_stream(const T & packet) { connection.send_stream(packet); } template void send_control(const T & packet) { connection.send_control(packet); } private: static void run(std::weak_ptr); }; } // namespace xrt::drivers::wivrn