move stuff in common, clang-format, update copyright
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
// Copyright 2022, Guillaume Meunier
|
||||
// Copyright 2022, Patrick Nicolas
|
||||
// SPDX-License-Identifier: BSL-1.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/>.
|
||||
*/
|
||||
|
||||
#include "encoder_settings.h"
|
||||
#include "util/u_config_json.h"
|
||||
@@ -10,7 +25,9 @@
|
||||
#include <string>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#ifdef XRT_HAVE_FFMPEG
|
||||
#include "wivrn_config.h"
|
||||
|
||||
#ifdef WIVRN_HAVE_FFMPEG
|
||||
#include "ffmpeg/VideoEncoderVA.h"
|
||||
#endif
|
||||
|
||||
@@ -19,16 +36,14 @@ using namespace xrt::drivers::wivrn;
|
||||
// TODO: size independent bitrate
|
||||
static const uint64_t default_bitrate = 10'000'000;
|
||||
|
||||
static bool
|
||||
is_nvidia(vk_bundle *vk)
|
||||
static bool is_nvidia(vk_bundle * vk)
|
||||
{
|
||||
VkPhysicalDeviceProperties physical_device_properties;
|
||||
vk->vkGetPhysicalDeviceProperties(vk->physical_device, &physical_device_properties);
|
||||
return physical_device_properties.vendorID == 0x10DE;
|
||||
}
|
||||
|
||||
static std::vector<xrt::drivers::wivrn::encoder_settings>
|
||||
get_encoder_default_settings(vk_bundle *vk, uint16_t width, uint16_t height)
|
||||
static std::vector<xrt::drivers::wivrn::encoder_settings> get_encoder_default_settings(vk_bundle * vk, uint16_t width, uint16_t height)
|
||||
{
|
||||
xrt::drivers::wivrn::encoder_settings settings{};
|
||||
settings.width = width;
|
||||
@@ -36,10 +51,11 @@ get_encoder_default_settings(vk_bundle *vk, uint16_t width, uint16_t height)
|
||||
settings.codec = xrt::drivers::wivrn::h265;
|
||||
settings.bitrate = default_bitrate;
|
||||
|
||||
if (is_nvidia(vk)) {
|
||||
#ifdef XRT_HAVE_CUDA
|
||||
if (is_nvidia(vk))
|
||||
{
|
||||
#ifdef WIVRN_HAVE_CUDA
|
||||
settings.encoder_name = encoder_nvenc;
|
||||
#elif defined(XRT_HAVE_X264)
|
||||
#elif defined(WIVRN_HAVE_X264)
|
||||
settings.encoder_name = encoder_x264;
|
||||
settings.codec = xrt::drivers::wivrn::h264;
|
||||
U_LOG_W("nvidia GPU detected, but cuda support not compiled");
|
||||
@@ -47,10 +63,12 @@ get_encoder_default_settings(vk_bundle *vk, uint16_t width, uint16_t height)
|
||||
U_LOG_E("no suitable encoder available (compile with x264 or cuda support)");
|
||||
return {};
|
||||
#endif
|
||||
} else {
|
||||
#ifdef XRT_HAVE_FFMPEG
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef WIVRN_HAVE_FFMPEG
|
||||
settings.encoder_name = encoder_vaapi;
|
||||
#elif defined(XRT_HAVE_X264)
|
||||
#elif defined(WIVRN_HAVE_X264)
|
||||
settings.encoder_name = encoder_x264;
|
||||
settings.codec = xrt::drivers::wivrn::h264;
|
||||
U_LOG_W("ffmpeg support not compiled, vaapi encoder not available");
|
||||
@@ -63,26 +81,28 @@ get_encoder_default_settings(vk_bundle *vk, uint16_t width, uint16_t height)
|
||||
return {settings};
|
||||
}
|
||||
|
||||
std::vector<encoder_settings>
|
||||
xrt::drivers::wivrn::get_encoder_settings(vk_bundle *vk, uint16_t width, uint16_t height)
|
||||
std::vector<encoder_settings> xrt::drivers::wivrn::get_encoder_settings(vk_bundle * vk, uint16_t width, uint16_t height)
|
||||
{
|
||||
u_config_json config_json{};
|
||||
std::unique_ptr<u_config_json, void (*)(u_config_json *)> raii(&config_json, u_config_json_close);
|
||||
|
||||
u_config_json_open_or_create_main_file(&config_json);
|
||||
if (!config_json.file_loaded) {
|
||||
if (!config_json.file_loaded)
|
||||
{
|
||||
U_LOG_D("no config file, using default");
|
||||
return get_encoder_default_settings(vk, width, height);
|
||||
}
|
||||
|
||||
const cJSON *config_wivrn = u_json_get(config_json.root, "config_wivrn");
|
||||
if (config_wivrn == NULL) {
|
||||
const cJSON * config_wivrn = u_json_get(config_json.root, "config_wivrn");
|
||||
if (config_wivrn == NULL)
|
||||
{
|
||||
U_LOG_D("no config_wivrn entry, using default");
|
||||
return get_encoder_default_settings(vk, width, height);
|
||||
}
|
||||
|
||||
const cJSON *config_encoder = u_json_get(config_wivrn, "encoders");
|
||||
if (config_encoder == NULL) {
|
||||
const cJSON * config_encoder = u_json_get(config_wivrn, "encoders");
|
||||
if (config_encoder == NULL)
|
||||
{
|
||||
U_LOG_D("no config_wivrn.encoders entry, using default");
|
||||
return get_encoder_default_settings(vk, width, height);
|
||||
}
|
||||
@@ -91,14 +111,16 @@ xrt::drivers::wivrn::get_encoder_settings(vk_bundle *vk, uint16_t width, uint16_
|
||||
|
||||
int next_group = 0;
|
||||
|
||||
for (int i = 0; i < num_encoders; ++i) {
|
||||
cJSON *encoder = cJSON_GetArrayItem(config_encoder, i);
|
||||
for (int i = 0; i < num_encoders; ++i)
|
||||
{
|
||||
cJSON * encoder = cJSON_GetArrayItem(config_encoder, i);
|
||||
xrt::drivers::wivrn::encoder_settings settings{};
|
||||
|
||||
auto name = u_json_get(encoder, "encoder");
|
||||
if (name && cJSON_IsString(name))
|
||||
settings.encoder_name = name->valuestring;
|
||||
else {
|
||||
else
|
||||
{
|
||||
U_LOG_E("missing \"encoder\" key in config_wivrn");
|
||||
continue;
|
||||
}
|
||||
@@ -133,20 +155,25 @@ xrt::drivers::wivrn::get_encoder_settings(vk_bundle *vk, uint16_t width, uint16_
|
||||
settings.group = group->valueint;
|
||||
|
||||
auto codec = u_json_get(encoder, "codec");
|
||||
if (codec && cJSON_IsString(codec)) {
|
||||
if (codec && cJSON_IsString(codec))
|
||||
{
|
||||
if (codec->valuestring == std::string("h264"))
|
||||
settings.codec = xrt::drivers::wivrn::h264;
|
||||
else if (codec->valuestring == std::string("h265"))
|
||||
settings.codec = xrt::drivers::wivrn::h265;
|
||||
else {
|
||||
else
|
||||
{
|
||||
U_LOG_E("invalid video codec %s", codec->valuestring);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
auto options = u_json_get(encoder, "options");
|
||||
if (options && cJSON_IsObject(options)) {
|
||||
for (auto child = options->child; child; child = child->next) {
|
||||
if (cJSON_IsString(child)) {
|
||||
if (options && cJSON_IsObject(options))
|
||||
{
|
||||
for (auto child = options->child; child; child = child->next)
|
||||
{
|
||||
if (cJSON_IsString(child))
|
||||
{
|
||||
settings.options[child->string] = child->valuestring;
|
||||
}
|
||||
}
|
||||
@@ -160,16 +187,16 @@ xrt::drivers::wivrn::get_encoder_settings(vk_bundle *vk, uint16_t width, uint16_
|
||||
return res;
|
||||
}
|
||||
|
||||
VkImageTiling
|
||||
xrt::drivers::wivrn::get_required_tiling(vk_bundle *vk,
|
||||
const std::vector<xrt::drivers::wivrn::encoder_settings> &settings)
|
||||
VkImageTiling xrt::drivers::wivrn::get_required_tiling(vk_bundle * vk,
|
||||
const std::vector<xrt::drivers::wivrn::encoder_settings> & settings)
|
||||
{
|
||||
|
||||
bool can_optimal = true;
|
||||
bool can_drm = vk->has_EXT_image_drm_format_modifier;
|
||||
for (const auto &item : settings) {
|
||||
#ifdef XRT_HAVE_FFMPEG
|
||||
if (item.encoder_name == encoder_vaapi) {
|
||||
for (const auto & item: settings)
|
||||
{
|
||||
#ifdef WIVRN_HAVE_FFMPEG
|
||||
if (item.encoder_name == encoder_vaapi)
|
||||
{
|
||||
can_optimal = false;
|
||||
if (not use_drm_format_modifiers)
|
||||
can_drm = false;
|
||||
|
||||
Reference in New Issue
Block a user