In-stream GUI bitrate adjustment
This commit is contained in:
@@ -172,6 +172,8 @@ private:
|
|||||||
XrTime running_application_req = 0;
|
XrTime running_application_req = 0;
|
||||||
thread_safe<to_headset::running_applications> running_applications;
|
thread_safe<to_headset::running_applications> running_applications;
|
||||||
|
|
||||||
|
std::atomic_uint32_t bitrate = 0;
|
||||||
|
|
||||||
stream(std::string server_name, scene & parent_scene);
|
stream(std::string server_name, scene & parent_scene);
|
||||||
|
|
||||||
bool forward_hid_input(from_headset::hid::input_t);
|
bool forward_hid_input(from_headset::hid::input_t);
|
||||||
@@ -207,6 +209,7 @@ public:
|
|||||||
void operator()(to_headset::tracking_control &&);
|
void operator()(to_headset::tracking_control &&);
|
||||||
void operator()(to_headset::audio_stream_description &&);
|
void operator()(to_headset::audio_stream_description &&);
|
||||||
void operator()(to_headset::video_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::refresh_rate_change &&);
|
||||||
void operator()(to_headset::application_list &&);
|
void operator()(to_headset::application_list &&);
|
||||||
void operator()(to_headset::application_icon &&);
|
void operator()(to_headset::application_icon &&);
|
||||||
|
|||||||
@@ -383,10 +383,12 @@ void scenes::stream::gui_compact_view()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config, float predicted_display_period)
|
static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config, uint32_t bitrate, float predicted_display_period)
|
||||||
{
|
{
|
||||||
const auto & refresh_rates = session.get_refresh_rates();
|
const auto & refresh_rates = session.get_refresh_rates();
|
||||||
from_headset::settings_changed packet{};
|
from_headset::settings_changed packet{
|
||||||
|
.bitrate_bps = bitrate,
|
||||||
|
};
|
||||||
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(refresh_rates, *config.preferred_refresh_rate)))
|
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(refresh_rates, *config.preferred_refresh_rate)))
|
||||||
{
|
{
|
||||||
packet.preferred_refresh_rate = *config.preferred_refresh_rate;
|
packet.preferred_refresh_rate = *config.preferred_refresh_rate;
|
||||||
@@ -418,7 +420,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
|
|||||||
{
|
{
|
||||||
session.set_refresh_rate(0);
|
session.set_refresh_rate(0);
|
||||||
config.preferred_refresh_rate = 0;
|
config.preferred_refresh_rate = 0;
|
||||||
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
|
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemHovered())
|
if (ImGui::IsItemHovered())
|
||||||
@@ -429,7 +431,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
|
|||||||
{
|
{
|
||||||
session.set_refresh_rate(rate);
|
session.set_refresh_rate(rate);
|
||||||
config.preferred_refresh_rate = rate;
|
config.preferred_refresh_rate = rate;
|
||||||
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
|
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,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))
|
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == config.minimum_refresh_rate, ImGuiSelectableFlags_SelectOnRelease))
|
||||||
{
|
{
|
||||||
config.minimum_refresh_rate = rate;
|
config.minimum_refresh_rate = rate;
|
||||||
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
|
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -458,6 +460,13 @@ void scenes::stream::gui_settings(float predicted_display_period)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bitrate_ = bitrate.load() / 1'000'000;
|
||||||
|
if (ImGui::SliderInt(_S("Bitrate (Mbps)"), &bitrate_, 1, 200))
|
||||||
|
{
|
||||||
|
bitrate.store(bitrate_ * 1'000'000);
|
||||||
|
send_settings_changed_packet(session, network_session.get(), config, bitrate_ * 1'000'000, predicted_display_period);
|
||||||
|
}
|
||||||
|
|
||||||
if (application::get_openxr_post_processing_supported())
|
if (application::get_openxr_post_processing_supported())
|
||||||
{
|
{
|
||||||
ImGui::Text("%s", _S("OpenXR post-processing"));
|
ImGui::Text("%s", _S("OpenXR post-processing"));
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ 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)
|
void scenes::stream::operator()(to_headset::refresh_rate_change && rate)
|
||||||
{
|
{
|
||||||
session.set_refresh_rate(rate.fps);
|
session.set_refresh_rate(rate.fps);
|
||||||
|
|||||||
@@ -248,11 +248,16 @@ struct headset_info_packet
|
|||||||
std::string variant;
|
std::string variant;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct settings_request
|
||||||
|
{};
|
||||||
|
|
||||||
struct settings_changed
|
struct settings_changed
|
||||||
{
|
{
|
||||||
float preferred_refresh_rate;
|
float preferred_refresh_rate;
|
||||||
// for automatic
|
// for automatic
|
||||||
float minimum_refresh_rate;
|
float minimum_refresh_rate;
|
||||||
|
|
||||||
|
uint32_t bitrate_bps;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct handshake
|
struct handshake
|
||||||
@@ -542,6 +547,7 @@ using packets = std::variant<
|
|||||||
pin_check_1,
|
pin_check_1,
|
||||||
pin_check_3,
|
pin_check_3,
|
||||||
headset_info_packet,
|
headset_info_packet,
|
||||||
|
settings_request,
|
||||||
settings_changed,
|
settings_changed,
|
||||||
feedback,
|
feedback,
|
||||||
audio_data,
|
audio_data,
|
||||||
@@ -749,6 +755,11 @@ struct tracking_control
|
|||||||
std::array<bool, size_t(id::last) + 1> enabled;
|
std::array<bool, size_t(id::last) + 1> enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct settings
|
||||||
|
{
|
||||||
|
uint32_t bitrate_bps;
|
||||||
|
};
|
||||||
|
|
||||||
struct refresh_rate_change
|
struct refresh_rate_change
|
||||||
{
|
{
|
||||||
float fps;
|
float fps;
|
||||||
@@ -797,6 +808,7 @@ using packets = std::variant<
|
|||||||
haptics,
|
haptics,
|
||||||
timesync_query,
|
timesync_query,
|
||||||
tracking_control,
|
tracking_control,
|
||||||
|
settings,
|
||||||
refresh_rate_change,
|
refresh_rate_change,
|
||||||
application_list,
|
application_list,
|
||||||
application_icon,
|
application_icon,
|
||||||
|
|||||||
@@ -838,14 +838,16 @@ void wivrn_comp_target::reset_encoders()
|
|||||||
cnx.send_control(to_headset::video_stream_description{desc});
|
cnx.send_control(to_headset::video_stream_description{desc});
|
||||||
}
|
}
|
||||||
|
|
||||||
void wivrn_comp_target::set_bitrate(int bitrate_bps)
|
void wivrn_comp_target::set_bitrate(uint32_t bitrate_bps)
|
||||||
{
|
{
|
||||||
|
bitrate = 0;
|
||||||
for (auto & encoder: encoders)
|
for (auto & encoder: encoders)
|
||||||
{
|
{
|
||||||
// Alpha will have multiplier of 0 and will be left unchanged.
|
// Alpha will have multiplier of 0 and will be left unchanged.
|
||||||
auto encoder_bps = (int)(bitrate_bps * encoder->bitrate_multiplier);
|
auto encoder_bps = (uint32_t)(bitrate_bps * encoder->bitrate_multiplier);
|
||||||
U_LOG_D("Encoder %d bitrate: %d", encoder->stream_idx, encoder_bps);
|
U_LOG_D("Encoder %d bitrate: %d", encoder->stream_idx, encoder_bps);
|
||||||
encoder->set_bitrate(encoder_bps);
|
encoder->set_bitrate(encoder_bps);
|
||||||
|
bitrate += encoder_bps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ struct wivrn_comp_target : public comp_target
|
|||||||
static std::vector<const char *> wanted_instance_extensions;
|
static std::vector<const char *> wanted_instance_extensions;
|
||||||
static std::vector<const char *> wanted_device_extensions;
|
static std::vector<const char *> wanted_device_extensions;
|
||||||
|
|
||||||
|
uint32_t bitrate = 0;
|
||||||
std::vector<encoder_settings> settings;
|
std::vector<encoder_settings> settings;
|
||||||
std::list<std::jthread> encoder_threads;
|
std::list<std::jthread> encoder_threads;
|
||||||
std::vector<std::shared_ptr<video_encoder>> encoders;
|
std::vector<std::shared_ptr<video_encoder>> encoders;
|
||||||
@@ -107,7 +108,7 @@ struct wivrn_comp_target : public comp_target
|
|||||||
|
|
||||||
void on_feedback(const from_headset::feedback &, const clock_offset &);
|
void on_feedback(const from_headset::feedback &, const clock_offset &);
|
||||||
void reset_encoders();
|
void reset_encoders();
|
||||||
void set_bitrate(int bitrate_bps);
|
void set_bitrate(uint32_t bitrate_bps);
|
||||||
|
|
||||||
void set_refresh_rate(float);
|
void set_refresh_rate(float);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -429,10 +429,29 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
|
|||||||
U_LOG_W("unexpected headset info packet, ignoring");
|
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)
|
void wivrn_session::operator()(from_headset::settings_changed && settings)
|
||||||
{
|
{
|
||||||
connection->info().preferred_refresh_rate = settings.preferred_refresh_rate;
|
connection->info().preferred_refresh_rate = settings.preferred_refresh_rate;
|
||||||
connection->info().minimum_refresh_rate = settings.minimum_refresh_rate;
|
connection->info().minimum_refresh_rate = settings.minimum_refresh_rate;
|
||||||
|
|
||||||
|
if (settings.bitrate_bps != 0)
|
||||||
|
{
|
||||||
|
std::lock_guard lock(comp_target_mutex);
|
||||||
|
if (comp_target)
|
||||||
|
comp_target->set_bitrate(settings.bitrate_bps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static xrt_device_name get_name(interaction_profile profile)
|
static xrt_device_name get_name(interaction_profile profile)
|
||||||
@@ -937,9 +956,18 @@ void wivrn_session::operator()(to_monado::disconnect &&)
|
|||||||
|
|
||||||
void wivrn_session::operator()(to_monado::set_bitrate && data)
|
void wivrn_session::operator()(to_monado::set_bitrate && data)
|
||||||
{
|
{
|
||||||
std::shared_lock lock(comp_target_mutex);
|
bool send_settings = false;
|
||||||
if (comp_target)
|
{
|
||||||
comp_target->set_bitrate(data.bitrate_bps);
|
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{});
|
||||||
}
|
}
|
||||||
|
|
||||||
struct refresh_rate_adjuster
|
struct refresh_rate_adjuster
|
||||||
@@ -1087,6 +1115,7 @@ void wivrn_session::reconnect()
|
|||||||
if (audio_handle)
|
if (audio_handle)
|
||||||
send_control(audio_handle->description());
|
send_control(audio_handle->description());
|
||||||
|
|
||||||
|
(*this)(from_headset::settings_request{});
|
||||||
event.state.visible = true;
|
event.state.visible = true;
|
||||||
event.state.focused = true;
|
event.state.focused = true;
|
||||||
result = push_event(event);
|
result = push_event(event);
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ public:
|
|||||||
void operator()(from_headset::pin_check_1 &&) {}
|
void operator()(from_headset::pin_check_1 &&) {}
|
||||||
void operator()(from_headset::pin_check_3 &&) {}
|
void operator()(from_headset::pin_check_3 &&) {}
|
||||||
void operator()(from_headset::headset_info_packet &&);
|
void operator()(from_headset::headset_info_packet &&);
|
||||||
|
void operator()(from_headset::settings_request &&);
|
||||||
void operator()(from_headset::settings_changed &&);
|
void operator()(from_headset::settings_changed &&);
|
||||||
void operator()(from_headset::handshake &&) {}
|
void operator()(from_headset::handshake &&) {}
|
||||||
void operator()(from_headset::trackings &&);
|
void operator()(from_headset::trackings &&);
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ void video_encoder::reset()
|
|||||||
idr->reset();
|
idr->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_encoder::set_bitrate(int bitrate_bps)
|
void video_encoder::set_bitrate(uint32_t bitrate_bps)
|
||||||
{
|
{
|
||||||
pending_bitrate = bitrate_bps;
|
pending_bitrate = bitrate_bps;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <cstdint>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -104,7 +105,7 @@ private:
|
|||||||
std::shared_ptr<sender> shared_sender;
|
std::shared_ptr<sender> shared_sender;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::atomic_int pending_bitrate;
|
std::atomic_uint32_t pending_bitrate;
|
||||||
std::atomic<float> pending_framerate;
|
std::atomic<float> pending_framerate;
|
||||||
std::unique_ptr<idr_handler> idr;
|
std::unique_ptr<idr_handler> idr;
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ public:
|
|||||||
void on_feedback(const from_headset::feedback &);
|
void on_feedback(const from_headset::feedback &);
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void set_bitrate(int bitrate_bps);
|
void set_bitrate(uint32_t bitrate_bps);
|
||||||
void set_framerate(float framerate);
|
void set_framerate(float framerate);
|
||||||
|
|
||||||
void encode(wivrn_session & cnx,
|
void encode(wivrn_session & cnx,
|
||||||
|
|||||||
Reference in New Issue
Block a user