configure bitrate on client only
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 &&);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
+13
-22
@@ -216,6 +216,15 @@ enum face_type : uint8_t
|
||||
htc,
|
||||
};
|
||||
|
||||
struct settings_changed
|
||||
{
|
||||
float preferred_refresh_rate;
|
||||
// for automatic
|
||||
float minimum_refresh_rate;
|
||||
|
||||
uint32_t bitrate_bps;
|
||||
};
|
||||
|
||||
struct headset_info_packet
|
||||
{
|
||||
uint16_t render_eye_width;
|
||||
@@ -223,9 +232,10 @@ struct headset_info_packet
|
||||
uint16_t stream_eye_width;
|
||||
uint16_t stream_eye_height;
|
||||
std::vector<float> available_refresh_rates;
|
||||
float preferred_refresh_rate;
|
||||
// for automatic
|
||||
float minimum_refresh_rate;
|
||||
|
||||
// runtime configurable settings
|
||||
settings_changed settings;
|
||||
|
||||
struct audio_description
|
||||
{
|
||||
uint8_t num_channels;
|
||||
@@ -251,18 +261,6 @@ struct headset_info_packet
|
||||
std::string variant;
|
||||
};
|
||||
|
||||
struct settings_request
|
||||
{};
|
||||
|
||||
struct settings_changed
|
||||
{
|
||||
float preferred_refresh_rate;
|
||||
// for automatic
|
||||
float minimum_refresh_rate;
|
||||
|
||||
uint32_t bitrate_bps;
|
||||
};
|
||||
|
||||
struct handshake
|
||||
{
|
||||
// Sending this on TCP means connection will be TCP only
|
||||
@@ -550,7 +548,6 @@ using packets = std::variant<
|
||||
pin_check_1,
|
||||
pin_check_3,
|
||||
headset_info_packet,
|
||||
settings_request,
|
||||
settings_changed,
|
||||
feedback,
|
||||
audio_data,
|
||||
@@ -733,11 +730,6 @@ struct tracking_control
|
||||
std::array<bool, size_t(id::last) + 1> enabled;
|
||||
};
|
||||
|
||||
struct settings
|
||||
{
|
||||
uint32_t bitrate_bps;
|
||||
};
|
||||
|
||||
struct refresh_rate_change
|
||||
{
|
||||
float fps;
|
||||
@@ -786,7 +778,6 @@ using packets = std::variant<
|
||||
haptics,
|
||||
timesync_query,
|
||||
tracking_control,
|
||||
settings,
|
||||
refresh_rate_change,
|
||||
application_list,
|
||||
application_icon,
|
||||
|
||||
@@ -23,24 +23,6 @@ Kirigami.ScrollablePage {
|
||||
|
||||
Kirigami.FormLayout {
|
||||
|
||||
Controls.SpinBox {
|
||||
id: bitrate
|
||||
Kirigami.FormData.label: i18n("Bitrate:")
|
||||
from: 1
|
||||
to: 200
|
||||
|
||||
textFromValue: (value, locale) => i18nc("bitrate", "%1 Mbit/s", value)
|
||||
valueFromText: function (text, locale) {
|
||||
var prefix_suffix = i18nc("bitrate", "%1 Mbit/s", "%1").split('%1');
|
||||
for (var i of prefix_suffix) {
|
||||
text = text.replace(i, "");
|
||||
}
|
||||
return Number.fromLocaleString(text);
|
||||
}
|
||||
|
||||
onValueModified: Settings.bitrate = value
|
||||
}
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
text: i18n("The current encoder configuration is not supported")
|
||||
@@ -314,9 +296,6 @@ Kirigami.ScrollablePage {
|
||||
Component.onCompleted: {
|
||||
openvr_libs.init()
|
||||
Settings.load(WivrnServer);
|
||||
// If bitrate was manually set higher, keep the limit
|
||||
bitrate.to = Math.max(bitrate.to, Settings.bitrate)
|
||||
bitrate.value = Settings.bitrate
|
||||
settings.allowUpdates = true;
|
||||
settings.load();
|
||||
}
|
||||
|
||||
@@ -114,7 +114,6 @@ void Settings::emitAllChanged()
|
||||
encoderChanged();
|
||||
codecChanged();
|
||||
tenbitChanged();
|
||||
bitrateChanged();
|
||||
tcpOnlyChanged();
|
||||
applicationChanged();
|
||||
openvrChanged();
|
||||
@@ -313,26 +312,6 @@ void Settings::set_tenbit(const bool & value)
|
||||
tenbitChanged();
|
||||
}
|
||||
|
||||
int Settings::bitrate() const
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_jsonSettings.value("bitrate", 50'000'000) / 1'000'000;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::set_bitrate(const int & value)
|
||||
{
|
||||
auto old = bitrate();
|
||||
m_jsonSettings["bitrate"] = value * 1'000'000;
|
||||
if (old != value)
|
||||
bitrateChanged();
|
||||
}
|
||||
|
||||
QString Settings::application() const
|
||||
{
|
||||
// Automatically started application
|
||||
@@ -500,7 +479,6 @@ void Settings::save(wivrn_server * server)
|
||||
void Settings::restore_defaults()
|
||||
{
|
||||
m_jsonSettings.erase("encoder");
|
||||
m_jsonSettings.erase("bitrate");
|
||||
m_jsonSettings.erase("application");
|
||||
m_jsonSettings.erase("hid-forwarding");
|
||||
m_jsonSettings.erase("debug-gui");
|
||||
|
||||
@@ -66,7 +66,6 @@ public:
|
||||
Q_PROPERTY(QList<video_codec> allowedCodecs READ allowedCodecs NOTIFY encoderChanged)
|
||||
Q_PROPERTY(bool can10bit READ can10bit NOTIFY codecChanged)
|
||||
Q_PROPERTY(bool tenbit READ tenbit WRITE set_tenbit NOTIFY tenbitChanged)
|
||||
Q_PROPERTY(int bitrate READ bitrate WRITE set_bitrate NOTIFY bitrateChanged)
|
||||
|
||||
Q_PROPERTY(bool tcpOnly READ tcpOnly WRITE set_tcpOnly NOTIFY tcpOnlyChanged)
|
||||
Q_PROPERTY(QString application READ application WRITE set_application NOTIFY applicationChanged)
|
||||
@@ -85,7 +84,6 @@ public:
|
||||
SETTER_GETTER_NOTIFY(encoder_name, encoder)
|
||||
SETTER_GETTER_NOTIFY(video_codec, codec)
|
||||
SETTER_GETTER_NOTIFY(bool, tenbit)
|
||||
SETTER_GETTER_NOTIFY(int, bitrate)
|
||||
SETTER_GETTER_NOTIFY(QString, application)
|
||||
SETTER_GETTER_NOTIFY(bool, hidForwarding)
|
||||
SETTER_GETTER_NOTIFY(bool, debugGui)
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<property name="SessionRunning" type="b" access="read"/>
|
||||
<property name="SteamCommand" type="s" access="read"/>
|
||||
<property name="JsonConfiguration" type="s" access="readwrite"/>
|
||||
<property name="Bitrate" type="u" access="readwrite"/>
|
||||
<property name="Bitrate" type="u" access="read"/>
|
||||
|
||||
<!-- Data from the headset info packet -->
|
||||
<property name="AvailableRefreshRates" type="ad" access="read">
|
||||
|
||||
@@ -12,11 +12,6 @@ If you installed WiVRn from a flatpack, the config is in `$HOME/.var/app/io.gith
|
||||
|
||||
All elements are optional and have default values.
|
||||
|
||||
## `bitrate`
|
||||
Default value: `50000000` (50Mb/s)
|
||||
|
||||
Bitrate of the video, in bit/s. Split among decoders based on size and codecs.
|
||||
|
||||
## `bit-depth`
|
||||
Default value: `8` (bits)
|
||||
|
||||
|
||||
@@ -159,9 +159,6 @@ configuration::configuration()
|
||||
grip_surface = *it;
|
||||
}
|
||||
|
||||
if (auto it = json.find("bitrate"); it != json.end())
|
||||
bitrate = *it;
|
||||
|
||||
if (auto it = json.find("encoder"); it != json.end())
|
||||
{
|
||||
if (it->is_array())
|
||||
|
||||
@@ -50,7 +50,6 @@ struct configuration
|
||||
};
|
||||
|
||||
std::array<encoder, 3> encoders; // left, right, alpha
|
||||
std::optional<int> bitrate;
|
||||
std::optional<int> bit_depth;
|
||||
std::optional<std::array<float, 3>> grip_surface;
|
||||
std::vector<std::string> application;
|
||||
|
||||
@@ -81,10 +81,10 @@ static inline struct vk_bundle * get_vk(struct wivrn_comp_target * cn)
|
||||
return &cn->c->base.vk;
|
||||
}
|
||||
|
||||
static float get_default_rate(const from_headset::headset_info_packet & info)
|
||||
static float get_default_rate(const from_headset::headset_info_packet & info, const from_headset::settings_changed & settings)
|
||||
{
|
||||
if (info.preferred_refresh_rate)
|
||||
return info.preferred_refresh_rate;
|
||||
if (settings.preferred_refresh_rate)
|
||||
return settings.preferred_refresh_rate;
|
||||
return info.available_refresh_rates.back();
|
||||
}
|
||||
|
||||
@@ -147,18 +147,14 @@ static void create_encoders(wivrn_comp_target * cn)
|
||||
|
||||
std::map<int, std::vector<std::shared_ptr<video_encoder>>> thread_params;
|
||||
|
||||
uint32_t bitrate = 0;
|
||||
|
||||
for (auto [i, settings]: std::ranges::enumerate_view(cn->settings))
|
||||
{
|
||||
bitrate += settings.bitrate;
|
||||
auto & encoder = cn->encoders.emplace_back(
|
||||
video_encoder::create(*cn->wivrn_bundle, settings, i));
|
||||
desc.codec[i] = settings.codec;
|
||||
|
||||
thread_params[settings.group].emplace_back(encoder);
|
||||
}
|
||||
wivrn_ipc_socket_monado->send(from_monado::bitrate_changed{bitrate});
|
||||
|
||||
for (auto & [group, params]: thread_params)
|
||||
{
|
||||
@@ -316,7 +312,8 @@ static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t prefer
|
||||
{
|
||||
cn->settings = get_encoder_settings(
|
||||
*cn->wivrn_bundle,
|
||||
cn->cnx.get_info());
|
||||
cn->cnx.get_info(),
|
||||
*cn->cnx.get_settings());
|
||||
print_encoders(cn->settings);
|
||||
|
||||
cn->c->settings.preferred.width = cn->settings[0].width;
|
||||
@@ -792,7 +789,7 @@ static xrt_result_t comp_wivrn_request_refresh_rate(struct comp_target * ct, flo
|
||||
struct wivrn_comp_target * cn = (struct wivrn_comp_target *)ct;
|
||||
cn->requested_refresh_rate = refresh_rate_hz;
|
||||
if (refresh_rate_hz == 0.0f)
|
||||
refresh_rate_hz = get_default_rate(cn->cnx.get_info());
|
||||
refresh_rate_hz = get_default_rate(cn->cnx.get_info(), *cn->cnx.get_settings());
|
||||
|
||||
cn->cnx.send_control(to_headset::refresh_rate_change{.fps = refresh_rate_hz});
|
||||
return XRT_SUCCESS;
|
||||
@@ -838,14 +835,11 @@ void wivrn_comp_target::reset_encoders()
|
||||
|
||||
void wivrn_comp_target::set_bitrate(uint32_t bitrate_bps)
|
||||
{
|
||||
bitrate = 0;
|
||||
for (auto & encoder: encoders)
|
||||
{
|
||||
// Alpha will have multiplier of 0 and will be left unchanged.
|
||||
auto encoder_bps = (uint32_t)(bitrate_bps * encoder->bitrate_multiplier);
|
||||
U_LOG_D("Encoder %d bitrate: %d", encoder->stream_idx, encoder_bps);
|
||||
encoder->set_bitrate(encoder_bps);
|
||||
bitrate += encoder_bps;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -880,7 +874,7 @@ wivrn_comp_target::wivrn_comp_target(wivrn::wivrn_session & cnx, struct comp_com
|
||||
.request_refresh_rate = comp_wivrn_request_refresh_rate,
|
||||
.destroy = comp_wivrn_destroy,
|
||||
},
|
||||
desc{.fps = get_default_rate(cnx.get_info())},
|
||||
desc{.fps = get_default_rate(cnx.get_info(), *cnx.get_settings())},
|
||||
pacer(U_TIME_1S_IN_NS / desc.fps),
|
||||
cnx(cnx)
|
||||
{
|
||||
|
||||
@@ -93,7 +93,6 @@ struct wivrn_comp_target : public comp_target
|
||||
static std::vector<const char *> wanted_instance_extensions;
|
||||
static std::vector<const char *> wanted_device_extensions;
|
||||
|
||||
uint32_t bitrate = 0;
|
||||
std::array<encoder_settings, 3> settings;
|
||||
std::list<std::jthread> encoder_threads;
|
||||
std::vector<std::shared_ptr<video_encoder>> encoders;
|
||||
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
std::string pin;
|
||||
encryption_state state;
|
||||
|
||||
wivrn::from_headset::headset_info_packet info_packet;
|
||||
from_headset::headset_info_packet info_packet;
|
||||
|
||||
void init(std::stop_token stop_token, std::function<void()> tick = []() {});
|
||||
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
|
||||
std::optional<from_headset::packets> poll_control(int timeout);
|
||||
|
||||
wivrn::from_headset::headset_info_packet & info()
|
||||
const from_headset::headset_info_packet & info()
|
||||
{
|
||||
return info_packet;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,8 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
left_controller(XRT_DEVICE_TOUCH_CONTROLLER, 0, &hmd, this),
|
||||
right_controller(XRT_DEVICE_TOUCH_CONTROLLER, 1, &hmd, this),
|
||||
left_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 0, &hmd, this),
|
||||
right_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 1, &hmd, this)
|
||||
right_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 1, &hmd, this),
|
||||
settings(get_info().settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -430,22 +431,9 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
|
||||
U_LOG_W("unexpected headset info packet, ignoring");
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::settings_request &&)
|
||||
{
|
||||
to_headset::settings settings{};
|
||||
{
|
||||
std::lock_guard lock(comp_target_mutex);
|
||||
if (comp_target)
|
||||
settings.bitrate_bps = comp_target->bitrate;
|
||||
}
|
||||
|
||||
send_control(std::move(settings));
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::settings_changed && settings)
|
||||
{
|
||||
connection->info().preferred_refresh_rate = settings.preferred_refresh_rate;
|
||||
connection->info().minimum_refresh_rate = settings.minimum_refresh_rate;
|
||||
*this->settings.lock() = settings;
|
||||
|
||||
if (settings.bitrate_bps != 0)
|
||||
{
|
||||
@@ -453,6 +441,8 @@ void wivrn_session::operator()(from_headset::settings_changed && settings)
|
||||
if (comp_target)
|
||||
comp_target->set_bitrate(settings.bitrate_bps);
|
||||
}
|
||||
|
||||
wivrn_ipc_socket_monado->send(std::move(settings));
|
||||
}
|
||||
|
||||
static xrt_device_name get_name(interaction_profile profile)
|
||||
@@ -957,18 +947,9 @@ void wivrn_session::operator()(to_monado::disconnect &&)
|
||||
|
||||
void wivrn_session::operator()(to_monado::set_bitrate && data)
|
||||
{
|
||||
bool send_settings = false;
|
||||
{
|
||||
std::shared_lock lock(comp_target_mutex);
|
||||
if (comp_target)
|
||||
{
|
||||
comp_target->set_bitrate(data.bitrate_bps);
|
||||
send_settings = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (send_settings)
|
||||
(*this)(from_headset::settings_request{});
|
||||
std::shared_lock lock(comp_target_mutex);
|
||||
if (comp_target)
|
||||
comp_target->set_bitrate(data.bitrate_bps);
|
||||
}
|
||||
|
||||
struct refresh_rate_adjuster
|
||||
@@ -976,16 +957,20 @@ struct refresh_rate_adjuster
|
||||
std::chrono::seconds period{10};
|
||||
std::chrono::steady_clock::time_point next = std::chrono::steady_clock::now() + period;
|
||||
pacing_app_factory & pacers;
|
||||
from_headset::headset_info_packet & info;
|
||||
const from_headset::headset_info_packet & info;
|
||||
thread_safe<from_headset::settings_changed> & settings;
|
||||
float last = 0;
|
||||
|
||||
refresh_rate_adjuster(from_headset::headset_info_packet & info, pacing_app_factory & pacers) :
|
||||
refresh_rate_adjuster(const from_headset::headset_info_packet & info, thread_safe<from_headset::settings_changed> & settings, pacing_app_factory & pacers) :
|
||||
pacers(pacers),
|
||||
info(info) {}
|
||||
info(info),
|
||||
settings(settings)
|
||||
{}
|
||||
|
||||
void adjust(wivrn_connection & cnx)
|
||||
{
|
||||
if (info.preferred_refresh_rate != 0 or info.available_refresh_rates.size() < 2 or std::chrono::steady_clock::now() < next)
|
||||
auto locked = settings.lock();
|
||||
if (locked->preferred_refresh_rate != 0 or info.available_refresh_rates.size() < 2 or std::chrono::steady_clock::now() < next)
|
||||
return;
|
||||
|
||||
// Maximum refresh rate the application can reach
|
||||
@@ -995,7 +980,7 @@ struct refresh_rate_adjuster
|
||||
auto requested = info.available_refresh_rates.back();
|
||||
for (auto rate: info.available_refresh_rates)
|
||||
{
|
||||
if (rate > info.minimum_refresh_rate and rate < app_rate * (rate == last ? 1. : 0.9))
|
||||
if (rate > locked->minimum_refresh_rate and rate < app_rate * (rate == last ? 1. : 0.9))
|
||||
requested = rate;
|
||||
}
|
||||
if (requested != last)
|
||||
@@ -1015,7 +1000,7 @@ struct refresh_rate_adjuster
|
||||
|
||||
void wivrn_session::run(std::stop_token stop)
|
||||
{
|
||||
refresh_rate_adjuster refresh(connection->info(), app_pacers);
|
||||
refresh_rate_adjuster refresh(connection->info(), settings, app_pacers);
|
||||
while (not stop.stop_requested())
|
||||
{
|
||||
try
|
||||
@@ -1116,7 +1101,6 @@ void wivrn_session::reconnect()
|
||||
if (audio_handle)
|
||||
send_control(audio_handle->description());
|
||||
|
||||
(*this)(from_headset::settings_request{});
|
||||
event.state.visible = true;
|
||||
event.state.focused = true;
|
||||
result = push_event(event);
|
||||
|
||||
@@ -139,6 +139,9 @@ class wivrn_session : public xrt_system_devices
|
||||
|
||||
std::shared_ptr<audio_device> audio_handle;
|
||||
|
||||
// run-time editable settings
|
||||
thread_safe<from_headset::settings_changed> settings;
|
||||
|
||||
// when sessions shall be destroyed, key is timestap, value is client id
|
||||
thread_safe<std::map<int64_t, int32_t>> session_loss;
|
||||
|
||||
@@ -165,6 +168,11 @@ public:
|
||||
return connection->info();
|
||||
};
|
||||
|
||||
locked<from_headset::settings_changed> get_settings()
|
||||
{
|
||||
return settings.lock();
|
||||
}
|
||||
|
||||
void unset_comp_target();
|
||||
|
||||
wivrn_hmd & get_hmd()
|
||||
@@ -185,7 +193,6 @@ public:
|
||||
void operator()(from_headset::pin_check_1 &&) {}
|
||||
void operator()(from_headset::pin_check_3 &&) {}
|
||||
void operator()(from_headset::headset_info_packet &&);
|
||||
void operator()(from_headset::settings_request &&);
|
||||
void operator()(from_headset::settings_changed &&);
|
||||
void operator()(from_headset::handshake &&) {}
|
||||
void operator()(from_headset::trackings &&);
|
||||
|
||||
@@ -40,8 +40,6 @@
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
// TODO: size independent bitrate
|
||||
static const uint64_t default_bitrate = 50'000'000;
|
||||
|
||||
static const double passthrough_bitrate_factor = 0.05;
|
||||
|
||||
@@ -132,7 +130,7 @@ class prober
|
||||
.height = 600,
|
||||
.codec = codec,
|
||||
.fps = 60,
|
||||
.bitrate = default_bitrate,
|
||||
.bitrate = 50'000'000,
|
||||
.bit_depth = 8,
|
||||
},
|
||||
0);
|
||||
@@ -164,7 +162,7 @@ class prober
|
||||
.height = 600,
|
||||
.codec = codec,
|
||||
.fps = 60,
|
||||
.bitrate = default_bitrate,
|
||||
.bitrate = 50'000'000,
|
||||
.bit_depth = 8,
|
||||
},
|
||||
0);
|
||||
@@ -281,7 +279,7 @@ static uint16_t align(uint16_t value, uint16_t alignment)
|
||||
return ((value + alignment - 1) / alignment) * alignment;
|
||||
}
|
||||
|
||||
std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle & bundle, const from_headset::headset_info_packet & info)
|
||||
std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle & bundle, const from_headset::headset_info_packet & info, const from_headset::settings_changed & settings)
|
||||
{
|
||||
configuration config;
|
||||
|
||||
@@ -293,7 +291,7 @@ std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle & bundle, c
|
||||
|
||||
for (auto [src, dst]: std::ranges::zip_view(config.encoders, res))
|
||||
{
|
||||
dst.fps = info.preferred_refresh_rate;
|
||||
dst.fps = settings.preferred_refresh_rate;
|
||||
dst.options = src.options;
|
||||
dst.device = src.device;
|
||||
|
||||
@@ -329,7 +327,7 @@ std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle & bundle, c
|
||||
for (auto & i: res)
|
||||
i.bit_depth = config.bit_depth.value_or(10);
|
||||
|
||||
split_bitrate(res, config.bitrate.value_or(default_bitrate));
|
||||
split_bitrate(res, settings.bitrate_bps);
|
||||
return res;
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -46,7 +46,7 @@ struct encoder_settings
|
||||
std::optional<std::string> device;
|
||||
};
|
||||
|
||||
std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle &, const from_headset::headset_info_packet & info);
|
||||
std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle &, const from_headset::headset_info_packet & info, const from_headset::settings_changed & settings);
|
||||
|
||||
void print_encoders(const std::array<wivrn::encoder_settings, 3> & encoders);
|
||||
|
||||
|
||||
+4
-4
@@ -509,6 +509,7 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
},
|
||||
[&](const wivrn::from_headset::settings_changed & settings) {
|
||||
wivrn_server_set_preferred_refresh_rate(dbus_server, settings.preferred_refresh_rate);
|
||||
wivrn_server_set_bitrate(dbus_server, settings.bitrate_bps);
|
||||
},
|
||||
[&](const wivrn::from_headset::start_app & request) {
|
||||
const auto & apps = list_applications();
|
||||
@@ -525,9 +526,6 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
inhibitor.reset();
|
||||
wivrn_server_set_headset_connected(dbus_server, false);
|
||||
},
|
||||
[&](const from_monado::bitrate_changed & value) {
|
||||
wivrn_server_set_bitrate(dbus_server, value.bitrate_bps);
|
||||
},
|
||||
[&](const from_monado::server_error & e) {
|
||||
wivrn_server_emit_server_error(dbus_server, e.where.c_str(), e.message.c_str());
|
||||
},
|
||||
@@ -733,7 +731,9 @@ void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & inf
|
||||
g_variant_builder_unref(builder);
|
||||
wivrn_server_set_available_refresh_rates(dbus_server, value_refresh_rates);
|
||||
|
||||
wivrn_server_set_preferred_refresh_rate(dbus_server, info.preferred_refresh_rate);
|
||||
wivrn_server_set_preferred_refresh_rate(dbus_server, info.settings.preferred_refresh_rate);
|
||||
|
||||
wivrn_server_set_bitrate(dbus_server, info.settings.bitrate_bps);
|
||||
|
||||
auto speaker = info.speaker.value_or(wivrn::from_headset::headset_info_packet::audio_description{});
|
||||
wivrn_server_set_speaker_channels(dbus_server, speaker.num_channels);
|
||||
|
||||
+1
-6
@@ -42,11 +42,6 @@ struct headset_connected
|
||||
struct headset_disconnected
|
||||
{};
|
||||
|
||||
struct bitrate_changed
|
||||
{
|
||||
uint32_t bitrate_bps;
|
||||
};
|
||||
|
||||
struct server_error
|
||||
{
|
||||
std::string where;
|
||||
@@ -55,10 +50,10 @@ struct server_error
|
||||
|
||||
using packets = std::variant<
|
||||
wivrn::from_headset::headset_info_packet,
|
||||
wivrn::from_headset::settings_changed,
|
||||
wivrn::from_headset::start_app,
|
||||
headset_connected,
|
||||
headset_disconnected,
|
||||
bitrate_changed,
|
||||
server_error>;
|
||||
} // namespace from_monado
|
||||
|
||||
|
||||
@@ -286,47 +286,6 @@ void disconnect()
|
||||
call_method(get_user_bus(), "Disconnect", "");
|
||||
}
|
||||
|
||||
void set_bitrate(std::string bitrate_str)
|
||||
{
|
||||
auto suffix = bitrate_str.back();
|
||||
|
||||
uint32_t bitrate = 0;
|
||||
size_t str_len = bitrate_str.size();
|
||||
|
||||
switch (std::tolower(suffix))
|
||||
{
|
||||
case 'm':
|
||||
bitrate = 1'000'000;
|
||||
str_len = bitrate_str.size() - 1;
|
||||
break;
|
||||
case 'k':
|
||||
bitrate = 1'000;
|
||||
str_len = bitrate_str.size() - 1;
|
||||
break;
|
||||
default:
|
||||
if (std::isdigit(suffix))
|
||||
bitrate = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bitrate = bitrate * std::stoi(bitrate_str.substr(0, str_len));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
bitrate = 0;
|
||||
}
|
||||
|
||||
if (bitrate == 0)
|
||||
{
|
||||
std::cerr << "Invalid bitrate value. Valid examples: 50M, 50000K, 50000000" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
set_property(get_user_bus(), "Bitrate", "u", bitrate);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
CLI::App app;
|
||||
@@ -374,14 +333,6 @@ int main(int argc, char ** argv)
|
||||
app.add_subcommand("disconnect", "Disconnect headset")
|
||||
->callback(disconnect);
|
||||
|
||||
std::string bitrate_str;
|
||||
auto bitrate_command = app.add_subcommand("set-bitrate", "Set encoding bitrate");
|
||||
bitrate_command->add_option("BITRATE", bitrate_str, "Desired total bitrate, e.g. 100M")->required();
|
||||
|
||||
bitrate_command->callback([&]() {
|
||||
return set_bitrate(bitrate_str);
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user