Add codec and 10-bit config in headset

This commit is contained in:
Sapphire
2025-12-11 13:42:16 +01:00
committed by Patrick Nicolas
parent 9b4a26b5a8
commit 6f32f049d7
14 changed files with 117 additions and 11 deletions
+21
View File
@@ -20,6 +20,7 @@
#include "configuration.h"
#include "application.h"
#include "utils/json_string.h"
#include "wivrn_packets.h"
#include <fstream>
#include <magic_enum.hpp>
@@ -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<wivrn::video_codec>())
{
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);
+4
View File
@@ -21,6 +21,7 @@
#include "hardware.h"
#include "wivrn_discover.h"
#include "wivrn_packets.h"
#include <map>
#include <mutex>
@@ -50,7 +51,10 @@ public:
std::optional<float> preferred_refresh_rate;
std::optional<float> minimum_refresh_rate;
float resolution_scale = 1.0;
std::optional<wivrn::video_codec> codec;
uint32_t bitrate_bps = 50'000'000;
uint8_t bit_depth = 10;
bool passthrough_enabled = false;
bool mic_unprocessed_audio = false;
+1
View File
@@ -274,6 +274,7 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co
void decoder::supported_codecs(std::vector<wivrn::video_codec> & 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);
+2
View File
@@ -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";
+3
View File
@@ -134,6 +134,9 @@ class lobby : public scene_impl<lobby>
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<wivrn::video_codec> supported_codecs;
ImTextureID about_picture;
virtual_keyboard keyboard;
+56
View File
@@ -691,6 +691,62 @@ void scenes::lobby::gui_settings()
imgui_ctx->vibrate_on_hover();
}
{
auto codec_name = [](const std::optional<wivrn::video_codec> 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;
+2 -2
View File
@@ -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)
+16 -1
View File
@@ -306,7 +306,22 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
if (not(config.check_feature(feature::microphone)))
info.microphone = {};
info.supported_codecs = decoder::supported_codecs();
if (config.codec)
{
info.supported_codecs = {*config.codec};
switch (*config.codec)
{
case h264:
case raw:
break;
case h265:
case av1:
info.bit_depth = config.bit_depth;
}
}
else
info.supported_codecs = decoder::supported_codecs();
return info;
}());
+2 -1
View File
@@ -24,7 +24,8 @@
#define _(x) boost::locale::gettext(x)
#define _F(x) fmt::runtime(boost::locale::gettext(x))
#define _S(x) boost::locale::gettext(x).c_str()
#define _cS(c, x) boost::locale::pgettext(c, x).c_str()
#define _C(c, x) boost::locale::pgettext(c, x)
#define _cS(c, x) _C(c, x).c_str()
#define gettext_noop(x) x
#define gettext_noop_context(c, x) x
+1 -1
View File
@@ -19,7 +19,7 @@
#include "json_string.h"
std::string json_string(const std::string & in)
std::string json_string(const std::string_view & in)
{
std::string out;
out.reserve(in.size() + 2);
+1 -1
View File
@@ -21,4 +21,4 @@
#include <string>
std::string json_string(const std::string & in);
std::string json_string(const std::string_view & in);
+1 -1
View File
@@ -50,7 +50,7 @@ struct configuration
};
std::array<encoder, 3> encoders; // left, right, alpha
std::optional<int> bit_depth;
std::optional<uint8_t> bit_depth;
std::optional<std::array<float, 3>> grip_surface;
std::vector<std::string> application;
bool debug_gui = false;
+6 -4
View File
@@ -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<encoder_settings, 3> 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;
+1
View File
@@ -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 \