Allow changing refresh rate during stream
This commit is contained in:
@@ -113,7 +113,7 @@ public:
|
||||
|
||||
std::optional<from_headset::packets> poll_control(int timeout);
|
||||
|
||||
const wivrn::from_headset::headset_info_packet & info() const
|
||||
wivrn::from_headset::headset_info_packet & info()
|
||||
{
|
||||
return info_packet;
|
||||
}
|
||||
|
||||
@@ -407,6 +407,12 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
|
||||
U_LOG_W("unexpected headset info packet, ignoring");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static xrt_device_name get_name(interaction_profile profile)
|
||||
{
|
||||
switch (profile)
|
||||
@@ -902,23 +908,17 @@ struct refresh_rate_adjuster
|
||||
{
|
||||
std::chrono::seconds period{10};
|
||||
std::chrono::steady_clock::time_point next = std::chrono::steady_clock::now() + period;
|
||||
bool enabled;
|
||||
pacing_app_factory & pacers;
|
||||
const from_headset::headset_info_packet & info;
|
||||
from_headset::headset_info_packet & info;
|
||||
float last = 0;
|
||||
|
||||
refresh_rate_adjuster(const from_headset::headset_info_packet & info, pacing_app_factory & pacers) :
|
||||
enabled(info.preferred_refresh_rate == 0 and info.available_refresh_rates.size() > 1),
|
||||
refresh_rate_adjuster(from_headset::headset_info_packet & info, pacing_app_factory & pacers) :
|
||||
pacers(pacers),
|
||||
info(info)
|
||||
{
|
||||
if (enabled)
|
||||
U_LOG_I("Automatic refresh rate adjustment enabled");
|
||||
}
|
||||
info(info) {}
|
||||
|
||||
void adjust(wivrn_connection & cnx)
|
||||
{
|
||||
if (not enabled or std::chrono::steady_clock::now() < next)
|
||||
if (info.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
|
||||
@@ -928,7 +928,7 @@ struct refresh_rate_adjuster
|
||||
auto requested = info.available_refresh_rates.back();
|
||||
for (auto rate: info.available_refresh_rates)
|
||||
{
|
||||
if (rate < app_rate * (rate == last ? 1. : 0.9))
|
||||
if (rate > info.minimum_refresh_rate and rate < app_rate * (rate == last ? 1. : 0.9))
|
||||
requested = rate;
|
||||
}
|
||||
if (requested != last)
|
||||
@@ -948,7 +948,7 @@ struct refresh_rate_adjuster
|
||||
|
||||
void wivrn_session::run(std::stop_token stop)
|
||||
{
|
||||
refresh_rate_adjuster refresh(get_info(), app_pacers);
|
||||
refresh_rate_adjuster refresh(connection->info(), app_pacers);
|
||||
while (not stop.stop_requested())
|
||||
{
|
||||
try
|
||||
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
|
||||
clock_offset get_offset();
|
||||
bool connected();
|
||||
const from_headset::headset_info_packet & get_info()
|
||||
const from_headset::headset_info_packet & get_info() const
|
||||
{
|
||||
return connection->info();
|
||||
};
|
||||
@@ -184,6 +184,7 @@ 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_changed &&);
|
||||
void operator()(from_headset::handshake &&) {}
|
||||
void operator()(from_headset::trackings &&);
|
||||
void operator()(const from_headset::tracking &);
|
||||
|
||||
+4
-1
@@ -512,10 +512,13 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
{
|
||||
std::visit(utils::overloaded{
|
||||
[&](const wivrn::from_headset::headset_info_packet & info) {
|
||||
on_headset_info_packet(std::get<wivrn::from_headset::headset_info_packet>(*packet));
|
||||
on_headset_info_packet(info);
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
},
|
||||
[&](const wivrn::from_headset::settings_changed & settings) {
|
||||
wivrn_server_set_preferred_refresh_rate(dbus_server, settings.preferred_refresh_rate);
|
||||
},
|
||||
[&](const wivrn::from_headset::start_app & request) {
|
||||
const auto & apps = list_applications();
|
||||
if (auto it = apps.find(request.app_id); it != apps.end())
|
||||
|
||||
Reference in New Issue
Block a user