NVIDIA DeepStream SDK API Reference

6.2 Release
infer_ioptions.h
Go to the documentation of this file.
1 
12 #ifndef __NVDSINFERSERVER_I_OPTIONS_H__
13 #define __NVDSINFERSERVER_I_OPTIONS_H__
14 
15 #include <infer_defines.h>
16 #include <nvdsinfer.h>
17 
18 #include <functional>
19 #include <list>
20 #include <memory>
21 #include <string>
22 #include <type_traits>
23 #include <vector>
24 
25 namespace nvdsinferserver {
26 
27 enum class OptionType : int {
28  oBool = 0,
29  oDouble,
30  oInt,
31  oUint,
32  oString,
33  oObject,
34  oArray,
35  oNone = -1,
36 };
37 
38 #define OPTION_SEQUENCE_ID "sequence_id" // uint64_t
39 #define OPTION_SEQUENCE_START "sequence_start" // bool
40 #define OPTION_SEQUENCE_END "sequence_end" // bool
41 #define OPTION_PRIORITY "priority" // uint64_t
42 #define OPTION_TIMEOUT "timeout_ms" // uint64_t
43 #define OPTION_NVDS_UNIQUE_ID "nvds_unique_id" // int64_t
44 #define OPTION_NVDS_SREAM_IDS "nvds_stream_ids" // source_id list, vector<uint64_t>
45 #define OPTION_NVDS_FRAME_META_LIST "nvds_frame_meta_list" // vector<NvDsFrameMeta*>
46 #define OPTION_NVDS_OBJ_META_LIST "nvds_obj_meta_list" // vector<NvDsObjectMeta*>
47 #define OPTION_NVDS_BATCH_META "nvds_batch_meta" // NvDsBatchMeta*
48 #define OPTION_NVDS_GST_BUFFER "nvds_gst_buffer" // GstBuffer*
49 #define OPTION_NVDS_BUF_SURFACE "nvds_buf_surface" // NvBufSurface*
50 #define OPTION_NVDS_BUF_SURFACE_PARAMS_LIST "nvds_buf_surface_params_list" // vector<NvBufSurfaceParams*>
51 #define OPTION_TIMESTAMP "timestamp" // uint64_t timestamp nano seconds
52 
53 class IOptions {
54 public:
55  IOptions() = default;
56  virtual ~IOptions() = default;
57  virtual bool hasValue(const std::string& key) const = 0;
58  virtual OptionType getType(const std::string& name) const = 0;
59  virtual uint32_t getCount() const = 0;
60  virtual std::string getKey(uint32_t idx) const = 0;
61 
62 protected:
64  const std::string& name, OptionType t, void*& ptr) const = 0;
65  virtual NvDsInferStatus getArraySize(const std::string& key, uint32_t& size) const = 0;
67  const std::string& name, OptionType ot, void** ptrBase, uint32_t size) const = 0;
68 
69  template <OptionType V>
70  struct OTypeV {
71  static constexpr OptionType v = V;
72  };
73  template <typename Value>
74  struct oType;
75 
76 public:
77  NvDsInferStatus getDouble(const std::string& name, double& v) const
78  {
79  return getValue<double>(name, v);
80  }
81  NvDsInferStatus getInt(const std::string& name, int64_t& v) const
82  {
83  return getValue<int64_t>(name, v);
84  }
85  NvDsInferStatus getUInt(const std::string& name, uint64_t& v) const
86  {
87  return getValue<uint64_t>(name, v);
88  }
89  NvDsInferStatus getString(const std::string& name, std::string& v)
90  {
91  return getValue<std::string>(name, v);
92  }
93  NvDsInferStatus getBool(const std::string& name, bool& v) const
94  {
95  return getValue<bool>(name, v);
96  }
97  template <typename Obj>
98  NvDsInferStatus getObj(const std::string& name, Obj*& obj) const
99  {
100  return getValue<Obj*>(name, obj);
101  }
102 
103  template <typename Value>
104  NvDsInferStatus getValue(const std::string& name, Value& value) const
105  {
106  using ValueType = std::remove_const_t<Value>;
108  void* ptr = nullptr;
109  auto status = getValuePtr(name, otype, ptr);
110  if (status == NVDSINFER_SUCCESS) {
111  assert(ptr);
112  value = *reinterpret_cast<ValueType*>(ptr);
113  }
114  return status;
115  }
116 
117  template <typename Value>
118  NvDsInferStatus getValueArray(const std::string& name, std::vector<Value>& values) const
119  {
120  using ValueType = std::remove_const_t<Value>;
122  uint32_t size = 0;
123  auto status = getArraySize(name, size);
124  if (status != NVDSINFER_SUCCESS) {
125  return status;
126  }
127  std::vector<ValueType*> valuePtrs(size);
128  void** ptrBase = reinterpret_cast<void**>(valuePtrs.data());
129  values.resize(size);
130  status = getRawPtrArray(name, otype, ptrBase, size);
131  if (status == NVDSINFER_SUCCESS) {
132  values.resize(size);
133  for (uint32_t i = 0; i < size; ++i) {
134  values[i] = *valuePtrs[i];
135  }
136  }
137  return status;
138  }
139 };
140 
141 template <OptionType v>
143 
144 template <typename Value>
146 };
147 template <>
148 struct IOptions::oType<bool> : IOptions::OTypeV<OptionType::oBool> {
149 };
150 template <>
151 struct IOptions::oType<double> : IOptions::OTypeV<OptionType::oDouble> {
152 };
153 template <>
154 struct IOptions::oType<int64_t> : IOptions::OTypeV<OptionType::oInt> {
155 };
156 template <>
157 struct IOptions::oType<uint64_t> : IOptions::OTypeV<OptionType::oUint> {
158 };
159 template <>
160 struct IOptions::oType<std::string> : IOptions::OTypeV<OptionType::oString> {
161 };
162 
163 } // namespace nvdsinferserver
164 
165 #endif // __NVDSINFERSERVER_I_OPTIONS_H__
nvdsinferserver::IOptions::getKey
virtual std::string getKey(uint32_t idx) const =0
nvdsinferserver
Copyright (c) 2021, NVIDIA CORPORATION.
Definition: infer_custom_process.h:23
nvdsinferserver::OptionType::oString
@ oString
nvdsinferserver::OptionType::oNone
@ oNone
nvdsinferserver::IOptions::getType
virtual OptionType getType(const std::string &name) const =0
nvdsinferserver::IOptions::hasValue
virtual bool hasValue(const std::string &key) const =0
nvdsinferserver::IOptions::getValueArray
NvDsInferStatus getValueArray(const std::string &name, std::vector< Value > &values) const
Definition: infer_ioptions.h:118
nvdsinferserver::IOptions::OTypeV
Definition: infer_ioptions.h:70
nvdsinferserver::OptionType::oDouble
@ oDouble
nvdsinferserver::IOptions::oType
Definition: infer_ioptions.h:74
nvdsinferserver::OptionType::oArray
@ oArray
infer_defines.h
nvdsinferserver::IOptions::getArraySize
virtual NvDsInferStatus getArraySize(const std::string &key, uint32_t &size) const =0
nvdsinferserver::IOptions::getString
NvDsInferStatus getString(const std::string &name, std::string &v)
Definition: infer_ioptions.h:89
NVDSINFER_SUCCESS
@ NVDSINFER_SUCCESS
NvDsInferContext operation succeeded.
Definition: nvdsinfer.h:219
nvdsinferserver::OptionType::oBool
@ oBool
nvdsinferserver::IOptions::getValue
NvDsInferStatus getValue(const std::string &name, Value &value) const
Definition: infer_ioptions.h:104
nvdsinferserver::IOptions::getDouble
NvDsInferStatus getDouble(const std::string &name, double &v) const
Definition: infer_ioptions.h:77
nvdsinferserver::IOptions::getCount
virtual uint32_t getCount() const =0
nvdsinferserver::IOptions::getRawPtrArray
virtual NvDsInferStatus getRawPtrArray(const std::string &name, OptionType ot, void **ptrBase, uint32_t size) const =0
nvdsinferserver::IOptions::getBool
NvDsInferStatus getBool(const std::string &name, bool &v) const
Definition: infer_ioptions.h:93
nvdsinferserver::OptionType::oUint
@ oUint
nvdsinfer.h
nvdsinferserver::IOptions
Definition: infer_ioptions.h:53
nvdsinferserver::IOptions::getObj
NvDsInferStatus getObj(const std::string &name, Obj *&obj) const
Definition: infer_ioptions.h:98
nvdsinferserver::IOptions::OTypeV::v
static constexpr OptionType v
Definition: infer_ioptions.h:71
nvdsinferserver::IOptions::IOptions
IOptions()=default
nvdsinferserver::IOptions::getInt
NvDsInferStatus getInt(const std::string &name, int64_t &v) const
Definition: infer_ioptions.h:81
nvdsinferserver::OptionType::oInt
@ oInt
nvdsinferserver::IOptions::~IOptions
virtual ~IOptions()=default
nvdsinferserver::IOptions::getValuePtr
virtual NvDsInferStatus getValuePtr(const std::string &name, OptionType t, void *&ptr) const =0
nvdsinferserver::OptionType::oObject
@ oObject
nvdsinferserver::IOptions::getUInt
NvDsInferStatus getUInt(const std::string &name, uint64_t &v) const
Definition: infer_ioptions.h:85
nvdsinferserver::OptionType
OptionType
Definition: infer_ioptions.h:27
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: nvdsinfer.h:217