namespace dlstreamer#

Overview#

namespace dlstreamer {

// namespaces

namespace dlstreamer::detail;
namespace dlstreamer::param;
namespace dlstreamer::tensor;
    namespace dlstreamer::tensor::key;

// typedefs

typedef std::shared_ptr<BaseFrame> BaseFramePtr;
typedef std::shared_ptr<BaseSink> BaseSinkPtr;
typedef std::shared_ptr<BaseSource> BaseSourcePtr;
typedef std::shared_ptr<BaseTransform> BaseTransformPtr;
typedef std::shared_ptr<Context> ContextPtr;
typedef std::shared_ptr<MemoryMapper> MemoryMapperPtr;
typedef std::shared_ptr<CPUContext> CPUContextPtr;
typedef std::shared_ptr<CPUTensor> CPUTensorPtr;
typedef std::variant<int, double, size_t, std::string, std::vector<int>, std::vector<double>, std::vector<size_t>, std::vector<std::string>, intptr_t, bool, std::pair<int, int>> Any;
typedef std::map<std::string, Any, std::less<void>> AnyMap;
typedef std::shared_ptr<Dictionary> DictionaryPtr;
typedef std::shared_ptr<const Dictionary> DictionaryCPtr;
typedef std::shared_ptr<DMAContext> DMAContextPtr;
typedef std::shared_ptr<DMATensor> DMATensorPtr;
typedef std::shared_ptr<Element> ElementPtr;
typedef std::vector<ParamDesc> ParamDescVector;
typedef std::shared_ptr<FFmpegContext> FFmpegContextPtr;
typedef std::shared_ptr<FFmpegFrame> FFmpegFramePtr;
typedef int64_t Format;
typedef std::vector<FrameInfo> FrameInfoVector;
typedef std::shared_ptr<GSTFrame> GstFramePtr;
typedef std::shared_ptr<GSTTensor> GstTensorPtr;
typedef std::shared_ptr<USMTensor> USMTensorPtr;
typedef std::shared_ptr<OpenCLContext> OpenCLContextPtr;

typedef CL_API_ENTRY cl_mem(CL_API_CALL* clCreateBufferWithPropertiesINTEL_fn)(
    cl_context context,
    const cl_bitfield *properties,
    cl_mem_flags flags,
    size_t size,
    void *host_ptr,
    cl_int *errcode_ret
    );

typedef std::shared_ptr<OpenCLTensor> OpenCLTensorPtr;
typedef std::shared_ptr<OpenCVContext> OpenCVContextPtr;
typedef std::shared_ptr<OpenCVTensor> OpenCVTensorPtr;
typedef std::shared_ptr<OpenCVUMatContext> OpenCVUMatContextPtr;
typedef std::shared_ptr<OpenCVUMatTensor> OpenCVUMatTensorPtr;
typedef std::shared_ptr<OpenVINOContext> OpenVINOContextPtr;
typedef std::shared_ptr<OpenVINOFrame> OpenVINOFramePtr;
typedef std::shared_ptr<OpenVINOTensor> OpenVINOTensorPtr;
typedef std::shared_ptr<Sink> SinkPtr;
typedef std::shared_ptr<Source> SourcePtr;
typedef std::shared_ptr<SYCLContext> SYCLContextPtr;
typedef std::shared_ptr<SYCLUSMTensor> SYCLUSMTensorPtr;
typedef std::vector<TensorPtr> TensorVector;
typedef std::vector<TensorInfo> TensorInfoVector;
typedef std::shared_ptr<Transform> TransformPtr;
typedef std::unique_ptr<T, std::function<void(T*)>> auto_ptr;
typedef std::shared_ptr<VAAPIContext> VAAPIContextPtr;
typedef std::shared_ptr<VAAPIFrame> VAAPIFramePtr;
typedef std::shared_ptr<VAAPITensor> VAAPITensorPtr;

// enums

enum AccessMode;
enum DataType;
enum ElementFlags;
enum ImageFormat;
enum MediaType;
enum MemoryType;

// structs

struct AudioFormat;
struct AudioInfo;
struct ElementDesc;
struct FrameInfo;
struct GstDLStreamerMemory;
struct ImageInfo;
struct ParamDesc;
struct TensorInfo;

// classes

class AffineTransformInfoMetadata;
class BaseContext;
class BaseDictionary;

template <class T>
class BaseElement;

class BaseFrame;
class BaseMemoryMapper;
class BaseMetadata;
class BaseSink;
class BaseSource;
class BaseTensor;
class BaseTransform;
class BaseTransformInplace;

template <typename T>
class BlockingQueue;

class CPUContext;
class CPUFrameAlloc;
class CPUTensor;
class CPUTensorAlloc;
class ClassificationMetadata;
class Context;
class DMAContext;
class DMATensor;
class DetectionMetadata;
class Dictionary;
class DictionaryProxy;
class Element;
class FFmpegContext;
class FFmpegFrame;
class Frame;
class FramePtr;
class GSTContext;
class GSTContextQuery;
class GSTDictionary;
class GSTFrame;
class GSTFrameBatch;
class GSTMetadata;
class GSTROIDictionary;
class GSTROIMetadata;
class GSTTensor;
class ImageLayout;
class InferenceResultMetadata;
class LevelZeroContext;
class MemoryMapper;
class MemoryMapperAnyToGST;
class MemoryMapperCPUToOpenCV;
class MemoryMapperCPUToOpenVINO;
class MemoryMapperCache;
class MemoryMapperChain;
class MemoryMapperDMAToOpenCL;
class MemoryMapperDMAToUSM;
class MemoryMapperDMAToVAAPI;
class MemoryMapperFFMPEGToVAAPI;
class MemoryMapperGSTToDMA;
class MemoryMapperGSTToOpenCL;
class MemoryMapperGSTToVAAPI;
class MemoryMapperOpenCLToCPU;
class MemoryMapperOpenCLToDMA;
class MemoryMapperOpenCLToOpenCVUMat;
class MemoryMapperOpenCLToOpenVINO;
class MemoryMapperOpenVINOToCPU;
class MemoryMapperSYCLUSMToCPU;
class MemoryMapperUSMToDMA;
class MemoryMapperVAAPIToDMA;
class MemoryMapperVAAPIToOpenVINO;
class Metadata;
class ModelInfoMetadata;
class ObjectIdMetadata;
class OpenCLContext;
class OpenCLTensor;
class OpenCLTensorRefCounted;
class OpenCVContext;
class OpenCVTensor;
class OpenCVUMatContext;
class OpenCVUMatTensor;
class OpenVINOContext;
class OpenVINOFrame;
class OpenVINOTensor;
class OpenVINOTensorBatch;

template <typename T>
class Pool;

class SYCLContext;
class SYCLUSMTensor;
class Sink;
class Source;
class SourceIdentifierMetadata;
class Tensor;
class TensorPtr;
class TimestampMetadata;
class Transform;
class TransformInplace;
class USMTensor;
class VAAPIContext;
class VAAPIFrame;
class VAAPIFrameAlloc;
class VAAPITensor;

// global variables

static constexpr int32_t ElementDescMagic = 0x34495239;
static constexpr static GstMapFlags GST_MAP_NATIVE_HANDLE = static_cast<GstMapFlags>(GST_MAP_FLAG_LAST<<1);

// global functions

static TensorInfo squeeze_tensor_info(const TensorInfo& info);

static TensorPtr get_tensor_slice(
    TensorPtr tensor,
    const std::vector<std::pair<size_t, size_t>>& slice,
    bool squeeze = false
);

template <typename T>
T any_cast(const Any& any);

template <typename T>
bool any_holds_type(const Any& any);

template <class Ty>
static Element* create_element(
    DictionaryCPtr params,
    const ContextPtr& app_context
);

ImageFormat avformat_to_image_format(int format);
FrameInfo avframe_to_info(AVFrame* frame);
G_BEGIN_DECLS GstAllocator* gst_dlstreamer_allocator_new(MemoryType memory_type);

GstMemory* gst_dlstreamer_allocator_wrap_tensor(
    GstAllocator* allocator,
    const TensorPtr& tensor
);

gboolean gst_is_dlstreamer_memory(GstMemory* mem);
G_END_DECLS TensorPtr gst_dlstreamer_memory_get_tensor_ptr(GstMemory* mem);
static ImageFormat gst_format_to_video_format(int format);
static GstVideoFormat video_format_to_gst_format(ImageFormat format);
static FrameInfo gst_video_info_to_frame_info(const GstVideoInfo* vinfo);
static GstCapsFeatures* memory_type_to_gst_caps_feature(MemoryType memory_type);
static GstCaps* frame_info_to_gst_caps(const FrameInfo& info);
static GstCaps* frame_info_vector_to_gst_caps(const FrameInfoVector& infos);
static FrameInfo gst_caps_to_frame_info(const GstCaps* caps, guint index = 0);
static AccessMode gst_map_flags_to_access_mode(GstMapFlags flags);

static std::optional<Any> gvalue_to_any(
    const GValue* gval,
    const ParamDesc* desc = nullptr
);

static void any_to_gvalue(
    Any value,
    GValue* gvalue,
    bool init = true,
    const ParamDesc* desc = nullptr
);

template <typename T>
static std::vector<T> gvalue_to_vector(const GValue* value);

template <typename T>
static void vector_to_gvalue(
    std::vector<T> vec,
    GValue* gvalue
);

static GParamSpec* param_desc_to_spec(
    const ParamDesc& param,
    GstStructure* enums_storage
);

static std::string get_property_as_string(GObject* object, const gchar* name);
static std::string image_format_to_string(ImageFormat format);

static MemoryMapperPtr create_mapper(
    std::vector<ContextPtr> context_chain,
    bool use_cache = false
);

template <typename T_DOWN, typename T_UP>
static std::shared_ptr<T_DOWN> ptr_cast(const std::shared_ptr<T_UP>& ptr_up);

const char* memory_type_to_string(MemoryType type);
static MemoryType memory_type_from_string(std::string str);
cl_channel_order num_channels_to_opencl(int channels);
cl_channel_type data_type_to_opencl(DataType type);
static int data_type_to_opencv(DataType type);
static DataType data_type_from_openvino(ov::element::Type element);
static ov::element::Type data_type_to_openvino(DataType type);
static TensorInfo ov_tensor_to_tensor_info(ov::Tensor tensor);

static SinkPtr create_sink(
    const ElementDesc& desc,
    const AnyMap& params = AnyMap(),
    const ContextPtr& app_context = nullptr
);

template <class Ty>
static std::unique_ptr<Ty> create_sink(
    const AnyMap& params = AnyMap(),
    const ContextPtr& app_context = nullptr
);

static SourcePtr create_source(
    const ElementDesc& desc,
    const AnyMap& params = AnyMap(),
    const ContextPtr& app_context = nullptr
);

template <class Ty>
static std::unique_ptr<Ty> create_source(
    const AnyMap& params = AnyMap(),
    const ContextPtr& app_context = nullptr
);

static size_t datatype_size(DataType datatype);

static std::vector<size_t> contiguous_stride(
    const std::vector<size_t>& shape,
    DataType type
);

template <typename T>
bool check_datatype(DataType);

bool check_datatype< uint8_t >(DataType dtype);
bool check_datatype< int32_t >(DataType dtype);
bool check_datatype< int64_t >(DataType dtype);
bool check_datatype< float >(DataType dtype);

static TransformPtr create_transform(
    const ElementDesc& desc,
    const AnyMap& params = AnyMap(),
    const ContextPtr& app_context = nullptr
);

template <class Ty>
static std::unique_ptr<Ty> create_transform(
    const AnyMap& params = AnyMap(),
    const ContextPtr& app_context = nullptr
);

static FrameInfo frame_info(FramePtr frame);

static std::vector<std::string> split_string(
    const std::string& input,
    char delimiter = ','
);

template <typename OUTPUT, typename INPUT, typename O>
static std::vector<OUTPUT> transform_vector(
    const std::vector<INPUT>& input,
    O op
);

template <typename Iter>
static std::string join_strings(
    Iter begin,
    Iter end,
    char delimiter = ','
);

static DictionaryPtr find_metadata(
    const Frame& frame,
    std::string_view meta_name
);

template <class T>
static std::shared_ptr<T> find_metadata(
    const Frame& frame,
    std::string_view meta_name,
    std::string_view format
);

template <class T>
static T add_metadata(
    Frame& frame,
    std::string_view meta_name = T::name
);

static void copy_dictionary(
    const Dictionary& src,
    Dictionary& dst,
    bool copy_name = false
);

static void copy_metadata(const Frame& src, Frame& dst);
static std::string any_to_string(Any value);
static std::string datatype_to_string(DataType datatype);
static DataType datatype_from_string(const std::string& str);
static std::string media_type_to_string(MediaType media_type);
static std::vector<size_t> shape_from_string(const std::string& str);
static std::string shape_to_string(const std::vector<size_t>& dims);
static std::string tensor_info_to_string(const TensorInfo& info);
static TensorInfo tensor_info_from_string(const std::string& str);
static std::string frame_info_to_string(const FrameInfo& finfo);
static uint32_t video_format_to_vaapi(ImageFormat format);
static uint32_t vaapi_video_format_to_rtformat(uint32_t video_format);

} // namespace dlstreamer

Detailed Documentation#

Typedefs#

typedef std::variant<int, double, size_t, std::string, std::vector<int>, std::vector<double>, std::vector<size_t>, std::vector<std::string>, intptr_t, bool, std::pair<int, int>> Any

Type-safe union of selective basic types (defined via std::variant, requires C++17).

Global Functions#

static MemoryMapperPtr create_mapper(
    std::vector<ContextPtr> context_chain,
    bool use_cache = false
)

Creates chain of memory mappers as requested by vector of ContextPtr objects, and returns mapper object with input context equal to first element in specified vector and output context equal to last element in specified vector of context objects.

Parameters:

context_chain

Vector of context objects defining mapping sequence

use_cache

If true, the returned mapper cashes internally all mapped TensorPtr and FramePtr objects to avoid mapping operation on same TensorPtr/FramePtr multiple times. This optimization is useful for case mapper works on pool of limited number TensorPtr/FramePtr objects.