Merge pull request #21883 from SergeyIvanov87:gapi_vpl_linux

G-API: VPL Source turn on Linux CPU version

* Turn on linux compilation

* Apply comments

* Change new files headline

* Add license header
This commit is contained in:
Sergey
2022-05-12 11:42:38 +03:00
committed by GitHub
parent 2010de9104
commit eff5605be5
34 changed files with 662 additions and 184 deletions
@@ -2440,7 +2440,11 @@ TEST(OneVPL_Source, Init)
std::vector<CfgParam> src_params;
src_params.push_back(CfgParam::create_implementation(MFX_IMPL_TYPE_HARDWARE));
#ifdef __WIN32
src_params.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
#elif defined(__linux__)
src_params.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_VAAPI));
#endif
src_params.push_back(CfgParam::create_decoder_id(MFX_CODEC_HEVC));
std::stringstream stream(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
@@ -36,6 +36,7 @@
#include "streaming/onevpl/accelerators/surface/cpu_frame_adapter.hpp"
#include "streaming/onevpl/accelerators/accel_policy_cpu.hpp"
#include "streaming/onevpl/accelerators/accel_policy_dx11.hpp"
#include "streaming/onevpl/accelerators/accel_policy_va_api.hpp"
#include "streaming/onevpl/accelerators/dx11_alloc_resource.hpp"
#include "streaming/onevpl/accelerators/utils/shared_lock.hpp"
#define private public
@@ -79,7 +80,7 @@ struct TestProcessingSession : public cv::gapi::wip::onevpl::EngineSession {
struct TestProcessingEngine: public cv::gapi::wip::onevpl::ProcessingEngineBase {
size_t pipeline_stage_num = 0;
int pipeline_stage_num = 0;
TestProcessingEngine(std::unique_ptr<cv::gapi::wip::onevpl::VPLAccelerationPolicy>&& accel) :
cv::gapi::wip::onevpl::ProcessingEngineBase(std::move(accel)) {
@@ -154,7 +155,7 @@ private:
mfxFrameAllocator m_allocator;
};
template <class LockProcessor, class UnlockProcessor>
std::map<mfxMemId, UnlockProcessor> TestLockableAllocator<LockProcessor, UnlockProcessor>::lock_processor_table {};
std::map<mfxMemId, LockProcessor> TestLockableAllocator<LockProcessor, UnlockProcessor>::lock_processor_table {};
template <class LockProcessor, class UnlockProcessor>
std::map<mfxMemId, UnlockProcessor> TestLockableAllocator<LockProcessor, UnlockProcessor>::unlock_processor_table {};
@@ -194,11 +195,11 @@ TEST(OneVPL_Source_Surface, InitSurface)
// check self consistency
EXPECT_EQ(reinterpret_cast<void*>(surf->get_handle()),
reinterpret_cast<void*>(mfx_core_handle));
EXPECT_EQ(0, surf->get_locks_count());
EXPECT_EQ(0, surf->obtain_lock());
EXPECT_EQ(1, surf->get_locks_count());
EXPECT_EQ(1, surf->release_lock());
EXPECT_EQ(0, surf->get_locks_count());
EXPECT_TRUE(0 == surf->get_locks_count());
EXPECT_TRUE(0 == surf->obtain_lock());
EXPECT_TRUE(1 == surf->get_locks_count());
EXPECT_TRUE(1 == surf->release_lock());
EXPECT_TRUE(0 == surf->get_locks_count());
}
TEST(OneVPL_Source_Surface, ConcurrentLock)
@@ -213,7 +214,7 @@ TEST(OneVPL_Source_Surface, ConcurrentLock)
auto surf = Surface::create_surface(std::move(handle), associated_memory);
// check self consistency
EXPECT_EQ(0, surf->get_locks_count());
EXPECT_TRUE(0 == surf->get_locks_count());
// MFX internal limitation: do not exceede U16 range
// so I16 is using here
@@ -238,7 +239,7 @@ TEST(OneVPL_Source_Surface, ConcurrentLock)
}
worker_thread.join();
EXPECT_EQ(lock_counter * 2, surf->get_locks_count());
EXPECT_TRUE(static_cast<size_t>(lock_counter * 2) == surf->get_locks_count());
}
TEST(OneVPL_Source_Surface, MemoryLifeTime)
@@ -271,7 +272,7 @@ TEST(OneVPL_Source_Surface, MemoryLifeTime)
}
// workspace memory must be alive
EXPECT_EQ(0, surfaces.size());
EXPECT_TRUE(0 == surfaces.size());
EXPECT_TRUE(associated_memory != nullptr);
EXPECT_TRUE(preallocated_memory_ptr.get() != nullptr);
@@ -293,7 +294,7 @@ TEST(OneVPL_Source_Surface, MemoryLifeTime)
associated_memory.reset();
// workspace memory must be still alive
EXPECT_EQ(0, surfaces.size());
EXPECT_TRUE(0 == surfaces.size());
EXPECT_TRUE(associated_memory == nullptr);
EXPECT_TRUE(preallocated_memory_ptr.get() != nullptr);
@@ -316,14 +317,14 @@ TEST(OneVPL_Source_CPU_FrameAdapter, InitFrameAdapter)
auto surf = Surface::create_surface(std::move(handle), associated_memory);
// check consistency
EXPECT_EQ(0, surf->get_locks_count());
EXPECT_TRUE(0 == surf->get_locks_count());
{
mfxSession stub_session = reinterpret_cast<mfxSession>(0x1);
VPLMediaFrameCPUAdapter adapter(surf, stub_session);
EXPECT_EQ(1, surf->get_locks_count());
EXPECT_TRUE(1 == surf->get_locks_count());
}
EXPECT_EQ(0, surf->get_locks_count());
EXPECT_TRUE(0 == surf->get_locks_count());
}
TEST(OneVPL_Source_CPU_Accelerator, InitDestroy)
@@ -385,13 +386,13 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConsume)
for (size_t i = 0; i < surface_count; i++) {
std::shared_ptr<Surface> surf = acceleration_policy->get_free_surface(key).lock();
EXPECT_TRUE(surf.get() != nullptr);
EXPECT_EQ(0, surf->obtain_lock());
EXPECT_TRUE(0 == surf->obtain_lock());
surfaces.push_back(std::move(surf));
}
// check consistency (no free surfaces)
EXPECT_EQ(acceleration_policy->get_surface_count(key), surface_count);
EXPECT_EQ(0, acceleration_policy->get_free_surface_count(key));
EXPECT_TRUE(0 == acceleration_policy->get_free_surface_count(key));
// fail consume non-free surfaces
for (size_t i = 0; i < surface_count; i++) {
@@ -400,7 +401,7 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConsume)
// release surfaces
for (auto& surf : surfaces) {
EXPECT_EQ(1, surf->release_lock());
EXPECT_TRUE(1 == surf->release_lock());
}
surfaces.clear();
@@ -412,7 +413,7 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConsume)
for (size_t i = 0; i < surface_count; i++) {
std::shared_ptr<Surface> surf = acceleration_policy->get_free_surface(key).lock();
EXPECT_TRUE(surf.get() != nullptr);
EXPECT_EQ(0, surf->obtain_lock());
EXPECT_TRUE(0 == surf->obtain_lock());
}
}
@@ -444,7 +445,7 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConcurrentConsume)
for (size_t i = 0; i < surface_count; i++) {
std::shared_ptr<Surface> surf = acceleration_policy->get_free_surface(key).lock();
EXPECT_TRUE(surf.get() != nullptr);
EXPECT_EQ(0, surf->obtain_lock());
EXPECT_TRUE(0 == surf->obtain_lock());
surfaces.push_back(std::move(surf));
}
@@ -458,7 +459,7 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConcurrentConsume)
// concurrent release surfaces
size_t surfaces_count = surfaces.size();
for (auto& surf : surfaces) {
EXPECT_EQ(1, surf->release_lock());
EXPECT_TRUE(1 == surf->release_lock());
std::this_thread::sleep_for(std::chrono::seconds(1));
}
surfaces.clear();
@@ -492,7 +493,7 @@ TEST(OneVPL_Source_ProcessingEngine, Init)
mfxSession mfx_session{};
engine.initialize_session(mfx_session, {}, std::shared_ptr<IDataProvider>{});
EXPECT_EQ(0, engine.get_ready_frames_count());
EXPECT_TRUE(0 == engine.get_ready_frames_count());
ProcessingEngineBase::ExecutionStatus ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::Continue);
EXPECT_EQ(0, engine.pipeline_stage_num);
@@ -508,12 +509,12 @@ TEST(OneVPL_Source_ProcessingEngine, Init)
ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::Processed);
EXPECT_EQ(3, engine.pipeline_stage_num);
EXPECT_EQ(1, engine.get_ready_frames_count());
EXPECT_TRUE(1 == engine.get_ready_frames_count());
ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::SessionNotFound);
EXPECT_EQ(3, engine.pipeline_stage_num);
EXPECT_EQ(1, engine.get_ready_frames_count());
EXPECT_TRUE(1 == engine.get_ready_frames_count());
cv::gapi::wip::Data frame;
engine.get_frame(frame);
@@ -603,7 +604,98 @@ TEST(OneVPL_Source_DX11_Accel, Init)
MFXClose(mfx_session);
MFXUnload(test_mfx_handle);
}
#endif // HAVE_DIRECTX
#endif // HAVE_D3D11
#ifdef __linux__
#if defined(HAVE_VA) || defined(HAVE_VA_INTEL)
TEST(OneVPL_Source_VAAPI_Accel, Init)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> cfg_params_w_vaapi;
cfg_params_w_vaapi.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_VAAPI));
VPLVAAPIAccelerationPolicy accel(std::make_shared<CfgParamDeviceSelector>(cfg_params_w_vaapi));
mfxLoader test_mfx_handle = MFXLoad();
mfxConfig cfg_inst_0 = MFXCreateConfig(test_mfx_handle);
EXPECT_TRUE(cfg_inst_0);
mfxVariant mfx_param_0;
mfx_param_0.Type = MFX_VARIANT_TYPE_U32;
mfx_param_0.Data.U32 = MFX_IMPL_TYPE_HARDWARE;
EXPECT_EQ(MFXSetConfigFilterProperty(cfg_inst_0,(mfxU8 *)CfgParam::implementation_name(),
mfx_param_0), MFX_ERR_NONE);
mfxConfig cfg_inst_1 = MFXCreateConfig(test_mfx_handle);
EXPECT_TRUE(cfg_inst_1);
mfxVariant mfx_param_1;
mfx_param_1.Type = MFX_VARIANT_TYPE_U32;
mfx_param_1.Data.U32 = MFX_ACCEL_MODE_VIA_VAAPI;
EXPECT_EQ(MFXSetConfigFilterProperty(cfg_inst_1,(mfxU8 *)CfgParam::acceleration_mode_name(),
mfx_param_1), MFX_ERR_NONE);
mfxConfig cfg_inst_2 = MFXCreateConfig(test_mfx_handle);
EXPECT_TRUE(cfg_inst_2);
mfxVariant mfx_param_2;
mfx_param_2.Type = MFX_VARIANT_TYPE_U32;
mfx_param_2.Data.U32 = MFX_CODEC_HEVC;
EXPECT_EQ(MFXSetConfigFilterProperty(cfg_inst_2,(mfxU8 *)CfgParam::decoder_id_name(),
mfx_param_2), MFX_ERR_NONE);
// create session
mfxSession mfx_session{};
mfxStatus sts = MFXCreateSession(test_mfx_handle, 0, &mfx_session);
EXPECT_EQ(MFX_ERR_NONE, sts);
// assign acceleration
EXPECT_NO_THROW(accel.init(mfx_session));
// create proper bitstream
mfxBitstream bitstream{};
const int BITSTREAM_BUFFER_SIZE = 2000000;
bitstream.MaxLength = BITSTREAM_BUFFER_SIZE;
bitstream.Data = (mfxU8 *)calloc(bitstream.MaxLength, sizeof(mfxU8));
EXPECT_TRUE(bitstream.Data);
// simulate read stream
bitstream.DataOffset = 0;
bitstream.DataLength = sizeof(streaming::onevpl::hevc_header) * sizeof(streaming::onevpl::hevc_header[0]);
memcpy(bitstream.Data, streaming::onevpl::hevc_header, bitstream.DataLength);
bitstream.CodecId = MFX_CODEC_HEVC;
// prepare dec params
mfxVideoParam mfxDecParams {};
mfxDecParams.mfx.CodecId = bitstream.CodecId;
mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
sts = MFXVideoDECODE_DecodeHeader(mfx_session, &bitstream, &mfxDecParams);
EXPECT_EQ(MFX_ERR_NONE, sts);
mfxFrameAllocRequest request{};
memset(&request, 0, sizeof(request));
sts = MFXVideoDECODE_QueryIOSurf(mfx_session, &mfxDecParams, &request);
EXPECT_EQ(MFX_ERR_NONE, sts);
// Allocate surfaces for decoder
VPLAccelerationPolicy::pool_key_t key = accel.create_surface_pool(request,
mfxDecParams.mfx.FrameInfo);
auto cand_surface = accel.get_free_surface(key).lock();
sts = MFXVideoDECODE_Init(mfx_session, &mfxDecParams);
EXPECT_EQ(MFX_ERR_NONE, sts);
MFXVideoDECODE_Close(mfx_session);
EXPECT_EQ(MFX_ERR_NONE, sts);
EXPECT_NO_THROW(accel.deinit(mfx_session));
MFXClose(mfx_session);
MFXUnload(test_mfx_handle);
}
#endif // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
#endif // __linux__
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
TEST(OneVPL_Source_DX11_Accel_VPL, Init)
{
using namespace cv::gapi::wip::onevpl;
@@ -1024,8 +1116,6 @@ TEST(OneVPL_Source_DX11_Accel_VPL, preproc)
}
} while(frame_num < min_available_frames_count);
}
#endif // HAVE_DIRECTX
#endif // HAVE_D3D11
TEST(OneVPL_Source_DX11_FrameLockable, LockUnlock_without_Adaptee)
{
@@ -1114,6 +1204,8 @@ TEST(OneVPL_Source_DX11_FrameLockable, LockUnlock_with_Adaptee)
EXPECT_EQ(w_lock_counter, exec_count);
EXPECT_EQ(w_unlock_counter, exec_count);
}
#endif // HAVE_DIRECTX
#endif // HAVE_D3D11
}
} // namespace opencv_test
#endif // HAVE_ONEVPL
@@ -16,6 +16,7 @@
#include "streaming/onevpl/demux/async_mfp_demux_data_provider.hpp"
#include "streaming/onevpl/source_priv.hpp"
#ifdef _WIN32
namespace opencv_test
{
namespace
@@ -299,4 +300,5 @@ TEST(OneVPL_Source_MFPAsyncDemux, produce_consume) {
}
} // namespace opencv_test
#endif // _WIN32
#endif // HAVE_ONEVPL
@@ -69,11 +69,11 @@ TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDevice)
using namespace cv::gapi::wip::onevpl;
CfgParamDeviceSelector selector;
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
EXPECT_TRUE(devs.size() == 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_TRUE(ctxs.size() == 1);
test_host_ctx_eq(*ctxs.begin());
}
@@ -83,10 +83,10 @@ TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithEmptyCfgParam)
std::vector<CfgParam> empty_params;
CfgParamDeviceSelector selector(empty_params);
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
EXPECT_TRUE(devs.size() == 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_TRUE(ctxs.size() == 1);
test_host_ctx_eq(*ctxs.begin());
}
@@ -97,11 +97,11 @@ TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithAccelNACfgParam)
cfg_params_w_no_accel.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_NA));
CfgParamDeviceSelector selector(cfg_params_w_no_accel);
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
EXPECT_TRUE(devs.size() == 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_TRUE(ctxs.size() == 1);
test_host_ctx_eq(*ctxs.begin());
}
@@ -113,11 +113,11 @@ TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithEmptyCfgParam_DX11
std::vector<CfgParam> empty_params;
CfgParamDeviceSelector selector(empty_params);
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
EXPECT_TRUE(devs.size() == 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_TRUE(ctxs.size() == 1);
test_host_ctx_eq(*ctxs.begin());
}
@@ -130,13 +130,13 @@ TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithDX11AccelCfgParam_
EXPECT_NO_THROW(selector_ptr.reset(new CfgParamDeviceSelector(cfg_params_w_dx11)));
IDeviceSelector::DeviceScoreTable devs = selector_ptr->select_devices();
EXPECT_EQ(devs.size(), 1);
EXPECT_TRUE(devs.size() == 1);
test_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority,
AccelType::DX11,
std::get<1>(*devs.begin()).get_ptr() /* compare just type */);
IDeviceSelector::DeviceContexts ctxs = selector_ptr->select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_TRUE(ctxs.size() == 1);
EXPECT_TRUE(ctxs.begin()->get_ptr());
}
@@ -182,12 +182,12 @@ TEST(OneVPL_Source_Device_Selector_CfgParam, ExternalDeviceWithDX11AccelCfgParam
cfg_params_w_dx11)));
IDeviceSelector::DeviceScoreTable devs = selector_ptr->select_devices();
EXPECT_EQ(devs.size(), 1);
EXPECT_TRUE(devs.size() == 1);
test_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority,
AccelType::DX11, device);
IDeviceSelector::DeviceContexts ctxs = selector_ptr->select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_TRUE(ctxs.size() == 1);
EXPECT_EQ(reinterpret_cast<ID3D11DeviceContext*>(ctxs.begin()->get_ptr()),
device_context);
}
@@ -201,7 +201,7 @@ TEST(OneVPL_Source_Device_Selector_CfgParam, DX11DeviceFromCfgParamWithDX11Disab
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> cfg_params_w_non_existed_dx11;
cfg_params_w_not_existed_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
cfg_params_w_non_existed_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
EXPECT_THROW(CfgParamDeviceSelector{cfg_params_w_non_existed_dx11},
std::logic_error);
}
@@ -40,6 +40,7 @@
#include "streaming/onevpl/accelerators/surface/dx11_frame_adapter.hpp"
#include "streaming/onevpl/accelerators/accel_policy_cpu.hpp"
#include "streaming/onevpl/accelerators/accel_policy_dx11.hpp"
#include "streaming/onevpl/accelerators/accel_policy_va_api.hpp"
#include "streaming/onevpl/accelerators/dx11_alloc_resource.hpp"
#include "streaming/onevpl/accelerators/utils/shared_lock.hpp"
#define private public
@@ -120,6 +121,28 @@ std::tuple<mfxLoader, mfxConfig> prepare_mfx(int mfx_codec, int mfx_accel_mode)
return std::make_tuple(mfx, cfg_inst_3);
}
static std::unique_ptr<cv::gapi::wip::onevpl::VPLAccelerationPolicy>
create_accel_policy_from_int(int accel,
std::shared_ptr<cv::gapi::wip::onevpl::IDeviceSelector> selector) {
using namespace cv::gapi::wip::onevpl;
std::unique_ptr<VPLAccelerationPolicy> decode_accel_policy;
if (accel == MFX_ACCEL_MODE_VIA_D3D11) {
decode_accel_policy.reset (new VPLDX11AccelerationPolicy(selector));
} else if (accel == MFX_ACCEL_MODE_VIA_VAAPI) {
decode_accel_policy.reset (new VPLVAAPIAccelerationPolicy(selector));
}
EXPECT_TRUE(decode_accel_policy.get());
return decode_accel_policy;
}
static std::unique_ptr<cv::gapi::wip::onevpl::VPLAccelerationPolicy>
create_accel_policy_from_int(int &accel,
std::vector<cv::gapi::wip::onevpl::CfgParam> &out_cfg_params) {
using namespace cv::gapi::wip::onevpl;
out_cfg_params.push_back(CfgParam::create_acceleration_mode(accel));
return create_accel_policy_from_int(accel, std::make_shared<CfgParamDeviceSelector>(out_cfg_params));
}
class SafeQueue {
public:
void push(cv::MediaFrame&& f) {
@@ -186,26 +209,32 @@ static cv::util::optional<cv::Rect> empty_roi;
class VPPPreprocParams : public ::testing::TestWithParam<preproc_args_t> {};
#if defined(HAVE_DIRECTX) && defined(HAVE_D3D11)
#define UT_ACCEL_TYPE MFX_ACCEL_MODE_VIA_D3D11
#elif __linux__
#define UT_ACCEL_TYPE MFX_ACCEL_MODE_VIA_VAAPI
#else
#define UT_ACCEL_TYPE -1
#endif
preproc_args_t files[] = {
preproc_args_t {"highgui/video/big_buck_bunny.h264",
MFX_CODEC_AVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_AVC, UT_ACCEL_TYPE,
cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1080}}},
preproc_args_t {"highgui/video/big_buck_bunny.h265",
MFX_CODEC_HEVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_HEVC, UT_ACCEL_TYPE,
cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1280}}}
};
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
TEST(OneVPL_Source_PreprocEngine, functional_single_thread)
class OneVPL_PreproEngineTest : public ::testing::TestWithParam<acceleration_t> {};
TEST_P(OneVPL_PreproEngineTest, functional_single_thread)
{
using namespace cv::gapi::wip::onevpl;
using namespace cv::gapi::wip;
std::vector<CfgParam> cfg_params_w_dx11;
cfg_params_w_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
std::unique_ptr<VPLAccelerationPolicy> decode_accel_policy (
new VPLDX11AccelerationPolicy(std::make_shared<CfgParamDeviceSelector>(cfg_params_w_dx11)));
int accel_type = GetParam();
std::vector<CfgParam> cfg_params_w_accel;
std::unique_ptr<VPLAccelerationPolicy> decode_accel_policy = create_accel_policy_from_int(accel_type, cfg_params_w_accel);
// create file data provider
std::string file_path = findDataFile("highgui/video/big_buck_bunny.h265");
@@ -214,7 +243,7 @@ TEST(OneVPL_Source_PreprocEngine, functional_single_thread)
mfxLoader mfx{};
mfxConfig mfx_cfg{};
std::tie(mfx, mfx_cfg) = prepare_mfx(MFX_CODEC_HEVC, MFX_ACCEL_MODE_VIA_D3D11);
std::tie(mfx, mfx_cfg) = prepare_mfx(MFX_CODEC_HEVC, accel_type);
// create decode session
mfxSession mfx_decode_session{};
@@ -225,7 +254,7 @@ TEST(OneVPL_Source_PreprocEngine, functional_single_thread)
auto device_selector = decode_accel_policy->get_device_selector();
VPLLegacyDecodeEngine decode_engine(std::move(decode_accel_policy));
auto sess_ptr = decode_engine.initialize_session(mfx_decode_session,
cfg_params_w_dx11,
cfg_params_w_accel,
data_provider);
// simulate net info
@@ -233,8 +262,7 @@ TEST(OneVPL_Source_PreprocEngine, functional_single_thread)
{1920, 1080}};
// create VPP preproc engine
VPPPreprocEngine preproc_engine(std::unique_ptr<VPLAccelerationPolicy>{
new VPLDX11AccelerationPolicy(device_selector)});
VPPPreprocEngine preproc_engine(create_accel_policy_from_int(accel_type, device_selector));
// launch pipeline
// 1) decode frame
@@ -261,7 +289,7 @@ TEST(OneVPL_Source_PreprocEngine, functional_single_thread)
// make test in loop
bool in_progress = false;
size_t frames_processed_count = 1;
int frames_processed_count = 1;
const auto &first_pp_param_value_impl =
cv::util::get<cv::gapi::wip::onevpl::vpp_pp_params>(first_pp_params.value().value);
try {
@@ -298,9 +326,12 @@ TEST(OneVPL_Source_PreprocEngine, functional_single_thread)
ASSERT_NE(frames_processed_count, 1);
}
void decode_function(cv::gapi::wip::onevpl::VPLLegacyDecodeEngine &decode_engine,
cv::gapi::wip::onevpl::ProcessingEngineBase::session_ptr sess_ptr,
SafeQueue &queue, size_t &decoded_number) {
INSTANTIATE_TEST_CASE_P(OneVPL_Source_PreprocEngine, OneVPL_PreproEngineTest,
testing::Values(UT_ACCEL_TYPE));
static void decode_function(cv::gapi::wip::onevpl::VPLLegacyDecodeEngine &decode_engine,
cv::gapi::wip::onevpl::ProcessingEngineBase::session_ptr sess_ptr,
SafeQueue &queue, int &decoded_number) {
// decode first frame
{
cv::MediaFrame decoded_frame;
@@ -320,9 +351,9 @@ void decode_function(cv::gapi::wip::onevpl::VPLLegacyDecodeEngine &decode_engine
queue.push_stop();
}
void preproc_function(cv::gapi::wip::IPreprocEngine &preproc_engine, SafeQueue&queue,
size_t &preproc_number, const out_frame_info_t &required_frame_param,
const cv::util::optional<cv::Rect> &roi_rect = {}) {
static void preproc_function(cv::gapi::wip::IPreprocEngine &preproc_engine, SafeQueue&queue,
int &preproc_number, const out_frame_info_t &required_frame_param,
const cv::util::optional<cv::Rect> &roi_rect = {}) {
using namespace cv::gapi::wip;
using namespace cv::gapi::wip::onevpl;
// create preproc session based on frame description & network info
@@ -385,10 +416,11 @@ void preproc_function(cv::gapi::wip::IPreprocEngine &preproc_engine, SafeQueue&q
ASSERT_NE(preproc_number, 1);
}
void multi_source_preproc_function(size_t source_num,
cv::gapi::wip::IPreprocEngine &preproc_engine, SafeQueue&queue,
size_t &preproc_number, const out_frame_info_t &required_frame_param,
const cv::util::optional<cv::Rect> &roi_rect = {}) {
#ifdef __WIN32__
static void multi_source_preproc_function(size_t source_num,
cv::gapi::wip::IPreprocEngine &preproc_engine, SafeQueue&queue,
int &preproc_number, const out_frame_info_t &required_frame_param,
const cv::util::optional<cv::Rect> &roi_rect = {}) {
using namespace cv::gapi::wip;
using namespace cv::gapi::wip::onevpl;
// create preproc session based on frame description & network info
@@ -450,6 +482,8 @@ void multi_source_preproc_function(size_t source_num,
ASSERT_FALSE(in_progress);
ASSERT_NE(preproc_number, 1);
}
#endif // __WIN32__
using roi_t = cv::util::optional<cv::Rect>;
using preproc_roi_args_t = decltype(std::tuple_cat(std::declval<preproc_args_t>(),
std::declval<std::tuple<roi_t>>()));
@@ -467,10 +501,8 @@ TEST_P(VPPPreprocROIParams, functional_roi_different_threads)
file_path = findDataFile(file_path);
std::vector<CfgParam> cfg_params_w_dx11;
cfg_params_w_dx11.push_back(CfgParam::create_acceleration_mode(accel));
std::unique_ptr<VPLAccelerationPolicy> decode_accel_policy (
new VPLDX11AccelerationPolicy(std::make_shared<CfgParamDeviceSelector>(cfg_params_w_dx11)));
std::vector<CfgParam> cfg_params_w_accel;
std::unique_ptr<VPLAccelerationPolicy> decode_accel_policy = create_accel_policy_from_int(accel, cfg_params_w_accel);
// create file data provider
std::shared_ptr<IDataProvider> data_provider(new FileDataProvider(file_path,
@@ -489,17 +521,16 @@ TEST_P(VPPPreprocROIParams, functional_roi_different_threads)
auto device_selector = decode_accel_policy->get_device_selector();
VPLLegacyDecodeEngine decode_engine(std::move(decode_accel_policy));
auto sess_ptr = decode_engine.initialize_session(mfx_decode_session,
cfg_params_w_dx11,
cfg_params_w_accel,
data_provider);
// create VPP preproc engine
VPPPreprocEngine preproc_engine(std::unique_ptr<VPLAccelerationPolicy>{
new VPLDX11AccelerationPolicy(device_selector)});
VPPPreprocEngine preproc_engine(create_accel_policy_from_int(accel, device_selector));
// launch threads
SafeQueue queue;
size_t decoded_number = 1;
size_t preproc_number = 0;
int decoded_number = 1;
int preproc_number = 0;
std::thread decode_thread(decode_function, std::ref(decode_engine), sess_ptr,
std::ref(queue), std::ref(decoded_number));
@@ -515,31 +546,31 @@ TEST_P(VPPPreprocROIParams, functional_roi_different_threads)
preproc_roi_args_t files_w_roi[] = {
preproc_roi_args_t {"highgui/video/big_buck_bunny.h264",
MFX_CODEC_AVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_AVC, UT_ACCEL_TYPE,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1080}}},
roi_t{cv::Rect{0,0,50,50}}},
preproc_roi_args_t {"highgui/video/big_buck_bunny.h264",
MFX_CODEC_AVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_AVC, UT_ACCEL_TYPE,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1080}}},
roi_t{}},
preproc_roi_args_t {"highgui/video/big_buck_bunny.h264",
MFX_CODEC_AVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_AVC, UT_ACCEL_TYPE,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1080}}},
roi_t{cv::Rect{0,0,100,100}}},
preproc_roi_args_t {"highgui/video/big_buck_bunny.h264",
MFX_CODEC_AVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_AVC, UT_ACCEL_TYPE,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1080}}},
roi_t{cv::Rect{100,100,200,200}}},
preproc_roi_args_t {"highgui/video/big_buck_bunny.h265",
MFX_CODEC_HEVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_HEVC, UT_ACCEL_TYPE,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1280}}},
roi_t{cv::Rect{0,0,100,100}}},
preproc_roi_args_t {"highgui/video/big_buck_bunny.h265",
MFX_CODEC_HEVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_HEVC, UT_ACCEL_TYPE,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1280}}},
roi_t{}},
preproc_roi_args_t {"highgui/video/big_buck_bunny.h265",
MFX_CODEC_HEVC, MFX_ACCEL_MODE_VIA_D3D11,
MFX_CODEC_HEVC, UT_ACCEL_TYPE,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1280}}},
roi_t{cv::Rect{100,100,200,200}}}
};
@@ -561,12 +592,10 @@ TEST_P(VPPInnerPreprocParams, functional_inner_preproc_size)
file_path = findDataFile(file_path);
std::vector<CfgParam> cfg_params_w_dx11_vpp;
std::vector<CfgParam> cfg_params_w_accel_vpp;
// create accel policy
cfg_params_w_dx11_vpp.push_back(CfgParam::create_acceleration_mode(accel));
std::unique_ptr<VPLAccelerationPolicy> accel_policy (
new VPLDX11AccelerationPolicy(std::make_shared<CfgParamDeviceSelector>(cfg_params_w_dx11_vpp)));
std::unique_ptr<VPLAccelerationPolicy> accel_policy = create_accel_policy_from_int(accel, cfg_params_w_accel_vpp);
// create file data provider
std::shared_ptr<IDataProvider> data_provider(new FileDataProvider(file_path,
@@ -582,20 +611,20 @@ TEST_P(VPPInnerPreprocParams, functional_inner_preproc_size)
EXPECT_EQ(MFX_ERR_NONE, sts);
// fill vpp params beforehand: resolution
cfg_params_w_dx11_vpp.push_back(CfgParam::create_vpp_out_width(
cfg_params_w_accel_vpp.push_back(CfgParam::create_vpp_out_width(
static_cast<uint16_t>(required_frame_param.size.width)));
cfg_params_w_dx11_vpp.push_back(CfgParam::create_vpp_out_height(
cfg_params_w_accel_vpp.push_back(CfgParam::create_vpp_out_height(
static_cast<uint16_t>(required_frame_param.size.height)));
// create transcode engine
auto device_selector = accel_policy->get_device_selector();
VPLLegacyTranscodeEngine engine(std::move(accel_policy));
auto sess_ptr = engine.initialize_session(mfx_decode_session,
cfg_params_w_dx11_vpp,
cfg_params_w_accel_vpp,
data_provider);
// make test in loop
bool in_progress = false;
size_t frames_processed_count = 1;
int frames_processed_count = 1;
try {
while(true) {
cv::MediaFrame decoded_frame = extract_decoded_frame(sess_ptr->session, engine);
@@ -618,7 +647,8 @@ TEST_P(VPPInnerPreprocParams, functional_inner_preproc_size)
INSTANTIATE_TEST_CASE_P(OneVPL_Source_PreprocInner, VPPInnerPreprocParams,
testing::ValuesIn(files));
// Dispatcher test suite
// enable only for WIN32 because there are not CPU processing on Linux by default
#ifdef __WIN32__
class VPPPreprocDispatcherROIParams : public ::testing::TestWithParam<preproc_roi_args_t> {};
TEST_P(VPPPreprocDispatcherROIParams, functional_roi_different_threads)
{
@@ -626,17 +656,15 @@ TEST_P(VPPPreprocDispatcherROIParams, functional_roi_different_threads)
using namespace cv::gapi::wip::onevpl;
source_t file_path;
decoder_t decoder_id;
acceleration_t accel = MFX_ACCEL_MODE_VIA_D3D11;
acceleration_t accel = 0;
out_frame_info_t required_frame_param;
roi_t opt_roi;
std::tie(file_path, decoder_id, std::ignore, required_frame_param, opt_roi) = GetParam();
std::tie(file_path, decoder_id, accel, required_frame_param, opt_roi) = GetParam();
file_path = findDataFile(file_path);
std::vector<CfgParam> cfg_params_w_dx11;
cfg_params_w_dx11.push_back(CfgParam::create_acceleration_mode(accel));
std::unique_ptr<VPLAccelerationPolicy> decode_accel_policy (
new VPLDX11AccelerationPolicy(std::make_shared<CfgParamDeviceSelector>(cfg_params_w_dx11)));
std::vector<CfgParam> cfg_params_w_accel;
std::unique_ptr<VPLAccelerationPolicy> decode_accel_policy = create_accel_policy_from_int(accel, cfg_params_w_accel);
// create file data provider
std::shared_ptr<IDataProvider> data_provider(new FileDataProvider(file_path,
@@ -661,7 +689,7 @@ TEST_P(VPPPreprocDispatcherROIParams, functional_roi_different_threads)
auto device_selector = decode_accel_policy->get_device_selector();
VPLLegacyDecodeEngine decode_engine(std::move(decode_accel_policy));
auto sess_ptr = decode_engine.initialize_session(mfx_decode_session,
cfg_params_w_dx11,
cfg_params_w_accel,
data_provider);
std::vector<CfgParam> cfg_params_cpu;
auto cpu_device_selector = std::make_shared<CfgParamDeviceSelector>(cfg_params_cpu);
@@ -673,16 +701,15 @@ TEST_P(VPPPreprocDispatcherROIParams, functional_roi_different_threads)
// create VPP preproc engines
VPPPreprocDispatcher preproc_dispatcher;
preproc_dispatcher.insert_worker<VPPPreprocEngine>(std::unique_ptr<VPLAccelerationPolicy>{
new VPLDX11AccelerationPolicy(device_selector)});
preproc_dispatcher.insert_worker<VPPPreprocEngine>(create_accel_policy_from_int(accel, device_selector));
preproc_dispatcher.insert_worker<VPPPreprocEngine>(std::unique_ptr<VPLAccelerationPolicy>{
new VPLCPUAccelerationPolicy(cpu_device_selector)});
// launch threads
SafeQueue queue;
size_t decoded_number = 1;
size_t cpu_decoded_number = 1;
size_t preproc_number = 0;
int decoded_number = 1;
int cpu_decoded_number = 1;
int preproc_number = 0;
std::thread decode_thread(decode_function, std::ref(decode_engine), sess_ptr,
std::ref(queue), std::ref(decoded_number));
@@ -704,7 +731,6 @@ TEST_P(VPPPreprocDispatcherROIParams, functional_roi_different_threads)
INSTANTIATE_TEST_CASE_P(OneVPL_Source_PreprocDispatcherROI, VPPPreprocDispatcherROIParams,
testing::ValuesIn(files_w_roi));
#endif // HAVE_DIRECTX
#endif // HAVE_D3D11
#endif // __WIN32__
} // namespace opencv_test
#endif // HAVE_ONEVPL