Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/gapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ if(HAVE_GAPI_ONEVPL)
src/streaming/onevpl/engine/processing_engine_base.cpp
src/streaming/onevpl/engine/decode/decode_engine_legacy.cpp
src/streaming/onevpl/engine/decode/decode_session.cpp
src/streaming/onevpl/onevpl_utils.cpp
src/streaming/onevpl/onevpl_cfg_params_parser.cpp
)
endif()

Expand Down
4 changes: 3 additions & 1 deletion modules/gapi/samples/onevpl_infer_single_roi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const std::string keys =
"{ input | | Path to the input demultiplexed video file }"
"{ output | | Path to the output RAW video file. Use .avi extension }"
"{ facem | face-detection-adas-0001.xml | Path to OpenVINO IE face detection model (.xml) }"
"{ faced | CPU | Target device for face detection model (e.g. CPU, GPU, VPU, ...) }"
"{ cfg_params | <prop name>:<value>;<prop name>:<value> | Semicolon separated list of oneVPL mfxVariants which is used for configuring source (see `MFXSetConfigFilterProperty` by https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html) }";


Expand Down Expand Up @@ -198,7 +199,8 @@ int main(int argc, char *argv[]) {

auto face_net = cv::gapi::ie::Params<custom::FaceDetector> {
face_model_path, // path to topology IR
get_weights_path(face_model_path) // path to weights
get_weights_path(face_model_path), // path to weights
cmd.get<std::string>("faced"), // device specifier
};
auto kernels = cv::gapi::kernels
< custom::OCVLocateROI
Expand Down
118 changes: 118 additions & 0 deletions modules/gapi/src/streaming/onevpl/onevpl_cfg_params_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation

#include <stdio.h>

#include <algorithm>
#include <sstream>

#include "streaming/onevpl/onevpl_cfg_params_parser.hpp"
#include "streaming/onevpl/onevpl_utils.hpp"
#include "logger.hpp"

#ifdef HAVE_ONEVPL
namespace cv {
namespace gapi {
namespace wip {

template <>
struct ParamCreator<oneVPL_cfg_param> {
template<typename ValueType>
oneVPL_cfg_param create (const std::string& name, ValueType&& value) {
return oneVPL_cfg_param::create(name, std::forward<ValueType>(value), is_major_flag);
}
bool is_major_flag = false;
};

template <>
struct ParamCreator<mfxVariant> {
template<typename ValueType>
mfxVariant create (const std::string& name, mfxU32 value) {
return create_impl(name, value);
}
private:
mfxVariant create_impl(const std::string&, mfxU32 value) {
mfxVariant ret;
ret.Type = MFX_VARIANT_TYPE_U32;
ret.Data.U32 = value;
return ret;
}
};

template<typename ValueType>
std::vector<ValueType> get_params_from_string(const std::string& str) {
std::vector<ValueType> ret;
std::string::size_type pos = 0;
std::string::size_type endline_pos = std::string::npos;
do
{
endline_pos = str.find_first_of("\r\n", pos);
std::string line = str.substr(pos, endline_pos == std::string::npos ? std::string::npos : endline_pos - pos);
if (line.empty()) break;

std::string::size_type name_endline_pos = line.find(':');
if (name_endline_pos == std::string::npos) {
throw std::runtime_error("Invalid cannot parse param from string: " + line +
". Name and value should be separated by \":\"" );
}

std::string name = line.substr(0, name_endline_pos);
std::string value = line.substr(name_endline_pos + 2);

ParamCreator<ValueType> creator;
if (name == "mfxImplDescription.Impl") {
ret.push_back(creator.create<mfxU32>(name, cstr_to_mfx_impl(value.c_str())));
} else if (name == "mfxImplDescription.mfxDecoderDescription.decoder.CodecID") {
ret.push_back(creator.create<mfxU32>(name, cstr_to_mfx_codec_id(value.c_str())));
} else if (name == "mfxImplDescription.AccelerationMode") {
ret.push_back(creator.create<mfxU32>(name, cstr_to_mfx_accel_mode(value.c_str())));
} else if (name == "mfxImplDescription.ApiVersion.Version") {
ret.push_back(creator.create<mfxU32>(name, cstr_to_mfx_version(value.c_str())));
} else {
GAPI_LOG_DEBUG(nullptr, "Cannot parse configuration param, name: " << name <<
", value: " << value);
}

pos = endline_pos + 1;
}
while (endline_pos != std::string::npos);

return ret;
}

template
std::vector<oneVPL_cfg_param> get_params_from_string(const std::string& str);
template
std::vector<mfxVariant> get_params_from_string(const std::string& str);

mfxVariant cfg_param_to_mfx_variant(const oneVPL_cfg_param& cfg_val) {
const oneVPL_cfg_param::name_t& name = cfg_val.get_name();
mfxVariant ret;
cv::util::visit(cv::util::overload_lambdas(
[&ret](uint8_t value) { ret.Type = MFX_VARIANT_TYPE_U8; ret.Data.U8 = value; },
[&ret](int8_t value) { ret.Type = MFX_VARIANT_TYPE_I8; ret.Data.I8 = value; },
[&ret](uint16_t value) { ret.Type = MFX_VARIANT_TYPE_U16; ret.Data.U16 = value; },
[&ret](int16_t value) { ret.Type = MFX_VARIANT_TYPE_I16; ret.Data.I16 = value; },
[&ret](uint32_t value) { ret.Type = MFX_VARIANT_TYPE_U32; ret.Data.U32 = value; },
[&ret](int32_t value) { ret.Type = MFX_VARIANT_TYPE_I32; ret.Data.I32 = value; },
[&ret](uint64_t value) { ret.Type = MFX_VARIANT_TYPE_U64; ret.Data.U64 = value; },
[&ret](int64_t value) { ret.Type = MFX_VARIANT_TYPE_I64; ret.Data.I64 = value; },
[&ret](float_t value) { ret.Type = MFX_VARIANT_TYPE_F32; ret.Data.F32 = value; },
[&ret](double_t value) { ret.Type = MFX_VARIANT_TYPE_F64; ret.Data.F64 = value; },
[&ret](void* value) { ret.Type = MFX_VARIANT_TYPE_PTR; ret.Data.Ptr = value; },
[&ret, &name] (const std::string& value) {
auto parsed = get_params_from_string<mfxVariant>(name + ": " + value + "\n");
if (parsed.empty()) {
throw std::logic_error("Unsupported parameter, name: " + name + ", value: " + value);
}
ret = *parsed.begin();
}), cfg_val.get_value());
return ret;
}
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // HAVE_ONEVPL
41 changes: 41 additions & 0 deletions modules/gapi/src/streaming/onevpl/onevpl_cfg_params_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation

#ifndef GAPI_STREAMING_ONEVPL_ONEVPL_CFG_PARAM_PARSER_HPP
#define GAPI_STREAMING_ONEVPL_ONEVPL_CFG_PARAM_PARSER_HPP

#ifdef HAVE_ONEVPL
#if (MFX_VERSION >= 2000)
#include <vpl/mfxdispatcher.h>
#endif // MFX_VERSION

#include <vpl/mfx.h>
#include <vpl/mfxvideo.h>

#include <map>
#include <string>

#include <opencv2/gapi/streaming/onevpl/onevpl_source.hpp>

namespace cv {
namespace gapi {
namespace wip {

template<typename ValueType>
std::vector<ValueType> get_params_from_string(const std::string& str);

template <typename ReturnType>
struct ParamCreator {
template<typename ValueType>
ReturnType create(const std::string& name, ValueType&& value);
};

mfxVariant cfg_param_to_mfx_variant(const oneVPL_cfg_param& value);
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // HAVE_ONEVPL
#endif // GAPI_STREAMING_ONEVPL_ONEVPL_CFG_PARAM_PARSER_HPP
Loading