From c4ca9a7bae944629f5091582607b7e3a7c1108d8 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Thu, 15 Apr 2021 12:08:22 +0300 Subject: [PATCH] Initial oneVPL support --- modules/videoio/cmake/detect_msdk.cmake | 17 +++++++++- modules/videoio/src/cap_mfx_common.hpp | 43 ++++++++++++++++++------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/modules/videoio/cmake/detect_msdk.cmake b/modules/videoio/cmake/detect_msdk.cmake index 41258a7fff..bc83465e76 100644 --- a/modules/videoio/cmake/detect_msdk.cmake +++ b/modules/videoio/cmake/detect_msdk.cmake @@ -1,3 +1,16 @@ +set(MFX_DEFS "") + +if(NOT HAVE_MFX) + find_package(VPL) + if(VPL_FOUND) + set(MFX_INCLUDE_DIRS "") + set(MFX_LIBRARIES "${VPL_IMPORTED_TARGETS}") + set(HAVE_MFX TRUE) + list(APPEND MFX_DEFS "HAVE_ONEVPL") + endif() +endif() + + if(NOT HAVE_MFX) set(paths "${MFX_HOME}" ENV "MFX_HOME" ENV "INTELMEDIASDKROOT") if(MSVC) @@ -24,6 +37,7 @@ if(NOT HAVE_MFX) set(HAVE_MFX TRUE) set(MFX_INCLUDE_DIRS "${MFX_INCLUDE}") set(MFX_LIBRARIES "${MFX_LIBRARY}") + list(APPEND MFX_DEFS "HAVE_MFX_PLUGIN") endif() endif() @@ -49,7 +63,8 @@ if(HAVE_MFX AND UNIX) endif() if(HAVE_MFX) - ocv_add_external_target(mediasdk "${MFX_INCLUDE_DIRS}" "${MFX_LIBRARIES}" "HAVE_MFX") + list(APPEND MFX_DEFS "HAVE_MFX") + ocv_add_external_target(mediasdk "${MFX_INCLUDE_DIRS}" "${MFX_LIBRARIES}" "${MFX_DEFS}") endif() set(HAVE_MFX ${HAVE_MFX} PARENT_SCOPE) diff --git a/modules/videoio/src/cap_mfx_common.hpp b/modules/videoio/src/cap_mfx_common.hpp index dca96b6ef9..2830592163 100644 --- a/modules/videoio/src/cap_mfx_common.hpp +++ b/modules/videoio/src/cap_mfx_common.hpp @@ -12,12 +12,22 @@ #include #include -#include -#include -#include -#include -#include -#include +#ifdef HAVE_ONEVPL +# include +# include +# include +# include +# include +#else +# include +# include +# include +# include +# include +# ifdef HAVE_MFX_PLUGIN +# include +# endif +#endif // // // Debug helpers // @@ -93,8 +103,6 @@ inline std::string mfxStatusToString(mfxStatus s) { case MFX_ERR_UNDEFINED_BEHAVIOR: return "MFX_ERR_UNDEFINED_BEHAVIOR"; case MFX_ERR_DEVICE_FAILED: return "MFX_ERR_DEVICE_FAILED"; case MFX_ERR_MORE_BITSTREAM: return "MFX_ERR_MORE_BITSTREAM"; - case MFX_ERR_INCOMPATIBLE_AUDIO_PARAM: return "MFX_ERR_INCOMPATIBLE_AUDIO_PARAM"; - case MFX_ERR_INVALID_AUDIO_PARAM: return "MFX_ERR_INVALID_AUDIO_PARAM"; case MFX_ERR_GPU_HANG: return "MFX_ERR_GPU_HANG"; case MFX_ERR_REALLOC_SURFACE: return "MFX_ERR_REALLOC_SURFACE"; case MFX_WRN_IN_EXECUTION: return "MFX_WRN_IN_EXECUTION"; @@ -105,8 +113,7 @@ inline std::string mfxStatusToString(mfxStatus s) { case MFX_WRN_VALUE_NOT_CHANGED: return "MFX_WRN_VALUE_NOT_CHANGED"; case MFX_WRN_OUT_OF_RANGE: return "MFX_WRN_OUT_OF_RANGE"; case MFX_WRN_FILTER_SKIPPED: return "MFX_WRN_FILTER_SKIPPED"; - case MFX_WRN_INCOMPATIBLE_AUDIO_PARAM: return "MFX_WRN_INCOMPATIBLE_AUDIO_PARAM"; - default: return ""; + default: return ""; } } @@ -174,33 +181,45 @@ class Plugin public: static Plugin * loadEncoderPlugin(MFXVideoSession &session, mfxU32 codecId) { +#ifdef HAVE_MFX_PLUGIN static const mfxPluginUID hevc_enc_uid = { 0x6f, 0xad, 0xc7, 0x91, 0xa0, 0xc2, 0xeb, 0x47, 0x9a, 0xb6, 0xdc, 0xd5, 0xea, 0x9d, 0xa3, 0x47 }; if (codecId == MFX_CODEC_HEVC) return new Plugin(session, hevc_enc_uid); +#else + CV_UNUSED(session); CV_UNUSED(codecId); +#endif return 0; } static Plugin * loadDecoderPlugin(MFXVideoSession &session, mfxU32 codecId) { +#ifdef HAVE_MFX_PLUGIN static const mfxPluginUID hevc_dec_uid = { 0x33, 0xa6, 0x1c, 0x0b, 0x4c, 0x27, 0x45, 0x4c, 0xa8, 0xd8, 0x5d, 0xde, 0x75, 0x7c, 0x6f, 0x8e }; if (codecId == MFX_CODEC_HEVC) return new Plugin(session, hevc_dec_uid); +#else + CV_UNUSED(session); CV_UNUSED(codecId); +#endif return 0; } ~Plugin() { +#ifdef HAVE_MFX_PLUGIN if (isGood()) MFXVideoUSER_UnLoad(session, &uid); +#endif } bool isGood() const { return res >= MFX_ERR_NONE; } private: - MFXVideoSession &session; - mfxPluginUID uid; mfxStatus res; private: +#ifdef HAVE_MFX_PLUGIN + MFXVideoSession &session; + mfxPluginUID uid; Plugin(MFXVideoSession &_session, mfxPluginUID _uid) : session(_session), uid(_uid) { res = MFXVideoUSER_Load(session, &uid, 1); } +#endif Plugin(const Plugin &); Plugin &operator=(const Plugin &); };