From 53853df33a9a8820798dfd177d6bb82ef1c6494a Mon Sep 17 00:00:00 2001 From: "Gale, Thy-Lan" Date: Tue, 10 Sep 2024 13:17:05 -0700 Subject: [PATCH] obs-qsv11: Add AV1 Screen Content Tools --- plugins/obs-qsv11/QSV_Encoder.h | 1 + plugins/obs-qsv11/QSV_Encoder_Internal.cpp | 32 +++++++++++++++++++ plugins/obs-qsv11/QSV_Encoder_Internal.h | 4 +++ .../obs-qsv11/obs-qsv-test/obs-qsv-test.cpp | 1 + 4 files changed, 38 insertions(+) diff --git a/plugins/obs-qsv11/QSV_Encoder.h b/plugins/obs-qsv11/QSV_Encoder.h index ab266774c..c69d20aba 100644 --- a/plugins/obs-qsv11/QSV_Encoder.h +++ b/plugins/obs-qsv11/QSV_Encoder.h @@ -56,6 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once +#define ONEVPL_EXPERIMENTAL #include #include #include diff --git a/plugins/obs-qsv11/QSV_Encoder_Internal.cpp b/plugins/obs-qsv11/QSV_Encoder_Internal.cpp index a90af811f..17dac34a9 100644 --- a/plugins/obs-qsv11/QSV_Encoder_Internal.cpp +++ b/plugins/obs-qsv11/QSV_Encoder_Internal.cpp @@ -195,6 +195,22 @@ static inline bool HasOptimizedBRCSupport(const mfxPlatform &platform, UNUSED_PARAMETER(rateControl); return false; } + +static inline bool HasAV1ScreenContentSupport(const mfxPlatform &platform, + const mfxVersion &version) +{ +#if (MFX_VERSION_MAJOR >= 2 && MFX_VERSION_MINOR >= 12) || MFX_VERSION_MAJOR > 2 + // Platform enums needed are introduced in VPL version 2.12 + if ((version.Major >= 2 && version.Minor >= 12) || version.Major > 2) + if (platform.CodeName >= MFX_PLATFORM_LUNARLAKE && + platform.CodeName != MFX_PLATFORM_ALDERLAKE_N && + platform.CodeName != MFX_PLATFORM_ARROWLAKE) + return true; +#endif + UNUSED_PARAMETER(platform); + UNUSED_PARAMETER(version); + return false; +} PRAGMA_WARN_POP mfxStatus QSV_Encoder_Internal::InitParams(qsv_param_t *pParams, @@ -372,6 +388,22 @@ mfxStatus QSV_Encoder_Internal::InitParams(qsv_param_t *pParams, extendedBuffers.push_back((mfxExtBuffer *)&m_ExtAv1TileParam); } + // AV1_SCREEN_CONTENT_TOOLS API is introduced in VPL version 2.11 +#if (MFX_VERSION_MAJOR >= 2 && MFX_VERSION_MINOR >= 11) || MFX_VERSION_MAJOR > 2 + if (codec == QSV_CODEC_AV1 && + HasAV1ScreenContentSupport(platform, m_ver)) { + memset(&m_ExtAV1ScreenContentTools, 0, + sizeof(m_ExtAV1ScreenContentTools)); + m_ExtAV1ScreenContentTools.Header.BufferId = + MFX_EXTBUFF_AV1_SCREEN_CONTENT_TOOLS; + m_ExtAV1ScreenContentTools.Header.BufferSz = + sizeof(m_ExtAV1ScreenContentTools); + m_ExtAV1ScreenContentTools.Palette = MFX_CODINGOPTION_ON; + extendedBuffers.push_back( + (mfxExtBuffer *)&m_ExtAV1ScreenContentTools); + } +#endif + #if defined(_WIN32) // TODO: Ask about this one on VAAPI too. memset(&m_ExtVideoSignalInfo, 0, sizeof(m_ExtVideoSignalInfo)); diff --git a/plugins/obs-qsv11/QSV_Encoder_Internal.h b/plugins/obs-qsv11/QSV_Encoder_Internal.h index 478f0b87a..c90efedf7 100644 --- a/plugins/obs-qsv11/QSV_Encoder_Internal.h +++ b/plugins/obs-qsv11/QSV_Encoder_Internal.h @@ -54,6 +54,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once +#define ONEVPL_EXPERIMENTAL #include #include #include "QSV_Encoder.h" @@ -121,6 +122,9 @@ private: mfxExtCodingOption m_co; mfxExtHEVCParam m_ExtHEVCParam{}; mfxExtAV1TileParam m_ExtAv1TileParam{}; +#if (MFX_VERSION_MAJOR >= 2 && MFX_VERSION_MINOR >= 11) || MFX_VERSION_MAJOR > 2 + mfxExtAV1ScreenContentTools m_ExtAV1ScreenContentTools{}; +#endif mfxExtVideoSignalInfo m_ExtVideoSignalInfo{}; mfxExtChromaLocInfo m_ExtChromaLocInfo{}; mfxExtMasteringDisplayColourVolume m_ExtMasteringDisplayColourVolume{}; diff --git a/plugins/obs-qsv11/obs-qsv-test/obs-qsv-test.cpp b/plugins/obs-qsv11/obs-qsv-test/obs-qsv-test.cpp index 11dafa375..14d3d07bd 100644 --- a/plugins/obs-qsv11/obs-qsv-test/obs-qsv-test.cpp +++ b/plugins/obs-qsv11/obs-qsv-test/obs-qsv-test.cpp @@ -1,3 +1,4 @@ +#define ONEVPL_EXPERIMENTAL #include #include #include