NVIDIA DeepStream SDK API Reference

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