Make encoder options explicit in cmake

This commit is contained in:
Patrick Nicolas
2023-11-25 14:37:36 +01:00
parent 3700a97aed
commit 10fa78c21c
8 changed files with 37 additions and 38 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=/usr -DWIVRN_BUILD_CLIENT=OFF -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=/usr -DWIVRN_BUILD_CLIENT=OFF -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DWIVRN_USE_VAAPI=ON -DWIVRN_USE_X264=ON
- name: Package build dependencies
# For easier packaging, build dependencies are made available as a separate archive
+16 -16
View File
@@ -21,6 +21,10 @@ option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the V
option(WIVRN_BUILD_CLIENT "Build WiVRn client" ON)
option(WIVRN_BUILD_SERVER "Build WiVRn server" ON)
option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware encoder" OFF)
option(WIVRN_USE_VAAPI "Enable vaapi (AMD/Intel) hardware encoder" OFF)
option(WIVRN_USE_X264 "Enable x264 software encoder" OFF)
option(ENABLE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." ON)
if(ENABLE_COLOURED_OUTPUT)
@@ -35,37 +39,34 @@ find_package(PkgConfig REQUIRED)
find_package(Vulkan REQUIRED)
if (WIVRN_BUILD_SERVER)
find_package(CUDAToolkit)
pkg_check_modules(LIBAV IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
pkg_check_modules(X264 IMPORTED_TARGET x264)
if(CUDAToolkit_FOUND)
set(WIVRN_HAVE_CUDA ON)
if (NOT WIVRN_USE_NVENC AND NOT WIVRN_USE_VAAPI AND NOT WIVRN_USE_X264)
message(FATAL_ERROR "No encoder selected, use at least one of WIVRN_USE_NVENC, WIVRN_USE_VAAPI or WIVRN_USE_X264")
endif()
if(LIBAV_FOUND)
set(WIVRN_HAVE_FFMPEG ON)
if (WIVRN_USE_NVENC)
find_package(CUDAToolkit REQUIRED)
endif()
if(X264_FOUND)
set(WIVRN_HAVE_X264 ON)
if (WIVRN_USE_VAAPI)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
endif()
if (NOT CUDAToolkit_FOUND AND NOT LIBAV_FOUND AND NOT X264_FOUND)
message(FATAL_ERROR "No encoder found")
if (WIVRN_USE_X264)
pkg_check_modules(X264 IMPORTED_TARGET x264)
endif()
if (WIVRN_USE_SYSTEMD)
pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET systemd)
endif()
pkg_check_modules(AVAHI IMPORTED_TARGET avahi-client)
pkg_check_modules(libpulse IMPORTED_TARGET libpulse)
pkg_check_modules(AVAHI REQUIRED IMPORTED_TARGET avahi-client)
pkg_check_modules(libpulse REQUIRED IMPORTED_TARGET libpulse)
find_package(Eigen3 REQUIRED)
find_package(nlohmann_json REQUIRED)
endif()
if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
pkg_check_modules(LIBAV IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
@@ -95,6 +96,5 @@ if (WIVRN_BUILD_CLIENT)
endif()
if (WIVRN_BUILD_SERVER)
find_package(nlohmann_json REQUIRED)
add_subdirectory(server)
endif()
+1 -1
View File
@@ -23,7 +23,7 @@ dnf swap mesa-va-drivers mesa-va-drivers-freeworld
### Compilation
From your checkout directory
```bash
cmake -B build-server . -GNinja -DWIVRN_BUILD_CLIENT=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake -B build-server . -GNinja -DWIVRN_BUILD_CLIENT=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWIVRN_USE_VAAPI=ON -DWIVRN_USE_X264=ON -DWIVRN_USE_NVENC=ON
cmake --build build-server
# Set WiVRn as the active OpenXR runtime, delete ~/.config/openxr/1/active_runtime.json after you are done using WiVRn
+3 -3
View File
@@ -19,6 +19,6 @@
#pragma once
#cmakedefine WIVRN_HAVE_X264
#cmakedefine WIVRN_HAVE_CUDA
#cmakedefine WIVRN_HAVE_FFMPEG
#cmakedefine WIVRN_USE_NVENC
#cmakedefine WIVRN_USE_VAAPI
#cmakedefine WIVRN_USE_X264
+3 -3
View File
@@ -81,12 +81,12 @@ target_compile_features(wivrn-server PRIVATE cxx_std_20)
target_include_directories(wivrn-server SYSTEM PRIVATE ${monado_SOURCE_DIR}/src/xrt/compositor/)
if(CUDAToolkit_FOUND)
if(WIVRN_USE_NVENC)
target_sources(wivrn-server PRIVATE driver/video_encoder_nvenc.cpp)
target_link_libraries(wivrn-server PRIVATE CUDA::cuda_driver nvidia-encode)
endif()
if(LIBAV_FOUND)
if(WIVRN_USE_VAAPI)
target_sources(
wivrn-server
PRIVATE driver/ffmpeg/VideoEncoderFFMPEG.cpp driver/ffmpeg/VideoEncoderVA.cpp
@@ -95,7 +95,7 @@ if(LIBAV_FOUND)
target_link_libraries(wivrn-server PRIVATE PkgConfig::LIBAV)
endif()
if(X264_FOUND)
if(WIVRN_USE_X264)
target_sources(wivrn-server PRIVATE driver/video_encoder_x264.cpp)
target_link_libraries(wivrn-server PRIVATE PkgConfig::X264)
endif()
+7 -6
View File
@@ -22,12 +22,13 @@
#include "video_encoder.h"
#include "vk/vk_helpers.h"
#include <cmath>
#include <string>
#include <vulkan/vulkan.h>
#include "wivrn_config.h"
#ifdef WIVRN_HAVE_FFMPEG
#ifdef WIVRN_USE_VAAPI
#include "ffmpeg/VideoEncoderVA.h"
#endif
@@ -56,9 +57,9 @@ static std::vector<xrt::drivers::wivrn::encoder_settings> get_encoder_default_se
if (is_nvidia(vk))
{
#ifdef WIVRN_HAVE_CUDA
#ifdef WIVRN_USE_NVENC
settings.encoder_name = encoder_nvenc;
#elif defined(WIVRN_HAVE_X264)
#elif defined(WIVRN_USE_X264)
settings.encoder_name = encoder_x264;
settings.codec = xrt::drivers::wivrn::h264;
U_LOG_W("nvidia GPU detected, but cuda support not compiled");
@@ -69,9 +70,9 @@ static std::vector<xrt::drivers::wivrn::encoder_settings> get_encoder_default_se
}
else
{
#ifdef WIVRN_HAVE_FFMPEG
#ifdef WIVRN_USE_VAAPI
settings.encoder_name = encoder_vaapi;
#elif defined(WIVRN_HAVE_X264)
#elif defined(WIVRN_USE_X264)
settings.encoder_name = encoder_x264;
settings.codec = xrt::drivers::wivrn::h264;
U_LOG_W("ffmpeg support not compiled, vaapi encoder not available");
@@ -127,7 +128,7 @@ VkImageTiling xrt::drivers::wivrn::get_required_tiling(vk_bundle * vk,
bool can_drm = vk->has_EXT_image_drm_format_modifier;
for (const auto & item: settings)
{
#ifdef WIVRN_HAVE_FFMPEG
#ifdef WIVRN_USE_VAAPI
if (item.encoder_name == encoder_vaapi)
{
can_optimal = false;
+6 -6
View File
@@ -27,13 +27,13 @@
#include "wivrn_config.h"
#ifdef WIVRN_HAVE_CUDA
#ifdef WIVRN_USE_NVENC
#include "video_encoder_nvenc.h"
#endif
#ifdef WIVRN_HAVE_FFMPEG
#ifdef WIVRN_USE_VAAPI
#include "ffmpeg/VideoEncoderVA.h"
#endif
#ifdef WIVRN_HAVE_X264
#ifdef WIVRN_USE_X264
#include "video_encoder_x264.h"
#endif
@@ -51,19 +51,19 @@ std::unique_ptr<VideoEncoder> VideoEncoder::Create(
{
using namespace std::string_literals;
std::unique_ptr<VideoEncoder> res;
#ifdef WIVRN_HAVE_X264
#ifdef WIVRN_USE_X264
if (settings.encoder_name == encoder_x264)
{
res = std::make_unique<VideoEncoderX264>(vk, pool, settings, input_width, input_height, fps);
}
#endif
#ifdef WIVRN_HAVE_CUDA
#ifdef WIVRN_USE_NVENC
if (settings.encoder_name == encoder_nvenc)
{
res = std::make_unique<VideoEncoderNvenc>(vk, settings, fps);
}
#endif
#ifdef WIVRN_HAVE_FFMPEG
#ifdef WIVRN_USE_VAAPI
if (settings.encoder_name == encoder_vaapi)
{
res = std::make_unique<VideoEncoderVA>(vk, settings, fps);
-2
View File
@@ -68,7 +68,6 @@ int create_listen_socket()
int fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
int ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
#ifdef XRT_HAVE_LIBBSD
// no other instance is running, or we would have never arrived here
if (ret < 0 && errno == EADDRINUSE)
{
@@ -82,7 +81,6 @@ int create_listen_socket()
}
ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
}
#endif
if (ret < 0)
{