diff --git a/CMakeLists.txt b/CMakeLists.txt index 196e5a40..2b9af012 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Default to PIC code diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 6dcaac29..1be1fbd5 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -66,7 +66,6 @@ endif() ############################################################################## # Main sources # -target_compile_features(wivrn PRIVATE cxx_std_23) target_compile_definitions(wivrn PRIVATE "XR_USE_TIMESPEC=1") set_target_properties(wivrn PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/client/decoder/android/android_decoder.cpp b/client/decoder/android/android_decoder.cpp index 61387bf8..066e8cde 100644 --- a/client/decoder/android/android_decoder.cpp +++ b/client/decoder/android/android_decoder.cpp @@ -537,8 +537,15 @@ static bool hardware_accelerated(AMediaCodec * media_codec) std::vector decoder::supported_codecs() { std::vector result; + // Make sure we update this code when codecs are changed + static_assert(magic_enum::enum_count() == 3); - for (auto codec: std::ranges::reverse_view(magic_enum::enum_values())) + // In order or preference, from preferred to least preferred + for (auto codec: { + wivrn::video_codec::av1, + wivrn::video_codec::h264, + wivrn::video_codec::h265, + }) { AMediaCodec_ptr media_codec(AMediaCodec_createDecoderByType(mime(codec))); diff --git a/docs/configuration.md b/docs/configuration.md index 4fa72f65..6e8ea30a 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -48,7 +48,7 @@ Identifier of the encoder, one of * `vulkan`: experimental, for any GPU that supports vulkan video encode ### `codec` -Default value: `av1` if supported by both headset and hardware encoder, else `h265`. +Default value: first supported by both headset and encoder of `av1`, `h264`, `h265`. One of `h264`, `h265` or `av1`. Not all encoders support every codec, `x264` and `vulkan` only support `h264`, `nvenc` only `h264` and `h265` diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 94601571..ef9b600a 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -35,6 +35,7 @@ #endif #if WIVRN_USE_VAAPI #include "ffmpeg/video_encoder_va.h" +#include #endif namespace wivrn @@ -117,6 +118,21 @@ static void check_scale(std::string_view encoder_name, video_codec codec, uint16 } #if WIVRN_USE_VAAPI + +static constexpr auto ffmpeg_version() +{ + std::array result; + std::string_view version = FFMPEG_VERSION; + for (auto & item: result) + { + auto dot = version.find("."); + auto number = version.substr(0, dot); + version = version.substr(dot + 1); + std::from_chars(number.begin(), number.end(), item); + } + return result; +} + static std::optional filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector & codecs) { VideoEncoderFFMPEG::mute_logs mute; @@ -132,6 +148,14 @@ static std::optional filter_codecs_vaapi(wivrn_vk_bundle & b }; for (auto codec: codecs) { + if constexpr (ffmpeg_version()[0] < 6) + { + if (codec == wivrn::video_codec::h264) + { + U_LOG_W("Skip h264 on ffmpeg < 6 due to poor performance"); + continue; + } + } try { s.codec = codec;