NVIDIA DeepStream SDK API Reference

7.0 Release
infer_ioptions.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #ifndef __NVDSINFERSERVER_I_OPTIONS_H__
14 #define __NVDSINFERSERVER_I_OPTIONS_H__
15 
16 #include <infer_defines.h>
17 #include <nvdsinfer.h>
18 
19 #include <functional>
20 #include <list>
21 #include <memory>
22 #include <string>
23 #include <type_traits>
24 #include <vector>
25 
26 namespace nvdsinferserver {
27 
28 enum class OptionType : int {
29  oBool = 0,
30  oDouble,
31  oInt,
32  oUint,
33  oString,
34  oObject,
35  oArray,
36  oNone = -1,
37 };
38 
39 #define OPTION_SEQUENCE_ID "sequence_id" // uint64_t
40 #define OPTION_SEQUENCE_START "sequence_start" // bool
41 #define OPTION_SEQUENCE_END "sequence_end" // bool
42 #define OPTION_PRIORITY "priority" // uint64_t
43 #define OPTION_TIMEOUT "timeout_ms" // uint64_t
44 #define OPTION_NVDS_UNIQUE_ID "nvds_unique_id" // int64_t
45 #define OPTION_NVDS_SREAM_IDS "nvds_stream_ids" // source_id list, vector<uint64_t>
46 #define OPTION_NVDS_FRAME_META_LIST "nvds_frame_meta_list" // vector<NvDsFrameMeta*>
47 #define OPTION_NVDS_OBJ_META_LIST "nvds_obj_meta_list" // vector<NvDsObjectMeta*>
48 #define OPTION_NVDS_BATCH_META "nvds_batch_meta" // NvDsBatchMeta*
49 #define OPTION_NVDS_GST_BUFFER "nvds_gst_buffer" // GstBuffer*
50 #define OPTION_NVDS_BUF_SURFACE "nvds_buf_surface" // NvBufSurface*
51 #define OPTION_NVDS_BUF_SURFACE_PARAMS_LIST "nvds_buf_surface_params_list" // vector<NvBufSurfaceParams*>
52 #define OPTION_TIMESTAMP "timestamp" // uint64_t timestamp nano seconds
53 
54 class IOptions {
55 public:
56  IOptions() = default;
57  virtual ~IOptions() = default;
58  virtual bool hasValue(const std::string& key) const = 0;
59  virtual OptionType getType(const std::string& name) const = 0;
60  virtual uint32_t getCount() const = 0;
61  virtual std::string getKey(uint32_t idx) const = 0;
62 
63 protected:
65  const std::string& name, OptionType t, void*& ptr) const = 0;
66  virtual NvDsInferStatus getArraySize(const std::string& key, uint32_t& size) const = 0;
68  const std::string& name, OptionType ot, void** ptrBase, uint32_t size) const = 0;
69 
70  template <OptionType V>
71  struct OTypeV {
72  static constexpr OptionType v = V;
73  };
74  template <typename Value>
75  struct oType;
76 
77 public:
78  NvDsInferStatus getDouble(const std::string& name, double& v) const
79  {
80  return getValue<double>(name, v);
81  }
82  NvDsInferStatus getInt(const std::string& name, int64_t& v) const
83  {
84  return getValue<int64_t>(name, v);
85  }
86  NvDsInferStatus getUInt(const std::string& name, uint64_t& v) const
87  {
88  return getValue<uint64_t>(name, v);
89  }
90  NvDsInferStatus getString(const std::string& name, std::string& v)
91  {
92  return getValue<std::string>(name, v);
93  }
94  NvDsInferStatus getBool(const std::string& name, bool& v) const
95  {
96  return getValue<bool>(name, v);
97  }
98  template <typename Obj>
99  NvDsInferStatus getObj(const std::string& name, Obj*& obj) const
100  {
101  return getValue<Obj*>(name, obj);
102  }
103 
104  template <typename Value>
105  NvDsInferStatus getValue(const std::string& name, Value& value) const
106  {
107  using ValueType = std::remove_const_t<Value>;
109  void* ptr = nullptr;
110  auto status = getValuePtr(name, otype, ptr);
111  if (status == NVDSINFER_SUCCESS) {
112  assert(ptr);
113  value = *reinterpret_cast<ValueType*>(ptr);
114  }
115  return status;
116  }
117 
118  template <typename Value>
119  NvDsInferStatus getValueArray(const std::string& name, std::vector<Value>& values) const
120  {
121  using ValueType = std::remove_const_t<Value>;
123  uint32_t size = 0;
124  auto status = getArraySize(name, size);
125  if (status != NVDSINFER_SUCCESS) {
126  return status;
127  }
128  std::vector<ValueType*> valuePtrs(size);
129  void** ptrBase = reinterpret_cast<void**>(valuePtrs.data());
130  values.resize(size);
131  status = getRawPtrArray(name, otype, ptrBase, size);
132  if (status == NVDSINFER_SUCCESS) {
133  values.resize(size);
134  for (uint32_t i = 0; i < size; ++i) {
135  values[i] = *valuePtrs[i];
136  }
137  }
138  return status;
139  }
140 };
141 
142 template <OptionType v>
144 
145 template <typename Value>
147 };
148 template <>
149 struct IOptions::oType<bool> : IOptions::OTypeV<OptionType::oBool> {
150 };
151 template <>
152 struct IOptions::oType<double> : IOptions::OTypeV<OptionType::oDouble> {
153 };
154 template <>
155 struct IOptions::oType<int64_t> : IOptions::OTypeV<OptionType::oInt> {
156 };
157 template <>
158 struct IOptions::oType<uint64_t> : IOptions::OTypeV<OptionType::oUint> {
159 };
160 template <>
161 struct IOptions::oType<std::string> : IOptions::OTypeV<OptionType::oString> {
162 };
163 
164 } // namespace nvdsinferserver
165 
166 #endif // __NVDSINFERSERVER_I_OPTIONS_H__
nvdsinferserver::IOptions::getKey
virtual std::string getKey(uint32_t idx) const =0
nvdsinferserver
This is a header file for pre-processing cuda kernels with normalization and mean subtraction require...
Definition: infer_custom_process.h:24
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:119
nvdsinferserver::IOptions::OTypeV
Definition: infer_ioptions.h:71
nvdsinferserver::OptionType::oDouble
@ oDouble
nvdsinferserver::IOptions::oType
Definition: infer_ioptions.h:75
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:90
nvdsinferserver::OptionType::oBool
@ oBool
nvdsinferserver::IOptions::getValue
NvDsInferStatus getValue(const std::string &name, Value &value) const
Definition: infer_ioptions.h:105
nvdsinferserver::IOptions::getDouble
NvDsInferStatus getDouble(const std::string &name, double &v) const
Definition: infer_ioptions.h:78
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:94
nvdsinferserver::OptionType::oUint
@ oUint
nvdsinfer.h
nvdsinferserver::IOptions
Definition: infer_ioptions.h:54
nvdsinferserver::IOptions::getObj
NvDsInferStatus getObj(const std::string &name, Obj *&obj) const
Definition: infer_ioptions.h:99
nvdsinferserver::IOptions::OTypeV::v
static constexpr OptionType v
Definition: infer_ioptions.h:72
nvdsinferserver::IOptions::IOptions
IOptions()=default
nvdsinferserver::IOptions::getInt
NvDsInferStatus getInt(const std::string &name, int64_t &v) const
Definition: infer_ioptions.h:82
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:86
nvdsinferserver::OptionType
OptionType
Definition: infer_ioptions.h:28
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: nvdsinfer.h:218