Change codec preference order to AV1,h264,h265
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -537,8 +537,15 @@ static bool hardware_accelerated(AMediaCodec * media_codec)
|
||||
std::vector<wivrn::video_codec> decoder::supported_codecs()
|
||||
{
|
||||
std::vector<wivrn::video_codec> result;
|
||||
// Make sure we update this code when codecs are changed
|
||||
static_assert(magic_enum::enum_count<wivrn::video_codec>() == 3);
|
||||
|
||||
for (auto codec: std::ranges::reverse_view(magic_enum::enum_values<wivrn::video_codec>()))
|
||||
// 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)));
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#endif
|
||||
#if WIVRN_USE_VAAPI
|
||||
#include "ffmpeg/video_encoder_va.h"
|
||||
#include <libavutil/ffversion.h>
|
||||
#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<int, 3> 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<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & codecs)
|
||||
{
|
||||
VideoEncoderFFMPEG::mute_logs mute;
|
||||
@@ -132,6 +148,14 @@ static std::optional<wivrn::video_codec> 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;
|
||||
|
||||
Reference in New Issue
Block a user