Support passthrough for stream

This commit is contained in:
Patrick Nicolas committed 2024-11-06 19:50:44 +01:00
1 parent 45412e3389
commit 410b112fcf
34 files changed
+571 -260

No files matched your search

+56 -3
View File
@@ -43,6 +43,10 @@ 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)
@@ -88,6 +92,7 @@ void print_encoders(const std::vector<wivrn::encoder_settings> & encoders)
}
std::string codec(magic_enum::enum_name(encoder.codec));
U_LOG_I("\t%s (%s)", encoder.encoder_name.c_str(), codec.c_str());
U_LOG_I("\tchannels: %s", std::string(magic_enum::enum_name(encoder.channels)).c_str());
U_LOG_I("\tsize:%dx%d offset:%dx%d",
encoder.width,
encoder.height,
@@ -102,7 +107,7 @@ static void check_scale(std::string_view encoder_name, video_codec codec, uint16
#if WIVRN_USE_NVENC
if (encoder_name == encoder_nvenc)
{
auto max = VideoEncoderNvenc::get_max_size(codec);
auto max = video_encoder_nvenc::get_max_size(codec);
if (width * scale[0] > max[0])
{
scale[0] = double(max[0] - 1) / width;
@@ -135,7 +140,7 @@ static constexpr auto ffmpeg_version()
static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & codecs)
{
VideoEncoderFFMPEG::mute_logs mute;
video_encoder_ffmpeg::mute_logs mute;
encoder_settings s{
{
.width = 800,
@@ -159,7 +164,7 @@ static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & b
try
{
s.codec = codec;
video_encoder_va test(bundle, s, 60);
video_encoder_va test(bundle, s, 60, 0);
return codec;
}
catch (...)
@@ -295,10 +300,27 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
}
if (config.encoders.empty())
config.encoders = get_encoder_default_settings(bundle, info.supported_codecs);
if (not config.encoder_passthrough)
config.encoder_passthrough.emplace();
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);
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);
@@ -330,6 +352,8 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
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.width = std::ceil(encoder.width.value_or(1) * width);
settings.height = std::ceil(encoder.height.value_or(1) * height);
@@ -355,6 +379,35 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
res.push_back(settings);
}
split_bitrate(res, bitrate);
// passthrough encoder
{
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;
settings.width += settings.width % 2;
settings.height += settings.height % 2;
settings.video_width = settings.width;
settings.video_height = settings.height;
settings.codec = *encoder.codec;
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);
}
return res;
}
} // namespace wivrn