diff --git a/client/configuration.cpp b/client/configuration.cpp index 9d146200..2edcf5fe 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -20,6 +20,7 @@ #include "configuration.h" #include "application.h" #include "utils/json_string.h" +#include "wivrn_packets.h" #include #include @@ -132,6 +133,21 @@ configuration::configuration(xr::system & system) if (auto val = root["stream_scale"]; val.is_double()) stream_scale = val.get_double(); + if (auto val = root["codec"]; val.is_string()) + { + const auto codec_str = val.get_string().value(); + for (const auto & [c, name]: magic_enum::enum_entries()) + { + if (codec_str == name) + { + codec = c; + } + } + } + + if (auto val = root["bit_depth"]; val.is_uint64()) + bit_depth = val.get_uint64(); + if (auto val = root["bitrate_bps"]; val.is_number()) bitrate_bps = val.get_uint64(); @@ -194,6 +210,8 @@ configuration::configuration(xr::system & system) preferred_refresh_rate.reset(); minimum_refresh_rate.reset(); resolution_scale = 1.0; + codec.reset(); + bit_depth = 10; bitrate_bps = 50'000'000; openxr_post_processing = {}; passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; @@ -260,6 +278,9 @@ void configuration::save() json << ",\"resolution_scale\":" << resolution_scale; if (stream_scale) json << ",\"stream_scale\":" << *stream_scale; + if (codec) + json << ",\"codec\":" << json_string(magic_enum::enum_name(*codec)); + json << ",\"bit_depth\":" << (uint64_t)bit_depth; json << ",\"bitrate_bps\":" << bitrate_bps; json << ",\"openxr_post_processing\":"; write_openxr_post_processing(json, openxr_post_processing); diff --git a/client/configuration.h b/client/configuration.h index 42ac86d2..dc4069b4 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -21,6 +21,7 @@ #include "hardware.h" #include "wivrn_discover.h" +#include "wivrn_packets.h" #include #include @@ -50,7 +51,10 @@ public: std::optional preferred_refresh_rate; std::optional minimum_refresh_rate; float resolution_scale = 1.0; + std::optional codec; uint32_t bitrate_bps = 50'000'000; + uint8_t bit_depth = 10; + bool passthrough_enabled = false; bool mic_unprocessed_audio = false; diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.cpp b/client/decoder/ffmpeg/ffmpeg_decoder.cpp index 0267eee3..1320934e 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.cpp +++ b/client/decoder/ffmpeg/ffmpeg_decoder.cpp @@ -274,6 +274,7 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co void decoder::supported_codecs(std::vector & res) { + // As long as we do software decoding, prefer faster ones res.push_back(wivrn::video_codec::h264); res.push_back(wivrn::video_codec::h265); res.push_back(wivrn::video_codec::av1); diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 6e338668..82d90f81 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -1281,6 +1281,8 @@ void scenes::lobby::on_focused() vps, image_cache); + supported_codecs = wivrn::decoder::supported_codecs(); + auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); auto tm = std::localtime(&t); std::string image = tm->tm_mon == 5 ? "wivrn-pride" : "wivrn"; diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index 39b9b975..9524db45 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -134,6 +134,9 @@ class lobby : public scene_impl tab current_tab = tab::server_list; tab last_current_tab = tab::server_list; int optional_feature_index = 0; // Which step of the first run screen are we in + + std::vector supported_codecs; + ImTextureID about_picture; virtual_keyboard keyboard; diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index c83b2a57..a3abc83c 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -691,6 +691,62 @@ void scenes::lobby::gui_settings() imgui_ctx->vibrate_on_hover(); } + { + auto codec_name = [](const std::optional codec) { + if (not codec) + return _C("Codec", "Automatic"); + switch (*codec) + { + case wivrn::h264: + return _C("Codec", "H.264"); + case wivrn::h265: + return _C("Codec", "H.265"); + case wivrn::av1: + return _C("Codec", "AV1"); + case wivrn::raw: + break; + } + assert(false); + __builtin_unreachable(); + }; + + if (ImGui::BeginCombo(_S("Codec"), codec_name(config.codec).c_str())) + { + if (ImGui::Selectable(codec_name({}).c_str(), not config.codec)) + { + config.codec = std::nullopt; + config.save(); + } + for (auto codec: supported_codecs) + { + // don't show raw in GUI + if (codec == wivrn::raw) + continue; + + if (ImGui::Selectable(codec_name(codec).c_str(), config.codec == codec)) + { + config.codec = codec; + config.save(); + } + } + + ImGui::EndCombo(); + imgui_ctx->vibrate_on_hover(); + } + + if (config.codec == wivrn::video_codec::av1 or config.codec == wivrn::video_codec::h265) + { + ImGui::SameLine(0.f, 10.f); + bool ten_bit = config.bit_depth == 10; + if (ImGui::Checkbox(_S("10-bit"), &ten_bit)) + { + config.bit_depth = ten_bit ? 10 : 8; + config.save(); + } + imgui_ctx->vibrate_on_hover(); + } + } + // Bitrate { const int mb = 1'000'000; diff --git a/client/scenes/lobby_gui_customize.cpp b/client/scenes/lobby_gui_customize.cpp index cf826806..f10bb0b4 100644 --- a/client/scenes/lobby_gui_customize.cpp +++ b/client/scenes/lobby_gui_customize.cpp @@ -62,8 +62,8 @@ void scenes::lobby::save_environment_json() << ",\"size\":" << model.size; // TODO only if not the default value - ss << ",\"local_screenshot\":" << json_string(model.local_screenshot_path); - ss << ",\"local_path\":" << json_string(model.local_gltf_path); + ss << ",\"local_screenshot\":" << json_string(model.local_screenshot_path.string()); + ss << ",\"local_path\":" << json_string(model.local_gltf_path.string()); ss << "},"; } if (not empty) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index e41b14de..c9d15d2b 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -306,7 +306,22 @@ std::shared_ptr scenes::stream::create(std::unique_ptr -std::string json_string(const std::string & in); +std::string json_string(const std::string_view & in); diff --git a/server/driver/configuration.h b/server/driver/configuration.h index 7148f07a..37879ec5 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -50,7 +50,7 @@ struct configuration }; std::array encoders; // left, right, alpha - std::optional bit_depth; + std::optional bit_depth; std::optional> grip_surface; std::vector application; bool debug_gui = false; diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index bd853e70..f4a0b2ca 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -263,7 +263,7 @@ public: return {encoder_vaapi, codec}; } #endif - U_LOG_W("No suitable harware accelerated codec found"); + U_LOG_W("No suitable hardware accelerated codec found"); #if WIVRN_USE_X264 if (config.name.empty() or config.name == encoder_x264) return {encoder_x264, video_codec::h264}; @@ -317,15 +317,17 @@ std::array get_encoder_settings(wivrn_vk_bundle & bundle, c dst.height /= 2; } - if (config.bit_depth and config.bit_depth != 8 and config.bit_depth != 10) + auto bit_depth = config.bit_depth ? config.bit_depth : info.bit_depth; + + if (bit_depth and bit_depth != 8 and 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; + bit_depth = 8; for (auto & i: res) - i.bit_depth = config.bit_depth.value_or(10); + i.bit_depth = bit_depth.value_or(10); split_bitrate(res, settings.bitrate_bps); return res; diff --git a/tools/update_messages.sh b/tools/update_messages.sh index f764b215..4831f4f9 100755 --- a/tools/update_messages.sh +++ b/tools/update_messages.sh @@ -9,6 +9,7 @@ xgettext \ --c++ --from-code=UTF-8 \ --keyword=_:1,1t \ --keyword=_S:1,1t \ + --keyword=_C:1c,2,2t \ --keyword=_cS:1c,2,2t \ --keyword=_F:1,1t \ --keyword=gettext_noop:1,1t \