change encode_10bit → bit-depth

This commit is contained in:
galister authored and xytovl committed 2025-07-11 23:09:37 +02:00
1 parent ed32676299
commit ec42db83bc
10 files changed
+66 -50

No files matched your search

+33 -31
View File
@@ -23,6 +23,7 @@
#include "utils/wivrn_vk_bundle.h"
#include "video_encoder.h"
#include "wivrn_packets.h"
#include <cmath>
#include <magic_enum.hpp>
#include <string>
@@ -92,10 +93,8 @@ void print_encoders(const std::vector<wivrn::encoder_settings> & encoders)
U_LOG_I("Group %d", group);
}
const char * suffix_10bit = encoder.use_10bit ? " 10-bit" : "";
std::string codec(magic_enum::enum_name(encoder.codec));
U_LOG_I("\t%s (%s%s)", encoder.encoder_name.c_str(), codec.c_str(), suffix_10bit);
U_LOG_I("\t%s (%s %d-bit)", encoder.encoder_name.c_str(), codec.c_str(), encoder.bit_depth);
U_LOG_I("\tchannels: %s", std::string(magic_enum::enum_name(encoder.channels)).c_str());
U_LOG_I("\tsize:%" PRIu16 "x%" PRIu16 " offset:%" PRIu16 "x%" PRIu16,
encoder.width,
@@ -144,7 +143,7 @@ static constexpr auto ffmpeg_version()
return result;
}
static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & codecs, bool use_10bit)
static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & codecs, int bit_depth)
{
video_encoder_ffmpeg::mute_logs mute;
encoder_settings s{
@@ -157,17 +156,18 @@ static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & b
"vaapi",
default_bitrate,
};
s.bit_depth = bit_depth;
for (auto codec: codecs)
{
if (codec == wivrn::video_codec::h264)
{
U_LOG_D("Will not use h264: 10-bit not supported");
continue;
}
if constexpr (ffmpeg_version()[0] < 6)
{
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;
@@ -218,15 +218,15 @@ static bool probe_nvenc(wivrn_vk_bundle & bundle)
}
#endif
static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs, configuration::encoder & config, bool encode_10bit)
static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs, configuration::encoder & config, int bit_depth)
{
if (config.name.empty())
{
if (is_nvidia(*bundle.physical_device))
{
#if WIVRN_USE_NVENC
if (encode_10bit)
U_LOG_W("cannot use nvenc due to missing 10-bit support (disable 10-bit to use nvenc)");
if (bit_depth != 8)
U_LOG_W("nvenc encoder does not support %d-bit encoding (set 8-bit to use nvenc)", bit_depth);
else if (probe_nvenc(bundle))
config.name = encoder_nvenc;
else
@@ -235,8 +235,8 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
#endif
{
#if WIVRN_USE_X264
if (encode_10bit)
U_LOG_E("no encoder found with 10-bit support (disable 10-bit to 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
{
config.name = encoder_x264;
@@ -252,8 +252,8 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
#if WIVRN_USE_VAAPI
config.name = encoder_vaapi;
#elif WIVRN_USE_X264
if (use_10bit)
U_LOG_E("no encoder found with 10-bit support (disable 10-bit to 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");
@@ -269,12 +269,12 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
#if WIVRN_USE_VAAPI
if (config.name == encoder_vaapi and not config.codec)
{
config.codec = filter_codecs_vaapi(bundle, headset_codecs, encode_10bit);
config.codec = filter_codecs_vaapi(bundle, headset_codecs, bit_depth);
if (not config.codec)
{
#if WIVRN_USE_X264
if (encode_10bit)
U_LOG_E("Failed to initialize vaapi, but can't use x264 due to 10-bit (disable 10-bit to 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");
@@ -297,13 +297,13 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
#endif
if (not config.codec)
config.codec = encode_10bit ? h265 : h264;
config.codec = bit_depth == 10 ? h265 : h264;
}
static std::vector<configuration::encoder> get_encoder_default_settings(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs, bool encode_10bit)
static std::vector<configuration::encoder> get_encoder_default_settings(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs, int bit_depth)
{
configuration::encoder base;
fill_defaults(bundle, headset_codecs, base, encode_10bit);
fill_defaults(bundle, headset_codecs, base, bit_depth);
#ifdef WIVRN_SPLIT_ENCODERS
if (base.name != encoder_x264 and base.name != encoder_nvenc)
@@ -360,8 +360,12 @@ static uint16_t align(uint16_t value, uint16_t alignment)
std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uint32_t & width, uint32_t & height, 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.encode_10bit);
config.encoders = get_encoder_default_settings(bundle, info.supported_codecs, config.bit_depth);
if (not config.encoder_passthrough)
config.encoder_passthrough.emplace();
@@ -369,7 +373,7 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
config.encoder_passthrough->height = 1;
config.encoder_passthrough->offset_x = 0;
config.encoder_passthrough->offset_y = 0;
fill_defaults(bundle, info.supported_codecs, *config.encoder_passthrough, config.encode_10bit);
fill_defaults(bundle, info.supported_codecs, *config.encoder_passthrough, config.bit_depth);
uint64_t bitrate = config.bitrate.value_or(default_bitrate);
std::array<double, 2> default_scale;
@@ -383,11 +387,9 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
height / passthrough_subsampling,
scale);
std::optional<bool> maybe_10bit{};
for (auto & encoder: config.encoders)
{
fill_defaults(bundle, info.supported_codecs, encoder, config.encode_10bit);
fill_defaults(bundle, info.supported_codecs, encoder, config.bit_depth);
assert(encoder.codec);
check_scale(encoder.name,
*encoder.codec,
@@ -426,7 +428,7 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
settings.video_width = settings.width;
settings.video_height = settings.height;
settings.codec = *encoder.codec;
settings.use_10bit = config.encode_10bit;
settings.bit_depth = config.bit_depth;
if (encoder.group)
settings.group = *encoder.group;
else
@@ -457,7 +459,7 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
settings.video_width = settings.width;
settings.video_height = settings.height;
settings.codec = *encoder.codec;
settings.use_10bit = config.encode_10bit;
settings.bit_depth = config.bit_depth;
if (encoder.group)
settings.group = *encoder.group;
else