mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-20 00:51:32 -08:00
change encode_10bit → bit-depth
This commit is contained in:
1 parent
ed32676299
commit
ec42db83bc
10 files changed
+66
-50
No files matched your search
@@ -22,7 +22,7 @@ Scaling is applied in a foveated fashion: the center has a 1:1 ratio and the res
|
||||
"scale": 0.5
|
||||
}
|
||||
```
|
||||
The x and y resolution of the streamed video are half the size on the headsed, reduces the required bandwidth and encoding/decoding time by about 4.
|
||||
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
|
||||
{
|
||||
@@ -36,6 +36,11 @@ Default value: `50000000` (50Mb/s)
|
||||
|
||||
Bitrate of the video, in bit/s. Split among decoders based on size and codecs.
|
||||
|
||||
## `bit-depth`
|
||||
Default value: `8` (bits)
|
||||
|
||||
Bit depth of the video. 8-bit is supported by all encoders. 10-bit is supported by `vaapi` encoders using `h265` or `av1`.
|
||||
|
||||
## `encoders`
|
||||
A list of encoders to use.
|
||||
|
||||
|
||||
@@ -200,8 +200,8 @@ configuration::configuration()
|
||||
if (auto it = json.find("use-steamvr-lh"); it != json.end())
|
||||
use_steamvr_lh = *it;
|
||||
|
||||
if (auto it = json.find("encode_10bit"); it != json.end())
|
||||
encode_10bit = *it;
|
||||
if (auto it = json.find("bit-depth"); it != json.end())
|
||||
bit_depth = *it;
|
||||
|
||||
if (auto it = json.find("tcp-only"); it != json.end())
|
||||
tcp_only = *it;
|
||||
|
||||
@@ -57,12 +57,12 @@ struct configuration
|
||||
std::vector<encoder> encoders;
|
||||
std::optional<encoder> encoder_passthrough;
|
||||
std::optional<int> bitrate;
|
||||
int bit_depth = 8;
|
||||
std::optional<std::array<double, 2>> scale;
|
||||
std::optional<std::array<float, 3>> grip_surface;
|
||||
std::vector<std::string> application;
|
||||
bool debug_gui = false;
|
||||
bool use_steamvr_lh = false;
|
||||
bool encode_10bit = false;
|
||||
bool tcp_only = false;
|
||||
service_publication publication = service_publication::avahi;
|
||||
|
||||
|
||||
@@ -409,7 +409,8 @@ static void comp_wivrn_create_images(struct comp_target * ct, const struct comp_
|
||||
|
||||
target_init_semaphores(cn);
|
||||
|
||||
if (cn->settings[0].use_10bit)
|
||||
// will fail on encoder init if bit_depth is arbitrary garbage
|
||||
if (cn->settings[0].bit_depth == 10)
|
||||
ct->format = VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16;
|
||||
else
|
||||
ct->format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -39,7 +39,7 @@ struct encoder_settings : public to_headset::video_stream_description::item
|
||||
std::map<std::string, std::string> options; // additional encoder-specific configuration
|
||||
// encoders in the same group are executed in sequence
|
||||
int group = 0;
|
||||
bool use_10bit;
|
||||
int bit_depth;
|
||||
std::optional<std::string> device;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
#include <filesystem>
|
||||
#include <libavutil/pixfmt.h>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
@@ -134,9 +135,10 @@ std::unordered_map<uint32_t, vk::Format> vulkan_drm_format_map_10bit = {
|
||||
{DRM_FORMAT_RG1616, vk::Format::eR10X6G10X6Unorm2Pack16},
|
||||
};
|
||||
|
||||
vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc, bool use_10bit)
|
||||
/// bit_depth not checked, valid values are 8 and 10
|
||||
vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc, int bit_depth)
|
||||
{
|
||||
if (use_10bit)
|
||||
if (bit_depth == 10)
|
||||
return vulkan_drm_format_map_10bit.at(drm_fourcc);
|
||||
else
|
||||
return vulkan_drm_format_map.at(drm_fourcc);
|
||||
@@ -170,11 +172,16 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
|
||||
{
|
||||
case video_codec::av1:
|
||||
case video_codec::h265:
|
||||
sw_format = settings.use_10bit ? AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
|
||||
if (settings.bit_depth == 10)
|
||||
sw_format = AV_PIX_FMT_P010;
|
||||
else if (settings.bit_depth == 8)
|
||||
sw_format = AV_PIX_FMT_NV12;
|
||||
else
|
||||
throw std::runtime_error("selected codec only supports 10-bit or 8-bit encoding");
|
||||
break;
|
||||
default:
|
||||
if (settings.use_10bit)
|
||||
throw std::runtime_error("selected codec does not support 10-bit encoding");
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("selected codec only supports 8-bit encoding");
|
||||
sw_format = AV_PIX_FMT_NV12;
|
||||
break;
|
||||
}
|
||||
@@ -226,7 +233,8 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
|
||||
av_dict_set(&opts, "rc_mode", "CBR", 0);
|
||||
break;
|
||||
case video_codec::h265:
|
||||
encoder_ctx->profile = settings.use_10bit ? FF_PROFILE_HEVC_MAIN_10 : FF_PROFILE_HEVC_MAIN;
|
||||
// bit_depth is either 8 or 10 here
|
||||
encoder_ctx->profile = settings.bit_depth == 10 ? FF_PROFILE_HEVC_MAIN_10 : FF_PROFILE_HEVC_MAIN;
|
||||
break;
|
||||
case video_codec::av1:
|
||||
encoder_ctx->profile = FF_PROFILE_AV1_MAIN;
|
||||
@@ -309,7 +317,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
|
||||
vk::StructureChain image_create_info{
|
||||
vk::ImageCreateInfo{
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = drm_to_vulkan_fmt(desc->layers[i].format, settings.use_10bit),
|
||||
.format = drm_to_vulkan_fmt(desc->layers[i].format, settings.bit_depth),
|
||||
.extent = {
|
||||
.width = uint32_t(drm_frame->width / (i == 0 ? 1 : 2)),
|
||||
.height = uint32_t(drm_frame->height / (i == 0 ? 1 : 2)),
|
||||
|
||||
@@ -144,8 +144,8 @@ video_encoder_nvenc::video_encoder_nvenc(
|
||||
fps(fps),
|
||||
bitrate(settings.bitrate)
|
||||
{
|
||||
if (settings.use_10bit)
|
||||
throw std::runtime_error("nvenc encoder does not support 10-bit encoding");
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("nvenc encoder only supports 8-bit encoding");
|
||||
|
||||
std::tie(cuda_fn, nvenc_fn, fn, cuda, session_handle) = init();
|
||||
assert(settings.width % 32 == 0);
|
||||
|
||||
@@ -192,8 +192,8 @@ std::unique_ptr<wivrn::video_encoder_vulkan_h264> wivrn::video_encoder_vulkan_h2
|
||||
vk::VideoEncodeCapabilitiesKHR,
|
||||
vk::VideoEncodeH264CapabilitiesKHR>(video_profile_info.get());
|
||||
|
||||
if (settings.use_10bit)
|
||||
throw std::runtime_error("h264 codec does not support 10-bit encoding");
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("h264 codec only supports 8-bit encoding");
|
||||
|
||||
std::unique_ptr<video_encoder_vulkan_h264> self(new video_encoder_vulkan_h264(vk, rect, video_caps, encode_caps, fps, stream_idx, settings));
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ video_encoder_x264::video_encoder_x264(
|
||||
uint8_t stream_idx) :
|
||||
video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, false)
|
||||
{
|
||||
if (settings.use_10bit)
|
||||
throw std::runtime_error("x264 encoder does not support 10-bit encoding");
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("x264 encoder only supports 8-bit encoding");
|
||||
|
||||
if (settings.codec != h264)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user