添加项目文件。

This commit is contained in:
CaiXiang
2024-09-25 09:43:03 +08:00
parent f5c6245902
commit 3e82af9e90
730 changed files with 350436 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
// 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 OPENCV_GAPI_STREAMING_ONEVPL_CFG_PARAMS_HPP
#define OPENCV_GAPI_STREAMING_ONEVPL_CFG_PARAMS_HPP
#include <map>
#include <memory>
#include <string>
#include <opencv2/gapi/streaming/source.hpp>
#include <opencv2/gapi/util/variant.hpp>
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
/**
* @brief Public class is using for creation of onevpl::GSource instances.
*
* Class members availaible through methods @ref CfgParam::get_name() and @ref CfgParam::get_value() are used by
* onevpl::GSource inner logic to create or find oneVPL particular implementation
* (software/hardware, specific API version and etc.).
*
* @note Because oneVPL may provide several implementations which are satisfying with multiple (or single one) @ref CfgParam
* criteria therefore it is possible to configure `preferred` parameters. This kind of CfgParams are created
* using `is_major = false` argument in @ref CfgParam::create method and are not used by creating oneVPL particular implementations.
* Instead they fill out a "score table" to select preferrable implementation from available list. Implementation are satisfying
* with most of these optional params would be chosen.
* If no one optional CfgParam params were present then first of available oneVPL implementation would be applied.
* Please get on https://spec.oneapi.io/versions/latest/elements/oneVPL/source/API_ref/VPL_disp_api_func.html?highlight=mfxcreateconfig#mfxsetconfigfilterproperty
* for using OneVPL configuration. In this schema `mfxU8 *name` represents @ref CfgParam::get_name() and
* `mfxVariant value` is @ref CfgParam::get_value()
*/
struct GAPI_EXPORTS CfgParam {
using name_t = std::string;
using value_t = cv::util::variant<uint8_t, int8_t,
uint16_t, int16_t,
uint32_t, int32_t,
uint64_t, int64_t,
float_t,
double_t,
void*,
std::string>;
/**
* Create onevp::GSource configuration parameter.
*
*@param name name of parameter.
*@param value value of parameter.
*@param is_major TRUE if parameter MUST be provided by OneVPL inner implementation, FALSE for optional (for resolve multiple available implementations).
*
*/
template<typename ValueType>
static CfgParam create(const std::string& name, ValueType&& value, bool is_major = true) {
CfgParam param(name, CfgParam::value_t(std::forward<ValueType>(value)), is_major);
return param;
}
struct Priv;
const name_t& get_name() const;
const value_t& get_value() const;
bool is_major() const;
bool operator==(const CfgParam& rhs) const;
bool operator< (const CfgParam& rhs) const;
bool operator!=(const CfgParam& rhs) const;
CfgParam& operator=(const CfgParam& src);
CfgParam& operator=(CfgParam&& src);
CfgParam(const CfgParam& src);
CfgParam(CfgParam&& src);
~CfgParam();
private:
CfgParam(const std::string& param_name, value_t&& param_value, bool is_major_param);
std::shared_ptr<Priv> m_priv;
};
} //namespace onevpl
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // OPENCV_GAPI_STREAMING_ONEVPL_CFG_PARAMS_HPP

View File

