1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
// 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
#ifdef HAVE_ONEVPL
#include "../perf_precomp.hpp"
#include "../../test/common/gapi_tests_common.hpp"
#include <opencv2/gapi/streaming/onevpl/source.hpp>
#include <opencv2/gapi/streaming/cap.hpp>
#include "streaming/onevpl/engine/preproc/preproc_engine.hpp"
#include "streaming/onevpl/engine/preproc/preproc_session.hpp"
#include "streaming/onevpl/accelerators/accel_policy_interface.hpp"
#include "streaming/onevpl/cfg_param_device_selector.hpp"
#include "streaming/onevpl/accelerators/accel_policy_dx11.hpp"
#include "streaming/onevpl/accelerators/accel_policy_cpu.hpp"
#include "streaming/onevpl/accelerators/accel_policy_va_api.hpp"
namespace opencv_test
{
using namespace perf;
const std::string files[] = {
"highgui/video/big_buck_bunny.h265",
"highgui/video/big_buck_bunny.h264",
"highgui/video/sample_322x242_15frames.yuv420p.libx265.mp4",
};
const std::string codec[] = {
"MFX_CODEC_HEVC",
"MFX_CODEC_AVC",
"",
};
using source_t = std::string;
using codec_t = std::string;
using accel_mode_t = std::string;
using source_description_t = std::tuple<source_t, codec_t, accel_mode_t>;
class OneVPLSourcePerf_Test : public TestPerfParams<source_description_t> {};
class VideoCapSourcePerf_Test : public TestPerfParams<source_t> {};
PERF_TEST_P_(OneVPLSourcePerf_Test, TestPerformance)
{
using namespace cv::gapi::wip::onevpl;
const auto params = GetParam();
source_t src = findDataFile(get<0>(params));
codec_t type = get<1>(params);
accel_mode_t mode = get<2>(params);
std::vector<CfgParam> cfg_params {
CfgParam::create_implementation("MFX_IMPL_TYPE_HARDWARE"),
};
if (!type.empty()) {
cfg_params.push_back(CfgParam::create_decoder_id(type.c_str()));
}
if (!mode.empty()) {
cfg_params.push_back(CfgParam::create_acceleration_mode(mode.c_str()));
}
auto source_ptr = cv::gapi::wip::make_onevpl_src(src, cfg_params);
cv::gapi::wip::Data out;
TEST_CYCLE()
{
source_ptr->pull(out);
}
SANITY_CHECK_NOTHING();
}
PERF_TEST_P_(VideoCapSourcePerf_Test, TestPerformance)
{
using namespace cv::gapi::wip;
source_t src = findDataFile(GetParam());
auto source_ptr = make_src<GCaptureSource>(src);
Data out;
TEST_CYCLE()
{
source_ptr->pull(out);
}
SANITY_CHECK_NOTHING();
}
#ifdef __WIN32__
INSTANTIATE_TEST_CASE_P(Streaming, OneVPLSourcePerf_Test,
Values(source_description_t(files[0], codec[0], ""),
source_description_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_D3D11"),
source_description_t(files[1], codec[1], ""),
source_description_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_D3D11"),
source_description_t(files[2], codec[2], ""),
source_description_t(files[2], codec[2], "MFX_ACCEL_MODE_VIA_D3D11")));
#elif __linux__
INSTANTIATE_TEST_CASE_P(Streaming, OneVPLSourcePerf_Test,
Values(source_description_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_VAAPI"),
source_description_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_VAAPI")));
#endif
INSTANTIATE_TEST_CASE_P(Streaming, VideoCapSourcePerf_Test,
Values(files[0],
files[1],
files[2]));
using pp_out_param_t = cv::GFrameDesc;
using source_description_preproc_t = decltype(std::tuple_cat(std::declval<source_description_t>(),
std::declval<std::tuple<pp_out_param_t>>()));
class OneVPLSourcePerf_PP_Test : public TestPerfParams<source_description_preproc_t> {};
PERF_TEST_P_(OneVPLSourcePerf_PP_Test, TestPerformance)
{
using namespace cv::gapi::wip::onevpl;
const auto params = GetParam();
source_t src = findDataFile(get<0>(params));
codec_t type = get<1>(params);
accel_mode_t mode = get<2>(params);
pp_out_param_t res = get<3>(params);
std::vector<CfgParam> cfg_params {
CfgParam::create_implementation("MFX_IMPL_TYPE_HARDWARE"),
};
if (!type.empty()) {
cfg_params.push_back(CfgParam::create_decoder_id(type.c_str()));
}
if (!mode.empty()) {
cfg_params.push_back(CfgParam::create_acceleration_mode(mode.c_str()));
}
cfg_params.push_back(CfgParam::create_vpp_out_width(static_cast<uint16_t>(res.size.width)));
cfg_params.push_back(CfgParam::create_vpp_out_height(static_cast<uint16_t>(res.size.height)));
cfg_params.push_back(CfgParam::create_vpp_out_crop_x(0));
cfg_params.push_back(CfgParam::create_vpp_out_crop_y(0));
cfg_params.push_back(CfgParam::create_vpp_out_crop_w(static_cast<uint16_t>(res.size.width)));
cfg_params.push_back(CfgParam::create_vpp_out_crop_h(static_cast<uint16_t>(res.size.height)));
auto source_ptr = cv::gapi::wip::make_onevpl_src(src, cfg_params);
cv::gapi::wip::Data out;
TEST_CYCLE()
{
source_ptr->pull(out);
}
SANITY_CHECK_NOTHING();
}
static pp_out_param_t full_hd = pp_out_param_t {cv::MediaFormat::NV12,
{1920, 1080}};
static pp_out_param_t cif = pp_out_param_t {cv::MediaFormat::NV12,
{352, 288}};
#ifdef __WIN32__
INSTANTIATE_TEST_CASE_P(Streaming_Source_PP, OneVPLSourcePerf_PP_Test,
Values(source_description_preproc_t(files[0], codec[0], "", full_hd),
source_description_preproc_t(files[0], codec[0], "", cif),
source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_D3D11", full_hd),
source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_D3D11", cif),
source_description_preproc_t(files[1], codec[1], "", full_hd),
source_description_preproc_t(files[1], codec[1], "", cif),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_D3D11",full_hd),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_D3D11",cif),
source_description_preproc_t(files[2], codec[2], "", full_hd),
source_description_preproc_t(files[2], codec[2], "", cif),
source_description_preproc_t(files[2], codec[2], "MFX_ACCEL_MODE_VIA_D3D11", full_hd),
source_description_preproc_t(files[2], codec[2], "MFX_ACCEL_MODE_VIA_D3D11", cif)));
#elif __linux__
INSTANTIATE_TEST_CASE_P(Streaming_Source_PP, OneVPLSourcePerf_PP_Test,
Values(source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_VAAPI", full_hd),
source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_VAAPI", cif),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_VAAPI",full_hd),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_VAAPI",cif)));
#endif
class OneVPLSourcePerf_PP_Engine_Test : public TestPerfParams<source_description_preproc_t> {};
PERF_TEST_P_(OneVPLSourcePerf_PP_Engine_Test, TestPerformance)
{
using namespace cv::gapi::wip;
using namespace cv::gapi::wip::onevpl;
const auto params = GetParam();
source_t src = findDataFile(get<0>(params));
codec_t type = get<1>(params);
accel_mode_t mode = get<2>(params);
const pp_out_param_t &required_frame_param = get<3>(params);
std::vector<CfgParam> cfg_params {
CfgParam::create_implementation("MFX_IMPL_TYPE_HARDWARE"),
};
if (!type.empty()) {
cfg_params.push_back(CfgParam::create_decoder_id(type.c_str()));
}
if (!mode.empty()) {
cfg_params.push_back(CfgParam::create_acceleration_mode(mode.c_str()));
}
auto device_selector = std::make_shared<CfgParamDeviceSelector>(cfg_params);
auto source_ptr = cv::gapi::wip::make_onevpl_src(src, cfg_params, device_selector);
// create VPP preproc engine
std::unique_ptr<VPLAccelerationPolicy> policy;
if (mode == "MFX_ACCEL_MODE_VIA_D3D11") {
policy.reset(new VPLDX11AccelerationPolicy(device_selector));
} else if (mode == "MFX_ACCEL_MODE_VIA_VAAPI") {
policy.reset(new VPLVAAPIAccelerationPolicy(device_selector));
} else if (mode.empty()){
policy.reset(new VPLCPUAccelerationPolicy(device_selector));
} else {
ASSERT_TRUE(false && "Unsupported acceleration policy type");
}
VPPPreprocEngine preproc_engine(std::move(policy));
cv::gapi::wip::Data out;
cv::util::optional<cv::Rect> empty_roi;
TEST_CYCLE()
{
source_ptr->pull(out);
cv::MediaFrame frame = cv::util::get<cv::MediaFrame>(out);
cv::util::optional<pp_params> param = preproc_engine.is_applicable(frame);
pp_session sess = preproc_engine.initialize_preproc(param.value(),
required_frame_param);
(void)preproc_engine.run_sync(sess, frame, empty_roi);
}
SANITY_CHECK_NOTHING();
}
#ifdef __WIN32__
INSTANTIATE_TEST_CASE_P(Streaming_Engine_PP, OneVPLSourcePerf_PP_Engine_Test,
Values(source_description_preproc_t(files[0], codec[0], "", full_hd),
source_description_preproc_t(files[0], codec[0], "", cif),
source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_D3D11", full_hd),
source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_D3D11", cif),
source_description_preproc_t(files[1], codec[1], "", full_hd),
source_description_preproc_t(files[1], codec[1], "", cif),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_D3D11",full_hd),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_D3D11",cif),
source_description_preproc_t(files[2], codec[2], "", full_hd),
source_description_preproc_t(files[2], codec[2], "", cif),
source_description_preproc_t(files[2], codec[2], "MFX_ACCEL_MODE_VIA_D3D11", full_hd),
source_description_preproc_t(files[2], codec[2], "MFX_ACCEL_MODE_VIA_D3D11", cif)));
#elif __linux__
INSTANTIATE_TEST_CASE_P(Streaming_Engine_PP, OneVPLSourcePerf_PP_Engine_Test,
Values(source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_VAAPI", full_hd),
source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_VAAPI", cif),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_VAAPI",full_hd),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_VAAPI",cif)));
#endif
class OneVPLSourcePerf_PP_Engine_Bypass_Test : public TestPerfParams<source_description_preproc_t> {};
PERF_TEST_P_(OneVPLSourcePerf_PP_Engine_Bypass_Test, TestPerformance)
{
using namespace cv::gapi::wip;
using namespace cv::gapi::wip::onevpl;
const auto params = GetParam();
source_t src = findDataFile(get<0>(params));
codec_t type = get<1>(params);
accel_mode_t mode = get<2>(params);
const pp_out_param_t &required_frame_param = get<3>(params);
std::vector<CfgParam> cfg_params {
CfgParam::create_implementation("MFX_IMPL_TYPE_HARDWARE"),
};
if (!type.empty()) {
cfg_params.push_back(CfgParam::create_decoder_id(type.c_str()));
}
if (!mode.empty()) {
cfg_params.push_back(CfgParam::create_acceleration_mode(mode.c_str()));
}
auto device_selector = std::make_shared<CfgParamDeviceSelector>(cfg_params);
auto source_ptr = cv::gapi::wip::make_onevpl_src(src, cfg_params, device_selector);
// create VPP preproc engine
std::unique_ptr<VPLAccelerationPolicy> policy;
if (mode == "MFX_ACCEL_MODE_VIA_D3D11") {
policy.reset(new VPLDX11AccelerationPolicy(device_selector));
} else if (mode == "MFX_ACCEL_MODE_VIA_VAAPI") {
policy.reset(new VPLVAAPIAccelerationPolicy(device_selector));
} else if (mode.empty()){
policy.reset(new VPLCPUAccelerationPolicy(device_selector));
} else {
ASSERT_TRUE(false && "Unsupported acceleration policy type");
}
VPPPreprocEngine preproc_engine(std::move(policy));
cv::gapi::wip::Data out;
cv::util::optional<cv::Rect> empty_roi;
TEST_CYCLE()
{
source_ptr->pull(out);
cv::MediaFrame frame = cv::util::get<cv::MediaFrame>(out);
cv::util::optional<pp_params> param = preproc_engine.is_applicable(frame);
pp_session sess = preproc_engine.initialize_preproc(param.value(),
required_frame_param);
(void)preproc_engine.run_sync(sess, frame, empty_roi);
}
SANITY_CHECK_NOTHING();
}
static pp_out_param_t res_672x384 = pp_out_param_t {cv::MediaFormat::NV12,
{672, 384}};
static pp_out_param_t res_336x256 = pp_out_param_t {cv::MediaFormat::NV12,
{336, 256}};
#ifdef __WIN32__
INSTANTIATE_TEST_CASE_P(Streaming_Engine_PP_Bypass, OneVPLSourcePerf_PP_Engine_Bypass_Test,
Values(source_description_preproc_t(files[0], codec[0], "", res_672x384),
source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_D3D11", res_672x384),
source_description_preproc_t(files[1], codec[1], "", res_672x384),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_D3D11", res_672x384),
source_description_preproc_t(files[2], codec[2], "", res_336x256),
source_description_preproc_t(files[2], codec[2], "MFX_ACCEL_MODE_VIA_D3D11", res_336x256)));
#elif __linux__
INSTANTIATE_TEST_CASE_P(Streaming_Engine_PP_Bypass, OneVPLSourcePerf_PP_Engine_Bypass_Test,
Values(source_description_preproc_t(files[0], codec[0], "MFX_ACCEL_MODE_VIA_VAAPI", res_672x384),
source_description_preproc_t(files[1], codec[1], "MFX_ACCEL_MODE_VIA_VAAPI", res_672x384)));
#endif
} // namespace opencv_test
#endif // HAVE_ONEVPL
|