From 1574f82b8e279f44cc3f86278a5ae789482d9e75 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 18 Aug 2025 23:25:19 +0200 Subject: [PATCH] Remove application::now() --- client/application.h | 5 ----- client/decoder/shard_accumulator.cpp | 16 ++++++++-------- client/decoder/shard_accumulator.h | 12 ++++++++++-- client/scenes/lobby_gui.cpp | 2 +- client/scenes/stream.cpp | 10 +++++----- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/client/application.h b/client/application.h index 076aa480..93301f98 100644 --- a/client/application.h +++ b/client/application.h @@ -343,11 +343,6 @@ public: // #endif } - static XrTime now() - { - return instance().xr_instance.now(); - } - static thread_safe & get_queue() { return instance().vk_queue; diff --git a/client/decoder/shard_accumulator.cpp b/client/decoder/shard_accumulator.cpp index 6b6106ce..900c05ee 100644 --- a/client/decoder/shard_accumulator.cpp +++ b/client/decoder/shard_accumulator.cpp @@ -18,9 +18,9 @@ */ #include "shard_accumulator.h" -#include "application.h" -#include "scenes/stream.h" +#include "scenes/stream.h" // IWYU pragma: keep #include "spdlog/spdlog.h" +#include "xr/instance.h" namespace wivrn { @@ -63,10 +63,10 @@ static bool is_complete(const shard_set & shards) return true; } -std::optional shard_set::insert(data_shard && shard) +std::optional shard_set::insert(data_shard && shard, xr::instance & instance) { if (empty()) - feedback.received_first_packet = application::now(); + feedback.received_first_packet = instance.now(); auto idx = shard.shard_idx; if (idx >= data.size()) @@ -121,12 +121,12 @@ void shard_accumulator::push_shard(video_stream_data_shard && shard) } else if (frame_diff == 0) { - auto shard_idx = current.insert(std::move(shard)); + auto shard_idx = current.insert(std::move(shard), instance); try_submit_frame(shard_idx); } else if (frame_diff == 1) { - next.insert(std::move(shard)); + next.insert(std::move(shard), instance); if (is_complete(next)) { debug_why_not_sent(current); @@ -191,7 +191,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) if (not frame_complete) return; - current.feedback.received_last_packet = application::now(); + current.feedback.received_last_packet = instance.now(); current.feedback.sent_to_decoder = current.feedback.received_last_packet; data_shard::timing_info_t timing_info = data_shards.back()->timing_info.value_or(data_shard::timing_info_t{}); current.feedback.encode_begin = timing_info.encode_begin; @@ -216,7 +216,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) void shard_accumulator::send_feedback(wivrn::from_headset::feedback & feedback) { if (not feedback.received_last_packet) - feedback.received_first_packet = application::now(); + feedback.received_first_packet = instance.now(); auto scene = weak_scene.lock(); if (scene) scene->send_feedback(feedback); diff --git a/client/decoder/shard_accumulator.h b/client/decoder/shard_accumulator.h index 4777de7f..406c0c49 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -34,6 +34,11 @@ using decoder_impl = ::wivrn::ffmpeg::decoder; #include #include +namespace xr +{ +class instance; +} + namespace wivrn { @@ -50,7 +55,7 @@ public: void reset(uint64_t frame_index); bool empty() const; - std::optional insert(data_shard &&); + std::optional insert(data_shard &&, xr::instance & instance); wivrn::from_headset::feedback feedback{}; @@ -70,11 +75,13 @@ private: shard_set current; shard_set next; std::weak_ptr weak_scene; + xr::instance & instance; public: explicit shard_accumulator( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, + xr::instance & instance, const wivrn::to_headset::video_stream_description::item & description, float fps, std::weak_ptr scene, @@ -82,7 +89,8 @@ public: decoder(std::make_shared(device, physical_device, description, fps, stream_index, scene, this)), current(stream_index), next(stream_index), - weak_scene(scene) + weak_scene(scene), + instance(instance) { next.reset(1); } diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index e61c7eb4..f747d5a2 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1804,7 +1804,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) if (*status.charge > 0.995) icon_nr = 5; else - icon_nr = application::now() / 500'000'000 % 5; + icon_nr = instance.now() / 500'000'000 % 5; } else icon_nr = std::round((*status.charge) * 4); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 267246de..3b427f98 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -391,7 +391,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrfeedback.received_from_decoder = application::now(); + handle->feedback.received_from_decoder = instance.now(); std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]); } @@ -535,7 +535,7 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p })) { state_ = state::streaming; - spdlog::info("Stream scene ready at t={}", application::now()); + spdlog::info("Stream scene ready at t={}", instance.now()); } } @@ -930,7 +930,7 @@ void scenes::stream::render(const XrFrameState & frame_state) if (not blit_handle or not *i.blit_pipeline) continue; - blit_handle->feedback.blitted = application::now(); + blit_handle->feedback.blitted = instance.now(); if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000) state_ = stream::state::stalled; ++blit_handle->feedback.times_displayed; @@ -1365,7 +1365,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y); decoders.push_back(accumulator_images{ - .decoder = std::make_unique(device, physical_device, item, description.fps, shared_from_this(), stream_index), + .decoder = std::make_unique(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index), }); } }