@@ -0,0 +1,105 @@
// 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_DATA_PROVIDER_INTERFACE_HPP
#define GAPI_STREAMING_ONEVPL_ONEVPL_DATA_PROVIDER_INTERFACE_HPP
#include <exception>
#include <memory>
#include <string>
#include <opencv2/gapi/own/exports.hpp> // GAPI_EXPORTS
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
struct GAPI_EXPORTS DataProviderException : public std::exception {
DataProviderException(const std::string& descr);
DataProviderException(std::string&& descr);
virtual ~DataProviderException() = default;
virtual const char* what() const noexcept override;
private:
std::string reason;
};
struct GAPI_EXPORTS DataProviderSystemErrorException final : public DataProviderException {
DataProviderSystemErrorException(int error_code, const std::string& desription = std::string());
~DataProviderSystemErrorException() = default;
};
struct GAPI_EXPORTS DataProviderUnsupportedException final : public DataProviderException {
DataProviderUnsupportedException(const std::string& description);
~DataProviderUnsupportedException() = default;
};
struct GAPI_EXPORTS DataProviderImplementationException : public DataProviderException {
DataProviderImplementationException(const std::string& description);
~DataProviderImplementationException() = default;
};
/**
* @brief Public interface allows to customize extraction of video stream data
* used by onevpl::GSource instead of reading stream from file (by default).
*
* Interface implementation constructor MUST provide consistency and creates fully operable object.
* If error happened implementation MUST throw `DataProviderException` kind exceptions
*
* @note Interface implementation MUST manage stream and other constructed resources by itself to avoid any kind of leak.
* For simple interface implementation example please see `StreamDataProvider` in `tests/streaming/gapi_streaming_tests.cpp`
*/
struct GAPI_EXPORTS IDataProvider {
using Ptr = std::shared_ptr<IDataProvider>;
using mfx_codec_id_type = uint32_t;
/**
* NB: here is supposed to be forward declaration of mfxBitstream
* But according to current oneVPL implementation it is impossible to forward
* declare untagged struct mfxBitstream.
*
* IDataProvider makes sense only for HAVE_VPL is ON and to keep IDataProvider
* interface API/ABI compliant between core library and user application layer
* let's introduce wrapper mfx_bitstream which inherits mfxBitstream in private
* G-API code section and declare forward for wrapper mfx_bitstream here
*/
struct mfx_bitstream;
virtual ~IDataProvider() = default;
/**
* The function is used by onevpl::GSource to extract codec id from data
*
*/
virtual mfx_codec_id_type get_mfx_codec_id() const = 0;
/**
* The function is used by onevpl::GSource to extract binary data stream from @ref IDataProvider
* implementation.
*
* It MUST throw `DataProviderException` kind exceptions in fail cases.
* It MUST return MFX_ERR_MORE_DATA in EOF which considered as not-fail case.
*
* @param in_out_bitsream the input-output reference on MFX bitstream buffer which MUST be empty at the first request
* to allow implementation to allocate it by itself and to return back. Subsequent invocation of `fetch_bitstream_data`
* MUST use the previously used in_out_bitsream to avoid skipping rest of frames which haven't been consumed
* @return true for fetched data, false on EOF and throws exception on error
*/
virtual bool fetch_bitstream_data(std::shared_ptr<mfx_bitstream> &in_out_bitsream) = 0;
/**
* The function is used by onevpl::GSource to check more binary data availability.
*
* It MUST return TRUE in case of EOF and NO_THROW exceptions.
*
* @return boolean value which detects end of stream
*/
virtual bool empty() const = 0;
};
} // namespace onevpl
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // GAPI_STREAMING_ONEVPL_ONEVPL_DATA_PROVIDER_INTERFACE_HPP

View File

