From 8d408c0792bee21abeecfa11c4502ca1014479bb Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Fri, 9 Feb 2024 00:01:20 +0100 Subject: [PATCH] Return to lobby when the video is stalled --- client/scenes/lobby.cpp | 2 +- client/scenes/lobby_gui.cpp | 8 +++++++- client/scenes/stream.cpp | 7 +++++-- client/scenes/stream.h | 16 ++++++++++++---- client/scenes/stream_network.cpp | 7 +++---- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 6e3ce28e..d8d0b804 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -526,7 +526,7 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render) { if (!next_scene->alive()) next_scene.reset(); - else if (next_scene->ready()) + else if (next_scene->current_state() == scenes::stream::state::streaming) application::push_scene(next_scene); } diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 07923608..501e6d01 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -23,6 +23,7 @@ #include "imgui_internal.h" #include "lobby.h" #include "version.h" +#include "stream.h" #include #include @@ -71,7 +72,12 @@ void scenes::lobby::gui_connecting() std::string status; if (next_scene) - status = "Waiting for video stream"; + { + if (next_scene->current_state() == scenes::stream::state::stalled) + status = "Video stream interrupted"; + else + status = "Waiting for video stream"; + } else if (async_session.valid()) status = async_session.get_progress(); else if (async_error) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 099a837c..23e6e845 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -230,11 +230,11 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p } } - if (!ready_ && std::all_of(decoders.begin(), decoders.end(), [](accumulator_images & i) { + if (state_ != state::streaming && std::all_of(decoders.begin(), decoders.end(), [](accumulator_images & i) { return i.latest_frames.back(); })) { - ready_ = true; + state_ = state::streaming; first_frame_time = application::now(); spdlog::info("Stream scene ready at t={}", first_frame_time); } @@ -465,6 +465,9 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render) return; } + if (state_ == state::stalled) + application::pop_scene(); + session.begin_frame(); auto [flags, views] = session.locate_views(viewconfig, predicted_display_time, world_space); diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 0dc9a7be..8fcf2fda 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -35,6 +35,15 @@ 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; @@ -79,8 +88,7 @@ class stream : public scene_impl, public std::enable_shared_from_this, 2> haptics_actions; std::vector> input_actions; - bool ready_ = false; - bool video_started_ = false; + state state_ = state::initializing; XrTime first_frame_time{}; const float dbrightness = 2; bool show_performance_metrics = false; @@ -116,9 +124,9 @@ public: void send_feedback(const xrt::drivers::wivrn::from_headset::feedback & feedback); - bool ready() const + state current_state() const { - return ready_; + return state_ ; } bool alive() const diff --git a/client/scenes/stream_network.cpp b/client/scenes/stream_network.cpp index a82399fe..fd4a67dc 100644 --- a/client/scenes/stream_network.cpp +++ b/client/scenes/stream_network.cpp @@ -27,9 +27,9 @@ void scenes::stream::process_packets() { try { - int n = network_session->poll(*this, std::chrono::milliseconds(5000)); - if (n == 0 && video_started_) - throw std::runtime_error("Timeout waiting for network packets"); + int n = network_session->poll(*this, std::chrono::milliseconds(500)); + if (n == 0 && state_ == state::streaming) + state_ = state::stalled; } catch (std::exception & e) { @@ -41,7 +41,6 @@ void scenes::stream::process_packets() void scenes::stream::operator()(to_headset::video_stream_data_shard && shard) { - video_started_ = true; shard_queue.push(std::move(shard)); }