1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #20570 from sivanov-work:vpl_source_data_adapter

G-API: oneVPL (simplification) Add data adapter & Cfg params

* Add cfg_param & data_provider

* Fix compilation after rebase

* Apply some comments

* Apply default ctor outside class definition comment

* Apply cfg param in source

* Fix compilation: add virtual dtor

* Move cfg_params in regular gapi src list

* Fix compilation: add export.hpp

* Add errno.h

* Add errno.h

* Apply namespace comment

* Add several Doxygen & rename cfg_param

* Fix build

* Update Doxygen docs for onevpl

* Fix typo
This commit is contained in:
Sergey Ivanov
2021-08-24 15:41:57 +03:00
committed by GitHub
parent b509a7060a
commit 65ef82a946
15 changed files with 665 additions and 113 deletions
@@ -25,6 +25,17 @@
#include <opencv2/gapi/streaming/desync.hpp>
#include <opencv2/gapi/streaming/format.hpp>
#include <opencv2/gapi/streaming/onevpl/source.hpp>
#ifdef HAVE_ONEVPL
#if (MFX_VERSION >= 2000)
#include <vpl/mfxdispatcher.h>
#endif
#include <vpl/mfx.h>
#endif // HAVE_ONEVPL
namespace opencv_test
{
namespace
@@ -273,6 +284,22 @@ void checkPullOverload(const cv::Mat& ref,
EXPECT_EQ(0., cv::norm(ref, out_mat, cv::NORM_INF));
}
struct StreamDataProvider : public cv::gapi::wip::onevpl::IDataProvider {
StreamDataProvider(std::istream& in) : data_stream (in) {
EXPECT_TRUE(in);
}
size_t fetch_data(size_t out_data_size, void* out_data_buf) override {
data_stream.read(reinterpret_cast<char*>(out_data_buf), out_data_size);
return data_stream.gcount();
}
bool empty() const override {
return data_stream.eof() || data_stream.bad();
}
private:
std::istream& data_stream;
};
} // anonymous namespace
TEST_P(GAPI_Streaming, SmokeTest_ConstInput_GMat)
@@ -2214,4 +2241,47 @@ TEST(GAPI_Streaming, TestPythonAPI)
cc.stop();
}
#ifdef HAVE_ONEVPL
const unsigned char hevc_header[] = {
0x00, 0x00, 0x00, 0x01, 0x40, 0x01, 0x0C, 0x06, 0xFF, 0xFF, 0x01, 0x40, 0x00,
0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x00,
0x00, 0x04, 0x02, 0x10, 0x30, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03,
0x01, 0xE5, 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x06, 0x01, 0x40, 0x00, 0x00,
0x03, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x00, 0x00,
0xA0, 0x10, 0x20, 0x61, 0x63, 0x41, 0x00, 0x86, 0x49, 0x1B, 0x2B, 0x20, 0x00,
0x00, 0x00, 0x01, 0x44, 0x01, 0xC0, 0x71, 0xC0, 0xD9, 0x20, 0x00, 0x00, 0x00,
0x01, 0x26, 0x01, 0xAF, 0x0C
};
TEST(OneVPL_Source, Init)
{
using CfgParam = cv::gapi::wip::onevpl::CfgParam;
std::vector<CfgParam> src_params;
src_params.push_back(CfgParam::create<uint32_t>("mfxImplDescription.Impl",
MFX_IMPL_TYPE_HARDWARE));
src_params.push_back(CfgParam::create<uint32_t>("mfxImplDescription.AccelerationMode",
MFX_ACCEL_MODE_VIA_D3D11, false));
src_params.push_back(CfgParam::create<uint32_t>("mfxImplDescription.mfxDecoderDescription.decoder.CodecID",
MFX_CODEC_HEVC));
std::stringstream stream(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
EXPECT_TRUE(stream.write(reinterpret_cast<char*>(const_cast<unsigned char *>(hevc_header)),
sizeof(hevc_header)));
std::shared_ptr<cv::gapi::wip::onevpl::IDataProvider> stream_data_provider = std::make_shared<StreamDataProvider>(stream);
cv::Ptr<cv::gapi::wip::IStreamSource> cap;
bool cap_created = false;
try {
cap = cv::gapi::wip::make_onevpl_src(stream_data_provider, src_params);
cap_created = true;
} catch (const std::exception&) {
}
ASSERT_TRUE(cap_created);
cv::gapi::wip::Data out;
while (cap->pull(out)) {
(void)out;
}
EXPECT_TRUE(stream_data_provider->empty());
}
#endif
} // namespace opencv_test