From fc7ec9e538b60d890c49fa8d88905594b9340602 Mon Sep 17 00:00:00 2001 From: loki Date: Tue, 17 Aug 2021 21:15:38 +0200 Subject: [PATCH] Better validation of vaapi capability --- sunshine/platform/linux/vaapi.cpp | 52 ++++++++++++++++++++----------- sunshine/video.cpp | 2 +- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/sunshine/platform/linux/vaapi.cpp b/sunshine/platform/linux/vaapi.cpp index 25c7788b..363c51ad 100644 --- a/sunshine/platform/linux/vaapi.cpp +++ b/sunshine/platform/linux/vaapi.cpp @@ -547,6 +547,27 @@ int vaapi_make_hwdevice_ctx(platf::hwdevice_t *base, AVBufferRef **hw_device_buf return 0; } +bool query(display_t::pointer display, profile_e profile) { + std::vector entrypoints; + entrypoints.resize(maxNumEntrypoints(display)); + + int count; + auto status = queryConfigEntrypoints(display, profile, entrypoints.data(), &count); + if(status) { + BOOST_LOG(error) << "Couldn't query entrypoints for profile::H264Main "sv << va::errorStr(status); + return false; + } + entrypoints.resize(count); + + for(auto entrypoint : entrypoints) { + if(entrypoint == entry_e::EncSlice || entrypoint == entry_e::EncSliceLP) { + return true; + } + } + + return false; +} + bool validate(int fd) { if(init()) { return false; @@ -561,34 +582,29 @@ bool validate(int fd) { std::string_view render_device { string, (std::size_t)bytes }; BOOST_LOG(error) << "Couldn't open a va display from DRM with device: "sv << render_device; - return -1; + return false; } int major, minor; auto status = initialize(display.get(), &major, &minor); if(status) { BOOST_LOG(error) << "Couldn't initialize va display: "sv << va::errorStr(status); - return -1; + return false; } - std::vector entrypoints; - entrypoints.resize(maxNumEntrypoints(display.get())); - - int count; - status = queryConfigEntrypoints(display.get(), profile_e::H264Main, entrypoints.data(), &count); - if(status) { - BOOST_LOG(error) << "Couldn't query entrypoints for profile::H264Main "sv << va::errorStr(status); - return -1; - } - entrypoints.resize(count); - - for(auto entrypoint : entrypoints) { - if(entrypoint == entry_e::EncSlice) { - return true; - } + if(!query(display.get(), profile_e::H264Main)) { + return false; } - return false; + if(config::video.hevc_mode > 1 && !query(display.get(), profile_e::HEVCMain)) { + return false; + } + + if(config::video.hevc_mode > 2 && !query(display.get(), profile_e::HEVCMain10)) { + return false; + } + + return true; } std::shared_ptr make_hwdevice(int width, int height) { diff --git a/sunshine/video.cpp b/sunshine/video.cpp index 6fbc72be..403db051 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -88,7 +88,7 @@ public: data[0] = sw_frame->data[0] + offsetY; if(sw_frame->format == AV_PIX_FMT_NV12) { - data[1] = sw_frame->data[1] + offsetUV; + data[1] = sw_frame->data[1] + offsetUV * 2; data[2] = nullptr; } else {