From da14e8450df036c2eebd6fe3457f551d0aed5bb5 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 14 Dec 2024 17:21:13 +0100 Subject: [PATCH] Don't recreate decoders if only fps changes --- client/scenes/stream.cpp | 43 +++++++++++++++++++++-------- server/driver/wivrn_comp_target.cpp | 3 +- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 3898dd6a..222797c6 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -935,6 +935,37 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript { std::unique_lock lock(decoder_mutex); + if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME)) + { + try + { + session.set_refresh_rate(description.fps); + } + catch (std::exception & e) + { + spdlog::warn("Failed to set refresh rate to {}: {}", description.fps, e.what()); + } + } + + if (std::ranges::equal(description.items, video_stream_description->items, [](const auto & a, const auto & b) { + // clang-format off + return a.width == b.width + and a.height == b.height + and a.video_width == b.video_width + and a.offset_x == b.offset_x + and a.offset_y == b.offset_y + and a.codec == b.codec + and a.channels == b.channels + and a.subsampling == b.subsampling + and a.range == b.range + and a.color_model == b.color_model; + //clang-format on + })) + { + video_stream_description = description; + return; + } + decoders.clear(); if (description.items.empty()) @@ -1048,18 +1079,6 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript }); } - if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME)) - { - try - { - session.set_refresh_rate(description.fps); - } - catch (std::exception & e) - { - spdlog::warn("Failed to set refresh rate to {}: {}", description.fps, e.what()); - } - } - for (const auto & [stream_index, item]: utils::enumerate(description.items)) { spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y); diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 1ea0c9bb..99dd6e69 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -738,7 +738,6 @@ static xrt_result_t comp_wivrn_request_refresh_rate(struct comp_target * ct, flo auto from = cn->desc.fps; cn->desc.fps = refresh_rate_hz; cn->pacer.set_frame_duration(U_TIME_1S_IN_NS / refresh_rate_hz); - cn->cnx.send_control(decltype(cn->desc)(cn->desc)); cn->cnx.push_event( { .display = { @@ -747,7 +746,7 @@ static xrt_result_t comp_wivrn_request_refresh_rate(struct comp_target * ct, flo .to_display_refresh_rate_hz = refresh_rate_hz, }, }); - cn->reset_encoders(); + cn->cnx.send_control(to_headset::video_stream_description{cn->desc}); return XRT_SUCCESS; }