diff --git a/modules/gapi/include/opencv2/gapi/streaming/onevpl/cfg_params.hpp b/modules/gapi/include/opencv2/gapi/streaming/onevpl/cfg_params.hpp index 25573afd4c..0db9a86e58 100644 --- a/modules/gapi/include/opencv2/gapi/streaming/onevpl/cfg_params.hpp +++ b/modules/gapi/include/opencv2/gapi/streaming/onevpl/cfg_params.hpp @@ -185,6 +185,8 @@ struct GAPI_EXPORTS CfgParam { const name_t& get_name() const; const value_t& get_value() const; bool is_major() const; + std::string to_string() const; + bool operator==(const CfgParam& rhs) const; bool operator< (const CfgParam& rhs) const; bool operator!=(const CfgParam& rhs) const; diff --git a/modules/gapi/samples/onevpl_infer_single_roi.cpp b/modules/gapi/samples/onevpl_infer_single_roi.cpp index 15f3813787..8759295f6a 100644 --- a/modules/gapi/samples/onevpl_infer_single_roi.cpp +++ b/modules/gapi/samples/onevpl_infer_single_roi.cpp @@ -59,7 +59,7 @@ const std::string keys = "{ vpp_frames_pool_size | 0 | OneVPL source applies this parameter as preallocated frames pool size for VPP preprocessing results}" "{ roi | -1,-1,-1,-1 | Region of interest (ROI) to use for inference. Identified automatically when not set }" "{ source_device | CPU | choose device for decoding }" - "{ preproc_device | CPU | choose device for preprocessing }"; + "{ preproc_device | | choose device for preprocessing }"; namespace { @@ -609,11 +609,6 @@ int main(int argc, char *argv[]) { if (is_gpu(source_device)) { std::cout << "enforce VPL Source deconding on device: " << source_device << std::endl; // use special 'Device' constructor for `onevpl::GSource` - // put accel type description for VPL source - source_cfgs.push_back(cfg::create_from_string( - "mfxImplDescription.AccelerationMode" - ":" - "MFX_ACCEL_MODE_VIA_D3D11")); cap = cv::gapi::wip::make_onevpl_src(file_path, source_cfgs, gpu_accel_device.value(), gpu_accel_ctx.value()); diff --git a/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_va_api.cpp b/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_va_api.cpp index 82bada7b70..ca5f1de94c 100644 --- a/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_va_api.cpp +++ b/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_va_api.cpp @@ -28,6 +28,7 @@ VPLVAAPIAccelerationPolicy::VPLVAAPIAccelerationPolicy(device_selector_ptr_t sel VPLAccelerationPolicy(selector), cpu_dispatcher(new VPLCPUAccelerationPolicy(selector)), va_handle() { + GAPI_LOG_INFO(nullptr, "created - TODO dispatchered on CPU acceleration"); #if defined(HAVE_VA) || defined(HAVE_VA_INTEL) // setup VAAPI device IDeviceSelector::DeviceScoreTable devices = get_device_selector()->select_devices(); diff --git a/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp b/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp index 28f01c5718..050c744447 100644 --- a/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp +++ b/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp @@ -65,7 +65,7 @@ private: struct Aux {}; #endif -static std::vector insertCfgparam(std::vector &¶m_array, AccelType type) { +std::vector update_param_with_accel_type(std::vector &¶m_array, AccelType type) { switch (type) { case AccelType::HOST: break; diff --git a/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.hpp b/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.hpp index c09218c41e..14c3998f13 100644 --- a/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.hpp +++ b/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.hpp @@ -21,6 +21,8 @@ namespace wip { namespace onevpl { class Aux; +std::vector update_param_with_accel_type(std::vector &¶m_array, AccelType type); + struct GAPI_EXPORTS CfgParamDeviceSelector final: public IDeviceSelector { CfgParamDeviceSelector(const CfgParams& params = {}); CfgParamDeviceSelector(Device::Ptr device_ptr, diff --git a/modules/gapi/src/streaming/onevpl/cfg_params.cpp b/modules/gapi/src/streaming/onevpl/cfg_params.cpp index b13f9cadb1..155fef70e5 100644 --- a/modules/gapi/src/streaming/onevpl/cfg_params.cpp +++ b/modules/gapi/src/streaming/onevpl/cfg_params.cpp @@ -4,6 +4,7 @@ // // Copyright (C) 2021 Intel Corporation +#include #include #include @@ -25,6 +26,15 @@ struct variant_comparator : cv::util::static_visitor { private: const CfgParam::value_t& rhs; }; + +struct variant_stringifier : cv::util::static_visitor { + template + std::string visit(const ValueType& lhs) const { + std::stringstream ss; + ss << lhs; + return ss.str(); + } +}; } // namespace util struct CfgParam::Priv { @@ -228,6 +238,11 @@ bool CfgParam::is_major() const { return m_priv->is_major_impl(); } +std::string CfgParam::to_string() const { + return get_name() + ":" + cv::util::visit(util::variant_stringifier{}, + get_value()); +} + bool CfgParam::operator< (const CfgParam& rhs) const { return *m_priv < *rhs.m_priv; } diff --git a/modules/gapi/src/streaming/onevpl/engine/decode/decode_engine_legacy.cpp b/modules/gapi/src/streaming/onevpl/engine/decode/decode_engine_legacy.cpp index 34db1bebfa..0ab8301799 100644 --- a/modules/gapi/src/streaming/onevpl/engine/decode/decode_engine_legacy.cpp +++ b/modules/gapi/src/streaming/onevpl/engine/decode/decode_engine_legacy.cpp @@ -186,6 +186,9 @@ VPLLegacyDecodeEngine::SessionParam VPLLegacyDecodeEngine::prepare_session_param mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY; } else if (accel_type == AccelType::HOST) { mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY; + } else if (accel_type == AccelType::VAAPI) { + // TODO make proper direction + mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY; } else { GAPI_Assert(false && "unsupported AccelType from device selector"); } diff --git a/modules/gapi/src/streaming/onevpl/source.cpp b/modules/gapi/src/streaming/onevpl/source.cpp index 3bad463e41..efcc9bf850 100644 --- a/modules/gapi/src/streaming/onevpl/source.cpp +++ b/modules/gapi/src/streaming/onevpl/source.cpp @@ -36,7 +36,7 @@ GSource::GSource(const std::string& filePath, GSource::GSource(const std::string& filePath, const CfgParams& cfg_params, const Device &device, const Context &ctx) : - GSource(filePath, cfg_params, + GSource(filePath, update_param_with_accel_type(CfgParams{cfg_params}, device.get_type()), std::make_shared(device, ctx, cfg_params)) { } diff --git a/modules/gapi/src/streaming/onevpl/source_priv.cpp b/modules/gapi/src/streaming/onevpl/source_priv.cpp index f460a2a6ed..e8d26b41e2 100644 --- a/modules/gapi/src/streaming/onevpl/source_priv.cpp +++ b/modules/gapi/src/streaming/onevpl/source_priv.cpp @@ -94,12 +94,12 @@ GSource::Priv::Priv(std::shared_ptr provider, GAPI_Assert(cfg_inst && "MFXCreateConfig failed"); if (!cfg_param_it->is_major()) { - GAPI_LOG_DEBUG(nullptr, "Skip not major param: " << cfg_param_it->get_name()); + GAPI_LOG_DEBUG(nullptr, "Skip not major param: " << cfg_param_it->to_string()); ++cfg_param_it; continue; } - GAPI_LOG_DEBUG(nullptr, "Apply major param: " << cfg_param_it->get_name()); + GAPI_LOG_DEBUG(nullptr, "Apply major param: " << cfg_param_it->to_string()); mfxVariant mfx_param = cfg_param_to_mfx_variant(*cfg_param_it); mfxStatus sts = MFXSetConfigFilterProperty(cfg_inst, (mfxU8 *)cfg_param_it->get_name().c_str(), @@ -189,8 +189,14 @@ GSource::Priv::Priv(std::shared_ptr provider, // Extract the most suitable VPL implementation by max score auto max_match_it = matches_count.rbegin(); - GAPI_Assert(max_match_it != matches_count.rend() && - "Cannot find matched MFX implementation for requested configuration"); + if (max_match_it == matches_count.rend()) { + std::stringstream ss; + for (const auto &p : cfg_params) { + ss << p.to_string() << std::endl; + } + GAPI_LOG_WARNING(nullptr, "No one suitable MFX implementation is found, requested params:\n" << ss.str()); + throw std::runtime_error("Cannot find any suitable MFX implementation for requested configuration"); + } // TODO impl_number is global for now impl_number = max_match_it->second;