From 5ab7731be3bce13b95a0051ff4da105e63d8e96b Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 8 Dec 2025 19:13:08 +0100 Subject: [PATCH] Remove server foveation config, rework defaults --- client/scenes/stream.cpp | 8 +- common/wivrn_packets.h | 7 +- dashboard/qml/SettingsPage.qml | 65 ----- dashboard/settings.cpp | 22 -- dashboard/settings.h | 2 - dbus/io.github.wivrn.Server.xml | 3 - docs/configuration.md | 21 -- server/driver/configuration.cpp | 19 +- server/driver/configuration.h | 4 +- server/driver/wivrn_comp_target.cpp | 5 +- server/driver/wivrn_hmd.cpp | 4 +- server/encoder/encoder_settings.cpp | 425 ++++++++++++---------------- server/encoder/encoder_settings.h | 2 +- server/main.cpp | 3 - 14 files changed, 211 insertions(+), 379 deletions(-) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 0cd6a794..23523f66 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -205,8 +205,12 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsession.locate_views( XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 4b7582d6..785a4301 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -218,8 +218,10 @@ enum face_type : uint8_t struct headset_info_packet { - uint32_t recommended_eye_width; - uint32_t recommended_eye_height; + uint16_t render_eye_width; + uint16_t render_eye_height; + uint16_t stream_eye_width; + uint16_t stream_eye_height; std::vector available_refresh_rates; float preferred_refresh_rate; // for automatic @@ -240,6 +242,7 @@ struct headset_info_packet face_type face_tracking; uint32_t num_generic_trackers; std::vector supported_codecs; // from preferred to least preferred + std::optional bit_depth; std::string system_name; // Used for the application list diff --git a/dashboard/qml/SettingsPage.qml b/dashboard/qml/SettingsPage.qml index 212707ad..5b9af47f 100644 --- a/dashboard/qml/SettingsPage.qml +++ b/dashboard/qml/SettingsPage.qml @@ -23,64 +23,6 @@ Kirigami.ScrollablePage { Kirigami.FormLayout { - Controls.CheckBox { - id: manual_foveation - checked: Settings.scale != -1 - Layout.row: 0 - Layout.column: 0 - text: i18nc("automatic foveation setup", "Manual foveation") - } - - GridLayout { - columns: 5 - enabled: manual_foveation.checked - Kirigami.FormData.label: i18n("Foveation strength:") - - Controls.Slider { - id: scale_slider - Layout.row: 0 - Layout.column: 0 - Layout.columnSpan: 3 - implicitWidth: 20 * Kirigami.Units.gridUnit - from: 0 - to: 80 - stepSize: 1 - } - - Controls.Label { - Layout.row: 0 - Layout.column: 3 - text: i18n("%1 %", scale_slider.value) - } - - Kirigami.ContextualHelpButton { - Layout.row: 0 - Layout.column: 4 - toolTipText: i18n("A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games.\n\nA weaker foveation gives a uniform sharpness in the whole image.\n\nThe recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking.") - } - - Controls.Label { - Layout.row: 1 - Layout.column: 0 - text: i18nc("weaker foveation", "Weaker") - } - Item { - Layout.row: 1 - Layout.column: 1 - // spacer item - Layout.fillWidth: true - } - Controls.Label { - Layout.row: 1 - Layout.column: 2 - text: i18nc("stronger foveation", "Stronger") - } - } - - Kirigami.Separator { - Kirigami.FormData.isSection: true - } - Controls.SpinBox { id: bitrate Kirigami.FormData.label: i18n("Bitrate:") @@ -380,7 +322,6 @@ Kirigami.ScrollablePage { } function save() { - Settings.scale = manual_foveation.checked ? 1 - scale_slider.value / 100.0 : -1; let openvr = openvr_combobox.model.get(openvr_combobox.currentIndex) if (openvr.is_custom) { Settings.openvr = openvr_text.text; @@ -399,12 +340,6 @@ Kirigami.ScrollablePage { } function load() { - if (Settings.scale > 0) { - scale_slider.value = Math.round(100 - Settings.scale * 100); - } else { - scale_slider.value = 50; - } - debug_gui.checked = Settings.debugGui; steamvr_lh.checked = Settings.steamVrLh; hid_forwarding.checked = Settings.hidForwarding; diff --git a/dashboard/settings.cpp b/dashboard/settings.cpp index 9070d5c9..03dbf750 100644 --- a/dashboard/settings.cpp +++ b/dashboard/settings.cpp @@ -115,7 +115,6 @@ void Settings::emitAllChanged() codecChanged(); tenbitChanged(); bitrateChanged(); - scaleChanged(); tcpOnlyChanged(); applicationChanged(); openvrChanged(); @@ -334,26 +333,6 @@ void Settings::set_bitrate(const int & value) bitrateChanged(); } -float Settings::scale() const -{ - // Foveation - auto it = m_jsonSettings.find("scale"); - if (it != m_jsonSettings.end() and it->is_number()) - return *it; - return -1; -} - -void Settings::set_scale(const float & value) -{ - auto old = scale(); - if (value == -1) - m_jsonSettings.erase("scale"); - else - m_jsonSettings["scale"] = value; - if (old != value) - scaleChanged(); -} - QString Settings::application() const { // Automatically started application @@ -521,7 +500,6 @@ void Settings::save(wivrn_server * server) void Settings::restore_defaults() { m_jsonSettings.erase("encoder"); - m_jsonSettings.erase("scale"); m_jsonSettings.erase("bitrate"); m_jsonSettings.erase("application"); m_jsonSettings.erase("hid-forwarding"); diff --git a/dashboard/settings.h b/dashboard/settings.h index 55a6ac69..1055c8bb 100644 --- a/dashboard/settings.h +++ b/dashboard/settings.h @@ -67,7 +67,6 @@ public: 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(float scale READ scale WRITE set_scale NOTIFY scaleChanged) Q_PROPERTY(bool tcpOnly READ tcpOnly WRITE set_tcpOnly NOTIFY tcpOnlyChanged) Q_PROPERTY(QString application READ application WRITE set_application NOTIFY applicationChanged) @@ -87,7 +86,6 @@ public: SETTER_GETTER_NOTIFY(video_codec, codec) SETTER_GETTER_NOTIFY(bool, tenbit) SETTER_GETTER_NOTIFY(int, bitrate) - SETTER_GETTER_NOTIFY(float, scale) SETTER_GETTER_NOTIFY(QString, application) SETTER_GETTER_NOTIFY(bool, hidForwarding) SETTER_GETTER_NOTIFY(bool, debugGui) diff --git a/dbus/io.github.wivrn.Server.xml b/dbus/io.github.wivrn.Server.xml index d1a332ae..dee821ff 100644 --- a/dbus/io.github.wivrn.Server.xml +++ b/dbus/io.github.wivrn.Server.xml @@ -48,9 +48,6 @@ - - - diff --git a/docs/configuration.md b/docs/configuration.md index c1f9fa2b..d7da0364 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -12,27 +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. -## `scale` -Default value: `0.5`, `0.35` if headset supports eye tracking - -Controls the size of the video stream, either a number between 0 and 1 or a pair of numbers between 0 and 1. If two numbers are provided the first one is horizontal scale and the second vertical. -Scaling is applied in a foveated fashion: the center has a 1:1 ratio and the rest is scaled so that the total number of pixels matches the desired scale. - -### Examples: -```json -{ - "scale": 0.5 -} -``` -The x and y resolution of the streamed video are half the size on the headset, reduces the required bandwidth and encoding/decoding time by about 4. - -```json -{ - "scale": [0.75, 0.5] -} -``` -Scales x by a 0.75 factor, and y by a 0.5 factor. - ## `bitrate` Default value: `50000000` (50Mb/s) diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index 7e3c8d86..833899c3 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -140,7 +140,6 @@ configuration::encoder parse_encoder(const nlohmann::json & item) if (item.contains(#property)) \ e.property = item[#property]; - SET_IF(group); SET_IF(codec); if (e.codec == wivrn::video_codec(-1)) throw std::runtime_error("invalid codec value " + item["codec"].get()); @@ -155,14 +154,6 @@ configuration::configuration() { auto json = read_configuration(); - if (auto it = json.find("scale"); it != json.end()) - { - if (it->is_number()) - scale = std::array{*it, *it}; - else - scale = *it; - } - if (auto it = json.find("grip-surface"); it != json.end()) { grip_surface = *it; @@ -173,17 +164,17 @@ configuration::configuration() if (auto it = json.find("encoder"); it != json.end()) { - if (it->is_object()) - { - std::ranges::fill(encoders, parse_encoder(*it)); - } - else if (it->is_array()) + if (it->is_array()) { for (size_t i = 0; i < std::min(encoders.size(), it->size()); ++i) { encoders[i] = parse_encoder(it->at(i)); } } + else + { + std::ranges::fill(encoders, parse_encoder(*it)); + } } if (auto it = json.find("application"); it != json.end()) diff --git a/server/driver/configuration.h b/server/driver/configuration.h index df926e1c..d2309eb3 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -44,7 +44,6 @@ struct configuration struct encoder { std::string name; - std::optional group; std::optional codec; std::map options; std::optional device; @@ -52,8 +51,7 @@ struct configuration std::array encoders; // left, right, alpha std::optional bitrate; - int bit_depth = 8; - std::optional> scale; + std::optional bit_depth; std::optional> grip_surface; std::vector application; bool debug_gui = false; diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 8b49b820..968813b7 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -316,10 +316,11 @@ static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t prefer { cn->settings = get_encoder_settings( *cn->wivrn_bundle, - cn->c->settings.preferred.width, - cn->c->settings.preferred.height, cn->cnx.get_info()); print_encoders(cn->settings); + + cn->c->settings.preferred.width = cn->settings[0].width; + cn->c->settings.preferred.height = cn->settings[0].height; } catch (const std::exception & e) { diff --git a/server/driver/wivrn_hmd.cpp b/server/driver/wivrn_hmd.cpp index 5a8efdae..5cbfb4a5 100644 --- a/server/driver/wivrn_hmd.cpp +++ b/server/driver/wivrn_hmd.cpp @@ -90,9 +90,9 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx, { const auto config = configuration(); - auto eye_width = info.recommended_eye_width; + auto eye_width = info.render_eye_width; eye_width = ((eye_width + 3) / 4) * 4; - auto eye_height = info.recommended_eye_height; + auto eye_height = info.render_eye_height; eye_height = ((eye_height + 3) / 4) * 4; // Setup info. diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 5d2ce210..63609507 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -24,8 +24,6 @@ #include "video_encoder.h" #include "wivrn_packets.h" -#include -#include #include #include #include @@ -47,12 +45,6 @@ static const uint64_t default_bitrate = 50'000'000; static const double passthrough_bitrate_factor = 0.05; -static bool is_nvidia(vk::PhysicalDevice physical_device) -{ - auto props = physical_device.getProperties(); - return props.vendorID == 0x10DE; -} - static void split_bitrate(std::array & encoders, uint64_t bitrate) { double total_weight = 0; @@ -96,289 +88,248 @@ void print_encoders(const std::array & encoders) } else str << "\n"; + str << "\n\t\t" << encoder.encoder_name << " (" << magic_enum::enum_name(encoder.codec) << " " << encoder.bit_depth << "-bit)" << "\n\t\tsize: " << encoder.width << "x" << encoder.height - << "\n\t\tbitrate: " << encoder.bitrate / 1'000'000 << "Mbit/s"; + << "\n\t\tbitrate: " << int(encoder.bitrate / 100'000) / 10. << "Mbit/s"; } U_LOG_I("%s", str.str().c_str()); } -static void check_scale(std::string_view encoder_name, video_codec codec, uint16_t width, uint16_t height, std::array & scale) +static void check_video_size(std::string_view encoder_name, video_codec codec, uint16_t & width, uint16_t & height) { #if WIVRN_USE_NVENC if (encoder_name == encoder_nvenc) { auto max = video_encoder_nvenc::get_max_size(codec); - if (width * scale[0] > max[0]) - { - scale[0] = double(max[0] - 1) / width; - U_LOG_W("Image is too wide for encoder, reducing scale to %f", scale[0]); - } - if (height * scale[1] > max[1]) - { - scale[1] = double(max[1] - 1) / width; - U_LOG_W("Image is too tall for encoder, reducing scale to %f", scale[1]); - } + width = std::min(max[0], width); + height = std::min(max[1], height); } #endif } +namespace +{ +class prober +{ + wivrn_vk_bundle & vk; + const from_headset::headset_info_packet & info; + const bool nvidia; + #if WIVRN_USE_VAAPI + std::unordered_map vaapi_support; -static constexpr auto ffmpeg_version() -{ - std::array result; - std::string_view version = FFMPEG_VERSION; - for (auto & item: result) + bool check_vaapi(video_codec codec) { - auto dot = version.find("."); - auto number = version.substr(version.find_first_of("0123456789"), dot); - version = version.substr(dot + 1); - auto res = std::from_chars(number.begin(), number.end(), item); - if (res.ec != std::errc{}) - throw std::invalid_argument("Failed to parse FFMPEG_VERSION " FFMPEG_VERSION); - } - return result; -} - -static std::optional filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector & codecs, int bit_depth) -{ - video_encoder_ffmpeg::mute_logs mute; - encoder_settings s{ - .width = 800, - .height = 600, - .fps = 60, - .encoder_name = "vaapi", - .bitrate = default_bitrate, - .bit_depth = bit_depth, - }; - - for (auto codec: codecs) - { - if (codec == wivrn::video_codec::h264) - { - if (bit_depth != 8) - { - U_LOG_D("Will not use h264: %d-bit not supported", bit_depth); - continue; - } - if constexpr (ffmpeg_version()[0] < 6) - { - U_LOG_W("Skip h264 on ffmpeg < 6 due to poor performance"); - continue; - } - } + if (auto it = vaapi_support.find(codec); it != vaapi_support.end()) + return it->second; try { - s.codec = codec; - video_encoder_va test(bundle, s, 0); - return codec; + video_encoder_va test( + vk, + encoder_settings{ + .width = 800, + .height = 600, + .codec = codec, + .fps = 60, + .bitrate = default_bitrate, + .bit_depth = 8, + }, + 0); + vaapi_support[codec] = true; + return true; } - catch (...) - {} - - U_LOG_I("Video codec %s not supported", std::string(magic_enum::enum_name(codec)).c_str()); - } - - return {}; -} -#endif - -#if WIVRN_USE_NVENC -static bool probe_nvenc(wivrn_vk_bundle & bundle, int bit_depth) -{ - static bool res = [&]() { - encoder_settings s{ - .width = 800, - .height = 608, - .codec = h264, - .fps = 60, - .encoder_name = encoder_nvenc, - .bitrate = default_bitrate, - .bit_depth = bit_depth, - }; - try - { - video_encoder_nvenc test(bundle, s, 0); - return true; - } - catch (std::exception & e) - { - U_LOG_W("nvenc not supported: %s", e.what()); - return false; - } }(); - return res; -} -#endif - -static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector & headset_codecs, configuration::encoder & config, int bit_depth) -{ - if (config.name.empty()) - { - if (is_nvidia(*bundle.physical_device)) + catch (std::exception & e) { -#if WIVRN_USE_NVENC - if (probe_nvenc(bundle, bit_depth)) - config.name = encoder_nvenc; - else -#else - U_LOG_W("nvidia GPU detected, but nvenc support not compiled"); + vaapi_support[codec] = false; + U_LOG_I("vaapi not supported for %s", std::string(magic_enum::enum_name(codec)).c_str()); + return false; + } + } #endif + +#if WIVRN_USE_NVENC + std::unordered_map nvenc_support; + + bool check_nvenc(video_codec codec) + { + if (auto it = vaapi_support.find(codec); it != vaapi_support.end()) + return it->second; + try + { + video_encoder_nvenc test( + vk, + encoder_settings{ + .width = 800, + .height = 600, + .codec = codec, + .fps = 60, + .bitrate = default_bitrate, + .bit_depth = 8, + }, + 0); + nvenc_support[codec] = true; + return true; + } + catch (std::exception & e) + { + nvenc_support[codec] = false; + U_LOG_I("nvenc not supported for %s", std::string(magic_enum::enum_name(codec)).c_str()); + return false; + } + } +#endif + + static bool is_nvidia(vk::PhysicalDevice physical_device) + { + auto props = physical_device.getProperties(); + return props.vendorID == 0x10DE; + } + +#if WIVRN_USE_VULKAN_ENCODE + bool has_vk_h264() + { + if (*vk.encode_queue == VK_NULL_HANDLE) + return false; + if (not std::ranges::contains(vk.device_extensions, std::string_view(VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME))) + return false; + + auto prop = vk.physical_device.getQueueFamilyProperties2>(); + assert(vk.encode_queue_family_index < prop.size()); + return bool(prop.at(vk.encode_queue_family_index).get().videoCodecOperations & vk::VideoCodecOperationFlagBitsKHR::eEncodeH264); + } + bool has_vk_h265() + { + if (*vk.encode_queue == VK_NULL_HANDLE) + return false; + if (not std::ranges::contains(vk.device_extensions, std::string_view(VK_KHR_VIDEO_ENCODE_H265_EXTENSION_NAME))) + return false; + + auto prop = vk.physical_device.getQueueFamilyProperties2>(); + assert(vk.encode_queue_family_index < prop.size()); + return bool(prop.at(vk.encode_queue_family_index).get().videoCodecOperations & vk::VideoCodecOperationFlagBitsKHR::eEncodeH265); + } +#endif + +public: + prober(wivrn_vk_bundle & vk, const from_headset::headset_info_packet & info) : + vk(vk), info(info), nvidia(is_nvidia(vk.physical_device)) {} + + std::pair select_encoder(const configuration::encoder & config) + { + if (config.codec == video_codec::raw or config.name == encoder_raw) + return {encoder_raw, video_codec::raw}; + +#if WIVRN_USE_NVENC + if ((nvidia and config.name.empty()) or config.name == encoder_nvenc) + { + for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs) { -#if WIVRN_USE_X264 - if (bit_depth != 8) - U_LOG_E("no encoder found with %d-bit support (set 8-bit to use x264)", bit_depth); - else + if (check_nvenc(codec)) + return {encoder_nvenc, codec}; + } + } +#endif + +#if WIVRN_USE_VULKAN_ENCODE + if (config.name.empty() or config.name == encoder_vulkan) + { + for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs) + { + switch (codec) { - config.name = encoder_x264; - config.codec = h264; + case h264: + if (has_vk_h264()) + return {encoder_vulkan, video_codec::h264}; + U_LOG_I("GPU does not support H.264 Vulkan video encode"); + break; + + case h265: + if (has_vk_h265()) + return {encoder_vulkan, video_codec::h265}; + U_LOG_I("GPU does not support H.265 Vulkan video encode"); + break; + case av1: + U_LOG_D("Vulkan video encode for AV1 is not implemented in WiVRn"); + case raw: + break; } -#else - U_LOG_E("no suitable encoder available (compile with x264 or nvenc support)"); -#endif } } - else - { -#if WIVRN_USE_VAAPI - config.name = encoder_vaapi; -#elif WIVRN_USE_X264 - if (bit_depth != 8) - U_LOG_E("no encoder found with %d-bit support (set 8-bit to use x264)", bit_depth); - else - { - U_LOG_W("ffmpeg support not compiled, vaapi encoder not available"); - config.name = encoder_x264; - config.codec = h264; - } -#else - U_LOG_E("no suitable encoder available (compile with x264 or nvenc support)"); #endif - } - } #if WIVRN_USE_VAAPI - if (config.name == encoder_vaapi and not config.codec) - { - config.codec = filter_codecs_vaapi(bundle, headset_codecs, bit_depth); - if (not config.codec) + for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs) { -#if WIVRN_USE_X264 - if (bit_depth != 8) - U_LOG_E("Failed to initialize vaapi, but can't use x264 due to %d-bit encoding (set 8-bit to use x264)", bit_depth); - else - { - U_LOG_W("Failed to initialize vaapi, fallback to software encoding"); - config.name = encoder_x264; - config.codec = h264; - } -#else - U_LOG_E("Failed to initialize vaapi"); -#endif + if (check_vaapi(codec)) + return {encoder_vaapi, codec}; } - } #endif - - if (config.name == encoder_vulkan and not config.codec) - { - if (bit_depth == 10) - config.codec = h265; - else - config.codec = h264; - } - + U_LOG_W("No suitable harware accelerated codec found"); #if WIVRN_USE_X264 - if (config.name == encoder_x264) - config.codec = h264; // this will fail if 10-bit is enabled + if (config.name.empty() or config.name == encoder_x264) + return {encoder_x264, video_codec::h264}; #endif - if (config.name == encoder_raw) - config.codec = raw; - - if (not config.codec) - config.codec = bit_depth == 10 ? h265 : h264; -} - -static std::array get_encoder_default_settings(wivrn_vk_bundle & bundle, const std::vector & headset_codecs, int bit_depth) -{ - configuration::encoder base; - fill_defaults(bundle, headset_codecs, base, bit_depth); - return {base, base, base}; -} + throw std::runtime_error("Failed to find a suitable video encoder"); + } +}; +} // namespace static uint16_t align(uint16_t value, uint16_t alignment) { return ((value + alignment - 1) / alignment) * alignment; } -std::array get_encoder_settings(wivrn_vk_bundle & bundle, uint32_t & width, uint32_t & height, const from_headset::headset_info_packet & info) +std::array get_encoder_settings(wivrn_vk_bundle & bundle, const from_headset::headset_info_packet & info) { configuration config; - if (config.bit_depth != 8 && config.bit_depth != 10) - throw std::runtime_error("invalid bit-depth setting. supported values: 8, 10"); - - if (config.encoders.empty()) - config.encoders = get_encoder_default_settings(bundle, info.supported_codecs, config.bit_depth); - - uint64_t bitrate = config.bitrate.value_or(default_bitrate); - std::array default_scale; - default_scale.fill(info.eye_gaze ? 0.35 : 0.5); - auto scale = config.scale.value_or(default_scale); - - for (auto & encoder: config.encoders) - { - fill_defaults(bundle, info.supported_codecs, encoder, config.bit_depth); - assert(encoder.codec); - check_scale(encoder.name, - *encoder.codec, - std::ceil(width), - std::ceil(height), - scale); - } - - width = align(width * scale[0], 64); - height = align(height * scale[1], 64); - std::array res; + + prober prober{bundle, info}; std::unordered_map groups; int next_group = 0; - for (const auto & encoder: config.encoders) + + for (auto [src, dst]: std::ranges::zip_view(config.encoders, res)) { - if (encoder.group) - { - groups[encoder.name] = *encoder.group; - next_group = std::max(next_group, *encoder.group + 1); - } + dst.fps = info.preferred_refresh_rate; + dst.options = src.options; + dst.device = src.device; + + std::tie(dst.encoder_name, dst.codec) = prober.select_encoder(src); + + auto [it, inserted] = groups.emplace(dst.encoder_name, next_group); + dst.group = it->second; + if (inserted) + ++next_group; } - for (const auto & [i, encoder]: std::ranges::enumerate_view(config.encoders)) - { - wivrn::encoder_settings settings{}; - settings.encoder_name = encoder.name; - settings.width = align(std::ceil(width), 32); - settings.height = align(std::ceil(height), 32); - // alpha is half resolution, but left and right side by side - if (i == 2) - settings.height /= 2; - settings.codec = *encoder.codec; - settings.bit_depth = config.bit_depth; - if (encoder.group) - settings.group = *encoder.group; - else - { - auto [it, inserted] = groups.emplace(encoder.name, next_group); - settings.group = it->second; - if (inserted) - ++next_group; - } - settings.options = encoder.options; - settings.device = encoder.device; - settings.fps = info.preferred_refresh_rate; + auto width = align(info.stream_eye_width, 64); + auto height = align(info.stream_eye_height, 64); + // Ensure we don't try to encode too large images (only for left/right, ignore alpha) + for (size_t i = 0; i < 2; ++i) + check_video_size(res[i].encoder_name, res[i].codec, width, height); - res[i] = settings; + for (auto [i, dst]: std::ranges::enumerate_view(res)) + { + dst.width = width; + dst.height = height; + if (i == 2) // alpha channel + dst.height /= 2; } - split_bitrate(res, bitrate); + + if (config.bit_depth and config.bit_depth != 8 and config.bit_depth != 10) + throw std::runtime_error("invalid bit-depth setting. supported values: 8, 10"); + + if (std::ranges::contains(res, video_codec::h264, &encoder_settings::codec) or + std::ranges::contains(res, video_codec::raw, &encoder_settings::codec)) + config.bit_depth = 8; + + for (auto & i: res) + i.bit_depth = config.bit_depth.value_or(10); + + split_bitrate(res, config.bitrate.value_or(default_bitrate)); return res; } } // namespace wivrn diff --git a/server/encoder/encoder_settings.h b/server/encoder/encoder_settings.h index b54e2f34..1bdaabc9 100644 --- a/server/encoder/encoder_settings.h +++ b/server/encoder/encoder_settings.h @@ -46,7 +46,7 @@ struct encoder_settings std::optional device; }; -std::array get_encoder_settings(wivrn_vk_bundle &, uint32_t & width, uint32_t & height, const from_headset::headset_info_packet & info); +std::array get_encoder_settings(wivrn_vk_bundle &, const from_headset::headset_info_packet & info); void print_encoders(const std::array & encoders); diff --git a/server/main.cpp b/server/main.cpp index 2d17f9fa..fa33255d 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -724,9 +724,6 @@ void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & inf { GVariantBuilder * builder; - GVariant * value_eye_size = g_variant_new("(uu)", info.recommended_eye_width, info.recommended_eye_height); - wivrn_server_set_recommended_eye_size(dbus_server, value_eye_size); - builder = g_variant_builder_new(G_VARIANT_TYPE("ad")); for (double rate: info.available_refresh_rates) {