From ee2802b97ed8ca9df9cd787055770785f65e9401 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 3 Mar 2024 09:30:58 +0100 Subject: [PATCH] Default to split encoders for vaapi --- docs/configuration.md | 2 ++ server/encoder/encoder_settings.cpp | 32 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 51e34c25..2686f7fd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -28,6 +28,8 @@ Bitrate of the video, in bit/s. Split among decoders based on size and codecs. ## `encoders` A list of encoders to use. +Default value: single encoder if using Nvidia or software encoding. Split into 3 sequential parts (1/8th, 3/8th, 4/8th) if using vaapi. + WiVRn has the ability to split the video in blocks that are processed independently, this may use resources more effectively and reduce latency. All the provided encoders are put into groups, groups are executed concurrently and items within a group are processed sequentially. diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 8f90e08c..107c24d8 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -67,13 +67,13 @@ static void split_bitrate(std::vector &en } } -static std::vector get_encoder_default_settings(vk::PhysicalDevice physical_device, uint16_t width, uint16_t height) +static std::vector get_encoder_default_settings(vk::PhysicalDevice physical_device, uint16_t width, uint16_t height, uint64_t bitrate) { xrt::drivers::wivrn::encoder_settings settings{}; settings.width = width; settings.height = height; settings.codec = xrt::drivers::wivrn::h265; - settings.bitrate = default_bitrate; + settings.bitrate = bitrate; settings.video_height = settings.height; settings.video_width = settings.width; @@ -94,7 +94,31 @@ static std::vector get_encoder_default_se else { #ifdef WIVRN_USE_VAAPI +/* Split in 3 parts: + * +--------+--------+ + * | | | + * | | | + * +--------+ | + * | | | + * | | | + * | | | + * | | | + * | | | + * +--------+--------+ + * All 3 are encoded sequentially, so that the smallest is ready earlier. + * Decoder can start work as fast as possible, reducing idle time. + * + */ settings.encoder_name = encoder_vaapi; + settings.width = std::ceil(width * 0.5); + std::vector encoders(3, settings); + + encoders[0].height = std::ceil(height * 0.25); + encoders[1].height = height - encoders[0].height; + encoders[1].offset_y = encoders[0].height; + encoders[2].offset_x = settings.width; + split_bitrate(encoders, bitrate); + return encoders; #elif defined(WIVRN_USE_X264) settings.encoder_name = encoder_x264; settings.codec = xrt::drivers::wivrn::h264; @@ -115,7 +139,7 @@ std::vector xrt::drivers::wivrn::get_encoder_settings(vk::Phys const auto & config = configuration::read_user_configuration(); uint64_t bitrate = config.bitrate.value_or(default_bitrate); if (config.encoders.empty()) - return get_encoder_default_settings(physical_device, width, height); + return get_encoder_default_settings(physical_device, width, height, bitrate); std::vector res; int next_group = 0; for (const auto & encoder: config.encoders) @@ -143,5 +167,5 @@ std::vector xrt::drivers::wivrn::get_encoder_settings(vk::Phys { U_LOG_E("Failed to read encoder configuration: %s", e.what()); } - return get_encoder_default_settings(physical_device, width, height); + return get_encoder_default_settings(physical_device, width, height, default_bitrate); }