configure bitrate on client only
This commit is contained in:
@@ -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 &&);
|
||||
|
||||
Reference in New Issue
Block a user