Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Vindicus999
2025-12-12 01:56:25 +00:00
74 changed files with 1206 additions and 2174 deletions
+46
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>
@@ -129,6 +130,27 @@ configuration::configuration(xr::system & system)
if (auto val = root["resolution_scale"]; val.is_double())
resolution_scale = val.get_double();
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();
if (auto val = root["enable_stream_gui"]; val.is_bool())
enable_stream_gui = val.get_bool();
@@ -188,8 +210,12 @@ 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;
stream_scale.reset();
}
}
@@ -250,6 +276,12 @@ void configuration::save()
if (minimum_refresh_rate)
json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate;
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);
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
@@ -269,3 +301,17 @@ void configuration::save()
json << ",\"high_power_mode\":" << std::boolalpha << high_power_mode;
json << "}";
}
void configuration::set_stream_scale(float val)
{
stream_scale = val;
}
float configuration::get_stream_scale() const
{
if (stream_scale)
return *stream_scale;
if (check_feature(feature::eye_gaze))
return 0.3;
return 0.5;
}
+9
View File
@@ -21,6 +21,7 @@
#include "hardware.h"
#include "wivrn_discover.h"
#include "wivrn_packets.h"
#include <map>
#include <mutex>
@@ -50,6 +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;
@@ -86,6 +91,7 @@ public:
private:
mutable std::mutex mutex;
std::map<feature, bool> features;
std::optional<float> stream_scale;
void parse_openxr_post_processing_options(simdjson::simdjson_result<simdjson::dom::object> root);
@@ -94,4 +100,7 @@ public:
configuration() = default;
void save();
void set_stream_scale(float);
float get_stream_scale() const;
};
+24 -19
View File
@@ -42,6 +42,7 @@ struct wivrn::android::decoder::mapped_hardware_buffer
{
vk::raii::DeviceMemory memory = nullptr;
vk::raii::Image vimage = nullptr;
vk::Extent2D extent{};
vk::raii::ImageView image_view = nullptr;
vk::ImageLayout layout = vk::ImageLayout::eUndefined;
};
@@ -85,11 +86,12 @@ struct android_blit_handle : public decoder::blit_handle
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
vk::ImageView image_view,
vk::Image image,
vk::Extent2D extent,
vk::ImageLayout & current_layout,
decltype(vk_data) vk_data,
decltype(image_reader) image_reader,
decltype(aimage) aimage) :
decoder::blit_handle(feedback, view_info, image_view, image, current_layout),
decoder::blit_handle(feedback, view_info, image_view, image, extent, current_layout),
vk_data(vk_data),
image_reader(image_reader),
aimage(std::move(aimage)) {}
@@ -103,19 +105,21 @@ namespace wivrn::android
decoder::decoder(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream> weak_scene,
shard_accumulator * accumulator) :
wivrn::decoder(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator)
stream_index(stream_index), device(device), weak_scene(weak_scene), accumulator(accumulator)
{
spdlog::info("hbm_mutex.native_handle() = {}", (void *)hbm_mutex.native_handle());
auto width = description.width;
auto height = description.height / (stream_index == 2 ? 2 : 1);
AImageReader * ir;
check(AImageReader_newWithUsage(
description.video_width,
description.video_height,
width,
height,
AIMAGE_FORMAT_PRIVATE,
AHARDWAREBUFFER_USAGE_CPU_READ_NEVER | AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,
scenes::stream::image_buffer_size + 4 /* maxImages */,
@@ -131,18 +135,18 @@ decoder::decoder(
"vkGetAndroidHardwareBufferPropertiesANDROID");
{
AMediaFormat_ptr format(AMediaFormat_new());
AMediaFormat_setString(format.get(), AMEDIAFORMAT_KEY_MIME, mime(description.codec));
AMediaFormat_setString(format.get(), AMEDIAFORMAT_KEY_MIME, mime(description.codec[stream_index]));
// AMediaFormat_setInt32(format.get(), "vendor.qti-ext-dec-low-latency.enable", 1); // Qualcomm low
// latency mode
AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_WIDTH, description.video_width);
AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_HEIGHT, description.video_height);
AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_OPERATING_RATE, std::ceil(fps));
AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_WIDTH, width);
AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_HEIGHT, height);
AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_OPERATING_RATE, std::ceil(description.fps));
AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_PRIORITY, 0);
media_codec.reset(AMediaCodec_createDecoderByType(mime(description.codec)));
media_codec.reset(AMediaCodec_createDecoderByType(mime(description.codec[stream_index])));
if (not media_codec)
throw std::runtime_error(std::string("Cannot create decoder for MIME type ") + mime(description.codec));
throw std::runtime_error(std::string("Cannot create decoder for MIME type ") + mime(description.codec[stream_index]));
char * codec_name;
check(AMediaCodec_getName(media_codec.get(), &codec_name), "AMediaCodec_getName");
@@ -308,6 +312,7 @@ void decoder::on_image_available(AImageReader * reader)
info->view_info,
*vk_data->image_view,
*vk_data->vimage,
vk_data->extent,
vk_data->layout,
std::move(vk_data),
image_reader,
@@ -361,11 +366,8 @@ void decoder::create_sampler(const AHardwareBuffer_Desc & buffer_desc, vk::Andro
};
// suggested values from decoder don't actually read the metadata, so it's garbage
if (description.range)
ycbcr_create_info.get<vk::SamplerYcbcrConversionCreateInfo>().ycbcrRange = vk::SamplerYcbcrRange(*description.range);
if (description.color_model)
ycbcr_create_info.get<vk::SamplerYcbcrConversionCreateInfo>().ycbcrModel = vk::SamplerYcbcrModelConversion(*description.color_model);
ycbcr_create_info.get<vk::SamplerYcbcrConversionCreateInfo>().ycbcrRange = vk::SamplerYcbcrRange::eItuFull;
ycbcr_create_info.get<vk::SamplerYcbcrConversionCreateInfo>().ycbcrModel = vk::SamplerYcbcrModelConversion::eYcbcr709;
ycbcr_conversion = vk::raii::SamplerYcbcrConversion(device, ycbcr_create_info.get<vk::SamplerYcbcrConversionCreateInfo>());
@@ -411,7 +413,6 @@ std::shared_ptr<decoder::mapped_hardware_buffer> decoder::map_hardware_buffer(AI
if (!*ycbcr_sampler || memcmp(&ahb_format, &format_properties, sizeof(format_properties)))
{
memcpy(&ahb_format, &format_properties, sizeof(format_properties));
extent_ = {buffer_desc.width, buffer_desc.height};
spdlog::info("decoded image size: {}x{}", buffer_desc.width, buffer_desc.height);
create_sampler(buffer_desc, ahb_format);
hardware_buffer_map.clear();
@@ -490,6 +491,10 @@ std::shared_ptr<decoder::mapped_hardware_buffer> decoder::map_hardware_buffer(AI
handle->vimage = std::move(vimage);
handle->image_view = std::move(image_view);
handle->memory = std::move(memory);
handle->extent = vk::Extent2D{
.width = buffer_desc.width,
.height = buffer_desc.height,
};
hardware_buffer_map[hardware_buffer] = handle;
return handle;
@@ -569,8 +574,8 @@ void decoder::supported_codecs(std::vector<wivrn::video_codec> & result)
// In order or preference, from preferred to least preferred
for (auto codec: {
wivrn::video_codec::av1,
wivrn::video_codec::h264,
wivrn::video_codec::h265,
wivrn::video_codec::h264,
})
{
AMediaCodec_ptr media_codec(AMediaCodec_createDecoderByType(mime(codec)));
+1 -3
View File
@@ -67,7 +67,6 @@ public:
private:
uint8_t stream_index;
float fps;
vk::raii::Device & device;
@@ -122,8 +121,7 @@ private:
public:
decoder(vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator);
+2 -4
View File
@@ -31,13 +31,12 @@ std::shared_ptr<wivrn::decoder> wivrn::decoder::make(
vk::raii::Device & device,
vk::raii::PhysicalDevice & phys_dev,
uint32_t vk_queue_family_index,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * acc)
{
switch (description.codec)
switch (description.codec[stream_index])
{
case h264:
case h265:
@@ -47,7 +46,6 @@ std::shared_ptr<wivrn::decoder> wivrn::decoder::make(
device,
phys_dev,
description,
fps,
stream_index,
scene,
acc);
+2 -13
View File
@@ -42,25 +42,18 @@ public:
wivrn::to_headset::video_stream_data_shard::view_info_t view_info;
vk::ImageView image_view = nullptr;
vk::Image image = nullptr;
vk::Extent2D extent{};
vk::ImageLayout & current_layout;
vk::Semaphore semaphore = nullptr;
uint64_t * semaphore_val = nullptr;
};
const wivrn::to_headset::video_stream_description::item description;
protected:
decoder(const wivrn::to_headset::video_stream_description::item & description) :
description(description) {}
vk::Extent2D extent_; // Must be populated when sampler is set
public:
static std::shared_ptr<decoder> make(
vk::raii::Device &,
vk::raii::PhysicalDevice &,
uint32_t vk_queue_family_index,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream>,
shard_accumulator *);
@@ -72,10 +65,6 @@ public:
const to_headset::video_stream_data_shard::view_info_t & view_info) = 0;
virtual vk::Sampler sampler() = 0;
const vk::Extent2D extent()
{
return extent_;
}
static std::vector<wivrn::video_codec> supported_codecs();
};
+14 -8
View File
@@ -73,6 +73,7 @@ struct decoder::ffmpeg_blit_handle : public wivrn::decoder::blit_handle
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
vk::ImageView image_view,
vk::Image image,
vk::Extent2D extent,
vk::ImageLayout & current_layout,
int image_index,
wivrn::ffmpeg::decoder * self) :
@@ -81,6 +82,7 @@ struct decoder::ffmpeg_blit_handle : public wivrn::decoder::blit_handle
view_info,
image_view,
image,
extent,
current_layout,
},
image_index(image_index),
@@ -100,16 +102,19 @@ struct decoder::ffmpeg_blit_handle : public wivrn::decoder::blit_handle
decoder::decoder(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
const wivrn::to_headset::video_stream_description::item & description,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator) :
wivrn::decoder(description),
device(device),
codec(nullptr, free_codec_context),
sws(nullptr, sws_freeContext),
weak_scene(scene),
accumulator(accumulator)
accumulator(accumulator),
extent{
.width = description.width,
.height = description.height / (stream_index == 2 ? 2u : 1u),
}
{
free_images.resize(image_count);
@@ -121,8 +126,8 @@ decoder::decoder(
.imageType = vk::ImageType::e2D,
.format = vk::Format::eA8B8G8R8SrgbPack32,
.extent = {
.width = description.width,
.height = description.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
},
.mipLevels = 1,
@@ -139,7 +144,6 @@ decoder::decoder(
decoded_images[i].image = image_allocation(device, image_info, alloc_info);
decoded_images[i].image.map();
extent_ = vk::Extent2D{description.width, description.height};
vk::ImageSubresource resource;
resource.aspectMask = vk::ImageAspectFlagBits::eColor;
@@ -164,7 +168,7 @@ decoder::decoder(
decoded_images[i].current_layout = vk::ImageLayout::eUndefined;
}
auto avcodec = avcodec_find_decoder(codec_id(description.codec));
auto avcodec = avcodec_find_decoder(codec_id(description.codec[stream_index]));
if (avcodec == nullptr)
{
throw std::runtime_error{"avcodec_find_decoder failed"};
@@ -233,7 +237,7 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co
if (!sws)
{
sws.reset(sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, description.width, description.height, AV_PIX_FMT_RGB0, SWS_BILINEAR, nullptr, nullptr, nullptr));
sws.reset(sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, extent.width, extent.height, AV_PIX_FMT_RGB0, SWS_BILINEAR, nullptr, nullptr, nullptr));
}
std::unique_lock lock(mutex);
@@ -259,6 +263,7 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co
view_info,
*decoded_images[index].image_view,
decoded_images[index].image,
extent,
decoded_images[index].current_layout,
index,
this);
@@ -269,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 -1
View File
@@ -73,13 +73,14 @@ private:
uint64_t frame_index;
std::weak_ptr<scenes::stream> weak_scene;
shard_accumulator * accumulator;
const vk::Extent2D extent;
std::mutex mutex;
public:
decoder(vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
const wivrn::to_headset::video_stream_description::item & description,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator);
+34 -39
View File
@@ -32,11 +32,12 @@ struct raw_blit_handle : public wivrn::decoder::blit_handle
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
vk::ImageView image_view,
vk::Image image,
vk::Extent2D extent,
vk::ImageLayout & current_layout,
vk::Semaphore semaphore,
uint64_t & semaphore_val,
std::atomic_bool & free) :
wivrn::decoder::blit_handle{feedback, view_info, image_view, image, current_layout, semaphore, &semaphore_val},
wivrn::decoder::blit_handle{feedback, view_info, image_view, image, extent, current_layout, semaphore, &semaphore_val},
free(free) {}
~raw_blit_handle()
{
@@ -46,8 +47,7 @@ struct raw_blit_handle : public wivrn::decoder::blit_handle
vk::raii::Sampler make_sampler(
vk::raii::Device & device,
vk::raii::SamplerYcbcrConversion & ycbcr_conversion,
to_headset::video_stream_description::channels_t channels)
vk::SamplerYcbcrConversion ycbcr_conversion)
{
vk::StructureChain info{
vk::SamplerCreateInfo{
@@ -60,17 +60,11 @@ vk::raii::Sampler make_sampler(
.maxAnisotropy = 1,
},
vk::SamplerYcbcrConversionInfo{
.conversion = *ycbcr_conversion,
.conversion = ycbcr_conversion,
},
};
switch (channels)
{
case wivrn::to_headset::video_stream_description::channels_t::colour:
break;
case wivrn::to_headset::video_stream_description::channels_t::alpha:
info.unlink<vk::SamplerYcbcrConversionInfo>();
break;
}
if (ycbcr_conversion == VK_NULL_HANDLE)
info.unlink<vk::SamplerYcbcrConversionInfo>();
return vk::raii::Sampler(device, info.get());
}
} // namespace
@@ -81,20 +75,18 @@ raw_decoder::raw_decoder(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
uint32_t vk_queue_family_index,
const wivrn::to_headset::video_stream_description::item & description,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator) :
decoder(description),
device(device),
ycbcr_conversion(device,
{
.format = vk::Format::eG8B8R82Plane420Unorm,
.ycbcrModel = vk::SamplerYcbcrModelConversion(description.color_model.value_or(VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709)),
.ycbcrRange = vk::SamplerYcbcrRange(description.range.value_or(VK_SAMPLER_YCBCR_RANGE_ITU_FULL)),
.chromaFilter = vk::Filter::eNearest,
}),
sampler_(make_sampler(device, ycbcr_conversion, description.channels)),
ycbcr_conversion(stream_index == 2 ? nullptr : vk::raii::SamplerYcbcrConversion(device, {
.format = vk::Format::eG8B8R82Plane420Unorm,
.ycbcrModel = vk::SamplerYcbcrModelConversion::eYcbcr709,
.ycbcrRange = vk::SamplerYcbcrRange::eItuFull,
.chromaFilter = vk::Filter::eNearest,
})),
sampler_(make_sampler(device, *ycbcr_conversion)),
command_pool(device, vk::CommandPoolCreateInfo{
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
.queueFamilyIndex = vk_queue_family_index,
@@ -105,22 +97,24 @@ raw_decoder::raw_decoder(
})[0]
.release()),
fence(device, vk::FenceCreateInfo{.flags = vk::FenceCreateFlagBits::eSignaled}),
stream_index(stream_index),
extent{
.width = description.width,
.height = description.height / (stream_index == 2 ? 2u : 1u),
},
weak_scene(scene),
accumulator(accumulator)
{
extent_ = vk::Extent2D{
.width = description.width,
.height = description.height,
};
vk::DeviceSize buffer_size = description.width * description.height;
vk::DeviceSize buffer_size = extent.width * extent.height;
vk::Format format{};
switch (description.channels)
switch (stream_index)
{
case to_headset::video_stream_description::channels_t::colour:
buffer_size += (description.width * description.height) / 2;
case 0: // colour left
case 1: // colour right
buffer_size += buffer_size / 2;
format = vk::Format::eG8B8R82Plane420Unorm;
break;
case to_headset::video_stream_description::channels_t::alpha:
case 2: // alpha (monochrome)
format = vk::Format::eR8Unorm;
break;
}
@@ -148,8 +142,8 @@ raw_decoder::raw_decoder(
.imageType = vk::ImageType::e2D,
.format = format,
.extent = {
.width = description.width,
.height = description.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
},
.mipLevels = 1,
@@ -220,6 +214,7 @@ void raw_decoder::frame_completed(
view_info,
*item->view_full,
item->image,
extent,
item->current_layout,
*item->semaphore,
item->semaphore_val,
@@ -263,20 +258,20 @@ void raw_decoder::frame_completed(
.layerCount = 1,
},
.imageExtent = {
.width = description.width,
.height = description.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
},
},
vk::BufferImageCopy{
.bufferOffset = vk::DeviceSize(description.width * description.height),
.bufferOffset = vk::DeviceSize(extent.width * extent.height),
.imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.layerCount = 1,
},
.imageExtent = {
.width = description.width / 2u,
.height = description.height / 2u,
.width = extent.width / 2u,
.height = extent.height / 2u,
.depth = 1,
},
},
@@ -286,7 +281,7 @@ void raw_decoder::frame_completed(
input[0],
item->image,
item->current_layout,
description.channels == to_headset::video_stream_description::channels_t::colour ? 2 : 1,
stream_index ? 2 : 1,
regions.data());
vk::ImageMemoryBarrier barrier{
+4 -10
View File
@@ -48,6 +48,9 @@ private:
vk::CommandBuffer cmd;
vk::raii::Fence fence;
uint8_t stream_index;
const vk::Extent2D extent;
std::array<image, image_count> image_pool;
std::weak_ptr<scenes::stream> weak_scene;
@@ -57,13 +60,12 @@ private:
std::array<buffer_allocation, 2> input;
uint8_t * input_pos;
from_headset::feedback feedback;
to_headset::video_stream_data_shard::view_info_t view_info;
public:
raw_decoder(vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
uint32_t vk_queue_family_index,
const wivrn::to_headset::video_stream_description::item & description,
const wivrn::to_headset::video_stream_description & description,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator);
@@ -79,14 +81,6 @@ public:
return *sampler_;
}
vk::Extent2D image_size()
{
return {
description.width,
description.height,
};
}
static std::vector<wivrn::video_codec> supported_codecs();
private:
+3 -3
View File
@@ -55,7 +55,7 @@ static bool is_complete(const shard_set & shards)
const auto & frame = shards.data;
if (frame.empty())
return false;
if (not(frame.back() and frame.back()->flags & video_stream_data_shard::end_of_frame))
if (not(frame.back() and frame.back()->timing_info))
return false;
for (const auto & shard: frame)
if (not shard)
@@ -99,7 +99,7 @@ static void debug_why_not_sent(const shard_set & shards)
++missing;
}
bool end = frame.back() and frame.back()->flags & video_stream_data_shard::end_of_frame;
bool end = frame.back() and frame.back()->timing_info;
spdlog::info("frame {} was not sent with {} data shards, {}{} missing", frame_idx, data, end ? "" : "at least ", missing);
}
@@ -185,7 +185,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
for (size_t idx = shard_idx; idx < last_idx; ++idx)
payload.emplace_back(data_shards[idx]->payload);
bool frame_complete = last_idx == data_shards.size() and data_shards.back()->flags & video_stream_data_shard::end_of_frame;
bool frame_complete = last_idx == data_shards.size() and data_shards.back()->timing_info;
decoder_->push_data(payload, data_shards[shard_idx]->frame_idx, not frame_complete);
if (not frame_complete)
+2 -13
View File
@@ -81,11 +81,10 @@ public:
vk::raii::PhysicalDevice & physical_device,
xr::instance & instance,
uint32_t vk_queue_family_index,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
const wivrn::to_headset::video_stream_description & description,
std::weak_ptr<scenes::stream> scene,
uint8_t stream_index) :
decoder_(decoder::make(device, physical_device, vk_queue_family_index, description, fps, stream_index, scene, this)),
decoder_(decoder::make(device, physical_device, vk_queue_family_index, description, stream_index, scene, this)),
current(stream_index),
next(stream_index),
weak_scene(scene),
@@ -96,21 +95,11 @@ public:
void push_shard(wivrn::to_headset::video_stream_data_shard &&);
auto & desc() const
{
return decoder_->description;
}
vk::Sampler sampler()
{
return decoder_->sampler();
}
const vk::Extent2D extent()
{
return decoder_->extent();
}
using blit_handle = decoder::blit_handle;
private:
-364
View File
@@ -1,364 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "blitter.h"
#include "application.h"
#include "utils/ranges.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "vk/specialization_constants.h"
#include <format>
#include <spdlog/spdlog.h>
namespace wivrn
{
static const uint32_t num_views = 2;
blitter::blitter(vk::raii::Device & device, size_t view) :
device(device), view(view)
{
}
void blitter::reset(const to_headset::video_stream_description & desc)
{
using channels_t = to_headset::video_stream_description::channels_t;
this->desc = desc;
current = {};
target = image_allocation();
image_view = nullptr;
rp = nullptr;
fb = nullptr;
sampler = nullptr;
pipelines.clear();
passthrough_rgb = passthrough_a = -1;
auto w = desc.width / num_views;
for (auto [i, item]: utils::enumerate(desc.items))
{
if (item.offset_x <= view * w and
item.offset_y == 0 and
item.offset_x + item.width * item.subsampling >= (view + 1) * w and
item.height * item.subsampling >= desc.height)
{
spdlog::info("Stream {} is eligible for blit-less path on view {}", i, view);
switch (item.channels)
{
case channels_t::colour:
passthrough_rgb = i;
break;
case channels_t::alpha:
passthrough_a = i;
break;
}
const bool alpha = item.channels == to_headset::video_stream_description::channels_t::alpha;
auto & r = alpha ? current.rect_a : current.rect_rgb;
r = vk::Rect2D{
.offset = {
.x = int32_t(view * w) - item.offset_x,
.y = 0,
},
};
}
}
if (passthrough_rgb != -1 and passthrough_a != -1)
return;
target = image_allocation(
device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = vk::Format::eB8G8R8A8Srgb,
.extent = {
.width = w,
.height = desc.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
},
{
.usage = VMA_MEMORY_USAGE_AUTO,
},
std::format("blit image {}", view));
image_view = device.createImageView(vk::ImageViewCreateInfo{
.image = vk::Image(target),
.viewType = vk::ImageViewType::e2D,
.format = target.info().format,
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.levelCount = 1,
.layerCount = 1,
}});
// render pass
{
vk::AttachmentReference color_ref{
.attachment = 0,
.layout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::SubpassDescription subpass{
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
.colorAttachmentCount = 1,
.pColorAttachments = &color_ref,
};
vk::AttachmentDescription color_desc{
.format = target.info().format,
.loadOp = vk::AttachmentLoadOp::eDontCare,
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
rp = device.createRenderPass(vk::RenderPassCreateInfo{
.attachmentCount = 1,
.pAttachments = &color_desc,
.subpassCount = 1,
.pSubpasses = &subpass,
});
}
fb = device.createFramebuffer(
vk::FramebufferCreateInfo{
.renderPass = *rp,
.attachmentCount = 1,
.pAttachments = &*image_view,
.width = w,
.height = desc.height,
.layers = 1,
});
sampler = device.createSampler(vk::SamplerCreateInfo{
.magFilter = vk::Filter::eLinear,
.minFilter = vk::Filter::eLinear,
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
});
pipelines.resize(desc.items.size());
for (auto [i, item]: utils::enumerate(desc.items))
{
pipelines[i].used = item.offset_x < (view + 1) * w and
item.offset_x + item.width * item.subsampling > view * w;
}
current.rgb = *image_view;
current.sampler_rgb = *sampler;
current.rect_rgb = vk::Rect2D{.extent = {w, desc.height}};
current.layout_rgb = vk::ImageLayout::eShaderReadOnlyOptimal;
}
void blitter::begin(vk::raii::CommandBuffer & cmd)
{
assert(not desc.items.empty());
if (*fb == VK_NULL_HANDLE)
{
current.rgb = nullptr;
current.a = nullptr;
current.sampler_rgb = nullptr;
current.sampler_a = nullptr;
return;
}
current.rgb = *image_view;
current.sampler_rgb = *sampler;
cmd.beginRenderPass(
{
.renderPass = *rp,
.framebuffer = *fb,
.renderArea = {
.offset = {0, 0},
.extent = {target.info().extent.width, target.info().extent.height},
},
},
vk::SubpassContents::eInline);
}
bool blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Sampler sampler, const vk::Extent2D & extent_, vk::ImageView image, vk::ImageLayout layout)
{
if (stream == passthrough_rgb)
{
current.rgb = image;
current.sampler_rgb = sampler;
current.layout_rgb = layout;
current.rect_rgb.extent = vk::Extent2D{
extent_.width * desc.items[stream].subsampling,
extent_.height * desc.items[stream].subsampling,
};
return true;
}
if (stream == passthrough_a)
{
current.a = image;
current.sampler_a = sampler;
current.layout_a = layout;
current.rect_a.extent = vk::Extent2D{
extent_.width * desc.items[stream].subsampling,
extent_.height * desc.items[stream].subsampling,
};
return false;
}
if (pipelines.empty())
return false;
assert(stream < pipelines.size());
auto & p = pipelines[stream];
if (not p.used)
return false;
const auto & extent = target.info().extent;
const auto & description = desc.items[stream];
if (not *p.pipeline)
{
const bool alpha = description.channels == to_headset::video_stream_description::channels_t::alpha;
vk::DescriptorSetLayoutBinding sampler_layout_binding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
.pImmutableSamplers = &sampler,
};
p.set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR,
.bindingCount = 1,
.pBindings = &sampler_layout_binding,
});
auto vert_constants = make_specialization_constants(
float(description.width) / extent_.width,
float(description.height) / extent_.height);
auto frag_constants = make_specialization_constants(
VkBool32(alpha));
// Create graphics pipeline
auto vertex_shader = load_shader(device, "stream.vert");
auto fragment_shader = load_shader(device, "stream.frag");
p.layout = device.createPipelineLayout(vk::PipelineLayoutCreateInfo{
.setLayoutCount = 1,
.pSetLayouts = &*p.set_layout,
});
vk::pipeline_builder pipeline_info{
.Stages = {{
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = vert_constants,
},
{
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = frag_constants,
}},
.VertexBindingDescriptions = {},
.VertexAttributeDescriptions = {},
.InputAssemblyState = {{
.topology = vk::PrimitiveTopology::eTriangleStrip,
}},
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
// and scissors is still used, put a vector with one element
.Viewports = {{}},
.Scissors = {{}},
.RasterizationState = {{
.polygonMode = vk::PolygonMode::eFill,
.lineWidth = 1,
}},
.MultisampleState = {{
.rasterizationSamples = vk::SampleCountFlagBits::e1,
}},
.ColorBlendAttachments = {
{.colorWriteMask = alpha ? vk::ColorComponentFlagBits::eA
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
.layout = *p.layout,
.renderPass = *rp,
.subpass = 0,
};
p.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
spdlog::info("Created blit pipeline for stream {}, view {}", stream, view);
}
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, *p.pipeline);
vk::DescriptorImageInfo image_info{
.imageView = image,
.imageLayout = layout,
};
cmd.pushDescriptorSetKHR(
vk::PipelineBindPoint::eGraphics,
*p.layout,
0,
vk::WriteDescriptorSet{
.dstBinding = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.pImageInfo = &image_info,
});
int x0 = description.offset_x - view * extent.width;
int y0 = description.offset_y;
int x1 = x0 + description.width * description.subsampling;
int y1 = y0 + description.height * description.subsampling;
cmd.setViewport(
0,
vk::Viewport{
.x = (float)x0,
.y = (float)y0,
.width = float(description.width * description.subsampling),
.height = float(description.height * description.subsampling),
.minDepth = 0,
.maxDepth = 1,
});
x0 = std::clamp<int>(x0, 0, extent.width);
x1 = std::clamp<int>(x1, 0, extent.width);
y0 = std::clamp<int>(y0, 0, extent.height);
y1 = std::clamp<int>(y1, 0, extent.height);
cmd.setScissor(
0,
vk::Rect2D{
.offset = {.x = x0, .y = y0},
.extent = {.width = uint32_t(x1 - x0), .height = uint32_t(y1 - y0)},
});
cmd.draw(3, 1, 0, 0);
return true;
}
blitter::output blitter::end(vk::raii::CommandBuffer & cmd)
{
if (*fb)
cmd.endRenderPass();
return current;
}
} // namespace wivrn
-73
View File
@@ -1,73 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "vk/allocation.h"
#include "wivrn_packets.h"
#include <vulkan/vulkan_raii.hpp>
namespace wivrn
{
class blitter
{
public:
struct output
{
vk::ImageView rgb;
vk::Sampler sampler_rgb;
vk::Rect2D rect_rgb;
vk::ImageLayout layout_rgb;
vk::ImageView a;
vk::Sampler sampler_a;
vk::Rect2D rect_a;
vk::ImageLayout layout_a;
};
private:
vk::raii::Device & device;
size_t view;
to_headset::video_stream_description desc;
// indices to simply passthrough, if -1 image needs to be blitted
int passthrough_rgb = -1;
int passthrough_a = -1;
image_allocation target;
vk::raii::ImageView image_view = nullptr;
vk::raii::RenderPass rp = nullptr;
vk::raii::Framebuffer fb = nullptr;
vk::raii::Sampler sampler = nullptr;
struct pipeline_t
{
vk::raii::DescriptorSetLayout set_layout = nullptr;
vk::raii::PipelineLayout layout = nullptr;
vk::raii::Pipeline pipeline = nullptr;
bool used = false; // true if we need this image for blitting
};
std::vector<pipeline_t> pipelines;
output current;
public:
blitter(vk::raii::Device & device, size_t view);
void reset(const to_headset::video_stream_description & desc);
void begin(vk::raii::CommandBuffer &);
// Return true if the image is used for this blitter's rgb
bool push_image(vk::raii::CommandBuffer & buf, uint8_t stream, vk::Sampler sampler, const vk::Extent2D &, vk::ImageView image, vk::ImageLayout);
output end(vk::raii::CommandBuffer &);
};
} // namespace wivrn
+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;
+101 -2
View File
@@ -32,12 +32,14 @@
#include "utils/i18n.h"
#include "utils/mapped_file.h"
#include "utils/overloaded.h"
#if WIVRN_CLIENT_DEBUG_MENU
#include "utils/ranges.h"
#endif
#include "version.h"
#include "xr/body_tracker.h"
#include <algorithm>
#include <cassert>
#include <chrono>
#include <chrono> // IWYU pragma: keep
#include <entt/entity/fwd.hpp>
#include <fastgltf/math.hpp>
#include <fastgltf/types.hpp>
@@ -642,13 +644,14 @@ void scenes::lobby::gui_settings()
imgui_ctx->vibrate_on_hover();
}
// Render resolution
{
const auto current = config.resolution_scale;
const auto width = stream_view.recommendedImageRectWidth;
const auto height = stream_view.recommendedImageRectHeight;
auto intScale = int(current * 10);
const auto slider = ImGui::SliderInt(
_("Resolution scale").append("##resolution_scale").c_str(),
_("Render resolution").append("##resolution_scale").c_str(),
&intScale,
5,
35,
@@ -667,6 +670,102 @@ void scenes::lobby::gui_settings()
}
}
// Stream resolution
{
const int step = 10;
const auto current = config.get_stream_scale();
auto intval = int(current * 100 / step);
const auto slider = ImGui::SliderInt(
_("Stream resolution").append("##stream_scale").c_str(),
&intval,
0,
100 / step,
fmt::format(_F("{}%%"), intval * step).c_str());
if (slider)
{
// clamp out of the slider to have the 50% value centered
intval = std::clamp(intval, 20 / step, 100 / step);
config.set_stream_scale(intval * step * 0.01);
config.save();
}
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;
const auto current = config.bitrate_bps;
auto val = int(current / mb);
const auto slider = ImGui::SliderInt(
_("Bitrate").append("##bitrate").c_str(),
&val,
1,
200,
fmt::format(_F("{}Mbit/s"), val).c_str());
if (slider)
{
config.bitrate_bps = val * mb;
config.save();
}
imgui_ctx->vibrate_on_hover();
}
if (instance.has_extension(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME))
{
if (ImGui::Checkbox(_S("High power mode"), &config.high_power_mode))
+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)
+112 -113
View File
@@ -153,9 +153,11 @@ static const std::array supported_depth_formats{
scenes::stream::stream(std::string server_name, scene & parent_scene) :
scene_impl<stream>(supported_color_formats, supported_depth_formats, parent_scene),
apps{*this, std::move(server_name)},
blitters{blitter(device, 0), blitter(device, 1)}
apps{*this, std::move(server_name)}
{
auto views = system.view_configuration_views(viewconfig);
width = views[0].recommendedImageRectWidth;
height = views[0].recommendedImageRectHeight;
}
static from_headset::visibility_mask_changed::masks get_visibility_mask(xr::instance & inst, xr::session & session, int view)
@@ -198,31 +200,34 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
.variant = application::get_messages_info().variant,
};
auto view = self->system.view_configuration_views(self->viewconfig)[0];
view = override_view(view, guess_model());
auto resolution_scale = application::get_config().resolution_scale;
view.recommendedImageRectWidth *= resolution_scale;
view.recommendedImageRectHeight *= resolution_scale;
info.recommended_eye_width = view.recommendedImageRectWidth;
info.recommended_eye_height = view.recommendedImageRectHeight;
auto [flags, views] = self->session.locate_views(
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,
self->instance.now(),
application::space(xr::spaces::view));
assert(views.size() == info.fov.size());
for (auto [i, j]: std::views::zip(views, info.fov))
{
j = i.fov;
auto [flags, views] = self->session.locate_views(
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,
self->instance.now(),
application::space(xr::spaces::view));
assert(views.size() == info.fov.size());
for (auto [i, j]: std::views::zip(views, info.fov))
j = i.fov;
}
const auto & config = application::get_config();
{
auto view = self->system.view_configuration_views(self->viewconfig)[0];
view = override_view(view, guess_model());
info.render_eye_width = view.recommendedImageRectWidth * config.resolution_scale;
info.render_eye_height = view.recommendedImageRectHeight * config.resolution_scale;
}
{
auto scale = config.get_stream_scale();
info.stream_eye_width = info.render_eye_width * scale;
info.stream_eye_height = info.render_eye_height * scale;
}
if (self->instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
{
info.available_refresh_rates = self->session.get_refresh_rates();
@@ -231,13 +236,13 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
{
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(info.available_refresh_rates, *config.preferred_refresh_rate)))
{
info.preferred_refresh_rate = *config.preferred_refresh_rate;
info.minimum_refresh_rate = config.minimum_refresh_rate.value_or(0);
info.settings.preferred_refresh_rate = *config.preferred_refresh_rate;
info.settings.minimum_refresh_rate = config.minimum_refresh_rate.value_or(0);
}
else
{
// Default to highest refresh rate
info.preferred_refresh_rate = info.available_refresh_rates.back();
info.settings.preferred_refresh_rate = info.available_refresh_rates.back();
}
}
}
@@ -246,9 +251,11 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
{
spdlog::warn("Unable to detect refresh rates");
info.available_refresh_rates = {guessed_fps};
info.preferred_refresh_rate = guessed_fps;
info.settings.preferred_refresh_rate = guessed_fps;
}
info.settings.bitrate_bps = config.bitrate_bps;
info.hand_tracking = config.check_feature(feature::hand_tracking);
info.eye_gaze = config.check_feature(feature::eye_gaze);
@@ -299,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;
}());
@@ -401,11 +423,6 @@ void scenes::stream::on_focused()
{
gui_status_last_change = instance.now();
auto views = system.view_configuration_views(viewconfig);
// stream_view = override_view(views[0], guess_model());
width = views[0].recommendedImageRectWidth;
height = views[0].recommendedImageRectHeight;
std::string profile = controller_name();
input.emplace(
*this,
@@ -488,9 +505,6 @@ void scenes::stream::on_focused()
assert(video_stream_description);
std::unique_lock lock(decoder_mutex);
setup_reprojection_swapchain(
video_stream_description->defoveated_width / view_count,
video_stream_description->defoveated_height);
if (application::get_config().high_power_mode)
{
@@ -545,9 +559,7 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]);
}
if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) {
return i.alpha() or not i.empty();
}))
if (state_ != state::streaming and not(decoders[0].empty() and decoders[1].empty()))
{
state_ = state::streaming;
spdlog::info("Stream scene ready at t={}", instance.now());
@@ -560,11 +572,6 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
}
}
bool scenes::stream::accumulator_images::alpha() const
{
return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha;
}
bool scenes::stream::accumulator_images::empty() const
{
for (const auto & frame: latest_frames)
@@ -575,7 +582,7 @@ bool scenes::stream::accumulator_images::empty() const
return true;
}
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::common_frame(XrTime display_time)
std::array<std::shared_ptr<shard_accumulator::blit_handle>, 3> scenes::stream::common_frame(XrTime display_time)
{
if (decoders.empty())
return {};
@@ -583,10 +590,8 @@ std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::com
thread_local std::vector<shard_accumulator::blit_handle *> common_frames;
common_frames.clear();
const bool alpha = decoders[0].latest_frames[0] and decoders[0].latest_frames[0]->view_info.alpha;
for (size_t i = 0; i < decoders.size(); ++i)
for (size_t i = 0; i < view_count + alpha; ++i)
{
if (decoders[i].alpha() and not alpha)
continue;
if (i == 0)
{
for (const auto & h: decoders[i].latest_frames)
@@ -609,8 +614,7 @@ std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::com
// clang-format on
}
}
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> result;
result.reserve(decoders.size());
std::array<std::shared_ptr<shard_accumulator::blit_handle>, view_count + 1> result;
if (not common_frames.empty())
{
auto min = std::ranges::min_element(common_frames,
@@ -623,12 +627,10 @@ std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::com
assert(*min);
auto frame_index = (*min)->feedback.frame_index;
for (const auto & decoder: decoders)
for (auto [i, decoder]: utils::enumerate(decoders))
{
if (alpha or not decoder.alpha())
result.emplace_back(decoder.frame(frame_index));
else
result.emplace_back(nullptr);
if (alpha or i < view_count)
result[i] = decoder.frame(frame_index);
}
}
else
@@ -647,9 +649,9 @@ std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::com
spdlog::warn(frames);
}
for (const auto & decoder: decoders)
for (auto [i, decoder]: utils::enumerate(decoders))
{
if (alpha or not decoder.alpha())
if (alpha or i < view_count)
{
auto min = std::ranges::min_element(decoder.latest_frames,
std::ranges::less{},
@@ -658,10 +660,8 @@ std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::com
return std::numeric_limits<XrTime>::max();
return std::abs(frame->view_info.display_time - display_time);
});
result.emplace_back(*min);
result[i] = *min;
}
else
result.emplace_back(nullptr);
}
}
return result;
@@ -768,19 +768,11 @@ void scenes::stream::render(const XrFrameState & frame_state)
last_display_time = frame_state.predictedDisplayTime;
std::shared_lock lock(decoder_mutex);
if (decoders.empty() or not frame_state.shouldRender)
if (not frame_state.shouldRender or (decoders[0].empty() and decoders[1].empty()))
{
// TODO: stop/restart video stream
session.begin_frame();
session.end_frame(frame_state.predictedDisplayTime, {});
std::unique_lock lock(frames_mutex);
for (auto & i: decoders)
{
for (auto & frame: i.latest_frames)
frame.reset();
}
return;
}
@@ -796,14 +788,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
application::pop_scene();
}
assert(swapchain);
if (device.waitForFences(*fence, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout)
throw std::runtime_error("Vulkan fence timeout");
device.resetFences(*fence);
// We don't need those after vkWaitForFences
current_blit_handles.clear();
current_blit_handles.fill(nullptr);
gpu_timestamps timestamps;
if (query_pool_filled)
@@ -843,13 +834,15 @@ void scenes::stream::render(const XrFrameState & frame_state)
// Search for frame with desired display time on all decoders
// If no such frame exists, use the latest frame for each decoder
current_blit_handles = common_frame(frame_state.predictedDisplayTime);
std::array<XrPosef, view_count> pose{};
std::array<XrFovf, view_count> fov{};
std::array<wivrn::to_headset::foveation_parameter, view_count> foveation{};
std::array<XrPosef, view_count> pose;
std::array<XrFovf, view_count> fov;
std::array<wivrn::to_headset::foveation_parameter, view_count> foveation;
bool use_alpha = false;
for (auto & blit_handle: current_blit_handles)
std::array<stream_defoveator::input, view_count> images;
for (size_t i = 0; i < view_count + use_alpha; ++i)
{
auto & blit_handle = current_blit_handles[i];
if (not blit_handle)
continue;
@@ -879,29 +872,44 @@ void scenes::stream::render(const XrFrameState & frame_state)
command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier);
blit_handle->current_layout = vk::ImageLayout::eGeneral;
}
}
// Blit images from the decoders
std::array<blitter::output, view_count> blitted;
for (auto [i, b]: utils::enumerate(blitters))
{
b.begin(command_buffer);
for (auto [j, blit_handle]: utils::enumerate(current_blit_handles))
if (i < view_count)
{
if (not blit_handle)
continue;
if (b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout))
foveation[i] = blit_handle->view_info.foveation[i];
pose[i] = blit_handle->view_info.pose[i];
fov[i] = blit_handle->view_info.fov[i];
// colour image
images[i] = {
.rgb = blit_handle->image_view,
.sampler_rgb = decoders[i].decoder->sampler(),
.rect_rgb = {
.extent = blit_handle->extent,
},
.layout_rgb = blit_handle->current_layout,
};
}
else
{
// alpha image, must set for each view
for (int j = 0; j < view_count; ++j)
{
pose[i] = blit_handle->view_info.pose[i];
fov[i] = blit_handle->view_info.fov[i];
foveation[i] = blit_handle->view_info.foveation[i];
images[j].a = blit_handle->image_view;
images[j].sampler_a = decoders[i].decoder->sampler();
images[j].rect_a = vk::Rect2D{
// in full size pixels
.offset = {
.x = j * video_stream_description->width,
},
.extent = {
.width = blit_handle->extent.width * 2,
.height = blit_handle->extent.height * 2,
},
};
images[j].layout_a = blit_handle->current_layout;
}
}
blitted[i] = b.end(command_buffer);
}
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
XrExtent2Di extents[view_count];
{
int32_t max_width = 0;
@@ -912,9 +920,11 @@ void scenes::stream::render(const XrFrameState & frame_state)
max_width = std::max(max_width, extents[i].width);
max_height = std::max(max_height, extents[i].height);
}
// If the defoveated image is larger than the swapchain, try to reallocate one
if (swapchain.width() < max_width or swapchain.height() < max_height)
if (not swapchain)
setup_reprojection_swapchain(max_width, max_height);
else if (swapchain.width() < max_width or swapchain.height() < max_height)
{
// If the defoveated image is larger than the swapchain, try to reallocate one
try
{
spdlog::info("Recreating swapchain, from {}x{} to {}x{}",
@@ -935,12 +945,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
}
}
}
assert(swapchain);
// defoveate the image
int image_index = swapchain.acquire();
swapchain.wait();
defoveator->defoveate(command_buffer, foveation, blitted, image_index);
defoveator->defoveate(command_buffer, foveation, images, image_index);
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
command_buffer.end();
vk::SubmitInfo submit_info;
@@ -1133,37 +1144,25 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
{
session.set_refresh_rate(description.fps);
spdlog::info("Creating decoders, size {}x{}", description.width, description.height);
std::unique_lock lock(decoder_mutex);
decoders.clear();
if (description.items.empty())
{
spdlog::info("Stopping video stream");
return;
}
video_stream_description = description;
for (auto & b: blitters)
b.reset(description);
for (const auto & [stream_index, item]: utils::enumerate(description.items))
for (const auto & [stream_index, item]: utils::enumerate(decoders))
{
spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y);
decoders.push_back(accumulator_images{
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, queue_family_index, item, description.fps, shared_from_this(), stream_index),
});
item = accumulator_images{
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, queue_family_index, description, shared_from_this(), stream_index),
};
}
}
void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint32_t swapchain_height)
{
assert(swapchain_width);
assert(swapchain_height);
device.waitIdle();
session.set_refresh_rate(video_stream_description->fps);
const uint32_t video_width = video_stream_description->width / view_count;
const uint32_t video_height = video_stream_description->height;
auto views = system.view_configuration_views(viewconfig);
swapchain = xr::swapchain(instance, session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
+5 -16
View File
@@ -24,7 +24,6 @@
#include "decoder/shard_accumulator.h"
#include "render/imgui_impl.h"
#include "scene.h"
#include "scenes/blitter.h"
#include "scenes/input_profile.h"
#include "stream_defoveator.h"
#include "utils/thread_safe.h"
@@ -55,8 +54,6 @@ public:
private:
static const size_t view_count = 2;
using stream_description = wivrn::to_headset::video_stream_description::item;
struct accumulator_images
{
std::unique_ptr<wivrn::shard_accumulator> decoder;
@@ -64,7 +61,6 @@ private:
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, image_buffer_size> latest_frames;
std::shared_ptr<wivrn::shard_accumulator::blit_handle> frame(uint64_t id) const;
bool alpha() const;
bool empty() const;
};
@@ -72,7 +68,7 @@ private:
// for frames inside accumulator images
std::mutex frames_mutex;
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> common_frame(XrTime display_time);
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, view_count + 1> common_frame(XrTime display_time);
std::unique_ptr<wivrn_session> network_session;
std::atomic<bool> exiting = false;
@@ -90,9 +86,7 @@ private:
std::shared_mutex decoder_mutex;
std::optional<to_headset::video_stream_description> video_stream_description;
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
std::array<blitter, view_count> blitters;
std::array<accumulator_images, view_count + 1> decoders; // Locked by decoder_mutex
std::optional<stream_defoveator> defoveator;
@@ -168,13 +162,11 @@ private:
void update_gui_position(xr::spaces controller);
// Keep a reference to the resources needed to blit the images until vkWaitForFences
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, view_count + 1> current_blit_handles;
XrTime running_application_req = 0;
thread_safe<to_headset::running_applications> running_applications;
std::atomic_uint32_t bitrate = 0;
stream(std::string server_name, scene & parent_scene);
bool forward_hid_input(from_headset::hid::input_t);
@@ -210,7 +202,6 @@ public:
void operator()(to_headset::tracking_control &&);
void operator()(to_headset::audio_stream_description &&);
void operator()(to_headset::video_stream_description &&);
void operator()(to_headset::settings &&);
void operator()(to_headset::refresh_rate_change &&);
void operator()(to_headset::application_list &&);
void operator()(to_headset::application_icon &&);
@@ -257,13 +248,11 @@ private:
struct gpu_timestamps
{
float gpu_barrier = 0;
float gpu_time = 0;
};
struct global_metric //: gpu_timestamps
struct global_metric
{
float gpu_barrier;
float gpu_time;
float cpu_time = 0;
float bandwidth_rx = 0;
@@ -312,7 +301,7 @@ private:
float compact_cpu_time = 0;
float compact_gpu_time = 0;
void accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps);
void accumulate_metrics(XrTime predicted_display_time, const std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, view_count + 1> & blit_handles, const gpu_timestamps & timestamps);
void gui_performance_metrics();
void gui_compact_view();
void gui_settings(float predicted_display_period);
+1 -1
View File
@@ -295,7 +295,7 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
std::span<wivrn::blitter::output> inputs,
const std::array<input, 2> & inputs,
int destination)
{
if (destination < 0 || destination >= (int)output_images.size())
+13 -2
View File
@@ -19,7 +19,6 @@
#pragma once
#include "blitter.h"
#include "vk/allocation.h"
#include "wivrn_packets.h"
#include <vulkan/vulkan_raii.hpp>
@@ -61,6 +60,18 @@ class stream_defoveator
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
public:
struct input
{
vk::ImageView rgb;
vk::Sampler sampler_rgb;
vk::Rect2D rect_rgb;
vk::ImageLayout layout_rgb;
vk::ImageView a;
vk::Sampler sampler_a;
vk::Rect2D rect_a;
vk::ImageLayout layout_a;
};
stream_defoveator(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
@@ -73,7 +84,7 @@ public:
void defoveate(
vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
std::span<wivrn::blitter::output> inputs,
const std::array<input, 2> & inputs,
int destination);
XrExtent2Di defoveated_size(const wivrn::to_headset::foveation_parameter &) const;
+15 -12
View File
@@ -86,7 +86,7 @@ ImPlotPoint getter(int index, void * data_)
}
} // namespace
void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps)
void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std::array<std::shared_ptr<shard_accumulator::blit_handle>, view_count + 1> & blit_handles, const gpu_timestamps & timestamps)
{
uint64_t rx = network_session->bytes_received();
uint64_t tx = network_session->bytes_sent();
@@ -171,8 +171,7 @@ void scenes::stream::gui_performance_metrics()
// clang-format off
plot(_("CPU time"), {{"", &global_metric::cpu_time}}, "s"),
plot(_("GPU time"), {{_("Reproject"), &global_metric::gpu_time},
{_("Blit"), &global_metric::gpu_barrier}}, "s"),
plot(_("GPU time"), {{_("Defoveate"), &global_metric::gpu_time}}, "s"),
plot(_("Network"), {{_("Download"), &global_metric::bandwidth_rx},
{_("Upload"), &global_metric::bandwidth_tx}}, "bit/s"),
@@ -383,11 +382,11 @@ void scenes::stream::gui_compact_view()
}
}
static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config, uint32_t bitrate, float predicted_display_period)
static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config, float predicted_display_period)
{
const auto & refresh_rates = session.get_refresh_rates();
from_headset::settings_changed packet{
.bitrate_bps = bitrate,
.bitrate_bps = config.bitrate_bps,
};
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(refresh_rates, *config.preferred_refresh_rate)))
{
@@ -421,7 +420,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
{
session.set_refresh_rate(0);
config.preferred_refresh_rate = 0;
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
config.save();
}
if (ImGui::IsItemHovered())
@@ -432,7 +431,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
{
session.set_refresh_rate(rate);
config.preferred_refresh_rate = rate;
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
config.save();
}
}
@@ -450,7 +449,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == config.minimum_refresh_rate, ImGuiSelectableFlags_SelectOnRelease))
{
config.minimum_refresh_rate = rate;
send_settings_changed_packet(session, network_session.get(), config, bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
config.save();
}
}
@@ -468,7 +467,7 @@ void scenes::stream::gui_settings(float predicted_display_period)
ImGui::SameLine(0.f, 10.f);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (size.y / 4.f) - style.FramePadding.y * 3.f);
if (ImGui::Button(fmt::format("{}Mbit/s", bitrate / 1'000'000).c_str()))
if (ImGui::Button(fmt::format("{}Mbit/s", config.bitrate_bps / 1'000'000).c_str()))
gui_status = gui_status::bitrate_settings;
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
@@ -590,23 +589,27 @@ void scenes::stream::gui_settings(float predicted_display_period)
void scenes::stream::gui_bitrate_settings(float predicted_display_period)
{
auto & config = application::get_config();
ImGui::PushFont(nullptr, constants::gui::font_size_large);
ImGui::Text("%s", _S("Use the right thumbstick to adjust the bitrate"));
ImGui::Text("%s", _S("Press A to go back"));
ImGui::Text("%s", fmt::format(_F("Bitrate: {}Mbit/s"), bitrate / 1'000'000).c_str());
ImGui::Text("%s", fmt::format(_F("Bitrate: {}Mbit/s"), config.bitrate_bps / 1'000'000).c_str());
ImGui::PopFont();
// Maximum speed of 20Mbit/s
float delta = application::read_action_float(settings_adjust).value_or(std::pair{0, 0}).second * 20'000'000.f * predicted_display_period;
bitrate = std::clamp(bitrate + static_cast<int32_t>(delta), 1'000'000u, 200'000'000u);
config.bitrate_bps = std::clamp(config.bitrate_bps + static_cast<int32_t>(delta), 1'000'000u, 200'000'000u);
bool ok = application::read_action_bool(foveation_ok).value_or(std::pair{0, false}).second;
if (ok)
{
config.save();
gui_status = gui_status::settings;
}
send_settings_changed_packet(session, network_session.get(), application::get_config(), bitrate, predicted_display_period);
send_settings_changed_packet(session, network_session.get(), application::get_config(), predicted_display_period);
}
void scenes::stream::gui_foveation_settings(float predicted_display_period)
-5
View File
@@ -74,11 +74,6 @@ void scenes::stream::operator()(to_headset::video_stream_description && desc)
}
}
void scenes::stream::operator()(to_headset::settings && settings)
{
bitrate = settings.bitrate_bps;
}
void scenes::stream::operator()(to_headset::refresh_rate_change && rate)
{
session.set_refresh_rate(rate.fps);
-63
View File
@@ -1,63 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#version 450
#ifdef VERT_SHADER
layout(constant_id = 0) const float useful_size_x = 1.0;
layout(constant_id = 1) const float useful_size_y = 1.0;
vec2 positions[3] = vec2[](
vec2(-1.0, -1.0),
vec2(3.0, -1.0),
vec2(-1.0, 3.0));
vec2 uvs[3] = vec2[](
vec2(0.0, 0.0),
vec2(2.0 * useful_size_x, 0.0),
vec2(0.0, 2.0 * useful_size_y));
layout(location = 0) out vec2 outUV;
void main()
{
outUV = uvs[gl_VertexIndex];
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
}
#endif
#ifdef FRAG_SHADER
layout(binding = 0) uniform sampler2D texSampler;
layout(constant_id = 0) const bool is_alpha = false;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = texture(texSampler, inUV);
outColor.a = outColor.r;
if (!is_alpha)
{
outColor.a = 1;
}
}
#endif
+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);
+24 -55
View File
@@ -216,14 +216,26 @@ enum face_type : uint8_t
htc,
};
struct headset_info_packet
struct settings_changed
{
uint32_t recommended_eye_width;
uint32_t recommended_eye_height;
std::vector<float> available_refresh_rates;
float preferred_refresh_rate;
// for automatic
float minimum_refresh_rate;
uint32_t bitrate_bps;
};
struct headset_info_packet
{
uint16_t render_eye_width;
uint16_t render_eye_height;
uint16_t stream_eye_width;
uint16_t stream_eye_height;
std::vector<float> available_refresh_rates;
// runtime configurable settings
settings_changed settings;
struct audio_description
{
uint8_t num_channels;
@@ -240,6 +252,7 @@ struct headset_info_packet
face_type face_tracking;
uint32_t num_generic_trackers;
std::vector<video_codec> supported_codecs; // from preferred to least preferred
std::optional<uint8_t> bit_depth;
std::string system_name;
// Used for the application list
@@ -248,18 +261,6 @@ struct headset_info_packet
std::string variant;
};
struct settings_request
{};
struct settings_changed
{
float preferred_refresh_rate;
// for automatic
float minimum_refresh_rate;
uint32_t bitrate_bps;
};
struct handshake
{
// Sending this on TCP means connection will be TCP only
@@ -547,7 +548,6 @@ using packets = std::variant<
pin_check_1,
pin_check_3,
headset_info_packet,
settings_request,
settings_changed,
feedback,
audio_data,
@@ -636,52 +636,27 @@ struct audio_stream_description
struct video_stream_description
{
enum class channels_t
{
colour,
alpha,
};
struct item
{
// useful dimensions of the video stream
uint16_t width;
uint16_t height;
// dimensions of the video, may include padding at the end
uint16_t video_width;
uint16_t video_height;
uint16_t offset_x;
uint16_t offset_y;
video_codec codec;
channels_t channels;
uint8_t subsampling; // applies to width/height only, offsets are in full size pixels
std::optional<VkSamplerYcbcrRange> range;
std::optional<VkSamplerYcbcrModelConversion> color_model;
};
// dimensions of the video stream per eye
// alpha is half resolution
uint16_t width;
uint16_t height;
std::array<video_codec, 3> codec; // left, right, alpha
float fps;
uint16_t defoveated_width;
uint16_t defoveated_height;
std::vector<item> items;
};
class video_stream_data_shard
{
public:
inline static const size_t max_payload_size = 1400;
enum flags : uint8_t
{
start_of_slice = 1,
end_of_slice = 1 << 1,
end_of_frame = 1 << 2,
};
// Identifier of stream in video_stream_description
// Identifier of stream:
// 0 left
// 1 right
// 2 alpha
uint8_t stream_item_idx;
// Counter increased for each frame
uint64_t frame_idx;
// Identifier of the shard within the frame
uint16_t shard_idx;
uint8_t flags;
// Position information, must be present on first video shard
struct view_info_t
@@ -755,11 +730,6 @@ struct tracking_control
std::array<bool, size_t(id::last) + 1> enabled;
};
struct settings
{
uint32_t bitrate_bps;
};
struct refresh_rate_change
{
float fps;
@@ -808,7 +778,6 @@ using packets = std::variant<
haptics,
timesync_query,
tracking_control,
settings,
refresh_rate_change,
application_list,
application_icon,
-143
View File
@@ -23,82 +23,6 @@ Kirigami.ScrollablePage {
Kirigami.FormLayout {
Controls.CheckBox {
id: manual_foveation
checked: Settings.scale != -1
Layout.row: 0
Layout.column: 0
text: i18nc("automatic foveation setup", "Manual foveation")
}
GridLayout {
columns: 5
enabled: manual_foveation.checked
Kirigami.FormData.label: i18n("Foveation strength:")
Controls.Slider {
id: scale_slider
Layout.row: 0
Layout.column: 0
Layout.columnSpan: 3
implicitWidth: 20 * Kirigami.Units.gridUnit
from: 0
to: 80
stepSize: 1
}
Controls.Label {
Layout.row: 0
Layout.column: 3
text: i18n("%1 %", scale_slider.value)
}
Kirigami.ContextualHelpButton {
Layout.row: 0
Layout.column: 4
toolTipText: i18n("A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games.\n\nA weaker foveation gives a uniform sharpness in the whole image.\n\nThe recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking.")
}
Controls.Label {
Layout.row: 1
Layout.column: 0
text: i18nc("weaker foveation", "Weaker")
}
Item {
Layout.row: 1
Layout.column: 1
// spacer item
Layout.fillWidth: true
}
Controls.Label {
Layout.row: 1
Layout.column: 2
text: i18nc("stronger foveation", "Stronger")
}
}
Kirigami.Separator {
Kirigami.FormData.isSection: true
}
Controls.SpinBox {
id: bitrate
Kirigami.FormData.label: i18n("Bitrate:")
from: 1
to: 200
textFromValue: (value, locale) => i18nc("bitrate", "%1 Mbit/s", value)
valueFromText: function (text, locale) {
var prefix_suffix = i18nc("bitrate", "%1 Mbit/s", "%1").split('%1');
for (var i of prefix_suffix) {
text = text.replace(i, "");
}
return Number.fromLocaleString(text);
}
onValueModified: Settings.bitrate = value
}
Kirigami.InlineMessage {
Layout.fillWidth: true
text: i18n("The current encoder configuration is not supported")
@@ -156,63 +80,6 @@ Kirigami.ScrollablePage {
}
}
RowLayout {
Kirigami.FormData.label: i18n("Codec:")
Controls.ComboBox {
id: codec_combo
enabled: Settings.simpleConfig && Settings.encoder != Settings.EncoderAuto
model: [
{
label: i18nc("automatic codec setup", "Auto"),
codec: Settings.CodecAuto
},
{
label: i18n("H.264"),
codec: Settings.H264
},
{
label: i18n("H.265"),
codec: Settings.H265
},
{
label: i18n("AV1"),
codec: Settings.Av1
}
]
onCurrentIndexChanged: if (settings.allowUpdates) {Settings.codec = model[currentIndex].codec}
textRole: "label"
delegate: Controls.ItemDelegate {
required property string label
required property var codec
width: codec_combo.width
text: i18n(label)
highlighted: ListView.isCurrentItem
enabled: Settings.allowedCodecs.includes(codec)
}
Connections {
target: Settings
function onCodecChanged() {
var codec = Settings.codec;
var i = codec_combo.model.findIndex( item => item.codec == codec)
if (i > -1)
codec_combo.currentIndex = i
}
}
}
Controls.CheckBox {
enabled: Settings.can10bit
text: i18n("10 bits")
checked: Settings.tenbit
onCheckedChanged: Settings.tenbit = checked
}
Kirigami.ContextualHelpButton {
toolTipText: i18n("10-bit encoding improves image quality but is not supported by all codecs and hardware")
}
}
Kirigami.Separator {
Kirigami.FormData.isSection: true
}
@@ -372,15 +239,11 @@ Kirigami.ScrollablePage {
Component.onCompleted: {
openvr_libs.init()
Settings.load(WivrnServer);
// If bitrate was manually set higher, keep the limit
bitrate.to = Math.max(bitrate.to, Settings.bitrate)
bitrate.value = Settings.bitrate
settings.allowUpdates = true;
settings.load();
}
function save() {
Settings.scale = manual_foveation.checked ? 1 - scale_slider.value / 100.0 : -1;
let openvr = openvr_combobox.model.get(openvr_combobox.currentIndex)
if (openvr.is_custom) {
Settings.openvr = openvr_text.text;
@@ -399,12 +262,6 @@ Kirigami.ScrollablePage {
}
function load() {
if (Settings.scale > 0) {
scale_slider.value = Math.round(100 - Settings.scale * 100);
} else {
scale_slider.value = 50;
}
debug_gui.checked = Settings.debugGui;
steamvr_lh.checked = Settings.steamVrLh;
hid_forwarding.checked = Settings.hidForwarding;
+94 -121
View File
@@ -114,8 +114,6 @@ void Settings::emitAllChanged()
encoderChanged();
codecChanged();
tenbitChanged();
bitrateChanged();
scaleChanged();
tcpOnlyChanged();
applicationChanged();
openvrChanged();
@@ -145,41 +143,49 @@ void Settings::load(const wivrn_server * server)
}
}
static Settings::encoder_name encoder_for_item(const nlohmann::json & item)
{
if (item.is_string())
return Settings::encoder_id_from_string(std::string(item));
if (item.is_object())
{
if (auto i = item.find("encoder"); i != item.end())
return Settings::encoder_id_from_string(std::string(*i));
}
return Settings::encoder_name::EncoderAuto;
}
static Settings::video_codec codec_for_item(const nlohmann::json & item)
{
if (item.is_object())
{
if (auto i = item.find("codec"); i != item.end())
return Settings::codec_id_from_string(std::string(*i));
}
return Settings::video_codec::CodecAuto;
}
bool Settings::simpleConfig() const
{
// Simple configuration: either unset, or all encoders + codecs are the same
// Simple configuration: either unset, single encoder or all encoders + codecs are the same
try
{
auto it = m_jsonSettings.find("encoders");
if (it == m_jsonSettings.end())
auto it = m_jsonSettings.find("encoder");
if (it == m_jsonSettings.end() or it->is_object() or it->is_string())
return true;
std::optional<encoder_name> encoder;
std::optional<video_codec> codec;
for (const auto & item: *it)
{
if (auto it = item.find("encoder"); it != item.end())
{
auto e = encoder_id_from_string(std::string(*it));
if (encoder and e != encoder)
return false;
encoder = e;
}
else
{
encoder = encoder_name::EncoderAuto;
}
auto e = encoder_for_item(item);
if (encoder and e != encoder)
return false;
encoder = e;
if (auto it = item.find("codec"); it != item.end())
{
auto e = codec_id_from_string(std::string(*it));
if (codec and e != codec)
return false;
codec = e;
}
else
{
codec = video_codec::CodecAuto;
}
auto c = codec_for_item(item);
if (codec and c != codec)
return false;
codec = c;
}
return true;
}
@@ -193,15 +199,12 @@ Settings::encoder_name Settings::encoder() const
{
try
{
auto it = m_jsonSettings.find("encoders");
auto it = m_jsonSettings.find("encoder");
if (it == m_jsonSettings.end())
return encoder_name::EncoderAuto;
for (const auto & item: *it)
{
if (auto it = item.find("encoder"); it != item.end())
return encoder_id_from_string(std::string(*it));
return encoder_name::EncoderAuto;
}
if (it->is_array() and it->size())
it = it->begin();
return encoder_for_item(*it);
}
catch (...)
{
@@ -211,42 +214,23 @@ Settings::encoder_name Settings::encoder() const
void Settings::set_encoder(const encoder_name & value)
{
auto old = encoder();
if (value == encoder())
return;
auto old_codec = codec();
switch (value)
{
case EncoderAuto:
m_jsonSettings.erase("encoders");
m_jsonSettings.erase("encoder");
break;
case Nvenc:
case Vaapi:
case Vulkan: {
auto & enc = m_jsonSettings["encoders"] = nlohmann::json::array();
for (float offset: {0.f, 0.5f})
{
auto obj = nlohmann::json::object({
{"width", 0.5},
{"encoder", encoder_from_id(value)},
});
if (offset)
obj["offset_x"] = offset;
if (value == Vulkan)
obj["codec"] = "h264";
enc.push_back(obj);
}
}
break;
case encoder_name::X264:
m_jsonSettings["encoders"] =
nlohmann::json::parse(R"([{"encoder": "x264", "codec": "h264"}])");
break;
}
if (value != old)
{
encoderChanged();
if (not can10bit())
set_tenbit(false);
case X264:
case Vulkan:
m_jsonSettings["encoder"] = encoder_from_id(value);
}
encoderChanged();
if (not can10bit())
set_tenbit(false);
if (old_codec != codec())
codecChanged();
simpleConfigChanged();
@@ -256,15 +240,12 @@ Settings::video_codec Settings::codec() const
{
try
{
auto it = m_jsonSettings.find("encoders");
auto it = m_jsonSettings.find("encoder");
if (it == m_jsonSettings.end())
return video_codec::CodecAuto;
for (const auto & item: *it)
{
if (auto it = item.find("codec"); it != item.end())
return codec_id_from_string(std::string(*it));
return video_codec::CodecAuto;
}
if (it->is_array() and it->size())
it = it->begin();
return codec_for_item(*it);
}
catch (...)
{
@@ -275,17 +256,49 @@ Settings::video_codec Settings::codec() const
void Settings::set_codec(const video_codec & value)
{
auto old = codec();
auto it = m_jsonSettings.find("encoders");
if (it == m_jsonSettings.end() or not it->is_array())
auto it = m_jsonSettings.find("encoder");
if (it == m_jsonSettings.end())
return;
for (auto & item: *it)
if (it->is_string())
{
m_jsonSettings["encoder"] = nlohmann::json::object({
{"encoder", *it},
{"codec", codec_from_id(value)},
});
}
if (it->is_object())
{
if (not item.is_object())
continue;
if (value == CodecAuto)
item.erase("codec");
{
if (auto encoder = it->find("encoder"); encoder != it->end())
*it = *encoder;
else
m_jsonSettings.erase("encoder");
}
else
item["codec"] = codec_from_id(value);
(*it)["codec"] = codec_from_id(value);
}
else if (it->is_array())
{
for (auto & item: *it)
{
if (it->is_string())
{
item = nlohmann::json::object({
{"encoder", item},
{"codec", codec_from_id(value)},
});
continue;
}
if (not item.is_object())
continue;
if (value == CodecAuto)
item.erase("codec");
else
item["codec"] = codec_from_id(value);
}
}
if (value != old)
{
@@ -309,51 +322,14 @@ bool Settings::tenbit() const
void Settings::set_tenbit(const bool & value)
{
auto old = tenbit();
m_jsonSettings["bit-depth"] = value ? 10 : 8;
if (codec() == CodecAuto)
m_jsonSettings.erase("bit-depth");
else
m_jsonSettings["bit-depth"] = value ? 10 : 8;
if (value != old)
tenbitChanged();
}
int Settings::bitrate() const
{
try
{
return m_jsonSettings.value("bitrate", 50'000'000) / 1'000'000;
}
catch (...)
{
return 50;
}
}
void Settings::set_bitrate(const int & value)
{
auto old = bitrate();
m_jsonSettings["bitrate"] = value * 1'000'000;
if (old != value)
bitrateChanged();
}
float Settings::scale() const
{
// Foveation
auto it = m_jsonSettings.find("scale");
if (it != m_jsonSettings.end() and it->is_number())
return *it;
return -1;
}
void Settings::set_scale(const float & value)
{
auto old = scale();
if (value == -1)
m_jsonSettings.erase("scale");
else
m_jsonSettings["scale"] = value;
if (old != value)
scaleChanged();
}
QString Settings::application() const
{
// Automatically started application
@@ -520,10 +496,7 @@ void Settings::save(wivrn_server * server)
void Settings::restore_defaults()
{
m_jsonSettings.erase("encoders");
m_jsonSettings.erase("encoder-passthrough");
m_jsonSettings.erase("scale");
m_jsonSettings.erase("bitrate");
m_jsonSettings.erase("encoder");
m_jsonSettings.erase("application");
m_jsonSettings.erase("hid-forwarding");
m_jsonSettings.erase("debug-gui");
-4
View File
@@ -66,8 +66,6 @@ public:
Q_PROPERTY(QList<video_codec> allowedCodecs READ allowedCodecs NOTIFY encoderChanged)
Q_PROPERTY(bool can10bit READ can10bit NOTIFY codecChanged)
Q_PROPERTY(bool tenbit READ tenbit WRITE set_tenbit NOTIFY tenbitChanged)
Q_PROPERTY(int bitrate READ bitrate WRITE set_bitrate NOTIFY bitrateChanged)
Q_PROPERTY(float scale READ scale WRITE set_scale NOTIFY scaleChanged)
Q_PROPERTY(bool tcpOnly READ tcpOnly WRITE set_tcpOnly NOTIFY tcpOnlyChanged)
Q_PROPERTY(QString application READ application WRITE set_application NOTIFY applicationChanged)
@@ -86,8 +84,6 @@ public:
SETTER_GETTER_NOTIFY(encoder_name, encoder)
SETTER_GETTER_NOTIFY(video_codec, codec)
SETTER_GETTER_NOTIFY(bool, tenbit)
SETTER_GETTER_NOTIFY(int, bitrate)
SETTER_GETTER_NOTIFY(float, scale)
SETTER_GETTER_NOTIFY(QString, application)
SETTER_GETTER_NOTIFY(bool, hidForwarding)
SETTER_GETTER_NOTIFY(bool, debugGui)
+1 -4
View File
@@ -45,12 +45,9 @@
<property name="SessionRunning" type="b" access="read"/>
<property name="SteamCommand" type="s" access="read"/>
<property name="JsonConfiguration" type="s" access="readwrite"/>
<property name="Bitrate" type="u" access="readwrite"/>
<property name="Bitrate" type="u" access="read"/>
<!-- Data from the headset info packet -->
<property name="RecommendedEyeSize" type="(uu)" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QSize"/>
</property>
<property name="AvailableRefreshRates" type="ad" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QList&lt;double&gt;"/>
</property>
+15 -87
View File
@@ -12,43 +12,16 @@ If you installed WiVRn from a flatpack, the config is in `$HOME/.var/app/io.gith
All elements are optional and have default values.
## `scale`
Default value: `0.5`, `0.35` if headset supports eye tracking
Controls the size of the video stream, either a number between 0 and 1 or a pair of numbers between 0 and 1. If two numbers are provided the first one is horizontal scale and the second vertical.
Scaling is applied in a foveated fashion: the center has a 1:1 ratio and the rest is scaled so that the total number of pixels matches the desired scale.
### Examples:
```json
{
"scale": 0.5
}
```
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
{
"scale": [0.75, 0.5]
}
```
Scales x by a 0.75 factor, and y by a 0.5 factor.
## `bitrate`
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` and `nvenc` encoders using `h265` or `av1`.
## `encoders`
A list of encoders to use.
## `encoder`
The encoder to use, either a single string or object applied to all streams, or a list of string or objects with values for left, right and alpha.
When a string it is used, it is equivalent to the `encoder` item of the object.
Default value: one encoder per eye
WiVRn has the ability to split the video in blocks that are processed independently, this may use resources more effectively and reduce latency.
WiVRn encodes each eye separately, and the alpha channel as one for both eyes. Each stream is 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.
### `encoder`
@@ -61,7 +34,7 @@ Identifier of the encoder, one of
* `vulkan`: experimental, for any GPU that supports vulkan video encode
### `codec`
Default value: first supported by both headset and encoder of `av1`, `h264`, `h265`.
Default value: best supported by both headset and encoder of `av1`, `h264`, `h265`.
One of `h264`, `h265`, `av1`, `raw`.
@@ -73,31 +46,24 @@ Not all encoders support every codec:
If `nvenc` encoder is in use, you can refer to [nvidia website](https://developer.nvidia.com/video-encode-decode-support-matrix) to make sure that your GPU supports encoding with the desired codec.
### `width`, `height`, `offset_x`, `offset_y` (advanced)
Default values: full image (`width` = 1, `height` = 1, `offset_x` = 0, `offset_y` = 0)
Specifies the portion of the video to encode: all values are in 0, 1 range. Left eye image ranges from x 0 to x 0.5 and y 0 to 1, Rigth eye is x from 0.5 to 1 and y 0 to 1.
### `group` (very advanced)
### `group` (advanced)
Default value: One value for each encoder type (nvenc, vaapi, vulkan, x264).
Identifier (number) of the encoder group. Encoders with the same identifier are executed sequentially, in the order they are defined in the configuration. Encoders with different identifiers are executed concurrently.
Default setting will have all encoders of a given type execute sequentially, and different types in parallel.
### Examples
1. Simple encoder
1. Simple configuration
```json
{
"bitrate": 50000000,
"encoders": [
{
"encoder": "vaapi",
"codec": "h265"
}
]
"encoder": {
"encoder": "vaapi",
"codec": "h265"
}
}
```
Creates a single encoder, using vaapi hardware encoding, h265 video codec (HEVC) and 50Mb/s bitrate.
Use vaapi hardware encoding, h265 video codec (HEVC) and 50Mb/s bitrate.
2. Hardware + software encoder
```json
@@ -107,52 +73,19 @@ Creates a single encoder, using vaapi hardware encoding, h265 video codec (HEVC)
{
"encoder": "vaapi",
"codec": "h265",
"width": 0.5,
"height": 1,
"offset_x": 0,
"offset_y": 0
},
{
"encoder": "x264",
"codec": "h264",
"width": 0.5,
"height": 1,
"offset_x": 0.5,
"offset_y": 0
}
]
}
```
Creates a hardware encoder for left eye, and a software encoder for right eye.
3. 2 Hardware encoders
```json
{
"bitrate": 50000000,
"encoders": [
{
"encoder": "vaapi",
"codec": "h265",
"width": 0.5,
"height": 1,
"offset_x": 0,
"offset_y": 0,
"group": 0
},
{
"encoder": "vaapi",
"codec": "h264",
"width": 0.5,
"height": 1,
"offset_x": 0.5,
"offset_y": 0,
"group": 0
}
"codec": "h265",
},
]
}
```
Creates two hardware encoders, one for left eye and one for right eye, executed sequentially as they have the same `group`.
This allows the left eye image to be encoded faster than the full image would be, so network transfer starts earlier, and decoding starts earlier. While the total encoding, transfer and decoding time remain the same or are longer, this can reduce the latency.
Creates a hardware encoder for left eye and transparency, and a software encoder for right eye.
### `device`, only for vaapi
Default value: unset
@@ -165,11 +98,6 @@ Default value: unset
Json object of additional options to pass directly to ffmpeg `avcodec_open2`'s `option` parameter.
## `encoder-passthrough`
The single encoder used for passthrough (transparency), contains the same elements as the other encoders, except for width/height and offsets which are ignored.
Default values are those computed for the first encoder.
## `application`
Default value: unset
+189 -138
View File
@@ -11,8 +11,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WiVRn\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-12-07 15:32+0100\n"
"PO-Revision-Date: 2025-12-07 17:05+0100\n"
"POT-Creation-Date: 2025-12-11 13:42+0100\n"
"PO-Revision-Date: 2025-12-11 14:32+0100\n"
"Last-Translator: Claudio Sampaio (Patola) <patola@gmail.com>\n"
"Language-Team: Portuguese <>\n"
"Language: pt_BR\n"
@@ -73,83 +73,83 @@ msgstr "Incapaz de conectar a {} ({}): {}"
msgid "Waiting for connection"
msgstr "Aguardando conexão"
#: client/scenes/lobby.cpp:1308
#: client/scenes/lobby.cpp:1310
msgid "Passthrough"
msgstr "Passthrough"
#: client/scenes/lobby.cpp:1320
#: client/scenes/lobby.cpp:1322
msgid "Default environment"
msgstr "Ambiente default"
#: client/scenes/lobby_gui.cpp:99
#: client/scenes/lobby_gui.cpp:101
msgctxt "openxr_post_processing"
msgid "Normal"
msgstr "Normal"
#: client/scenes/lobby_gui.cpp:102
#: client/scenes/lobby_gui.cpp:104
msgctxt "openxr_post_processing"
msgid "Quality"
msgstr "Qualidade"
#: client/scenes/lobby_gui.cpp:104
#: client/scenes/lobby_gui.cpp:106
msgctxt "openxr_post_processing"
msgid "Disabled"
msgstr "Desabilitado"
#: client/scenes/lobby_gui.cpp:112 client/scenes/lobby_gui.cpp:256
#: client/scenes/stream_gui.cpp:1012
#: client/scenes/lobby_gui.cpp:114 client/scenes/lobby_gui.cpp:258
#: client/scenes/stream_gui.cpp:1015
msgid "Disconnect"
msgstr "Desconectar"
#: client/scenes/lobby_gui.cpp:132 client/scenes/lobby_gui_customize.cpp:749
#: client/scenes/lobby_gui.cpp:134 client/scenes/lobby_gui_customize.cpp:749
#: client/scenes/lobby_gui_customize.cpp:840
#: client/scenes/lobby_gui_customize.cpp:896 client/scenes/stream_gui.cpp:1008
#: client/scenes/lobby_gui_customize.cpp:896 client/scenes/stream_gui.cpp:1011
msgid "Close"
msgstr "Fechar"
#: client/scenes/lobby_gui.cpp:138
#: client/scenes/lobby_gui.cpp:140
msgid "Connection"
msgstr "Conexão"
#: client/scenes/lobby_gui.cpp:140
#: client/scenes/lobby_gui.cpp:142
#, c++-format
msgid "Connection to {}"
msgstr "Conexão a {}"
#: client/scenes/lobby_gui.cpp:170
#: client/scenes/lobby_gui.cpp:172
msgid "PIN"
msgstr "PIN"
#: client/scenes/lobby_gui.cpp:192
#: client/scenes/lobby_gui.cpp:194
msgid "Input the PIN displayed on the dashboard"
msgstr "Entre o PIN mostrado no painel"
#: client/scenes/lobby_gui.cpp:282
#: client/scenes/lobby_gui.cpp:284
msgid "Name"
msgstr "Nome"
#: client/scenes/lobby_gui.cpp:293
#: client/scenes/lobby_gui.cpp:295
msgid "Address"
msgstr "Endereço"
#: client/scenes/lobby_gui.cpp:302
#: client/scenes/lobby_gui.cpp:304
msgid "Port"
msgstr "Porta"
#: client/scenes/lobby_gui.cpp:310
#: client/scenes/lobby_gui.cpp:312
msgid "TCP only"
msgstr "TCP somente"
#: client/scenes/lobby_gui.cpp:317 client/scenes/lobby_gui_customize.cpp:651
#: client/scenes/stream_gui.cpp:965
#: client/scenes/lobby_gui.cpp:319 client/scenes/lobby_gui_customize.cpp:651
#: client/scenes/stream_gui.cpp:968
msgid "Cancel"
msgstr "Cancelar"
#: client/scenes/lobby_gui.cpp:331
#: client/scenes/lobby_gui.cpp:333
msgid "Save"
msgstr "Salvar"
#: client/scenes/lobby_gui.cpp:384
#: client/scenes/lobby_gui.cpp:386
msgid ""
"Start a WiVRn server on your\n"
"local network"
@@ -157,46 +157,46 @@ msgstr ""
"Inicie um servidor WiVRn em sua\n"
"rede local"
#: client/scenes/lobby_gui.cpp:416
#: client/scenes/lobby_gui.cpp:418
msgid "Autoconnect"
msgstr "Autoconectar"
#: client/scenes/lobby_gui.cpp:442
#: client/scenes/lobby_gui.cpp:444
msgid "Connect"
msgstr "Conectar"
#: client/scenes/lobby_gui.cpp:452 client/wivrn_client.cpp:186
#: client/scenes/lobby_gui.cpp:454 client/wivrn_client.cpp:186
msgid "Incompatible server version"
msgstr "Versão de servidor incompatível"
#: client/scenes/lobby_gui.cpp:454
#: client/scenes/lobby_gui.cpp:456
msgid "Server not available"
msgstr "Servidor não disponível"
#: client/scenes/lobby_gui.cpp:536
#: client/scenes/lobby_gui.cpp:538
msgctxt "language selection, replace with the name of the language"
msgid "English"
msgstr "Português (Brasil)"
#: client/scenes/lobby_gui.cpp:550
#: client/scenes/lobby_gui.cpp:552
msgid "Language"
msgstr "Linguagem"
#: client/scenes/lobby_gui.cpp:550 client/scenes/lobby_gui.cpp:552
#: client/scenes/lobby_gui.cpp:552 client/scenes/lobby_gui.cpp:554
msgid "System language"
msgstr "Linguagem do Sistema"
#: client/scenes/lobby_gui.cpp:577 client/scenes/stream_gui.cpp:418
#: client/scenes/lobby_gui.cpp:579 client/scenes/stream_gui.cpp:417
msgid "Refresh rate"
msgstr "Taxa de atualização"
#: client/scenes/lobby_gui.cpp:577 client/scenes/lobby_gui.cpp:579
#: client/scenes/stream_gui.cpp:418 client/scenes/stream_gui.cpp:420
#: client/scenes/lobby_gui.cpp:579 client/scenes/lobby_gui.cpp:581
#: client/scenes/stream_gui.cpp:417 client/scenes/stream_gui.cpp:419
msgctxt "automatic refresh rate"
msgid "Automatic"
msgstr "Automático"
#: client/scenes/lobby_gui.cpp:586 client/scenes/stream_gui.cpp:428
#: client/scenes/lobby_gui.cpp:588 client/scenes/stream_gui.cpp:427
msgid ""
"Select refresh rate based on measured application performance.\n"
"May cause flicker when a change happens."
@@ -204,73 +204,119 @@ msgstr ""
"Seleciona a taxa de atualização baseada no desempenho medido do aplicativo.\n"
"Pode causar oscilações quando uma alteração ocorrer."
#: client/scenes/lobby_gui.cpp:603 client/scenes/stream_gui.cpp:446
#: client/scenes/lobby_gui.cpp:605 client/scenes/stream_gui.cpp:445
msgid "Minimum refresh rate"
msgstr "Taxa de atualização mínima"
#: client/scenes/lobby_gui.cpp:629
#: client/scenes/lobby_gui.cpp:631
msgid "Foveation level"
msgstr "Nível de foveação"
#: client/scenes/lobby_gui.cpp:651
msgid "Resolution scale"
msgstr "Escala de resolução"
#: client/scenes/lobby_gui.cpp:654
msgid "Render resolution"
msgstr "Resolução de renderização"
#: client/scenes/lobby_gui.cpp:655
#: client/scenes/lobby_gui.cpp:658
#, c-format, c++-format
msgid "{}%% - {}x{} per eye"
msgstr "{}%% - {}x{} por olho"
#: client/scenes/lobby_gui.cpp:666
#: client/scenes/lobby_gui.cpp:669
#, c++-format
msgid "Resolution larger than {}x{} may not be supported by the headset"
msgstr "Resolução maior que {}x{} pode não ser suportada pelo headset"
#: client/scenes/lobby_gui.cpp:672
#: client/scenes/lobby_gui.cpp:679
msgid "Stream resolution"
msgstr "Resolução da stream"
#: client/scenes/lobby_gui.cpp:683
#, c-format, c++-format
msgid "{}%%"
msgstr "{}%%"
#: client/scenes/lobby_gui.cpp:697
msgctxt "Codec"
msgid "Automatic"
msgstr "Automático"
#: client/scenes/lobby_gui.cpp:701
msgctxt "Codec"
msgid "H.264"
msgstr "H.264"
#: client/scenes/lobby_gui.cpp:703
msgctxt "Codec"
msgid "H.265"
msgstr "H.265"
#: client/scenes/lobby_gui.cpp:705
msgctxt "Codec"
msgid "AV1"
msgstr "AV1"
#: client/scenes/lobby_gui.cpp:713
msgid "Codec"
msgstr "Codec"
#: client/scenes/lobby_gui.cpp:741
msgid "10-bit"
msgstr "10-bit"
#: client/scenes/lobby_gui.cpp:756
msgid "Bitrate"
msgstr "Bitrate"
#: client/scenes/lobby_gui.cpp:760
#, c++-format
msgid "{}Mbit/s"
msgstr "{}Mbit/s"
#: client/scenes/lobby_gui.cpp:771
msgid "High power mode"
msgstr "Modo de alta potência"
#: client/scenes/lobby_gui.cpp:675
#: client/scenes/lobby_gui.cpp:774
msgid "Increase power usage to allow higher resolution and refresh rate"
msgstr ""
"Aumenta a potência para permitir resolução e taxa de atualização mais altas"
#: client/scenes/lobby_gui.cpp:681
#: client/scenes/lobby_gui.cpp:780
msgid "Enable microphone"
msgstr "Ativar microfone"
#: client/scenes/lobby_gui.cpp:690
#: client/scenes/lobby_gui.cpp:789
msgid "Unprocessed Microphone Audio"
msgstr "Áudio Não-processado de Microfone"
#: client/scenes/lobby_gui.cpp:696
#: client/scenes/lobby_gui.cpp:795
msgid "Force disable audio filters, such as noise cancellation"
msgstr ""
"Força a desativação de filtros de áudio tais como cancelamento de ruído"
#: client/scenes/lobby_gui.cpp:703
#: client/scenes/lobby_gui.cpp:802
msgid "Enable hand tracking"
msgstr "Ativar rastreamento de mãos"
#: client/scenes/lobby_gui.cpp:709 client/scenes/lobby_gui.cpp:721
#: client/scenes/lobby_gui.cpp:733 client/scenes/lobby_gui.cpp:750
#: client/scenes/lobby_gui.cpp:808 client/scenes/lobby_gui.cpp:820
#: client/scenes/lobby_gui.cpp:832 client/scenes/lobby_gui.cpp:849
#: client/scenes/lobby_gui_customize.cpp:636
msgid "This feature is not supported by your headset"
msgstr "Este recurso não é suportado pelo seu headset"
#: client/scenes/lobby_gui.cpp:715
#: client/scenes/lobby_gui.cpp:814
msgid "Enable eye tracking"
msgstr "Ativar rastreamento ocular"
#: client/scenes/lobby_gui.cpp:727
#: client/scenes/lobby_gui.cpp:826
msgid "Enable face tracking"
msgstr "Ativar rastreamento facial"
#: client/scenes/lobby_gui.cpp:741
#: client/scenes/lobby_gui.cpp:840
msgid "Enable body tracking"
msgstr "Ativar rastreamento corporal"
#: client/scenes/lobby_gui.cpp:755
#: client/scenes/lobby_gui.cpp:854
msgid ""
"Requires 'Hand and body tracking' to be enabled in the Quest movement "
"tracking settings,\n"
@@ -282,11 +328,11 @@ msgstr ""
"estimados\n"
"com base nas posições do controle e do headset."
#: client/scenes/lobby_gui.cpp:765
#: client/scenes/lobby_gui.cpp:864
msgid "Enable lower body tracking"
msgstr "Ativar rastreamento corporal inferior"
#: client/scenes/lobby_gui.cpp:771
#: client/scenes/lobby_gui.cpp:870
msgid ""
"Estimate lower body joint positions using Generative Legs\n"
"Requires 'Hand and body tracking' to be enabled in the Quest movement "
@@ -297,11 +343,11 @@ msgstr ""
"Requer que 'Rastreamento corporal e das mãos' esteja ativado nas\n"
"configurações de Rastreamento de Movimento do Quest"
#: client/scenes/lobby_gui.cpp:774
#: client/scenes/lobby_gui.cpp:873
msgid "Enable hip tracking"
msgstr "Ativar rastreamento de quadril"
#: client/scenes/lobby_gui.cpp:780
#: client/scenes/lobby_gui.cpp:879
msgid ""
"Only takes affect with lower body tracking enabled\n"
"May be desired when using another source of hip tracking"
@@ -309,11 +355,11 @@ msgstr ""
"Só tem efeito com o rastreamento corporal inferior ativado\n"
"Pode ser desejado ao usar outra fonte de rastreamento de quadril"
#: client/scenes/lobby_gui.cpp:788
#: client/scenes/lobby_gui.cpp:887
msgid "Enable in-stream window"
msgstr "Habilitar janela na stream"
#: client/scenes/lobby_gui.cpp:791
#: client/scenes/lobby_gui.cpp:890
msgid ""
"Enables the configuration window to be shown while the game is streaming.\n"
"If enabled, the window is activated by pressing both thumbsticks."
@@ -322,15 +368,15 @@ msgstr ""
"streamado.\n"
"Se habilitado, a janela é ativada clicando os dois joysticks simultaneamente."
#: client/scenes/lobby_gui.cpp:805 client/scenes/stream_gui.cpp:480
#: client/scenes/lobby_gui.cpp:904 client/scenes/stream_gui.cpp:479
msgid "OpenXR post-processing"
msgstr "Pós-processamento OpenXR"
#: client/scenes/lobby_gui.cpp:809 client/scenes/stream_gui.cpp:484
#: client/scenes/lobby_gui.cpp:908 client/scenes/stream_gui.cpp:483
msgid "Supersampling"
msgstr "Supersampling"
#: client/scenes/lobby_gui.cpp:829 client/scenes/stream_gui.cpp:505
#: client/scenes/lobby_gui.cpp:928 client/scenes/stream_gui.cpp:504
msgid ""
"Reduce flicker for high contrast edges.\n"
"Useful when the input resolution is high compared to the headset display"
@@ -338,11 +384,11 @@ msgstr ""
"Reduz flicker para arestas de alto contraste.\n"
"Útil quando a resolução de entrada é alta comparada ao display do headset"
#: client/scenes/lobby_gui.cpp:834 client/scenes/stream_gui.cpp:510
#: client/scenes/lobby_gui.cpp:933 client/scenes/stream_gui.cpp:509
msgid "Sharpening"
msgstr "Aumento de nitidez"
#: client/scenes/lobby_gui.cpp:854 client/scenes/stream_gui.cpp:531
#: client/scenes/lobby_gui.cpp:953 client/scenes/stream_gui.cpp:530
msgid ""
"Improve clarity of high contrast edges and counteract blur.\n"
"Useful when the input resolution is low compared to the headset display"
@@ -350,129 +396,129 @@ msgstr ""
"Melhora a clareza de arestas de alto contraste e minimiza o desfoque.\n"
"Útil quando a resolução de entrada é baixa comparada ao display do headset"
#: client/scenes/lobby_gui.cpp:1038 client/scenes/lobby_gui.cpp:1046
#: client/scenes/stream_gui.cpp:172 client/scenes/stream_gui.cpp:374
#: client/scenes/lobby_gui.cpp:1137 client/scenes/lobby_gui.cpp:1145
#: client/scenes/stream_gui.cpp:172 client/scenes/stream_gui.cpp:373
msgid "CPU time"
msgstr "Tempo de CPU"
#: client/scenes/lobby_gui.cpp:1042
#: client/scenes/lobby_gui.cpp:1141
msgid "CPU time [ms]"
msgstr "Tempo de CPU [ms]"
#: client/scenes/lobby_gui.cpp:1052 client/scenes/lobby_gui.cpp:1060
#: client/scenes/stream_gui.cpp:174 client/scenes/stream_gui.cpp:375
#: client/scenes/lobby_gui.cpp:1151 client/scenes/lobby_gui.cpp:1159
#: client/scenes/stream_gui.cpp:174 client/scenes/stream_gui.cpp:374
msgid "GPU time"
msgstr "Tempo de GPU"
#: client/scenes/lobby_gui.cpp:1056
#: client/scenes/lobby_gui.cpp:1155
msgid "GPU time [ms]"
msgstr "Tempo de GPU [ms]"
#: client/scenes/lobby_gui.cpp:1120
#: client/scenes/lobby_gui.cpp:1219
msgid "Enable the microphone?"
msgstr "Habilitar o microfone?"
#: client/scenes/lobby_gui.cpp:1125
#: client/scenes/lobby_gui.cpp:1224
msgid "Enable eye tracking?"
msgstr "Habilitar o rastreamento ocular?"
#: client/scenes/lobby_gui.cpp:1130
#: client/scenes/lobby_gui.cpp:1229
msgid "Enable face tracking?"
msgstr "Habilitar o rastreamento facial?"
#: client/scenes/lobby_gui.cpp:1135
#: client/scenes/lobby_gui.cpp:1234
msgid "Enable body tracking?"
msgstr "Habilitar o rastreamento corporal?"
#: client/scenes/lobby_gui.cpp:1143
#: client/scenes/lobby_gui.cpp:1242
msgid "Welcome to WiVRn"
msgstr "Bem vindo(a) ao WiVRn"
#: client/scenes/lobby_gui.cpp:1171
#: client/scenes/lobby_gui.cpp:1270
msgid "Yes"
msgstr "Sim"
#: client/scenes/lobby_gui.cpp:1178
#: client/scenes/lobby_gui.cpp:1277
msgid "No"
msgstr "Não"
#: client/scenes/lobby_gui.cpp:1197 client/scenes/lobby_gui.cpp:1843
#: client/scenes/lobby_gui.cpp:1296 client/scenes/lobby_gui.cpp:1942
msgid "Licenses"
msgstr "Licenças"
#: client/scenes/lobby_gui.cpp:1473
#: client/scenes/lobby_gui.cpp:1572
msgid "Microphone is enabled"
msgstr "O microfone está ativado"
#: client/scenes/lobby_gui.cpp:1474
#: client/scenes/lobby_gui.cpp:1573
msgid "Microphone is disabled"
msgstr "O microfone está desativado"
#: client/scenes/lobby_gui.cpp:1483
#: client/scenes/lobby_gui.cpp:1582
msgid "Hand tracking is enabled"
msgstr "O rastreamento de mãos está ativado"
#: client/scenes/lobby_gui.cpp:1484
#: client/scenes/lobby_gui.cpp:1583
msgid "Hand tracking is disabled"
msgstr "O rastreamento de mãos está desativado"
#: client/scenes/lobby_gui.cpp:1493
#: client/scenes/lobby_gui.cpp:1592
msgid "Eye tracking is enabled"
msgstr "O rastreamento ocular está ativado"
#: client/scenes/lobby_gui.cpp:1494
#: client/scenes/lobby_gui.cpp:1593
msgid "Eye tracking is disabled"
msgstr "O rastreamento ocular está desativado"
#: client/scenes/lobby_gui.cpp:1504
#: client/scenes/lobby_gui.cpp:1603
msgid "Face tracking is enabled"
msgstr "O rastreamento facial está ativado"
#: client/scenes/lobby_gui.cpp:1505
#: client/scenes/lobby_gui.cpp:1604
msgid "Face tracking is disabled"
msgstr "O rastreamento facial está desativado"
#: client/scenes/lobby_gui.cpp:1519
#: client/scenes/lobby_gui.cpp:1618
msgid "Body tracking is enabled"
msgstr "O rastreamento corporal está ativado"
#: client/scenes/lobby_gui.cpp:1520
#: client/scenes/lobby_gui.cpp:1619
msgid "Body tracking is disabled"
msgstr "O rastreamento corporal está desativado"
#: client/scenes/lobby_gui.cpp:1536
#: client/scenes/lobby_gui.cpp:1635
msgid "Add server"
msgstr "Adicionar servidor"
#: client/scenes/lobby_gui.cpp:1822
#: client/scenes/lobby_gui.cpp:1921
msgid "Server list"
msgstr "Lista de servidores"
#: client/scenes/lobby_gui.cpp:1825 client/scenes/stream_gui.cpp:993
#: client/scenes/lobby_gui.cpp:1924 client/scenes/stream_gui.cpp:996
msgid "Settings"
msgstr "Ajustes"
#: client/scenes/lobby_gui.cpp:1828
#: client/scenes/lobby_gui.cpp:1927
msgid "Post-processing"
msgstr "Pós-processamento"
#: client/scenes/lobby_gui.cpp:1831
#: client/scenes/lobby_gui.cpp:1930
msgid "Customize"
msgstr "Personalizar"
#: client/scenes/lobby_gui.cpp:1835
#: client/scenes/lobby_gui.cpp:1934
msgid "Debug"
msgstr "Depurar"
#: client/scenes/lobby_gui.cpp:1840
#: client/scenes/lobby_gui.cpp:1939
msgid "About"
msgstr "Sobre"
#: client/scenes/lobby_gui.cpp:1846
#: client/scenes/lobby_gui.cpp:1945
msgid "Exit"
msgstr "Sair"
#: client/scenes/lobby_gui.cpp:1863
#: client/scenes/lobby_gui.cpp:1962
msgid ""
"Press the grip button or put your palm up\n"
"to move the main window"
@@ -480,7 +526,7 @@ msgstr ""
"Pressione o botão de aderência ou coloque a palma da mão para cima\n"
"para mover a janela principal"
#: client/scenes/lobby_gui.cpp:1865
#: client/scenes/lobby_gui.cpp:1964
msgid "Press the grip button to move the main window"
msgstr "Pressione o botão de aderência para mover a janela principal"
@@ -560,110 +606,106 @@ msgid "Open local glTF model"
msgstr "Abrir modelo local glTF"
#: client/scenes/stream_gui.cpp:174
msgid "Reproject"
msgstr "Reprojeção"
msgid "Defoveate"
msgstr "Defovear"
#: client/scenes/stream_gui.cpp:175
msgid "Blit"
msgstr "Blit"
#: client/scenes/stream_gui.cpp:177
#: client/scenes/stream_gui.cpp:176
msgid "Network"
msgstr "Rede"
#: client/scenes/stream_gui.cpp:177 client/scenes/stream_gui.cpp:372
#: client/scenes/stream_gui.cpp:176 client/scenes/stream_gui.cpp:371
msgid "Download"
msgstr "Download"
#: client/scenes/stream_gui.cpp:178 client/scenes/stream_gui.cpp:373
#: client/scenes/stream_gui.cpp:177 client/scenes/stream_gui.cpp:372
msgid "Upload"
msgstr "Upload"
#: client/scenes/stream_gui.cpp:247
#: client/scenes/stream_gui.cpp:246
#, c++-format
msgid "Decoder {}"
msgstr "Decodificador {}"
#: client/scenes/stream_gui.cpp:259
#: client/scenes/stream_gui.cpp:258
msgid "Timings [ms]"
msgstr "Tempos [ms]"
#: client/scenes/stream_gui.cpp:319
#: client/scenes/stream_gui.cpp:318
msgid "Encode"
msgstr "Codificação"
#: client/scenes/stream_gui.cpp:320
#: client/scenes/stream_gui.cpp:319
msgid "Send"
msgstr "Envio"
#: client/scenes/stream_gui.cpp:321
#: client/scenes/stream_gui.cpp:320
msgid "Receive"
msgstr "Recepção"
#: client/scenes/stream_gui.cpp:322
#: client/scenes/stream_gui.cpp:321
msgid "Decode"
msgstr "Decodificação"
#: client/scenes/stream_gui.cpp:323
#: client/scenes/stream_gui.cpp:322
msgid "Blitted"
msgstr "Blitagem"
#: client/scenes/stream_gui.cpp:324
#: client/scenes/stream_gui.cpp:323
msgid "Displayed"
msgstr "Exibição"
#: client/scenes/stream_gui.cpp:325
#: client/scenes/stream_gui.cpp:324
msgid "Predicted"
msgstr "Previsão"
#: client/scenes/stream_gui.cpp:345
#: client/scenes/stream_gui.cpp:344
#, c++-format
msgid "Estimated motion to photons latency: {}ms"
msgstr "Movimento estimado para a latência de fótons: {}ms"
#: client/scenes/stream_gui.cpp:352
#: client/scenes/stream_gui.cpp:351
msgid "Press the grip button to move the window"
msgstr "Pressione o botão de aderência para mover a janela"
#: client/scenes/stream_gui.cpp:354 client/scenes/stream_gui.cpp:921
#: client/scenes/stream_gui.cpp:353 client/scenes/stream_gui.cpp:924
msgid "Press both thumbsticks to display the WiVRn window"
msgstr "Pressione ambos os thumbsticks para mostrar a janela do WiVRn"
#: client/scenes/stream_gui.cpp:376
#: client/scenes/stream_gui.cpp:375
msgid "Motion to photon latency"
msgstr "Latência (de movimento para fótons)"
#: client/scenes/stream_gui.cpp:465
#: client/scenes/stream_gui.cpp:464
msgid "Bitrate:"
msgstr "Bitrate:"
#: client/scenes/stream_gui.cpp:475
#: client/scenes/stream_gui.cpp:474
msgid "Click to adjust bitrate"
msgstr "Clique para ajustar a bitrate"
#: client/scenes/stream_gui.cpp:538
#: client/scenes/stream_gui.cpp:537
msgid "Foveation center override"
msgstr "Ajuste do centro de foveação"
#: client/scenes/stream_gui.cpp:541
#: client/scenes/stream_gui.cpp:540
msgid "Enable"
msgstr "Habilitar"
#: client/scenes/stream_gui.cpp:549 client/scenes/stream_gui.cpp:617
#: client/scenes/stream_gui.cpp:548 client/scenes/stream_gui.cpp:620
#, c++-format
msgid "Height {:.1f} deg"
msgstr "Altura {:.1f} graus"
#: client/scenes/stream_gui.cpp:550 client/scenes/stream_gui.cpp:618
#: client/scenes/stream_gui.cpp:549 client/scenes/stream_gui.cpp:621
#, c++-format
msgid "Distance {:.2f} m"
msgstr "Distância {:.2f} m"
#: client/scenes/stream_gui.cpp:551
#: client/scenes/stream_gui.cpp:550
msgid "Default"
msgstr "Padrão"
#: client/scenes/stream_gui.cpp:562
#: client/scenes/stream_gui.cpp:561
msgid "Change"
msgstr "Modificar"
@@ -680,43 +722,43 @@ msgstr "Pressione A para voltar"
msgid "Bitrate: {}Mbit/s"
msgstr "Bitrate: {}Mbit/s"
#: client/scenes/stream_gui.cpp:615
#: client/scenes/stream_gui.cpp:618
msgid "Use the thumbsticks to move the foveation center"
msgstr "Use os thumbsticks para mover o centro da foveação"
#: client/scenes/stream_gui.cpp:616
#: client/scenes/stream_gui.cpp:619
msgid "Press A to save or B to cancel"
msgstr "Pressione A para salvar ou B para cancelar"
#: client/scenes/stream_gui.cpp:674
#: client/scenes/stream_gui.cpp:677
msgid "Running XR applications:"
msgstr "Aplicativos XR rodando:"
#: client/scenes/stream_gui.cpp:691
#: client/scenes/stream_gui.cpp:694
msgid "Overlays"
msgstr "Overlays"
#: client/scenes/stream_gui.cpp:730
#: client/scenes/stream_gui.cpp:733
msgid "Request to quit, may be ignored by the application"
msgstr "Requisição para sair, pode ser ignorada pelo aplicativo"
#: client/scenes/stream_gui.cpp:980
#: client/scenes/stream_gui.cpp:983
msgid "Applications"
msgstr "Aplicativos"
#: client/scenes/stream_gui.cpp:983
#: client/scenes/stream_gui.cpp:986
msgid "Start"
msgstr "Iniciar"
#: client/scenes/stream_gui.cpp:996
#: client/scenes/stream_gui.cpp:999
msgid "Stats"
msgstr "Estatísticas"
#: client/scenes/stream_gui.cpp:1002
#: client/scenes/stream_gui.cpp:1005
msgid "Statistics overlay"
msgstr "Overlay de estatísticas"
#: client/scenes/stream_gui.cpp:1005
#: client/scenes/stream_gui.cpp:1008
msgid "Compact view"
msgstr "Visualização compacta"
@@ -736,6 +778,15 @@ msgstr "Incapaz de verificar PIN"
msgid "Pairing is disabled on server"
msgstr "Pareamento está desabilitado no servidor"
#~ msgid "Resolution scale"
#~ msgstr "Escala de resolução"
#~ msgid "Reproject"
#~ msgstr "Reprojeção"
#~ msgid "Blit"
#~ msgstr "Blit"
#, c++-format
#~ msgid "HTTP error {} when downloading index.json"
#~ msgstr "Erro de HTTP {} ao baixar index.json"
@@ -1,7 +1,7 @@
From 253c8071648498da89536556db9154e3941b4d41 Mon Sep 17 00:00:00 2001
From 4dc055eccff32e27da9e332ab6f380eb199d9e2c Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 22 Oct 2024 15:23:19 +0200
Subject: [PATCH 1/6] c/multi: early wake of compositor
Subject: [PATCH 1/7] c/multi: early wake of compositor
---
.../compositor/multi/comp_multi_compositor.c | 14 +++++++++
@@ -51,7 +51,7 @@ index 3351defa4..e8f0c8295 100644
{
int64_t predicted_display_time_ns;
diff --git a/src/xrt/compositor/multi/comp_multi_system.c b/src/xrt/compositor/multi/comp_multi_system.c
index 199025a13..35ca4aa29 100644
index 4db923457..80cbbbc26 100644
--- a/src/xrt/compositor/multi/comp_multi_system.c
+++ b/src/xrt/compositor/multi/comp_multi_system.c
@@ -24,6 +24,8 @@
@@ -93,7 +93,7 @@ index 199025a13..35ca4aa29 100644
}
static void
@@ -529,10 +538,13 @@ multi_main_loop(struct multi_system_compositor *msc)
@@ -530,10 +539,13 @@ multi_main_loop(struct multi_system_compositor *msc)
broadcast_timings_to_clients(msc, predicted_display_time_ns);
// Now we can wait.
@@ -109,7 +109,7 @@ index 199025a13..35ca4aa29 100644
// Now we know the diff, broadcast to pacers.
broadcast_timings_to_pacers(msc, predicted_display_time_ns, predicted_display_period_ns, diff_ns);
@@ -718,6 +730,8 @@ system_compositor_destroy(struct xrt_system_compositor *xsc)
@@ -721,6 +733,8 @@ system_compositor_destroy(struct xrt_system_compositor *xsc)
xrt_comp_native_destroy(&msc->xcn);
os_mutex_destroy(&msc->list_and_timing_lock);
@@ -118,7 +118,7 @@ index 199025a13..35ca4aa29 100644
free(msc);
}
@@ -772,6 +786,8 @@ comp_multi_create_system_compositor(struct xrt_compositor_native *xcn,
@@ -775,6 +789,8 @@ comp_multi_create_system_compositor(struct xrt_compositor_native *xcn,
msc->sessions.state = do_warm_start ? MULTI_SYSTEM_STATE_INIT_WARM_START : MULTI_SYSTEM_STATE_STOPPED;
os_mutex_init(&msc->list_and_timing_lock);
@@ -1,7 +1,7 @@
From 543a4b3aefdbfab45a881129e539bb57fa43646e Mon Sep 17 00:00:00 2001
From 99c1547e6cc41db4c55c72892b46878a22b4c3a9 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 8 Oct 2024 22:13:15 +0200
Subject: [PATCH 2/6] Use extern socket fd
Subject: [PATCH 2/7] Use extern socket fd
---
src/xrt/ipc/server/ipc_server_mainloop_linux.c | 8 ++++++++
@@ -1,14 +1,14 @@
From a2dd5416fea5e97931b91dddf82b4431d8908939 Mon Sep 17 00:00:00 2001
From 92dae610f58935a3db4ff46d0fcf9cf18cd10e21 Mon Sep 17 00:00:00 2001
From: galister <85970-galister@users.noreply.gitlab.freedesktop.org>
Date: Sat, 23 Nov 2024 02:42:12 +0900
Subject: [PATCH 3/6] change environment blend mode selection logic
Subject: [PATCH 3/7] change environment blend mode selection logic
---
src/xrt/compositor/multi/comp_multi_system.c | 26 +++++++++++++-------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/xrt/compositor/multi/comp_multi_system.c b/src/xrt/compositor/multi/comp_multi_system.c
index 35ca4aa29..1d162a45d 100644
index 80cbbbc26..4a397d7ec 100644
--- a/src/xrt/compositor/multi/comp_multi_system.c
+++ b/src/xrt/compositor/multi/comp_multi_system.c
@@ -233,23 +233,31 @@ find_active_blend_mode(struct multi_compositor **overlay_sorted_clients, size_t
@@ -1,7 +1,7 @@
From 58d2c3f51a6c1b4fcad4c5e23c267931e0ef5580 Mon Sep 17 00:00:00 2001
From 5f278ee8a2234bb7a8463b8c028ffd9454cbe30a Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Sat, 15 Mar 2025 22:19:48 +0100
Subject: [PATCH 4/6] st/oxr: forward 0 refresh rate
Subject: [PATCH 4/7] st/oxr: forward 0 refresh rate
---
src/xrt/compositor/main/comp_compositor.c | 2 +-
@@ -1,7 +1,7 @@
From ddae46a3ef27f71172be70de4bdf99be7d65ee36 Mon Sep 17 00:00:00 2001
From 8d3fb92d6436b0111185682d7e99b7d2ec040724 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Wed, 11 Sep 2024 22:56:29 +0200
Subject: [PATCH 5/6] Replace distortion with foveation
Subject: [PATCH 5/7] Replace distortion with foveation
---
src/xrt/compositor/CMakeLists.txt | 4 +-
@@ -11,15 +11,15 @@ Subject: [PATCH 5/6] Replace distortion with foveation
src/xrt/compositor/render/render_interface.h | 95 ++--
src/xrt/compositor/render/render_resources.c | 106 ++---
src/xrt/compositor/shaders/clear.comp | 4 +-
src/xrt/compositor/shaders/distortion.comp | 180 ++++----
src/xrt/compositor/shaders/distortion.comp | 182 ++++----
.../compositor/util/comp_high_level_render.c | 6 +-
.../compositor/util/comp_high_level_render.h | 9 +-
src/xrt/compositor/util/comp_render.h | 11 +-
src/xrt/compositor/util/comp_render_cs.c | 112 ++---
12 files changed, 354 insertions(+), 592 deletions(-)
12 files changed, 356 insertions(+), 592 deletions(-)
diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt
index 1ba5ec438..eb068f5fc 100644
index 1ba5ec438..7435a9ce3 100644
--- a/src/xrt/compositor/CMakeLists.txt
+++ b/src/xrt/compositor/CMakeLists.txt
@@ -105,7 +105,7 @@ if(XRT_HAVE_VULKAN)
@@ -41,10 +41,10 @@ index 1ba5ec438..eb068f5fc 100644
render/render_interface.h
render/render_resources.c
diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c
index 51a14e9fc..2cbdc5e68 100644
index 16c16fd7a..40b219cef 100644
--- a/src/xrt/compositor/main/comp_renderer.c
+++ b/src/xrt/compositor/main/comp_renderer.c
@@ -991,7 +991,8 @@ dispatch_compute(struct comp_renderer *r,
@@ -1005,7 +1005,8 @@ dispatch_compute(struct comp_renderer *r,
// Target Vulkan resources..
VkImage target_image = r->c->target->images[r->acquired_buffer].handle;
@@ -54,7 +54,7 @@ index 51a14e9fc..2cbdc5e68 100644
// Target view information.
struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS];
@@ -1008,7 +1009,8 @@ dispatch_compute(struct comp_renderer *r,
@@ -1022,7 +1023,8 @@ dispatch_compute(struct comp_renderer *r,
eye_poses, //
fovs, //
target_image, //
@@ -1094,10 +1094,10 @@ index 1f0e732b8..e02307415 100644
+ imageStore(target, ivec3(offset.x + ix, offset.y + iy, 0), colour);
}
diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp
index 0b28d8bf3..41de849e6 100644
index 0b28d8bf3..df2b612b0 100644
--- a/src/xrt/compositor/shaders/distortion.comp
+++ b/src/xrt/compositor/shaders/distortion.comp
@@ -4,136 +4,104 @@
@@ -4,136 +4,106 @@
#version 460
#extension GL_GOOGLE_include_directive : require
@@ -1171,17 +1171,6 @@ index 0b28d8bf3..41de849e6 100644
-}
-
-vec2 transform_uv_subimage(vec2 uv, uint iz)
-{
- vec2 values = uv;
-
- // To deal with OpenGL flip and sub image view.
- values.xy = values.xy * ubo.post_transform[iz].zw + ubo.post_transform[iz].xy;
-
- // Ready to be used.
- return values.xy;
-}
-
-vec2 transform_uv_timewarp(vec2 uv, uint iz)
+ mat4 transform[2];
+} ubo;
+layout(set = 0, binding = 4) uniform writeonly restrict image2DArray chroma;
@@ -1196,6 +1185,17 @@ index 0b28d8bf3..41de849e6 100644
+
+vec3 rgb_to_ycbcr(vec3 color)
{
- vec2 values = uv;
-
- // To deal with OpenGL flip and sub image view.
- values.xy = values.xy * ubo.post_transform[iz].zw + ubo.post_transform[iz].xy;
-
- // Ready to be used.
- return values.xy;
-}
-
-vec2 transform_uv_timewarp(vec2 uv, uint iz)
-{
- vec4 values = vec4(uv, -1, 1);
-
- // From uv to tan angle (tangent space).
@@ -1231,7 +1231,7 @@ index 0b28d8bf3..41de849e6 100644
uint iz = gl_GlobalInvocationID.z;
ivec2 offset = ivec2(ubo.views[iz].xy);
ivec2 extent = ivec2(ubo.views[iz].zw);
- ivec2 extent = ivec2(ubo.views[iz].zw);
-
- if (ix >= extent.x || iy >= extent.y) {
+ uint iy = gl_GlobalInvocationID.y;
@@ -1252,27 +1252,24 @@ index 0b28d8bf3..41de849e6 100644
- vec2 r_uv = texture(distortion[iz + 0], dist_uv).xy;
- vec2 g_uv = texture(distortion[iz + 2], dist_uv).xy;
- vec2 b_uv = texture(distortion[iz + 4], dist_uv).xy;
-
- // Do any transformation needed.
- r_uv = transform_uv(r_uv, iz);
- g_uv = transform_uv(g_uv, iz);
- b_uv = transform_uv(b_uv, iz);
+ uint xmin = foveation.x[MAX_DIM * iz + ix];
+ uint xmax = foveation.x[MAX_DIM * iz + ix + 1];
+ if (xmin == xmax)
+ return;
- // Do any transformation needed.
- r_uv = transform_uv(r_uv, iz);
- g_uv = transform_uv(g_uv, iz);
- b_uv = transform_uv(b_uv, iz);
+ uint xstep = (xmax - xmin + MAX_SAMPLES - 1) / MAX_SAMPLES;
+ uint ystep = (ymax - ymin + MAX_SAMPLES - 1) / MAX_SAMPLES;
- // Sample the source with distorted and chromatic-aberration corrected samples.
- vec4 colour = vec4( //
- texture(source[iz], r_uv).r, //
- texture(source[iz], g_uv).g, //
- texture(source[iz], b_uv).b, //
- 1); //
+ uint xstep = (xmax - xmin + MAX_SAMPLES - 1) / MAX_SAMPLES;
+ uint ystep = (ymax - ymin + MAX_SAMPLES - 1) / MAX_SAMPLES;
- // Do colour correction here since there are no automatic conversion in hardware available.
- colour = vec4(from_linear_to_srgb(colour.rgb), 1);
+ vec4 colour = vec4(0);
+ uint count = 0;
+ for (uint y = ymin ; y < ymax; y += ystep) {
@@ -1284,7 +1281,7 @@ index 0b28d8bf3..41de849e6 100644
+ colour /= count;
+ colour.xyz = rgb_to_ycbcr(from_linear_to_srgb(colour.rgb));
+
+ imageStore(luma, ivec3(offset.x + ix, offset.y + iy, 0), vec4(colour.x));
+ imageStore(luma, ivec3(ix, iy, iz), vec4(colour.x));
+
+ vec4 sum = colour;
+ for (uint i = 0 ; i < gl_SubgroupSize; ++i)
@@ -1300,12 +1297,17 @@ index 0b28d8bf3..41de849e6 100644
+ }
+ }
- imageStore(target, ivec2(offset.x + ix, offset.y + iy), colour);
- // Do colour correction here since there are no automatic conversion in hardware available.
- colour = vec4(from_linear_to_srgb(colour.rgb), 1);
+ if (ix %2 == 0 && iy %2 == 0)
+ {
+ imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy/2, 0), vec4(sum.y, sum.z, 0, 0) / 4);
+ imageStore(luma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy/2, 1), vec4(sum.w, 0, 0, 0) / 4);
+ imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy/2, 1), vec4(0.5, 0.5, 0, 0));
+ // actual chroma
+ imageStore(chroma, ivec3(gl_GlobalInvocationID.xy/2, iz), vec4(sum.y, sum.z, 0, 0) / 4);
- imageStore(target, ivec2(offset.x + ix, offset.y + iy), colour);
+ // alpha in luma
+ imageStore(luma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy/2, 2), vec4(sum.w, 0, 0, 0) / 4);
+ imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy/2, 2), vec4(0.5, 0.5, 0, 0));
+ }
}
diff --git a/src/xrt/compositor/util/comp_high_level_render.c b/src/xrt/compositor/util/comp_high_level_render.c
@@ -1,14 +1,14 @@
From e0cacca9e23baee0cc7bda8133e3e49357fe132f Mon Sep 17 00:00:00 2001
From 202b9acfb598ab61f75d8cb7aa9c9cb08460674b Mon Sep 17 00:00:00 2001
From: no name <git-am@invalid>
Date: Sun, 28 Sep 2025 11:33:10 +0200
Subject: [PATCH 6/6] d/steamvr_lh: prevent crash on vive pro2/WiVRn
Subject: [PATCH 6/7] d/steamvr_lh: prevent crash on vive pro2/WiVRn
---
src/xrt/drivers/steamvr_lh/steamvr_lh.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/xrt/drivers/steamvr_lh/steamvr_lh.cpp b/src/xrt/drivers/steamvr_lh/steamvr_lh.cpp
index c63c14529..2e7b247e6 100644
index 111a4d225..cdc06d0a7 100644
--- a/src/xrt/drivers/steamvr_lh/steamvr_lh.cpp
+++ b/src/xrt/drivers/steamvr_lh/steamvr_lh.cpp
@@ -895,7 +895,7 @@ steamvr_lh_create_devices(struct xrt_prober *xp, struct xrt_system_devices **out
@@ -1,7 +1,7 @@
From 6f7304dee78dcbf0b485177465d10b4878668ede Mon Sep 17 00:00:00 2001
From 0bce153782cc0fedcdbf997afa2da81b4efe92e8 Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Fri, 7 Nov 2025 20:41:16 -0600
Subject: [PATCH] st/oxr: push XrEventDataInteractionProfileChanged when
Subject: [PATCH 7/7] st/oxr: push XrEventDataInteractionProfileChanged when
profile changes to NULL
---
+16 -22
View File
@@ -140,11 +140,6 @@ configuration::encoder parse_encoder(const nlohmann::json & item)
if (item.contains(#property)) \
e.property = item[#property];
SET_IF(width);
SET_IF(height);
SET_IF(offset_x);
SET_IF(offset_y);
SET_IF(group);
SET_IF(codec);
if (e.codec == wivrn::video_codec(-1))
throw std::runtime_error("invalid codec value " + item["codec"].get<std::string>());
@@ -159,31 +154,30 @@ configuration::configuration()
{
auto json = read_configuration();
if (auto it = json.find("scale"); it != json.end())
{
if (it->is_number())
scale = std::array<double, 2>{*it, *it};
else
scale = *it;
}
if (auto it = json.find("grip-surface"); it != json.end())
{
grip_surface = *it;
}
if (auto it = json.find("bitrate"); it != json.end())
bitrate = *it;
if (auto it = json.find("encoders"); it != json.end())
if (auto it = json.find("encoder"); it != json.end())
{
for (const auto & encoder: *it)
encoders.push_back(parse_encoder(encoder));
if (it->is_array())
{
for (size_t i = 0; i < std::min(encoders.size(), it->size()); ++i)
{
encoders[i] = parse_encoder(it->at(i));
}
}
else if (it->is_string())
{
std::ranges::fill(encoders, encoder{.name = *it});
}
else
{
std::ranges::fill(encoders, parse_encoder(*it));
}
}
if (auto it = json.find("encoder-passthrough"); it != json.end())
encoder_passthrough = parse_encoder(*it);
if (auto it = json.find("application"); it != json.end())
{
if (it->is_string())
+2 -10
View File
@@ -44,21 +44,13 @@ struct configuration
struct encoder
{
std::string name;
std::optional<double> width;
std::optional<double> height;
std::optional<double> offset_x;
std::optional<double> offset_y;
std::optional<int> group;
std::optional<wivrn::video_codec> codec;
std::map<std::string, std::string> options;
std::optional<std::string> device;
};
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::array<encoder, 3> encoders; // left, right, alpha
std::optional<uint8_t> bit_depth;
std::optional<std::array<float, 3>> grip_surface;
std::vector<std::string> application;
bool debug_gui = false;
+24 -32
View File
@@ -31,6 +31,7 @@
#include "xrt_cast.h"
#include <algorithm>
#include <ranges>
#include <vector>
#include <vulkan/vulkan.hpp>
#include <vulkan/vulkan_core.h>
@@ -80,10 +81,10 @@ static inline struct vk_bundle * get_vk(struct wivrn_comp_target * cn)
return &cn->c->base.vk;
}
static float get_default_rate(const from_headset::headset_info_packet & info)
static float get_default_rate(const from_headset::headset_info_packet & info, const from_headset::settings_changed & settings)
{
if (info.preferred_refresh_rate)
return info.preferred_refresh_rate;
if (settings.preferred_refresh_rate)
return settings.preferred_refresh_rate;
return info.available_refresh_rates.back();
}
@@ -143,25 +144,17 @@ static void create_encoders(wivrn_comp_target * cn)
to_headset::video_stream_description & desc = cn->desc;
desc.width = cn->width;
desc.height = cn->height;
const auto & hmd = cn->cnx.get_hmd().hmd;
desc.defoveated_width = hmd->views[0].display.w_pixels * 2;
desc.defoveated_height = hmd->views[0].display.h_pixels;
std::map<int, std::vector<std::shared_ptr<video_encoder>>> thread_params;
uint32_t bitrate = 0;
for (auto & settings: cn->settings)
for (auto [i, settings]: std::ranges::enumerate_view(cn->settings))
{
bitrate += settings.bitrate;
uint8_t stream_index = cn->encoders.size();
auto & encoder = cn->encoders.emplace_back(
video_encoder::create(*cn->wivrn_bundle, settings, stream_index, desc.width, desc.height, desc.fps));
desc.items.push_back(settings);
video_encoder::create(*cn->wivrn_bundle, settings, i));
desc.codec[i] = settings.codec;
thread_params[settings.group].emplace_back(encoder);
}
wivrn_ipc_socket_monado->send(from_monado::bitrate_changed{bitrate});
for (auto & [group, params]: thread_params)
{
@@ -204,7 +197,7 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 2, // colour then alpha
.arrayLayers = 3, // left, right then alpha
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = flags | vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eTransferSrc,
@@ -218,10 +211,10 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
#if WIVRN_USE_VULKAN_ENCODE
if (
vk->features.video_maintenance_1 and
std::ranges::any_of(
std::ranges::contains(
cn->settings,
[](const auto & item) { return item.encoder_name == encoder_vulkan //
and item.offset_x == 0 and item.offset_y == 0; }))
encoder_vulkan,
&encoder_settings::encoder_name))
{
image_info.get().flags |= vk::ImageCreateFlagBits::eVideoProfileIndependentKHR;
image_info.get().usage |= vk::ImageUsageFlagBits::eVideoEncodeSrcKHR;
@@ -255,7 +248,7 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
.levelCount = 1,
.layerCount = 2,
.layerCount = vk::RemainingArrayLayers,
},
});
item.image_view_cbcr = vk::raii::ImageView(device,
@@ -267,7 +260,7 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.levelCount = 1,
.layerCount = 2,
.layerCount = vk::RemainingArrayLayers,
},
});
cn->images[i].view = VkImageView(*item.image_view_y);
@@ -319,10 +312,12 @@ static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t prefer
{
cn->settings = get_encoder_settings(
*cn->wivrn_bundle,
cn->c->settings.preferred.width,
cn->c->settings.preferred.height,
cn->cnx.get_info());
cn->cnx.get_info(),
*cn->cnx.get_settings());
print_encoders(cn->settings);
cn->c->settings.preferred.width = cn->settings[0].width;
cn->c->settings.preferred.height = cn->settings[0].height;
}
catch (const std::exception & e)
{
@@ -491,7 +486,7 @@ static void comp_wivrn_present_thread(std::stop_token stop_token, wivrn_comp_tar
{
for (auto & encoder: encoders)
{
if (encoder->channels == to_headset::video_stream_description::channels_t::colour or view_info.alpha)
if (encoder->stream_idx < 2 or view_info.alpha)
encoder->encode(cn->cnx, view_info, frame_index);
}
}
@@ -572,7 +567,7 @@ static VkResult comp_wivrn_present(struct comp_target * ct,
std::vector<vk::Semaphore> present_done_sem;
for (auto & encoder: cn->encoders)
{
if (encoder->channels == to_headset::video_stream_description::channels_t::alpha and not do_alpha)
if (encoder->stream_idx == 2 and not do_alpha)
continue;
auto [transfer, sem] = encoder->present_image(psc_image.image, command_buffer, info.frame_id);
need_queue_transfer |= transfer;
@@ -595,7 +590,7 @@ static VkResult comp_wivrn_present(struct comp_target * ct,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 2},
.layerCount = vk::RemainingArrayLayers},
};
command_buffer.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer,
@@ -615,7 +610,7 @@ static VkResult comp_wivrn_present(struct comp_target * ct,
cn->wivrn_bundle->queue.submit(submit_info, *cn->psc.fence);
for (auto & encoder: cn->encoders)
{
if (encoder->channels == to_headset::video_stream_description::channels_t::alpha and not do_alpha)
if (encoder->stream_idx == 2 and not do_alpha)
continue;
encoder->post_submit();
}
@@ -794,7 +789,7 @@ static xrt_result_t comp_wivrn_request_refresh_rate(struct comp_target * ct, flo
struct wivrn_comp_target * cn = (struct wivrn_comp_target *)ct;
cn->requested_refresh_rate = refresh_rate_hz;
if (refresh_rate_hz == 0.0f)
refresh_rate_hz = get_default_rate(cn->cnx.get_info());
refresh_rate_hz = get_default_rate(cn->cnx.get_info(), *cn->cnx.get_settings());
cn->cnx.send_control(to_headset::refresh_rate_change{.fps = refresh_rate_hz});
return XRT_SUCCESS;
@@ -840,14 +835,11 @@ void wivrn_comp_target::reset_encoders()
void wivrn_comp_target::set_bitrate(uint32_t bitrate_bps)
{
bitrate = 0;
for (auto & encoder: encoders)
{
// Alpha will have multiplier of 0 and will be left unchanged.
auto encoder_bps = (uint32_t)(bitrate_bps * encoder->bitrate_multiplier);
U_LOG_D("Encoder %d bitrate: %d", encoder->stream_idx, encoder_bps);
encoder->set_bitrate(encoder_bps);
bitrate += encoder_bps;
}
}
@@ -882,7 +874,7 @@ wivrn_comp_target::wivrn_comp_target(wivrn::wivrn_session & cnx, struct comp_com
.request_refresh_rate = comp_wivrn_request_refresh_rate,
.destroy = comp_wivrn_destroy,
},
desc{.fps = get_default_rate(cnx.get_info())},
desc{.fps = get_default_rate(cnx.get_info(), *cnx.get_settings())},
pacer(U_TIME_1S_IN_NS / desc.fps),
cnx(cnx)
{
+1 -2
View File
@@ -93,8 +93,7 @@ struct wivrn_comp_target : public comp_target
static std::vector<const char *> wanted_instance_extensions;
static std::vector<const char *> wanted_device_extensions;
uint32_t bitrate = 0;
std::vector<encoder_settings> settings;
std::array<encoder_settings, 3> settings;
std::list<std::jthread> encoder_threads;
std::vector<std::shared_ptr<video_encoder>> encoders;
+2 -2
View File
@@ -55,7 +55,7 @@ private:
std::string pin;
encryption_state state;
wivrn::from_headset::headset_info_packet info_packet;
from_headset::headset_info_packet info_packet;
void init(std::stop_token stop_token, std::function<void()> tick = []() {});
@@ -113,7 +113,7 @@ public:
std::optional<from_headset::packets> poll_control(int timeout);
wivrn::from_headset::headset_info_packet & info()
const from_headset::headset_info_packet & info()
{
return info_packet;
}
+1 -1
View File
@@ -302,7 +302,7 @@ void wivrn_foveation::compute_params(
}
wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts & hmd) :
foveated_width(hmd.screens[0].w_pixels / 2),
foveated_width(hmd.screens[0].w_pixels),
foveated_height(hmd.screens[0].h_pixels),
angle_offset(get_angle_offset()),
convergence_distance(get_convergence_distance()),
+6 -8
View File
@@ -90,9 +90,9 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
{
const auto config = configuration();
auto eye_width = info.recommended_eye_width;
auto eye_width = info.render_eye_width;
eye_width = ((eye_width + 3) / 4) * 4;
auto eye_height = info.recommended_eye_height;
auto eye_height = info.render_eye_height;
eye_height = ((eye_height + 3) / 4) * 4;
// Setup info.
@@ -103,7 +103,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
hmd->distortion.models = XRT_DISTORTION_MODEL_NONE;
hmd->distortion.preferred = XRT_DISTORTION_MODEL_NONE;
hmd->screens[0].w_pixels = eye_width * 2;
hmd->screens[0].w_pixels = eye_width;
hmd->screens[0].h_pixels = eye_height;
// Left
@@ -208,19 +208,17 @@ xrt_result_t wivrn_hmd::get_battery_status(bool * out_present,
void wivrn_hmd::set_foveated_size(uint32_t width, uint32_t height)
{
assert(width % 2 == 0);
uint32_t eye_width = width / 2;
hmd->screens[0].w_pixels = width;
hmd->screens[0].h_pixels = height;
for (int i = 0; i < 2; ++i)
{
auto & view = hmd->views[i];
view.viewport.x_pixels = i * eye_width;
// offset is only applicable for alpha channel
view.viewport.x_pixels = i * width;
view.viewport.y_pixels = 0;
view.viewport.w_pixels = eye_width;
view.viewport.w_pixels = width;
view.viewport.h_pixels = height;
}
}
+18 -34
View File
@@ -155,7 +155,8 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
left_controller(XRT_DEVICE_TOUCH_CONTROLLER, 0, &hmd, this),
right_controller(XRT_DEVICE_TOUCH_CONTROLLER, 1, &hmd, this),
left_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 0, &hmd, this),
right_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 1, &hmd, this)
right_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 1, &hmd, this),
settings(get_info().settings)
{
try
{
@@ -430,22 +431,9 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
U_LOG_W("unexpected headset info packet, ignoring");
}
void wivrn_session::operator()(from_headset::settings_request &&)
{
to_headset::settings settings{};
{
std::lock_guard lock(comp_target_mutex);
if (comp_target)
settings.bitrate_bps = comp_target->bitrate;
}
send_control(std::move(settings));
}
void wivrn_session::operator()(from_headset::settings_changed && settings)
{
connection->info().preferred_refresh_rate = settings.preferred_refresh_rate;
connection->info().minimum_refresh_rate = settings.minimum_refresh_rate;
*this->settings.lock() = settings;
if (settings.bitrate_bps != 0)
{
@@ -453,6 +441,8 @@ void wivrn_session::operator()(from_headset::settings_changed && settings)
if (comp_target)
comp_target->set_bitrate(settings.bitrate_bps);
}
wivrn_ipc_socket_monado->send(std::move(settings));
}
static xrt_device_name get_name(interaction_profile profile)
@@ -957,18 +947,9 @@ void wivrn_session::operator()(to_monado::disconnect &&)
void wivrn_session::operator()(to_monado::set_bitrate && data)
{
bool send_settings = false;
{
std::shared_lock lock(comp_target_mutex);
if (comp_target)
{
comp_target->set_bitrate(data.bitrate_bps);
send_settings = true;
}
}
if (send_settings)
(*this)(from_headset::settings_request{});
std::shared_lock lock(comp_target_mutex);
if (comp_target)
comp_target->set_bitrate(data.bitrate_bps);
}
struct refresh_rate_adjuster
@@ -976,16 +957,20 @@ struct refresh_rate_adjuster
std::chrono::seconds period{10};
std::chrono::steady_clock::time_point next = std::chrono::steady_clock::now() + period;
pacing_app_factory & pacers;
from_headset::headset_info_packet & info;
const from_headset::headset_info_packet & info;
thread_safe<from_headset::settings_changed> & settings;
float last = 0;
refresh_rate_adjuster(from_headset::headset_info_packet & info, pacing_app_factory & pacers) :
refresh_rate_adjuster(const from_headset::headset_info_packet & info, thread_safe<from_headset::settings_changed> & settings, pacing_app_factory & pacers) :
pacers(pacers),
info(info) {}
info(info),
settings(settings)
{}
void adjust(wivrn_connection & cnx)
{
if (info.preferred_refresh_rate != 0 or info.available_refresh_rates.size() < 2 or std::chrono::steady_clock::now() < next)
auto locked = settings.lock();
if (locked->preferred_refresh_rate != 0 or info.available_refresh_rates.size() < 2 or std::chrono::steady_clock::now() < next)
return;
// Maximum refresh rate the application can reach
@@ -995,7 +980,7 @@ struct refresh_rate_adjuster
auto requested = info.available_refresh_rates.back();
for (auto rate: info.available_refresh_rates)
{
if (rate > info.minimum_refresh_rate and rate < app_rate * (rate == last ? 1. : 0.9))
if (rate > locked->minimum_refresh_rate and rate < app_rate * (rate == last ? 1. : 0.9))
requested = rate;
}
if (requested != last)
@@ -1015,7 +1000,7 @@ struct refresh_rate_adjuster
void wivrn_session::run(std::stop_token stop)
{
refresh_rate_adjuster refresh(connection->info(), app_pacers);
refresh_rate_adjuster refresh(connection->info(), settings, app_pacers);
while (not stop.stop_requested())
{
try
@@ -1116,7 +1101,6 @@ void wivrn_session::reconnect()
if (audio_handle)
send_control(audio_handle->description());
(*this)(from_headset::settings_request{});
event.state.visible = true;
event.state.focused = true;
result = push_event(event);
+8 -1
View File
@@ -139,6 +139,9 @@ class wivrn_session : public xrt_system_devices
std::shared_ptr<audio_device> audio_handle;
// run-time editable settings
thread_safe<from_headset::settings_changed> settings;
// when sessions shall be destroyed, key is timestap, value is client id
thread_safe<std::map<int64_t, int32_t>> session_loss;
@@ -165,6 +168,11 @@ public:
return connection->info();
};
locked<from_headset::settings_changed> get_settings()
{
return settings.lock();
}
void unset_comp_target();
wivrn_hmd & get_hmd()
@@ -185,7 +193,6 @@ public:
void operator()(from_headset::pin_check_1 &&) {}
void operator()(from_headset::pin_check_3 &&) {}
void operator()(from_headset::headset_info_packet &&);
void operator()(from_headset::settings_request &&);
void operator()(from_headset::settings_changed &&);
void operator()(from_headset::handshake &&) {}
void operator()(from_headset::trackings &&);
+194 -334
View File
@@ -24,8 +24,6 @@
#include "video_encoder.h"
#include "wivrn_packets.h"
#include <charconv>
#include <cmath>
#include <magic_enum.hpp>
#include <string>
#include <vulkan/vulkan.h>
@@ -42,27 +40,17 @@
namespace wivrn
{
// TODO: size independent bitrate
static const uint64_t default_bitrate = 50'000'000;
// subsampling is also in monado's distortion shader
static const uint8_t passthrough_subsampling = 2;
static const double passthrough_bitrate_factor = 0.05;
#define WIVRN_SPLIT_ENCODERS 1
static bool is_nvidia(vk::PhysicalDevice physical_device)
{
auto props = physical_device.getProperties();
return props.vendorID == 0x10DE;
}
static void split_bitrate(std::vector<wivrn::encoder_settings> & encoders, uint64_t bitrate)
static void split_bitrate(std::array<wivrn::encoder_settings, 3> & encoders, uint64_t bitrate)
{
double total_weight = 0;
for (auto & encoder: encoders)
for (auto [i, encoder]: std::ranges::enumerate_view(encoders))
{
double w = encoder.width * encoder.height;
if (i == 2)
w *= passthrough_bitrate_factor;
switch (encoder.codec)
{
case wivrn::h264:
@@ -84,7 +72,7 @@ static void split_bitrate(std::vector<wivrn::encoder_settings> & encoders, uint6
}
}
void print_encoders(const std::vector<wivrn::encoder_settings> & encoders)
void print_encoders(const std::array<wivrn::encoder_settings, 3> & encoders)
{
int group = -1;
std::stringstream str;
@@ -98,378 +86,250 @@ void print_encoders(const std::vector<wivrn::encoder_settings> & encoders)
}
else
str << "\n";
str << "\n\t\t" << encoder.encoder_name << " (" << magic_enum::enum_name(encoder.codec) << " " << encoder.bit_depth << "-bit)"
<< "\n\t\tchannels: " << magic_enum::enum_name(encoder.channels)
<< "\n\t\tsize: " << encoder.width << "x" << encoder.height << " offset: " << encoder.offset_x << "x" << encoder.offset_y
<< "\n\t\tbitrate: " << encoder.bitrate / 1'000'000 << "Mbit/s";
<< "\n\t\tsize: " << encoder.width << "x" << encoder.height
<< "\n\t\tbitrate: " << int(encoder.bitrate / 100'000) / 10. << "Mbit/s";
}
U_LOG_I("%s", str.str().c_str());
}
static void check_scale(std::string_view encoder_name, video_codec codec, uint16_t width, uint16_t height, std::array<double, 2> & scale)
static void check_video_size(std::string_view encoder_name, video_codec codec, uint16_t & width, uint16_t & height)
{
#if WIVRN_USE_NVENC
if (encoder_name == encoder_nvenc)
{
auto max = video_encoder_nvenc::get_max_size(codec);
if (width * scale[0] > max[0])
{
scale[0] = double(max[0] - 1) / width;
U_LOG_W("Image is too wide for encoder, reducing scale to %f", scale[0]);
}
if (height * scale[1] > max[1])
{
scale[1] = double(max[1] - 1) / width;
U_LOG_W("Image is too tall for encoder, reducing scale to %f", scale[1]);
}
width = std::min<uint16_t>(max[0], width);
height = std::min<uint16_t>(max[1], height);
}
#endif
}
namespace
{
class prober
{
wivrn_vk_bundle & vk;
const from_headset::headset_info_packet & info;
const bool nvidia;
#if WIVRN_USE_VAAPI
std::unordered_map<video_codec, bool> vaapi_support;
static constexpr auto ffmpeg_version()
{
std::array<int, 3> result;
std::string_view version = FFMPEG_VERSION;
for (auto & item: result)
bool check_vaapi(video_codec codec)
{
auto dot = version.find(".");
auto number = version.substr(version.find_first_of("0123456789"), dot);
version = version.substr(dot + 1);
auto res = std::from_chars(number.begin(), number.end(), item);
if (res.ec != std::errc{})
throw std::invalid_argument("Failed to parse FFMPEG_VERSION " FFMPEG_VERSION);
}
return result;
}
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{
{
.width = 800,
.height = 600,
.video_width = 800,
.video_height = 600,
},
"vaapi",
default_bitrate,
};
s.bit_depth = bit_depth;
for (auto codec: codecs)
{
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;
}
}
if (auto it = vaapi_support.find(codec); it != vaapi_support.end())
return it->second;
try
{
s.codec = codec;
video_encoder_va test(bundle, s, 60, 0);
return codec;
video_encoder_va test(
vk,
encoder_settings{
.width = 800,
.height = 600,
.codec = codec,
.fps = 60,
.bitrate = 50'000'000,
.bit_depth = 8,
},
0);
vaapi_support[codec] = true;
return true;
}
catch (...)
{}
U_LOG_I("Video codec %s not supported", std::string(magic_enum::enum_name(codec)).c_str());
}
return {};
}
#endif
#if WIVRN_USE_NVENC
static bool probe_nvenc(wivrn_vk_bundle & bundle, int bit_depth)
{
static bool res = [&]() {
encoder_settings s{
{
.width = 800,
.height = 608,
.video_width = 800,
.video_height = 608,
.codec = h264,
},
encoder_nvenc,
default_bitrate,
};
s.bit_depth = bit_depth;
try
{
video_encoder_nvenc test(bundle, s, 60, 0);
return true;
}
catch (std::exception & e)
{
U_LOG_W("nvenc not supported: %s", e.what());
return false;
} }();
return res;
}
#endif
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))
catch (std::exception & e)
{
#if WIVRN_USE_NVENC
if (probe_nvenc(bundle, bit_depth))
config.name = encoder_nvenc;
else
#else
U_LOG_W("nvidia GPU detected, but nvenc support not compiled");
vaapi_support[codec] = false;
U_LOG_I("vaapi not supported for %s", std::string(magic_enum::enum_name(codec)).c_str());
return false;
}
}
#endif
#if WIVRN_USE_NVENC
std::unordered_map<video_codec, bool> nvenc_support;
bool check_nvenc(video_codec codec)
{
if (auto it = vaapi_support.find(codec); it != vaapi_support.end())
return it->second;
try
{
video_encoder_nvenc test(
vk,
encoder_settings{
.width = 800,
.height = 600,
.codec = codec,
.fps = 60,
.bitrate = 50'000'000,
.bit_depth = 8,
},
0);
nvenc_support[codec] = true;
return true;
}
catch (std::exception & e)
{
nvenc_support[codec] = false;
U_LOG_I("nvenc not supported for %s", std::string(magic_enum::enum_name(codec)).c_str());
return false;
}
}
#endif
static bool is_nvidia(vk::PhysicalDevice physical_device)
{
auto props = physical_device.getProperties();
return props.vendorID == 0x10DE;
}
#if WIVRN_USE_VULKAN_ENCODE
bool has_vk_h264()
{
if (*vk.encode_queue == VK_NULL_HANDLE)
return false;
if (not std::ranges::contains(vk.device_extensions, std::string_view(VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME)))
return false;
auto prop = vk.physical_device.getQueueFamilyProperties2<vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyVideoPropertiesKHR>>();
assert(vk.encode_queue_family_index < prop.size());
return bool(prop.at(vk.encode_queue_family_index).get<vk::QueueFamilyVideoPropertiesKHR>().videoCodecOperations & vk::VideoCodecOperationFlagBitsKHR::eEncodeH264);
}
bool has_vk_h265()
{
if (*vk.encode_queue == VK_NULL_HANDLE)
return false;
if (not std::ranges::contains(vk.device_extensions, std::string_view(VK_KHR_VIDEO_ENCODE_H265_EXTENSION_NAME)))
return false;
auto prop = vk.physical_device.getQueueFamilyProperties2<vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyVideoPropertiesKHR>>();
assert(vk.encode_queue_family_index < prop.size());
return bool(prop.at(vk.encode_queue_family_index).get<vk::QueueFamilyVideoPropertiesKHR>().videoCodecOperations & vk::VideoCodecOperationFlagBitsKHR::eEncodeH265);
}
#endif
public:
prober(wivrn_vk_bundle & vk, const from_headset::headset_info_packet & info) :
vk(vk), info(info), nvidia(is_nvidia(vk.physical_device)) {}
std::pair<std::string, video_codec> select_encoder(const configuration::encoder & config)
{
if (config.codec == video_codec::raw or config.name == encoder_raw)
return {encoder_raw, video_codec::raw};
#if WIVRN_USE_NVENC
if ((nvidia and config.name.empty()) or config.name == encoder_nvenc)
{
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
{
#if WIVRN_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
if (check_nvenc(codec))
return {encoder_nvenc, codec};
}
}
#endif
#if WIVRN_USE_VULKAN_ENCODE
if (config.name.empty() or config.name == encoder_vulkan)
{
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
{
switch (codec)
{
config.name = encoder_x264;
config.codec = h264;
case h264:
if (has_vk_h264())
return {encoder_vulkan, video_codec::h264};
U_LOG_I("GPU does not support H.264 Vulkan video encode");
break;
case h265:
if (has_vk_h265())
return {encoder_vulkan, video_codec::h265};
U_LOG_I("GPU does not support H.265 Vulkan video encode");
break;
case av1:
U_LOG_D("Vulkan video encode for AV1 is not implemented in WiVRn");
case raw:
break;
}
#else
U_LOG_E("no suitable encoder available (compile with x264 or nvenc support)");
#endif
}
}
else
{
#if WIVRN_USE_VAAPI
config.name = encoder_vaapi;
#elif WIVRN_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");
config.name = encoder_x264;
config.codec = h264;
}
#else
U_LOG_E("no suitable encoder available (compile with x264 or nvenc support)");
#endif
}
}
#if WIVRN_USE_VAAPI
if (config.name == encoder_vaapi and not config.codec)
{
config.codec = filter_codecs_vaapi(bundle, headset_codecs, bit_depth);
if (not config.codec)
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
{
#if WIVRN_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");
config.name = encoder_x264;
config.codec = h264;
}
#else
U_LOG_E("Failed to initialize vaapi");
#endif
if (check_vaapi(codec))
return {encoder_vaapi, codec};
}
}
#endif
if (config.name == encoder_vulkan and not config.codec)
{
if (bit_depth == 10)
config.codec = h265;
else
config.codec = h264;
}
U_LOG_W("No suitable hardware accelerated codec found");
#if WIVRN_USE_X264
if (config.name == encoder_x264)
config.codec = h264; // this will fail if 10-bit is enabled
if (config.name.empty() or config.name == encoder_x264)
return {encoder_x264, video_codec::h264};
#endif
if (config.name == encoder_raw)
config.codec = raw;
if (not config.codec)
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, int bit_depth)
{
configuration::encoder base;
fill_defaults(bundle, headset_codecs, base, bit_depth);
#ifdef WIVRN_SPLIT_ENCODERS
if (base.name != encoder_x264)
{
/* Split in 2 parts:
* +--------+--------+
* | | |
* | left | right |
* | eye | eye |
* | | |
* +--------+--------+
* Encoded sequentially, so the first eye is ready and transmitted earlier.
* Decoder can start work as fast as possible, reducing idle time.
* Splitting on eye boundaries allows for fast-path on headset.
*
*/
return {
{
.name = base.name,
.width = 0.5,
.group = 0,
.codec = base.codec,
},
{
.name = base.name,
.width = 0.5,
.offset_x = 0.5,
.group = 0,
.codec = base.codec,
},
};
throw std::runtime_error("Failed to find a suitable video encoder");
}
#endif
return {base};
}
};
} // namespace
static uint16_t align(uint16_t value, uint16_t alignment)
{
return ((value + alignment - 1) / alignment) * 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)
std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle & bundle, const from_headset::headset_info_packet & info, const from_headset::settings_changed & settings)
{
configuration config;
if (config.bit_depth != 8 && config.bit_depth != 10)
throw std::runtime_error("invalid bit-depth setting. supported values: 8, 10");
std::array<wivrn::encoder_settings, 3> res;
if (config.encoders.empty())
config.encoders = get_encoder_default_settings(bundle, info.supported_codecs, config.bit_depth);
if (not config.encoder_passthrough)
config.encoder_passthrough = config.encoders.front();
config.encoder_passthrough->width = 1;
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.bit_depth);
uint64_t bitrate = config.bitrate.value_or(default_bitrate);
std::array<double, 2> default_scale;
default_scale.fill(info.eye_gaze ? 0.35 : 0.5);
auto scale = config.scale.value_or(default_scale);
check_scale(config.encoder_passthrough->name,
*config.encoder_passthrough->codec,
// passthrough stream is subsampled
width / passthrough_subsampling,
height / passthrough_subsampling,
scale);
for (auto & encoder: config.encoders)
{
fill_defaults(bundle, info.supported_codecs, encoder, config.bit_depth);
assert(encoder.codec);
check_scale(encoder.name,
*encoder.codec,
std::ceil(encoder.width.value_or(1) * width),
std::ceil(encoder.height.value_or(1) * height),
scale);
}
width = align(width * scale[0], 64);
height = align(height * scale[1], 64);
std::vector<wivrn::encoder_settings> res;
prober prober{bundle, info};
std::unordered_map<std::string, int> groups;
int next_group = 0;
for (const auto & encoder: config.encoders)
for (auto [src, dst]: std::ranges::zip_view(config.encoders, res))
{
if (encoder.group)
{
groups[encoder.name] = *encoder.group;
next_group = std::max(next_group, *encoder.group + 1);
}
dst.fps = settings.preferred_refresh_rate;
dst.options = src.options;
dst.device = src.device;
std::tie(dst.encoder_name, dst.codec) = prober.select_encoder(src);
auto [it, inserted] = groups.emplace(dst.encoder_name, next_group);
dst.group = it->second;
if (inserted)
++next_group;
}
for (const auto & encoder: config.encoders)
{
wivrn::encoder_settings settings{};
settings.channels = to_headset::video_stream_description::channels_t::colour;
settings.subsampling = 1;
settings.encoder_name = encoder.name;
settings.offset_x = align(std::ceil(encoder.offset_x.value_or(0) * width), 32);
settings.offset_y = align(std::ceil(encoder.offset_y.value_or(0) * height), 32);
settings.width = align(std::ceil(encoder.width.value_or(1) * width), 32);
settings.height = align(std::ceil(encoder.height.value_or(1) * height), 32);
settings.width = std::min<uint16_t>(settings.width, width - settings.offset_x);
settings.height = std::min<uint16_t>(settings.height, height - settings.offset_y);
settings.video_width = settings.width;
settings.video_height = settings.height;
settings.codec = *encoder.codec;
settings.bit_depth = config.bit_depth;
if (encoder.group)
settings.group = *encoder.group;
else
{
auto [it, inserted] = groups.emplace(encoder.name, next_group);
settings.group = it->second;
if (inserted)
++next_group;
}
settings.options = encoder.options;
settings.device = encoder.device;
auto width = align(info.stream_eye_width, 64);
auto height = align(info.stream_eye_height, 64);
// Ensure we don't try to encode too large images (only for left/right, ignore alpha)
for (size_t i = 0; i < 2; ++i)
check_video_size(res[i].encoder_name, res[i].codec, width, height);
res.push_back(settings);
}
split_bitrate(res, bitrate);
// passthrough encoder
for (auto [i, dst]: std::ranges::enumerate_view(res))
{
const auto & encoder = *config.encoder_passthrough;
wivrn::encoder_settings settings{};
settings.channels = to_headset::video_stream_description::channels_t::alpha;
settings.subsampling = passthrough_subsampling;
settings.encoder_name = encoder.name;
settings.width = width / settings.subsampling;
settings.height = height / settings.subsampling;
assert(settings.width % 32 == 0);
assert(settings.height % 32 == 0);
settings.video_width = settings.width;
settings.video_height = settings.height;
settings.codec = *encoder.codec;
settings.bit_depth = config.bit_depth;
if (encoder.group)
settings.group = *encoder.group;
else
{
auto [it, inserted] = groups.emplace(encoder.name, next_group);
settings.group = it->second;
if (inserted)
++next_group;
}
settings.options = encoder.options;
settings.device = encoder.device;
settings.bitrate = bitrate * passthrough_bitrate_factor;
res.push_back(settings);
dst.width = width;
dst.height = height;
if (i == 2) // alpha channel
dst.height /= 2;
}
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))
bit_depth = 8;
for (auto & i: res)
i.bit_depth = bit_depth.value_or(10);
split_bitrate(res, settings.bitrate_bps);
return res;
}
} // namespace wivrn
+7 -4
View File
@@ -24,14 +24,17 @@
#include <map>
#include <optional>
#include <string>
#include <vector>
namespace wivrn
{
struct wivrn_vk_bundle;
struct encoder_settings : public to_headset::video_stream_description::item
struct encoder_settings
{
uint16_t width;
uint16_t height;
video_codec codec; // left, right, alpha
float fps;
// encoder identifier, such as nvenc, vaapi or x264
std::string encoder_name;
uint64_t bitrate; // bit/s
@@ -43,8 +46,8 @@ struct encoder_settings : public to_headset::video_stream_description::item
std::optional<std::string> device;
};
std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle &, uint32_t & width, uint32_t & height, const from_headset::headset_info_packet & info);
std::array<encoder_settings, 3> get_encoder_settings(wivrn_vk_bundle &, const from_headset::headset_info_packet & info, const from_headset::settings_changed & settings);
void print_encoders(const std::vector<wivrn::encoder_settings> & encoders);
void print_encoders(const std::array<wivrn::encoder_settings, 3> & encoders);
} // namespace wivrn
+2 -2
View File
@@ -37,8 +37,8 @@ public:
};
protected:
video_encoder_ffmpeg(uint8_t stream_idx, to_headset::video_stream_description::channels_t channels, double bitrate_multiplier) :
wivrn::video_encoder(stream_idx, channels, std::make_unique<default_idr_handler>(), bitrate_multiplier, true) {}
video_encoder_ffmpeg(uint8_t stream_idx, const encoder_settings & settings) :
wivrn::video_encoder(stream_idx, settings, std::make_unique<default_idr_handler>(), true) {}
virtual void push_frame(bool idr, uint8_t slot) = 0;
+12 -34
View File
@@ -157,10 +157,9 @@ vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc, int bit_depth)
} // namespace
video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
wivrn::encoder_settings & settings,
float fps,
const wivrn::encoder_settings & settings,
uint8_t stream_idx) :
video_encoder_ffmpeg(stream_idx, settings.channels, settings.bitrate_multiplier),
video_encoder_ffmpeg(stream_idx, settings),
synchronization2(vk.vk.features.synchronization_2)
{
auto drm_hw_ctx = make_drm_hw_ctx(vk.physical_device, settings.device);
@@ -173,9 +172,6 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
throw std::system_error(err, av_error_category(), "FFMPEG vaapi hardware context creation failed");
av_buffer_ptr vaapi_hw_ctx(tmp);
settings.video_width += settings.video_width % 2;
settings.video_height += settings.video_height % 2;
AVPixelFormat sw_format;
switch (settings.codec)
@@ -196,19 +192,9 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
break;
}
auto vaapi_frame_ctx = make_hwframe_ctx(vaapi_hw_ctx.get(), AV_PIX_FMT_VAAPI, sw_format, settings.video_width, settings.video_height);
auto vaapi_frame_ctx = make_hwframe_ctx(vaapi_hw_ctx.get(), AV_PIX_FMT_VAAPI, sw_format, extent.width, extent.height);
assert(av_pix_fmt_count_planes(sw_format) == 2);
rect = vk::Rect2D{
.offset = {
.x = settings.offset_x,
.y = settings.offset_y,
},
.extent = {
.width = settings.width,
.height = settings.height,
}};
err = av_hwframe_ctx_create_derived(&tmp,
AV_PIX_FMT_DRM_PRIME,
drm_hw_ctx.get(),
@@ -257,11 +243,11 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
av_dict_set(&opts, option.first.c_str(), option.second.c_str(), 0);
}
encoder_ctx->width = settings.video_width;
encoder_ctx->height = settings.video_height;
encoder_ctx->width = extent.width;
encoder_ctx->height = extent.height;
encoder_ctx->time_base = {std::chrono::steady_clock::duration::period::num,
std::chrono::steady_clock::duration::period::den};
encoder_ctx->framerate = AVRational{(int)fps, 1};
encoder_ctx->framerate = AVRational{(int)settings.fps * 1000, 1000};
encoder_ctx->sample_aspect_ratio = AVRational{1, 1};
encoder_ctx->pix_fmt = AV_PIX_FMT_VAAPI;
encoder_ctx->color_range = AVCOL_RANGE_JPEG;
@@ -466,20 +452,16 @@ std::pair<bool, vk::Semaphore> video_encoder_va::present_image(vk::Image y_cbcr,
vk::ImageCopy{
.srcSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.srcOffset = {
.x = rect.offset.x,
.y = rect.offset.y,
},
.dstSubresource = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.layerCount = 1,
},
.extent = {
.width = rect.extent.width,
.height = rect.extent.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
}});
@@ -491,20 +473,16 @@ std::pair<bool, vk::Semaphore> video_encoder_va::present_image(vk::Image y_cbcr,
vk::ImageCopy{
.srcSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.srcOffset = {
.x = rect.offset.x / 2,
.y = rect.offset.y / 2,
},
.dstSubresource = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.layerCount = 1,
},
.extent = {
.width = rect.extent.width / 2,
.height = rect.extent.height / 2,
.width = extent.width / 2,
.height = extent.height / 2,
.depth = 1,
}});
+1 -2
View File
@@ -43,11 +43,10 @@ class video_encoder_va : public video_encoder_ffmpeg
};
av_buffer_ptr drm_frame_ctx;
std::array<in_t, num_slots> in;
vk::Rect2D rect;
bool synchronization2 = false;
public:
video_encoder_va(wivrn_vk_bundle &, wivrn::encoder_settings & settings, float fps, uint8_t stream_index);
video_encoder_va(wivrn_vk_bundle &, const wivrn::encoder_settings & settings, uint8_t stream_index);
std::pair<bool, vk::Semaphore> present_image(vk::Image y_cbcr, vk::raii::CommandBuffer & cmd_buf, uint8_t slot, uint64_t frame_index) override;
+18 -23
View File
@@ -102,26 +102,21 @@ std::shared_ptr<video_encoder::sender> video_encoder::sender::get()
std::unique_ptr<video_encoder> video_encoder::create(
wivrn_vk_bundle & wivrn_vk,
encoder_settings & settings,
uint8_t stream_idx,
int input_width,
int input_height,
float fps)
const encoder_settings & settings,
uint8_t stream_idx)
{
using namespace std::string_literals;
std::unique_ptr<video_encoder> res;
settings.range = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
settings.color_model = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709;
if (settings.encoder_name == encoder_vulkan)
{
#if WIVRN_USE_VULKAN_ENCODE
switch (settings.codec)
{
case video_codec::h264:
res = video_encoder_vulkan_h264::create(wivrn_vk, settings, fps, stream_idx);
res = video_encoder_vulkan_h264::create(wivrn_vk, settings, stream_idx);
break;
case video_codec::h265:
res = video_encoder_vulkan_h265::create(wivrn_vk, settings, fps, stream_idx);
res = video_encoder_vulkan_h265::create(wivrn_vk, settings, stream_idx);
break;
case video_codec::av1:
throw std::runtime_error("av1 not supported for vulkan video encode");
@@ -135,7 +130,7 @@ std::unique_ptr<video_encoder> video_encoder::create(
if (settings.encoder_name == encoder_x264)
{
#if WIVRN_USE_X264
res = std::make_unique<video_encoder_x264>(wivrn_vk, settings, fps, stream_idx);
res = std::make_unique<video_encoder_x264>(wivrn_vk, settings, stream_idx);
#else
throw std::runtime_error("x264 encoder not enabled");
#endif
@@ -143,7 +138,7 @@ std::unique_ptr<video_encoder> video_encoder::create(
if (settings.encoder_name == encoder_nvenc)
{
#if WIVRN_USE_NVENC
res = std::make_unique<video_encoder_nvenc>(wivrn_vk, settings, fps, stream_idx);
res = std::make_unique<video_encoder_nvenc>(wivrn_vk, settings, stream_idx);
#else
throw std::runtime_error("nvenc support not enabled");
#endif
@@ -151,7 +146,7 @@ std::unique_ptr<video_encoder> video_encoder::create(
if (settings.encoder_name == encoder_vaapi)
{
#if WIVRN_USE_VAAPI
res = std::make_unique<video_encoder_va>(wivrn_vk, settings, fps, stream_idx);
res = std::make_unique<video_encoder_va>(wivrn_vk, settings, stream_idx);
#else
throw std::runtime_error("vaapi support not enabled");
#endif
@@ -159,7 +154,7 @@ std::unique_ptr<video_encoder> video_encoder::create(
if (settings.encoder_name == encoder_raw)
{
res = std::make_unique<video_encoder_raw>(wivrn_vk, settings, fps, stream_idx);
res = std::make_unique<video_encoder_raw>(wivrn_vk, settings, stream_idx);
}
if (not res)
@@ -190,12 +185,18 @@ std::unique_ptr<video_encoder> video_encoder::create(
return res;
}
video_encoder::video_encoder(uint8_t stream_idx, to_headset::video_stream_description::channels_t channels, std::unique_ptr<idr_handler> idr, double bitrate_multiplier, bool async_send) :
video_encoder::video_encoder(uint8_t stream_idx,
const encoder_settings & settings,
std::unique_ptr<idr_handler> idr,
bool async_send) :
stream_idx(stream_idx),
channels(channels),
bitrate_multiplier(bitrate_multiplier),
bitrate_multiplier(settings.bitrate_multiplier),
shared_sender(async_send ? sender::get() : nullptr),
idr(std::move(idr))
idr(std::move(idr)),
extent{
.width = settings.width,
.height = settings.height,
}
{
assert(this->idr);
}
@@ -315,7 +316,6 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
ssize_t max_payload_size = cnx->has_stream() ? to_headset::video_stream_data_shard::max_payload_size : std::numeric_limits<uint32_t>::max();
shard.flags = to_headset::video_stream_data_shard::start_of_slice;
auto begin = data.begin();
auto end = data.end();
while (begin != end)
@@ -324,12 +324,8 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
auto next = std::min(end, begin + payload_size);
if (next == end)
{
shard.flags |= to_headset::video_stream_data_shard::end_of_slice;
if (end_of_frame)
{
shard.flags |= to_headset::video_stream_data_shard::end_of_frame;
shard.timing_info = timing_info;
}
}
shard.payload = {begin, next};
try
@@ -344,7 +340,6 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
// Ignore network errors
}
++shard.shard_idx;
shard.flags = 0;
shard.view_info.reset();
begin = next;
}
+4 -7
View File
@@ -76,7 +76,6 @@ private:
public:
const uint8_t stream_idx;
const to_headset::video_stream_description::channels_t channels;
static const uint8_t num_slots = 2;
const double bitrate_multiplier;
@@ -108,17 +107,15 @@ protected:
std::atomic_uint32_t pending_bitrate;
std::atomic<float> pending_framerate;
std::unique_ptr<idr_handler> idr;
const vk::Extent2D extent;
public:
static std::unique_ptr<video_encoder> create(
wivrn_vk_bundle &,
encoder_settings & settings,
uint8_t stream_idx,
int input_width,
int input_height,
float fps);
const encoder_settings & settings,
uint8_t stream_idx);
video_encoder(uint8_t stream_idx, to_headset::video_stream_description::channels_t channels, std::unique_ptr<idr_handler>, double bitrate_multiplier, bool async_send);
video_encoder(uint8_t stream_idx, const encoder_settings & settings, std::unique_ptr<idr_handler>, bool async_send);
virtual ~video_encoder();
// return value: true if image should be transitioned to queue and layout for vulkan video encode
+34 -49
View File
@@ -150,30 +150,19 @@ void video_encoder_nvenc::set_init_params_fps(float framerate)
video_encoder_nvenc::video_encoder_nvenc(
wivrn_vk_bundle & vk,
encoder_settings & settings,
float fps,
const encoder_settings & settings,
uint8_t stream_idx) :
video_encoder(stream_idx, settings.channels, std::make_unique<default_idr_handler>(), settings.bitrate_multiplier, true),
video_encoder(stream_idx, settings, std::make_unique<default_idr_handler>(), true),
vk(vk),
shared_state(video_encoder_nvenc_shared_state::get()),
fps(fps),
fps(settings.fps),
bitrate(settings.bitrate)
{
if (settings.bit_depth != 8 && settings.bit_depth != 10)
throw std::runtime_error("nvenc encoder only supports 8-bit and 10-bit encoding");
assert(settings.width % 32 == 0);
assert(settings.height % 32 == 0);
rect = vk::Rect2D{
.offset = {
.x = settings.offset_x,
.y = settings.offset_y,
},
.extent = {
.width = settings.width,
.height = settings.height,
},
};
assert(extent.width % 32 == 0);
assert(extent.height % 32 == 0);
NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS session_params = {
.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER,
@@ -284,10 +273,10 @@ video_encoder_nvenc::video_encoder_nvenc(
.version = NV_ENC_INITIALIZE_PARAMS_VER,
.encodeGUID = encodeGUID,
.presetGUID = presetGUID,
.encodeWidth = settings.video_width,
.encodeHeight = settings.video_height,
.darWidth = settings.video_width,
.darHeight = settings.video_height,
.encodeWidth = extent.width,
.encodeHeight = extent.height,
.darWidth = extent.width,
.darHeight = extent.height,
.enableEncodeAsync = 0,
.enablePTD = 1,
.encodeConfig = &config,
@@ -303,7 +292,7 @@ video_encoder_nvenc::video_encoder_nvenc(
NVENC_CHECK(shared_state->fn.nvEncCreateBitstreamBuffer(session_handle, &out_buf_params));
outputBuffer = out_buf_params.bitstreamBuffer;
vk::DeviceSize buffer_size = rect.extent.width * settings.video_height * bytesPerPixel * 3 / 2;
vk::DeviceSize buffer_size = extent.width * extent.height * bytesPerPixel * 3 / 2;
vk::StructureChain buffer_create_info{
vk::BufferCreateInfo{
@@ -365,9 +354,9 @@ video_encoder_nvenc::video_encoder_nvenc(
NV_ENC_REGISTER_RESOURCE resource_params{
.version = NV_ENC_REGISTER_RESOURCE_VER,
.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR,
.width = settings.video_width,
.height = settings.video_height,
.pitch = rect.extent.width * bytesPerPixel,
.width = extent.width,
.height = extent.height,
.pitch = extent.width * bytesPerPixel,
.resourceToRegister = (void *)frame,
.bufferFormat = (bitDepth == NV_ENC_BIT_DEPTH_10 ? NV_ENC_BUFFER_FORMAT_YUV420_10BIT : NV_ENC_BUFFER_FORMAT_NV12),
.bufferUsage = NV_ENC_INPUT_IMAGE,
@@ -392,35 +381,31 @@ std::pair<bool, vk::Semaphore> video_encoder_nvenc::present_image(vk::Image y_cb
*in[slot].yuv,
std::array{
vk::BufferImageCopy{
.bufferRowLength = rect.extent.width,
.bufferRowLength = extent.width,
.imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.imageOffset = {
.x = rect.offset.x,
.y = rect.offset.y,
},
.imageExtent = {
.width = rect.extent.width,
.height = rect.extent.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
}},
vk::BufferImageCopy{.bufferOffset = rect.extent.width * rect.extent.height * bytesPerPixel, .bufferRowLength = uint32_t(rect.extent.width / 2), .imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = uint32_t(channels),
.layerCount = 1,
},
.imageOffset = {
.x = rect.offset.x / 2,
.y = rect.offset.y / 2,
},
.imageExtent = {
.width = rect.extent.width / 2,
.height = rect.extent.height / 2,
.depth = 1,
}}});
vk::BufferImageCopy{
.bufferOffset = extent.width * extent.height * bytesPerPixel,
.bufferRowLength = uint32_t(extent.width / 2),
.imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.imageExtent = {
.width = extent.width / 2,
.height = extent.height / 2,
.depth = 1,
},
}});
return {false, nullptr};
}
@@ -479,9 +464,9 @@ std::optional<video_encoder::data> video_encoder_nvenc::encode(uint8_t slot, uin
NV_ENC_PIC_PARAMS frame_params{
.version = NV_ENC_PIC_PARAMS_VER,
.inputWidth = rect.extent.width,
.inputHeight = rect.extent.height,
.inputPitch = rect.extent.width,
.inputWidth = extent.width,
.inputHeight = extent.height,
.inputPitch = extent.width,
.encodePicFlags = 0,
.frameIdx = 0,
.inputTimeStamp = 0,
+1 -3
View File
@@ -34,8 +34,6 @@ class video_encoder_nvenc : public video_encoder
{
private:
wivrn_vk_bundle & vk;
// relevant part of the input image to encode
vk::Rect2D rect;
std::shared_ptr<video_encoder_nvenc_shared_state> shared_state;
@@ -60,7 +58,7 @@ private:
void set_init_params_fps(float framerate);
public:
video_encoder_nvenc(wivrn_vk_bundle & vk, encoder_settings & settings, float fps, uint8_t stream_idx);
video_encoder_nvenc(wivrn_vk_bundle & vk, const encoder_settings & settings, uint8_t stream_idx);
~video_encoder_nvenc();
std::pair<bool, vk::Semaphore> present_image(vk::Image y_cbcr, vk::raii::CommandBuffer & cmd_buf, uint8_t slot, uint64_t frame_index) override;
+13 -38
View File
@@ -37,33 +37,16 @@ public:
wivrn::video_encoder_raw::video_encoder_raw(
wivrn_vk_bundle & vk,
encoder_settings & settings,
float fps,
const encoder_settings & settings,
uint8_t stream_idx) :
video_encoder(stream_idx, settings.channels, std::make_unique<dummy_idr_handler>(), settings.bitrate_multiplier, true)
video_encoder(stream_idx, settings, std::make_unique<dummy_idr_handler>(), true)
{
if (settings.bit_depth != 8)
throw std::runtime_error("Raw encoding is only supported for 8 bit");
rect = vk::Rect2D{
.offset = {
.x = settings.offset_x,
.y = settings.offset_y,
},
.extent = {
.width = settings.width,
.height = settings.height,
},
};
vk::DeviceSize buffer_size = settings.width * settings.height;
switch (settings.channels)
{
case to_headset::video_stream_description::channels_t::colour:
buffer_size += buffer_size / 2;
break;
case to_headset::video_stream_description::channels_t::alpha:
break;
}
vk::DeviceSize buffer_size = extent.width * extent.height;
if (stream_idx < 2)
buffer_size += buffer_size / 2;
for (auto & slot: buffers)
{
slot = buffer_allocation(
@@ -86,33 +69,25 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_raw::present_image(vk::Image
vk::BufferImageCopy{
.imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.imageOffset = {
.x = rect.offset.x,
.y = rect.offset.y,
},
.imageExtent = {
.width = rect.extent.width,
.height = rect.extent.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
},
},
vk::BufferImageCopy{
.bufferOffset = rect.extent.width * rect.extent.height,
.bufferOffset = extent.width * extent.height,
.imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.imageOffset = {
.x = rect.offset.x / 2,
.y = rect.offset.y / 2,
},
.imageExtent = {
.width = rect.extent.width / 2,
.height = rect.extent.height / 2,
.width = extent.width / 2,
.height = extent.height / 2,
.depth = 1,
},
},
@@ -122,7 +97,7 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_raw::present_image(vk::Image
vk::ImageLayout::eTransferSrcOptimal,
buffers[slot],
std::span(regions.data(),
channels == to_headset::video_stream_description::channels_t::colour ? 2 : 1));
stream_idx == 2 ? 2 : 1));
return {false, nullptr};
}
+1 -2
View File
@@ -29,10 +29,9 @@ namespace wivrn
class video_encoder_raw : public video_encoder
{
std::array<buffer_allocation, num_slots> buffers;
vk::Rect2D rect;
public:
video_encoder_raw(wivrn_vk_bundle & vk, encoder_settings & settings, float fps, uint8_t stream_idx);
video_encoder_raw(wivrn_vk_bundle & vk, const encoder_settings & settings, uint8_t stream_idx);
std::pair<bool, vk::Semaphore> present_image(vk::Image y_cbcr, vk::raii::CommandBuffer & cmd_buf, uint8_t slot, uint64_t frame_index) override;
+16 -29
View File
@@ -157,16 +157,13 @@ vk::VideoFormatPropertiesKHR wivrn::video_encoder_vulkan::select_video_format(
wivrn::video_encoder_vulkan::video_encoder_vulkan(
wivrn_vk_bundle & vk,
vk::Rect2D rect,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & in_encode_caps,
float fps,
uint8_t stream_idx,
const encoder_settings & settings) :
video_encoder(stream_idx, settings.channels, std::make_unique<dpb_state>(), settings.bitrate_multiplier, true),
video_encoder(stream_idx, settings, std::make_unique<dpb_state>(), true),
vk(vk),
encode_caps(patch_capabilities(in_encode_caps)),
rect(rect),
num_dpb_slots(std::min(video_caps.maxDpbSlots, 16u))
{
// Initialize Rate control
@@ -192,7 +189,7 @@ wivrn::video_encoder_vulkan::video_encoder_vulkan(
rate_control_layer = vk::VideoEncodeRateControlLayerInfoKHR{
.averageBitrate = std::min(settings.bitrate, encode_caps.maxBitrate),
.maxBitrate = std::min(2 * settings.bitrate, encode_caps.maxBitrate),
.frameRateNumerator = uint32_t(fps * 1'000'000),
.frameRateNumerator = uint32_t(settings.fps * 1'000'000),
.frameRateDenominator = 1'000'000,
};
rate_control = vk::VideoEncodeRateControlInfoKHR{
@@ -224,8 +221,8 @@ wivrn::video_encoder_vulkan::video_encoder_vulkan(
std::max(video_caps.pictureAccessGranularity.height, encode_caps.encodeInputPictureGranularity.height);
aligned_extent = vk::Extent3D{
.width = align(rect.extent.width, std::max(cb_min_size, granWidth)),
.height = align(rect.extent.height, std::max(cb_min_size, granHeight)),
.width = align(extent.width, std::max(cb_min_size, granWidth)),
.height = align(extent.height, std::max(cb_min_size, granHeight)),
.depth = 1,
};
}
@@ -291,7 +288,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
for (auto & item: slot_data)
{
// very conservative bound
size_t output_buffer_size = rect.extent.width * rect.extent.height * 3;
size_t output_buffer_size = extent.width * extent.height * 3;
output_buffer_size = align(output_buffer_size, video_caps.minBitstreamBufferSizeAlignment);
item.output_buffer = buffer_allocation(
vk.device,
@@ -371,11 +368,11 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
.subresourceRange = {.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1},
};
if (rect.offset != vk::Offset2D{0, 0} or not vk.vk.features.video_maintenance_1)
if (not vk.vk.features.video_maintenance_1)
{
image_view_template.subresourceRange.baseArrayLayer = 0;
for (size_t i = 0; i < num_slots; ++i)
@@ -386,8 +383,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
.imageType = vk::ImageType::e2D,
.format = picture_format.format,
.extent = {
.width = rect.extent.width,
.height = rect.extent.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
},
.mipLevels = 1,
@@ -444,7 +441,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
dpb.items.push_back({
.image_view = std::move(v),
.resource = {
.codedExtent = rect.extent,
.codedExtent = extent,
.imageViewBinding = v1,
},
.info = dpb.infos[i],
@@ -650,44 +647,34 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
vk::ImageCopy{
.srcSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.srcOffset = {
.x = rect.offset.x,
.y = rect.offset.y,
.z = 0,
},
.dstSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
.baseArrayLayer = 0,
.layerCount = 1,
},
.extent = {
.width = rect.extent.width,
.height = rect.extent.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
},
},
vk::ImageCopy{
.srcSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.srcOffset = {
.x = rect.offset.x / 2,
.y = rect.offset.y / 2,
.z = 0,
},
.dstSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = 0,
.layerCount = 1,
},
.extent = {
.width = rect.extent.width / 2,
.height = rect.extent.height / 2,
.width = extent.width / 2,
.height = extent.height / 2,
.depth = 1,
},
},
-3
View File
@@ -66,7 +66,6 @@ class video_encoder_vulkan : public video_encoder
const vk::PhysicalDeviceVideoFormatInfoKHR &);
bool session_initialized = false;
const vk::Rect2D rect;
protected:
const uint8_t num_dpb_slots;
@@ -75,10 +74,8 @@ protected:
std::optional<vk::VideoEncodeRateControlInfoKHR> rate_control;
video_encoder_vulkan(wivrn_vk_bundle & vk,
vk::Rect2D rect,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
float fps,
uint8_t stream_idx,
const encoder_settings & settings);
+9 -23
View File
@@ -71,13 +71,11 @@ static StdVideoH264LevelIdc compute_level(const StdVideoH264SequenceParameterSet
wivrn::video_encoder_vulkan_h264::video_encoder_vulkan_h264(
wivrn_vk_bundle & vk,
vk::Rect2D rect,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
float fps,
uint8_t stream_idx,
const encoder_settings & settings) :
video_encoder_vulkan(vk, rect, video_caps, encode_caps, fps, stream_idx, settings),
video_encoder_vulkan(vk, video_caps, encode_caps, stream_idx, settings),
sps{
.flags =
{
@@ -94,7 +92,7 @@ wivrn::video_encoder_vulkan_h264::video_encoder_vulkan_h264(
.separate_colour_plane_flag = 0,
.gaps_in_frame_num_value_allowed_flag = 0,
.qpprime_y_zero_transform_bypass_flag = 0,
.frame_cropping_flag = (rect.extent.width % 16) || (rect.extent.height) % 16,
.frame_cropping_flag = (extent.width % 16) || (extent.height) % 16,
.seq_scaling_matrix_present_flag = 0,
.vui_parameters_present_flag = 0,
},
@@ -112,12 +110,12 @@ wivrn::video_encoder_vulkan_h264::video_encoder_vulkan_h264(
.num_ref_frames_in_pic_order_cnt_cycle = 0,
.max_num_ref_frames = uint8_t(num_dpb_slots - 1),
.reserved1 = 0,
.pic_width_in_mbs_minus1 = (rect.extent.width - 1) / 16,
.pic_height_in_map_units_minus1 = (rect.extent.height - 1) / 16,
.pic_width_in_mbs_minus1 = (extent.width - 1) / 16,
.pic_height_in_map_units_minus1 = (extent.height - 1) / 16,
.frame_crop_left_offset = 0,
.frame_crop_right_offset = (rect.extent.width % 16) / 2,
.frame_crop_right_offset = (extent.width % 16) / 2,
.frame_crop_top_offset = 0,
.frame_crop_bottom_offset = (rect.extent.height % 16) / 2,
.frame_crop_bottom_offset = (extent.height % 16) / 2,
.reserved2 = 0,
.pOffsetForRefFrame = nullptr,
.pScalingLists = nullptr,
@@ -147,7 +145,7 @@ wivrn::video_encoder_vulkan_h264::video_encoder_vulkan_h264(
.pScalingLists = nullptr,
}
{
sps.level_idc = compute_level(sps, fps, num_dpb_slots, settings.bitrate);
sps.level_idc = compute_level(sps, settings.fps, num_dpb_slots, settings.bitrate);
if (not std::ranges::any_of(vk.device_extensions, [](std::string_view ext) { return ext == VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME; }))
{
throw std::runtime_error("Vulkan video encode H264 extension not available");
@@ -213,27 +211,15 @@ auto get_video_caps(vk::raii::PhysicalDevice & phys_dev)
std::unique_ptr<wivrn::video_encoder_vulkan_h264> wivrn::video_encoder_vulkan_h264::create(
wivrn_vk_bundle & vk,
encoder_settings & settings,
float fps,
const encoder_settings & settings,
uint8_t stream_idx)
{
vk::Rect2D rect{
.offset = {
.x = settings.offset_x,
.y = settings.offset_y,
},
.extent = {
.width = settings.width,
.height = settings.height,
},
};
if (settings.bit_depth != 8)
throw std::runtime_error("h264 codec only supports 8-bit encoding");
auto [video_caps, encode_caps, encode_h264_caps, video_profile_info] = get_video_caps(vk.physical_device);
std::unique_ptr<video_encoder_vulkan_h264> self(new video_encoder_vulkan_h264(vk, rect, video_caps, encode_caps, fps, stream_idx, settings));
std::unique_ptr<video_encoder_vulkan_h264> self(new video_encoder_vulkan_h264(vk, video_caps, encode_caps, stream_idx, settings));
vk::VideoEncodeH264SessionParametersAddInfoKHR h264_add_info{};
h264_add_info.setStdSPSs(self->sps);
+1 -4
View File
@@ -49,10 +49,8 @@ class video_encoder_vulkan_h264 : public video_encoder_vulkan
vk::VideoEncodeH264RateControlLayerInfoKHR rate_control_layer_h264;
video_encoder_vulkan_h264(wivrn_vk_bundle & vk,
vk::Rect2D rect,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
float fps,
uint8_t stream_idx,
const encoder_settings & settings);
@@ -66,8 +64,7 @@ protected:
public:
static std::unique_ptr<video_encoder_vulkan_h264> create(wivrn_vk_bundle & vk,
encoder_settings & settings,
float fps,
const encoder_settings & settings,
uint8_t stream_idx);
std::vector<uint8_t> get_sps_pps();
+6 -14
View File
@@ -61,13 +61,11 @@ static uint32_t find_msb(uint32_t v)
wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(
wivrn_vk_bundle & vk,
vk::Rect2D rect,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
float fps,
uint8_t stream_idx,
const encoder_settings & settings) :
video_encoder_vulkan(vk, rect, video_caps, encode_caps, fps, stream_idx, settings),
video_encoder_vulkan(vk, video_caps, encode_caps, stream_idx, settings),
vui{
.flags = {
.aspect_ratio_info_present_flag = 1,
@@ -97,7 +95,7 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(
.general_frame_only_constraint_flag = 1,
},
.general_profile_idc = (settings.bit_depth == 10) ? STD_VIDEO_H265_PROFILE_IDC_MAIN_10 : STD_VIDEO_H265_PROFILE_IDC_MAIN,
.general_level_idc = choose_level(rect.extent.width, rect.extent.height, fps)},
.general_level_idc = choose_level(extent.width, extent.height, settings.fps)},
vps{
.flags = {
.vps_temporal_id_nesting_flag = 1, // radv breaks without
@@ -150,9 +148,9 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(
.motion_vector_resolution_control_idc = 0,
.sps_num_palette_predictor_initializers_minus1 = 0,
.conf_win_left_offset = 0u,
.conf_win_right_offset = (aligned_extent.width - rect.extent.width) >> 1, // 4:2:0
.conf_win_right_offset = (aligned_extent.width - extent.width) >> 1, // 4:2:0
.conf_win_top_offset = 0u,
.conf_win_bottom_offset = (aligned_extent.height - rect.extent.height) >> 1, // 4:2:0
.conf_win_bottom_offset = (aligned_extent.height - extent.height) >> 1, // 4:2:0
.pProfileTierLevel = &ptl,
.pDecPicBufMgr = &dpb,
.pScalingLists = nullptr,
@@ -272,19 +270,13 @@ static auto get_video_caps(vk::raii::PhysicalDevice & phys_dev, int bit_depth)
std::unique_ptr<wivrn::video_encoder_vulkan_h265> wivrn::video_encoder_vulkan_h265::create(
wivrn_vk_bundle & vk,
encoder_settings & settings,
float fps,
const encoder_settings & settings,
uint8_t stream_idx)
{
vk::Rect2D rect{
.offset = {.x = settings.offset_x, .y = settings.offset_y},
.extent = {.width = settings.width, .height = settings.height},
};
auto [video_caps, encode_caps, encode_h265_caps, video_profile_info] = get_video_caps(vk.physical_device, settings.bit_depth);
std::unique_ptr<video_encoder_vulkan_h265> self(
new video_encoder_vulkan_h265(vk, rect, video_caps, encode_caps, fps, stream_idx, settings));
new video_encoder_vulkan_h265(vk, video_caps, encode_caps, stream_idx, settings));
vk::VideoEncodeH265SessionParametersAddInfoKHR add_info{};
add_info.setStdVPSs(self->vps);
+1 -4
View File
@@ -60,10 +60,8 @@ class video_encoder_vulkan_h265 : public video_encoder_vulkan
vk::VideoEncodeH265RateControlLayerInfoKHR rc_layer_h265{};
video_encoder_vulkan_h265(wivrn_vk_bundle & vk,
vk::Rect2D rect,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
float fps,
uint8_t stream_idx,
const encoder_settings & settings);
@@ -77,8 +75,7 @@ protected:
public:
static std::unique_ptr<video_encoder_vulkan_h265> create(wivrn_vk_bundle & vk,
encoder_settings & settings,
float fps,
const encoder_settings & settings,
uint8_t stream_idx);
std::vector<uint8_t> get_vps_sps_pps();
+20 -46
View File
@@ -88,47 +88,29 @@ void video_encoder_x264::InsertInPendingNal(pending_nal && nal)
video_encoder_x264::video_encoder_x264(
wivrn_vk_bundle & vk,
encoder_settings & settings,
float fps,
const encoder_settings & settings,
uint8_t stream_idx) :
video_encoder(stream_idx, settings.channels, std::make_unique<default_idr_handler>(), settings.bitrate_multiplier, false)
video_encoder(stream_idx, settings, std::make_unique<default_idr_handler>(), false)
{
if (settings.bit_depth != 8)
throw std::runtime_error("x264 encoder only supports 8-bit encoding");
if (settings.codec != h264)
{
U_LOG_W("requested x264 encoder with codec != h264");
settings.codec = h264;
}
// encoder requires width and height to be even
settings.video_width += settings.video_width % 2;
settings.video_height += settings.video_height % 2;
chroma_width = settings.video_width / 2;
chroma_width = extent.width / 2;
// FIXME: enforce even values
rect = vk::Rect2D{
.offset = {
.x = settings.offset_x,
.y = settings.offset_y,
},
.extent = {
.width = settings.width,
.height = settings.height,
},
};
num_mb = ((settings.video_width + 15) / 16) * ((settings.video_height + 15) / 16);
num_mb = ((extent.width + 15) / 16) * ((extent.height + 15) / 16);
x264_param_default_preset(&param, "ultrafast", "zerolatency");
param.nalu_process = &ProcessCb;
// param.i_slice_max_size = 1300;
param.i_slice_count = 32;
param.i_width = settings.video_width;
param.i_height = settings.video_height;
param.i_width = extent.width;
param.i_height = extent.height;
param.i_log_level = X264_LOG_WARNING;
param.i_fps_num = fps * 1'000'000;
param.i_fps_num = settings.fps * 1'000'000;
param.i_fps_den = 1'000'000;
param.b_repeat_headers = 1;
param.b_aud = 0;
@@ -140,12 +122,12 @@ video_encoder_x264::video_encoder_x264(
param.vui.i_colmatrix = 1; // BT.709
param.vui.i_transfer = 13; // sRGB
param.vui.i_sar_width = settings.width;
param.vui.i_sar_height = settings.height;
param.vui.i_sar_width = extent.width;
param.vui.i_sar_height = extent.height;
param.rc.i_rc_method = X264_RC_ABR;
param.rc.i_bitrate = settings.bitrate / 1000; // x264 uses kbit/s
param.rc.i_vbv_max_bitrate = param.rc.i_bitrate;
param.rc.i_vbv_buffer_size = param.rc.i_bitrate / fps * 1.1;
param.rc.i_vbv_buffer_size = param.rc.i_bitrate / settings.fps * 1.1;
x264_param_apply_profile(&param, "main");
@@ -162,7 +144,7 @@ video_encoder_x264::video_encoder_x264(
i.luma = buffer_allocation(
vk.device,
{
.size = vk::DeviceSize(settings.video_width * settings.video_height),
.size = vk::DeviceSize(extent.width * extent.height),
.usage = vk::BufferUsageFlagBits::eTransferDst,
},
{
@@ -172,7 +154,7 @@ video_encoder_x264::video_encoder_x264(
"x264 luma buffer");
i.chroma = buffer_allocation(
vk.device, {
.size = vk::DeviceSize(settings.video_width * settings.video_height / 2),
.size = vk::DeviceSize(extent.width * extent.height / 2),
.usage = vk::BufferUsageFlagBits::eTransferDst,
},
{
@@ -187,9 +169,9 @@ video_encoder_x264::video_encoder_x264(
pic.img.i_csp = X264_CSP_NV12;
pic.img.i_plane = 2;
pic.img.i_stride[0] = settings.video_width;
pic.img.i_stride[0] = extent.width;
pic.img.plane[0] = (uint8_t *)i.luma.map();
pic.img.i_stride[1] = settings.video_width;
pic.img.i_stride[1] = extent.width;
pic.img.plane[1] = (uint8_t *)i.chroma.map();
}
}
@@ -204,16 +186,12 @@ std::pair<bool, vk::Semaphore> video_encoder_x264::present_image(vk::Image y_cbc
.bufferRowLength = chroma_width * 2,
.imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.imageOffset = {
.x = rect.offset.x,
.y = rect.offset.y,
},
.imageExtent = {
.width = rect.extent.width,
.height = rect.extent.height,
.width = extent.width,
.height = extent.height,
.depth = 1,
}});
cmd_buf.copyImageToBuffer(
@@ -224,16 +202,12 @@ std::pair<bool, vk::Semaphore> video_encoder_x264::present_image(vk::Image y_cbc
.bufferRowLength = chroma_width,
.imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = uint32_t(channels),
.baseArrayLayer = stream_idx,
.layerCount = 1,
},
.imageOffset = {
.x = rect.offset.x / 2,
.y = rect.offset.y / 2,
},
.imageExtent = {
.width = rect.extent.width / 2,
.height = rect.extent.height / 2,
.width = extent.width / 2,
.height = extent.height / 2,
.depth = 1,
}});
return {false, nullptr};
+1 -3
View File
@@ -47,8 +47,6 @@ class video_encoder_x264 : public video_encoder
std::array<in_t, num_slots> in;
uint32_t chroma_width;
vk::Rect2D rect;
struct pending_nal
{
int first_mb;
@@ -62,7 +60,7 @@ class video_encoder_x264 : public video_encoder
std::list<pending_nal> pending_nals;
public:
video_encoder_x264(wivrn_vk_bundle & vk, encoder_settings & settings, float fps, uint8_t stream_idx);
video_encoder_x264(wivrn_vk_bundle & vk, const encoder_settings & settings, uint8_t stream_idx);
std::pair<bool, vk::Semaphore> present_image(vk::Image y_cbcr, vk::raii::CommandBuffer & cmd_buf, uint8_t slot, uint64_t frame_index) override;
+4 -7
View File
@@ -509,6 +509,7 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
},
[&](const wivrn::from_headset::settings_changed & settings) {
wivrn_server_set_preferred_refresh_rate(dbus_server, settings.preferred_refresh_rate);
wivrn_server_set_bitrate(dbus_server, settings.bitrate_bps);
},
[&](const wivrn::from_headset::start_app & request) {
const auto & apps = list_applications();
@@ -525,9 +526,6 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
inhibitor.reset();
wivrn_server_set_headset_connected(dbus_server, false);
},
[&](const from_monado::bitrate_changed & value) {
wivrn_server_set_bitrate(dbus_server, value.bitrate_bps);
},
[&](const from_monado::server_error & e) {
wivrn_server_emit_server_error(dbus_server, e.where.c_str(), e.message.c_str());
},
@@ -724,9 +722,6 @@ void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & inf
{
GVariantBuilder * builder;
GVariant * value_eye_size = g_variant_new("(uu)", info.recommended_eye_width, info.recommended_eye_height);
wivrn_server_set_recommended_eye_size(dbus_server, value_eye_size);
builder = g_variant_builder_new(G_VARIANT_TYPE("ad"));
for (double rate: info.available_refresh_rates)
{
@@ -736,7 +731,9 @@ void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & inf
g_variant_builder_unref(builder);
wivrn_server_set_available_refresh_rates(dbus_server, value_refresh_rates);
wivrn_server_set_preferred_refresh_rate(dbus_server, info.preferred_refresh_rate);
wivrn_server_set_preferred_refresh_rate(dbus_server, info.settings.preferred_refresh_rate);
wivrn_server_set_bitrate(dbus_server, info.settings.bitrate_bps);
auto speaker = info.speaker.value_or(wivrn::from_headset::headset_info_packet::audio_description{});
wivrn_server_set_speaker_channels(dbus_server, speaker.num_channels);
+1 -6
View File
@@ -42,11 +42,6 @@ struct headset_connected
struct headset_disconnected
{};
struct bitrate_changed
{
uint32_t bitrate_bps;
};
struct server_error
{
std::string where;
@@ -55,10 +50,10 @@ struct server_error
using packets = std::variant<
wivrn::from_headset::headset_info_packet,
wivrn::from_headset::settings_changed,
wivrn::from_headset::start_app,
headset_connected,
headset_disconnected,
bitrate_changed,
server_error>;
} // namespace from_monado
+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 \
-49
View File
@@ -286,47 +286,6 @@ void disconnect()
call_method(get_user_bus(), "Disconnect", "");
}
void set_bitrate(std::string bitrate_str)
{
auto suffix = bitrate_str.back();
uint32_t bitrate = 0;
size_t str_len = bitrate_str.size();
switch (std::tolower(suffix))
{
case 'm':
bitrate = 1'000'000;
str_len = bitrate_str.size() - 1;
break;
case 'k':
bitrate = 1'000;
str_len = bitrate_str.size() - 1;
break;
default:
if (std::isdigit(suffix))
bitrate = 1;
break;
}
try
{
bitrate = bitrate * std::stoi(bitrate_str.substr(0, str_len));
}
catch (std::exception & e)
{
bitrate = 0;
}
if (bitrate == 0)
{
std::cerr << "Invalid bitrate value. Valid examples: 50M, 50000K, 50000000" << std::endl;
return;
}
set_property(get_user_bus(), "Bitrate", "u", bitrate);
}
int main(int argc, char ** argv)
{
CLI::App app;
@@ -374,14 +333,6 @@ int main(int argc, char ** argv)
app.add_subcommand("disconnect", "Disconnect headset")
->callback(disconnect);
std::string bitrate_str;
auto bitrate_command = app.add_subcommand("set-bitrate", "Set encoding bitrate");
bitrate_command->add_option("BITRATE", bitrate_str, "Desired total bitrate, e.g. 100M")->required();
bitrate_command->callback([&]() {
return set_bitrate(bitrate_str);
});
try
{
CLI11_PARSE(app, argc, argv);