@@ -0,0 +1,102 @@
// 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_DEVICE_SELECTOR_INTERFACE_HPP
#define GAPI_STREAMING_ONEVPL_DEVICE_SELECTOR_INTERFACE_HPP
#include <limits>
#include <map>
#include <string>
#include <vector>
#include "opencv2/gapi/own/exports.hpp" // GAPI_EXPORTS
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
enum class AccelType: uint8_t {
HOST,
DX11,
LAST_VALUE = std::numeric_limits<uint8_t>::max()
};
GAPI_EXPORTS const char* to_cstring(AccelType type);
struct IDeviceSelector;
struct GAPI_EXPORTS Device {
friend struct IDeviceSelector;
using Ptr = void*;
~Device();
const std::string& get_name() const;
Ptr get_ptr() const;
AccelType get_type() const;
private:
Device(Ptr device_ptr, const std::string& device_name,
AccelType device_type);
std::string name;
Ptr ptr;
AccelType type;
};
struct GAPI_EXPORTS Context {
friend struct IDeviceSelector;
using Ptr = void*;
~Context();
Ptr get_ptr() const;
AccelType get_type() const;
private:
Context(Ptr ctx_ptr, AccelType ctx_type);
Ptr ptr;
AccelType type;
};
struct GAPI_EXPORTS IDeviceSelector {
using Ptr = std::shared_ptr<IDeviceSelector>;
struct GAPI_EXPORTS Score {
friend struct IDeviceSelector;
using Type = int16_t;
static constexpr Type MaxActivePriority = std::numeric_limits<Type>::max();
static constexpr Type MinActivePriority = 0;
static constexpr Type MaxPassivePriority = MinActivePriority - 1;
static constexpr Type MinPassivePriority = std::numeric_limits<Type>::min();
Score(Type val);
~Score();
operator Type () const;
Type get() const;
friend bool operator< (Score lhs, Score rhs) {
return lhs.get() < rhs.get();
}
private:
Type value;
};
using DeviceScoreTable = std::map<Score, Device>;
using DeviceContexts = std::vector<Context>;
virtual ~IDeviceSelector();
virtual DeviceScoreTable select_devices() const = 0;
virtual DeviceContexts select_context() = 0;
protected:
template<typename Entity, typename ...Args>
static Entity create(Args &&...args) {
return Entity(std::forward<Args>(args)...);
}
};
} // namespace onevpl
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // GAPI_STREAMING_ONEVPL_DEVICE_SELECTOR_INTERFACE_HPP

View File

@@ -0,0 +1,90 @@
// 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 OPENCV_GAPI_STREAMING_ONEVPL_ONEVPL_SOURCE_HPP
#define OPENCV_GAPI_STREAMING_ONEVPL_ONEVPL_SOURCE_HPP
#include <opencv2/gapi/garg.hpp>
#include <opencv2/gapi/streaming/meta.hpp>
#include <opencv2/gapi/streaming/source.hpp>
#include <opencv2/gapi/streaming/onevpl/cfg_params.hpp>
#include <opencv2/gapi/streaming/onevpl/data_provider_interface.hpp>
#include <opencv2/gapi/streaming/onevpl/device_selector_interface.hpp>
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
using CfgParams = std::vector<CfgParam>;
/**
* @brief G-API streaming source based on OneVPL implementation.
*
* This class implements IStreamSource interface.
* Its constructor takes source file path (in usual way) or @ref onevpl::IDataProvider
* interface implementation (for not file-based sources). It also allows to pass-through
* oneVPL configuration parameters by using several @ref onevpl::CfgParam.
*
* @note stream sources are passed to G-API via shared pointers, so
* please gapi::make_onevpl_src<> to create objects and ptr() to pass a
* GSource to cv::gin().
*/
class GAPI_EXPORTS GSource : public IStreamSource
{
public:
struct Priv;
GSource(const std::string& filePath,
const CfgParams& cfg_params = CfgParams{});
GSource(const std::string& filePath,
const CfgParams& cfg_params,
const std::string& device_id,
void* accel_device_ptr,
void* accel_ctx_ptr);
GSource(const std::string& filePath,
const CfgParams& cfg_params,
std::shared_ptr<IDeviceSelector> selector);
GSource(std::shared_ptr<IDataProvider> source,
const CfgParams& cfg_params = CfgParams{});
GSource(std::shared_ptr<IDataProvider> source,
const CfgParams& cfg_params,
const std::string& device_id,
void* accel_device_ptr,
void* accel_ctx_ptr);
GSource(std::shared_ptr<IDataProvider> source,
const CfgParams& cfg_params,
std::shared_ptr<IDeviceSelector> selector);
~GSource() override;
bool pull(cv::gapi::wip::Data& data) override;
GMetaArg descr_of() const override;
private:
explicit GSource(std::unique_ptr<Priv>&& impl);
std::unique_ptr<Priv> m_priv;
};
} // namespace onevpl
using GVPLSource = onevpl::GSource;
template<class... Args>
GAPI_EXPORTS_W cv::Ptr<IStreamSource> inline make_onevpl_src(Args&&... args)
{
return make_src<onevpl::GSource>(std::forward<Args>(args)...);
}
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // OPENCV_GAPI_STREAMING_ONEVPL_ONEVPL_SOURCE_HPP