linux client: only show 10-bit if supported
This commit is contained in:
@@ -71,22 +71,53 @@ std::shared_ptr<wivrn::decoder> wivrn::decoder::make(
|
|||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<wivrn::video_codec> supported_codecs_()
|
static std::vector<wivrn::video_codec_capability> supported_codecs_()
|
||||||
{
|
{
|
||||||
std::vector<wivrn::video_codec> res;
|
std::vector<wivrn::video_codec> codecs;
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
wivrn::android::decoder::supported_codecs(res);
|
wivrn::android::decoder::supported_codecs(codecs);
|
||||||
#elif WIVRN_USE_V4L2
|
#elif WIVRN_USE_V4L2
|
||||||
wivrn::v4l2::decoder::supported_codecs(res);
|
wivrn::v4l2::decoder::supported_codecs(codecs);
|
||||||
#else
|
#else
|
||||||
wivrn::ffmpeg::decoder::supported_codecs(res);
|
wivrn::ffmpeg::decoder::supported_codecs(codecs);
|
||||||
#endif
|
#endif
|
||||||
res.push_back(wivrn::video_codec::raw);
|
codecs.push_back(wivrn::video_codec::raw);
|
||||||
|
|
||||||
|
std::vector<wivrn::video_codec_capability> res;
|
||||||
|
res.reserve(codecs.size());
|
||||||
|
for (auto codec: codecs)
|
||||||
|
res.push_back({.codec = codec, .supports_10bit = wivrn::decoder::supports_10bit(codec)});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<wivrn::video_codec> & wivrn::decoder::supported_codecs()
|
const std::vector<wivrn::video_codec_capability> & wivrn::decoder::supported_codecs()
|
||||||
{
|
{
|
||||||
static std::vector<wivrn::video_codec> res = supported_codecs_();
|
static std::vector<wivrn::video_codec_capability> res = supported_codecs_();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wivrn::decoder::supports_10bit(wivrn::video_codec codec)
|
||||||
|
{
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
return codec == wivrn::video_codec::h265 or codec == wivrn::video_codec::av1;
|
||||||
|
#elif WIVRN_USE_V4L2
|
||||||
|
switch (codec)
|
||||||
|
{
|
||||||
|
case wivrn::video_codec::h265: {
|
||||||
|
static const bool supported = wivrn::v4l2::decoder::supports_10bit(codec);
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
case wivrn::video_codec::av1: {
|
||||||
|
static const bool supported = wivrn::v4l2::decoder::supports_10bit(codec);
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
case wivrn::video_codec::h264:
|
||||||
|
case wivrn::video_codec::raw:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
__builtin_unreachable();
|
||||||
|
#else
|
||||||
|
// ffmpeg
|
||||||
|
return codec == wivrn::video_codec::h265 or codec == wivrn::video_codec::av1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public:
|
|||||||
|
|
||||||
virtual vk::Sampler sampler() = 0;
|
virtual vk::Sampler sampler() = 0;
|
||||||
|
|
||||||
static const std::vector<wivrn::video_codec> & supported_codecs();
|
static const std::vector<wivrn::video_codec_capability> & supported_codecs();
|
||||||
|
static bool supports_10bit(wivrn::video_codec codec);
|
||||||
};
|
};
|
||||||
} // namespace wivrn
|
} // namespace wivrn
|
||||||
|
|||||||
@@ -88,13 +88,13 @@ bool is_iris_decoder(int fd)
|
|||||||
(capabilities & V4L2_CAP_VIDEO_M2M_MPLANE) && (capabilities & V4L2_CAP_STREAMING);
|
(capabilities & V4L2_CAP_VIDEO_M2M_MPLANE) && (capabilities & V4L2_CAP_STREAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool supports_format(int fd, uint32_t pixel_format)
|
bool supports_format(int fd, v4l2_buf_type type, uint32_t pixel_format)
|
||||||
{
|
{
|
||||||
for (uint32_t index = 0;; ++index)
|
for (uint32_t index = 0;; ++index)
|
||||||
{
|
{
|
||||||
v4l2_fmtdesc fmt{};
|
v4l2_fmtdesc fmt{};
|
||||||
fmt.index = index;
|
fmt.index = index;
|
||||||
fmt.type = output_type;
|
fmt.type = type;
|
||||||
if (xioctl(fd, VIDIOC_ENUM_FMT, &fmt) < 0)
|
if (xioctl(fd, VIDIOC_ENUM_FMT, &fmt) < 0)
|
||||||
return false;
|
return false;
|
||||||
if (fmt.pixelformat == pixel_format)
|
if (fmt.pixelformat == pixel_format)
|
||||||
@@ -118,7 +118,7 @@ wivrn::fd_base find_device(wivrn::video_codec codec)
|
|||||||
|
|
||||||
const bool suitable =
|
const bool suitable =
|
||||||
is_iris_decoder(probe_fd) &&
|
is_iris_decoder(probe_fd) &&
|
||||||
supports_format(probe_fd, pixel_format);
|
supports_format(probe_fd, output_type, pixel_format);
|
||||||
|
|
||||||
close(probe_fd);
|
close(probe_fd);
|
||||||
|
|
||||||
@@ -1028,6 +1028,19 @@ bool decoder::available_for(wivrn::video_codec codec)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool decoder::supports_10bit(wivrn::video_codec codec)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto device = find_device(codec);
|
||||||
|
return supports_format(device.get_fd(), capture_type, V4L2_PIX_FMT_P010);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void decoder::supported_codecs(std::vector<wivrn::video_codec> & result)
|
void decoder::supported_codecs(std::vector<wivrn::video_codec> & result)
|
||||||
{
|
{
|
||||||
if (available_for(wivrn::video_codec::h265))
|
if (available_for(wivrn::video_codec::h265))
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool available_for(wivrn::video_codec codec);
|
static bool available_for(wivrn::video_codec codec);
|
||||||
|
static bool supports_10bit(wivrn::video_codec codec);
|
||||||
static void supported_codecs(std::vector<wivrn::video_codec> & result);
|
static void supported_codecs(std::vector<wivrn::video_codec> & result);
|
||||||
};
|
};
|
||||||
} // namespace wivrn::v4l2
|
} // namespace wivrn::v4l2
|
||||||
|
|||||||
@@ -345,9 +345,9 @@ void settings_streaming(const settings_context & ctx)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<wivrn::video_codec> codecs;
|
std::vector<wivrn::video_codec> codecs;
|
||||||
for (auto c: wivrn::decoder::supported_codecs())
|
for (auto capability: wivrn::decoder::supported_codecs())
|
||||||
if (c != wivrn::raw)
|
if (capability.codec != wivrn::raw)
|
||||||
codecs.push_back(c);
|
codecs.push_back(capability.codec);
|
||||||
|
|
||||||
list.push_back({
|
list.push_back({
|
||||||
.id = "##codec",
|
.id = "##codec",
|
||||||
@@ -370,7 +370,7 @@ void settings_streaming(const settings_context & ctx)
|
|||||||
.disabled_tooltip = disconnect_tip,
|
.disabled_tooltip = disconnect_tip,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (config.codec == wivrn::h265 or config.codec == wivrn::av1)
|
if (config.codec && wivrn::decoder::supports_10bit(*config.codec))
|
||||||
{
|
{
|
||||||
list.push_back({
|
list.push_back({
|
||||||
.id = "##ten_bit",
|
.id = "##ten_bit",
|
||||||
|
|||||||
@@ -343,7 +343,8 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
|||||||
|
|
||||||
if (config.codec)
|
if (config.codec)
|
||||||
{
|
{
|
||||||
info.supported_codecs = {*config.codec};
|
const bool supports_10bit = decoder::supports_10bit(*config.codec);
|
||||||
|
info.supported_codecs = {{.codec = *config.codec, .supports_10bit = supports_10bit}};
|
||||||
switch (*config.codec)
|
switch (*config.codec)
|
||||||
{
|
{
|
||||||
case h264:
|
case h264:
|
||||||
@@ -351,11 +352,13 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
|||||||
break;
|
break;
|
||||||
case h265:
|
case h265:
|
||||||
case av1:
|
case av1:
|
||||||
info.bit_depth = config.bit_depth;
|
info.bit_depth = supports_10bit ? config.bit_depth : 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
info.supported_codecs = decoder::supported_codecs();
|
info.supported_codecs = decoder::supported_codecs();
|
||||||
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}());
|
}());
|
||||||
|
|||||||
+10
-2
@@ -222,6 +222,14 @@ enum video_codec
|
|||||||
raw,
|
raw,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct video_codec_capability
|
||||||
|
{
|
||||||
|
video_codec codec;
|
||||||
|
bool supports_10bit;
|
||||||
|
|
||||||
|
bool operator==(const video_codec_capability &) const = default;
|
||||||
|
};
|
||||||
|
|
||||||
enum class stream_tab : uint8_t
|
enum class stream_tab : uint8_t
|
||||||
{
|
{
|
||||||
hidden,
|
hidden,
|
||||||
@@ -347,8 +355,8 @@ struct headset_info_packet
|
|||||||
body_type body_tracking;
|
body_type body_tracking;
|
||||||
// htc body only
|
// htc body only
|
||||||
uint32_t num_generic_trackers;
|
uint32_t num_generic_trackers;
|
||||||
std::vector<video_codec> supported_codecs; // from preferred to least preferred
|
std::vector<video_codec_capability> supported_codecs; // from preferred to least preferred
|
||||||
std::optional<uint8_t> bit_depth;
|
std::optional<uint8_t> bit_depth; // explicit preference
|
||||||
std::string system_name;
|
std::string system_name;
|
||||||
|
|
||||||
// Used for the application list
|
// Used for the application list
|
||||||
|
|||||||
@@ -223,10 +223,22 @@ public:
|
|||||||
if (config.codec == video_codec::raw or config.name == encoder_raw)
|
if (config.codec == video_codec::raw or config.name == encoder_raw)
|
||||||
return {encoder_raw, video_codec::raw};
|
return {encoder_raw, video_codec::raw};
|
||||||
|
|
||||||
|
std::vector<video_codec> codecs;
|
||||||
|
if (config.codec)
|
||||||
|
{
|
||||||
|
codecs.push_back(*config.codec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
codecs.reserve(info.supported_codecs.size());
|
||||||
|
for (const auto & capability: info.supported_codecs)
|
||||||
|
codecs.push_back(capability.codec);
|
||||||
|
}
|
||||||
|
|
||||||
#if WIVRN_USE_VULKAN_ENCODE
|
#if WIVRN_USE_VULKAN_ENCODE
|
||||||
if (config.name.empty() or config.name == encoder_vulkan)
|
if (config.name.empty() or config.name == encoder_vulkan)
|
||||||
{
|
{
|
||||||
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
|
for (auto codec: codecs)
|
||||||
{
|
{
|
||||||
if (has_vk(codec))
|
if (has_vk(codec))
|
||||||
return {encoder_vulkan, codec};
|
return {encoder_vulkan, codec};
|
||||||
@@ -237,7 +249,7 @@ public:
|
|||||||
#if WIVRN_USE_NVENC
|
#if WIVRN_USE_NVENC
|
||||||
if ((nvidia and config.name.empty()) or config.name == encoder_nvenc)
|
if ((nvidia and config.name.empty()) or config.name == encoder_nvenc)
|
||||||
{
|
{
|
||||||
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
|
for (auto codec: codecs)
|
||||||
{
|
{
|
||||||
if (check_nvenc(codec))
|
if (check_nvenc(codec))
|
||||||
return {encoder_nvenc, codec};
|
return {encoder_nvenc, codec};
|
||||||
@@ -248,7 +260,7 @@ public:
|
|||||||
#if WIVRN_USE_VAAPI
|
#if WIVRN_USE_VAAPI
|
||||||
if (config.name.empty() or config.name == encoder_vaapi)
|
if (config.name.empty() or config.name == encoder_vaapi)
|
||||||
{
|
{
|
||||||
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
|
for (auto codec: codecs)
|
||||||
{
|
{
|
||||||
if (check_vaapi(codec))
|
if (check_vaapi(codec))
|
||||||
return {encoder_vaapi, codec};
|
return {encoder_vaapi, codec};
|
||||||
@@ -309,11 +321,20 @@ std::array<encoder_settings, 3> get_encoder_settings(wivrn::vk_bundle & bundle,
|
|||||||
if (bit_depth and bit_depth != 8 and bit_depth != 10)
|
if (bit_depth and bit_depth != 8 and bit_depth != 10)
|
||||||
throw std::runtime_error("invalid bit-depth setting. supported values: 8, 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
|
const bool all_encoders_10bit = std::ranges::all_of(res, [&](const encoder_settings & encoder) {
|
||||||
std::ranges::contains(res, video_codec::raw, &encoder_settings::codec))
|
auto it = std::ranges::find(info.supported_codecs, encoder.codec, &video_codec_capability::codec);
|
||||||
|
return it != info.supported_codecs.end() and it->supports_10bit;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (bit_depth == 10 and not all_encoders_10bit)
|
||||||
|
{
|
||||||
|
U_LOG_I("Using 8-bit encoding due to mixed encoder support.");
|
||||||
bit_depth = 8;
|
bit_depth = 8;
|
||||||
|
}
|
||||||
else if (not bit_depth)
|
else if (not bit_depth)
|
||||||
bit_depth = 10;
|
{
|
||||||
|
bit_depth = all_encoders_10bit ? 10 : 8;
|
||||||
|
}
|
||||||
|
|
||||||
auto check_format = [&](vk::Format format) {
|
auto check_format = [&](vk::Format format) {
|
||||||
try
|
try
|
||||||
|
|||||||
+2
-2
@@ -815,9 +815,9 @@ void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & inf
|
|||||||
{h264, "h264"},
|
{h264, "h264"},
|
||||||
{h265, "h265"},
|
{h265, "h265"},
|
||||||
{av1, "av1"}};
|
{av1, "av1"}};
|
||||||
for (video_codec codec: info.supported_codecs)
|
for (const auto & capability: info.supported_codecs)
|
||||||
{
|
{
|
||||||
auto it = codec_names.find(codec);
|
auto it = codec_names.find(capability.codec);
|
||||||
if (it != codec_names.end())
|
if (it != codec_names.end())
|
||||||
codecs.push_back(it->second);
|
codecs.push_back(it->second);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user