configure bitrate on client only

This commit is contained in:
Patrick Nicolas
2025-12-10 14:32:01 +01:00
parent e0cbd202a8
commit 0b526cef9d
25 changed files with 107 additions and 217 deletions
+5
View File
@@ -132,6 +132,9 @@ configuration::configuration(xr::system & system)
if (auto val = root["stream_scale"]; val.is_double())
stream_scale = val.get_double();
if (auto val = root["bitrate_bps"]; val.is_number())
bitrate_bps = val.get_uint64();
if (auto val = root["enable_stream_gui"]; val.is_bool())
enable_stream_gui = val.get_bool();
@@ -192,6 +195,7 @@ configuration::configuration(xr::system & system)
minimum_refresh_rate.reset();
resolution_scale = 1.0;
stream_scale = 0.5;
bitrate_bps = 50'000'000;
openxr_post_processing = {};
passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color;
}
@@ -255,6 +259,7 @@ void configuration::save()
json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate;
json << ",\"resolution_scale\":" << resolution_scale;
json << ",\"stream_scale\":" << stream_scale;
json << ",\"bitrate_bps\":" << bitrate_bps;
json << ",\"openxr_post_processing\":";
write_openxr_post_processing(json, openxr_post_processing);
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
+1
View File
@@ -51,6 +51,7 @@ public:
std::optional<float> minimum_refresh_rate;
float resolution_scale = 1.0;
float stream_scale = 0.5;
uint32_t bitrate_bps = 50'000'000;
bool passthrough_enabled = false;
bool mic_unprocessed_audio = false;
+22 -1
View File
@@ -32,12 +32,14 @@
#include "utils/i18n.h"
#include "utils/mapped_file.h"
#include "utils/overloaded.h"
#if WIVRN_CLIENT_DEBUG_MENU
#include "utils/ranges.h"
#endif
#include "version.h"
#include "xr/body_tracker.h"
#include <algorithm>
#include <cassert>
#include <chrono>
#include <chrono> // IWYU pragma: keep
#include <entt/entity/fwd.hpp>
#include <fastgltf/math.hpp>
#include <fastgltf/types.hpp>
@@ -689,6 +691,25 @@ void scenes::lobby::gui_settings()
imgui_ctx->vibrate_on_hover();
}
// Bitrate
{
const int mb = 1'000'000;
const auto current = config.bitrate_bps;
auto val = int(current / mb);
const auto slider = ImGui::SliderInt(
_("Bitrate").append("##bitrate").c_str(),
&val,
1,
200,
fmt::format(_F("{}Mbit/s"), val).c_str());
if (slider)
{
config.bitrate_bps = val * mb;
config.save();
}
imgui_ctx->vibrate_on_hover();
}
if (instance.has_extension(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME))
{
if (ImGui::Checkbox(_S("High power mode"), &config.high_power_mode))
+6 -4
View File
@@ -233,13 +233,13 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
{
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(info.available_refresh_rates, *config.preferred_refresh_rate)))
{
info.preferred_refresh_rate = *config.preferred_refresh_rate;
info.minimum_refresh_rate = config.minimum_refresh_rate.value_or(0);
info.settings.preferred_refresh_rate = *config.preferred_refresh_rate;
info.settings.minimum_refresh_rate = config.minimum_refresh_rate.value_or(0);
}
else
{
// Default to highest refresh rate
info.preferred_refresh_rate = info.available_refresh_rates.back();
info.settings.preferred_refresh_rate = info.available_refresh_rates.back();
}
}
}
@@ -248,9 +248,11 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
{
spdlog::warn("Unable to detect refresh rates");
info.available_refresh_rates = {guessed_fps};
info.preferred_refresh_rate = guessed_fps;
info.settings.preferred_refresh_rate = guessed_fps;
}
info.settings.bitrate_bps = config.bitrate_bps;
info.hand_tracking = config.check_feature(feature::hand_tracking);
info.eye_gaze = config.check_feature(feature::eye_gaze);
-3
View File
@@ -167,8 +167,6 @@ private:
XrTime running_application_req = 0;
thread_safe<to_headset::running_applications> running_applications;
std::atomic_uint32_t bitrate = 0;
stream(std::string server_name, scene & parent_scene);
bool forward_hid_input(from_headset::hid::input_t);
@@ -204,7 +202,6 @@ public:
void operator()(to_headset::tracking_control &&);
void operator()(to_headset::audio_stream_description &&);
void operator()(to_headset::video_stream_description &&);
void operator()(to_headset::settings &&);
void operator()(to_headset::refresh_rate_change &&);
void operator()(to_headset::application_list &&);
void operator()(to_headset::application_icon &&);
+13 -9
View File
@@ -382,11 +382,11 @@ void scenes::stream::gui_compact_view()
}
}
static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config, uint32_t bitrate, float predicted_display_period)
static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config, float predicted_display_period)
{
const auto & refresh_rates = session.get_refresh_rates();
from_headset::settings_changed packet{
.bitrate_bps = bitrate,
.bitrate_bps = config.bitrate_bps,
};
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(refresh_rates, *config.preferred_refresh_rate)))
{
@@ -420,7 +420,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
{
session.set_refresh_rate(0);
config.preferred_refresh_rate = 0;
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
config.save();
}
if (ImGui::IsItemHovered())
@@ -431,7 +431,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
{
session.set_refresh_rate(rate);
config.preferred_refresh_rate = rate;
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
config.save();
}
}
@@ -449,7 +449,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == config.minimum_refresh_rate, ImGuiSelectableFlags_SelectOnRelease))
{
config.minimum_refresh_rate = rate;
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
config.save();
}
}
@@ -467,7 +467,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
ImGui::SameLine(0.f, 10.f);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (size.y / 4.f) - style.FramePadding.y * 3.f);
if (ImGui::Button(fmt::format("{}Mbit/s", bitrate / 1'000'000).c_str()))
if (ImGui::Button(fmt::format("{}Mbit/s", config.bitrate_bps / 1'000'000).c_str()))
gui_status = gui_status::bitrate_settings;
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
@@ -589,23 +589,27 @@ void scenes::stream::gui_settings(float predicted_display_period)
void scenes::stream::gui_bitrate_settings(float predicted_display_period)
{
auto & config = application::get_config();
ImGui::PushFont(nullptr, constants::gui::font_size_large);
ImGui::Text("%s", _S("Use the right thumbstick to adjust the bitrate"));
ImGui::Text("%s", _S("Press A to go back"));
ImGui::Text("%s", fmt::format(_F("Bitrate: {}Mbit/s"), bitrate / 1'000'000).c_str());
ImGui::Text("%s", fmt::format(_F("Bitrate: {}Mbit/s"), config.bitrate_bps / 1'000'000).c_str());
ImGui::PopFont();
// Maximum speed of 20Mbit/s
float delta = application::read_action_float(settings_adjust).value_or(std::pair{0, 0}).second * 20'000'000.f * predicted_display_period;
bitrate = std::clamp(bitrate + static_cast<int32_t>(delta), 1'000'000u, 200'000'000u);
config.bitrate_bps = std::clamp(config.bitrate_bps + static_cast<int32_t>(delta), 1'000'000u, 200'000'000u);
bool ok = application::read_action_bool(foveation_ok).value_or(std::pair{0, false}).second;
if (ok)
{
config.save();
gui_status = gui_status::settings;
}
send_settings_changed_packet(session, network_session.get(), application::get_config(), bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), application::get_config(), predicted_display_period);
}
void scenes::stream::gui_foveation_settings(float predicted_display_period)
-5
View File
@@ -74,11 +74,6 @@ void scenes::stream::operator()(to_headset::video_stream_description && desc)
}
}
void scenes::stream::operator()(to_headset::settings && settings)
{
bitrate = settings.bitrate_bps;
}
void scenes::stream::operator()(to_headset::refresh_rate_change && rate)
{
session.set_refresh_rate(rate.fps);