NVIDIA DeepStream SDK API Reference

9.1 Release
sources/includes/nvdsinferserver/infer_ioptions.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __NVDSINFERSERVER_I_OPTIONS_H__
19 #define __NVDSINFERSERVER_I_OPTIONS_H__
20 
21 #include <infer_defines.h>
22 #include <nvdsinfer.h>
23 
24 #include <functional>
25 #include <list>
26 #include <memory>
27 #include <string>
28 #include <type_traits>
29 #include <vector>
30 
31 namespace nvdsinferserver {
32 
33 enum class OptionType : int {
34  oBool = 0,
35  oDouble,
36  oInt,
37  oUint,
38  oString,
39  oObject,
40  oArray,
41  oNone = -1,
42 };
43 
44 #define OPTION_SEQUENCE_ID "sequence_id" // uint64_t
45 #define OPTION_SEQUENCE_START "sequence_start" // bool
46 #define OPTION_SEQUENCE_END "sequence_end" // bool
47 #define OPTION_PRIORITY "priority" // uint64_t
48 #define OPTION_TIMEOUT "timeout_ms" // uint64_t
49 #define OPTION_NVDS_UNIQUE_ID "nvds_unique_id" // int64_t
50 #define OPTION_NVDS_SREAM_IDS "nvds_stream_ids" // source_id list, vector<uint64_t>
51 #define OPTION_NVDS_FRAME_META_LIST "nvds_frame_meta_list" // vector<NvDsFrameMeta*>
52 #define OPTION_NVDS_OBJ_META_LIST "nvds_obj_meta_list" // vector<NvDsObjectMeta*>
53 #define OPTION_NVDS_BATCH_META "nvds_batch_meta" // NvDsBatchMeta*
54 #define OPTION_NVDS_GST_BUFFER "nvds_gst_buffer" // GstBuffer*
55 #define OPTION_NVDS_BUF_SURFACE "nvds_buf_surface" // NvBufSurface*
56 #define OPTION_NVDS_BUF_SURFACE_PARAMS_LIST "nvds_buf_surface_params_list" // vector<NvBufSurfaceParams*>
57 #define OPTION_TIMESTAMP "timestamp" // uint64_t timestamp nano seconds
58 
59 class IOptions {
60 public:
61  IOptions() = default;
62  virtual ~IOptions() = default;
63  virtual bool hasValue(const std::string& key) const = 0;
64  virtual OptionType getType(const std::string& name) const = 0;
65  virtual uint32_t getCount() const = 0;
66  virtual std::string getKey(uint32_t idx) const = 0;
67 
68 protected:
70  const std::string& name, OptionType t, void*& ptr) const = 0;
71  virtual NvDsInferStatus getArraySize(const std::string& key, uint32_t& size) const = 0;
73  const std::string& name, OptionType ot, void** ptrBase, uint32_t size) const = 0;
74 
75  template <OptionType V>
76  struct OTypeV {
77  static constexpr OptionType v = V;
78  };
79  template <typename Value>
80  struct oType;
81 
82 public:
83  NvDsInferStatus getDouble(const std::string& name, double& v) const
84  {
85  return getValue<double>(name, v);
86  }
87  NvDsInferStatus getInt(const std::string& name, int64_t& v) const
88  {
89  return getValue<int64_t>(name, v);
90  }
91  NvDsInferStatus getUInt(const std::string& name, uint64_t& v) const
92  {
93  return getValue<uint64_t>(name, v);
94  }
95  NvDsInferStatus getString(const std::string& name, std::string& v)
96  {
97  return getValue<std::string>(name, v);
98  }
99  NvDsInferStatus getBool(const std::string& name, bool& v) const
100  {
101  return getValue<bool>(name, v);
102  }
103  template <typename Obj>
104  NvDsInferStatus getObj(const std::string& name, Obj*& obj) const
105  {
106  return getValue<Obj*>(name, obj);
107  }
108 
109  template <typename Value>
110  NvDsInferStatus getValue(const std::string& name, Value& value) const
111  {
112  using ValueType = std::remove_const_t<Value>;
114  void* ptr = nullptr;
115  auto status = getValuePtr(name, otype, ptr);
116  if (status == NVDSINFER_SUCCESS) {
117  assert(ptr);
118  value = *reinterpret_cast<ValueType*>(ptr);
119  }
120  return status;
121  }
122 
123  template <typename Value>
124  NvDsInferStatus getValueArray(const std::string& name, std::vector<Value>& values) const
125  {
126  using ValueType = std::remove_const_t<Value>;
128  uint32_t size = 0;
129  auto status = getArraySize(name, size);
130  if (status != NVDSINFER_SUCCESS) {
131  return status;
132  }
133  std::vector<ValueType*> valuePtrs(size);
134  void** ptrBase = reinterpret_cast<void**>(valuePtrs.data());
135  values.resize(size);
136  status = getRawPtrArray(name, otype, ptrBase, size);
137  if (status == NVDSINFER_SUCCESS) {
138  values.resize(size);
139  for (uint32_t i = 0; i < size; ++i) {
140  values[i] = *valuePtrs[i];
141  }
142  }
143  return status;
144  }
145 };
146 
147 template <OptionType v>
149 
150 template <typename Value>
152 };
153 template <>
154 struct IOptions::oType<bool> : IOptions::OTypeV<OptionType::oBool> {
155 };
156 template <>
157 struct IOptions::oType<double> : IOptions::OTypeV<OptionType::oDouble> {
158 };
159 template <>
160 struct IOptions::oType<int64_t> : IOptions::OTypeV<OptionType::oInt> {
161 };
162 template <>
163 struct IOptions::oType<uint64_t> : IOptions::OTypeV<OptionType::oUint> {
164 };
165 template <>
166 struct IOptions::oType<std::string> : IOptions::OTypeV<OptionType::oString> {
167 };
168 
169 } // namespace nvdsinferserver
170 
171 #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: sources/gst-plugins/gst-nvinferserver/gstnvinferserver_impl.h:69
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: sources/includes/nvdsinferserver/infer_ioptions.h:124
nvdsinferserver::IOptions::OTypeV
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:76
nvdsinferserver::OptionType::oDouble
@ oDouble
nvdsinferserver::IOptions::oType
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:80
infer_defines.h
nvdsinferserver::OptionType::oArray
@ oArray
NVDSINFER_SUCCESS
@ NVDSINFER_SUCCESS
NvDsInferContext operation succeeded.
Definition: sources/includes/nvdsinfer.h:233
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: sources/includes/nvdsinferserver/infer_ioptions.h:95
nvdsinferserver::OptionType::oBool
@ oBool
nvdsinferserver::IOptions::getValue
NvDsInferStatus getValue(const std::string &name, Value &value) const
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:110
nvdsinferserver::IOptions::getDouble
NvDsInferStatus getDouble(const std::string &name, double &v) const
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:83
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: sources/includes/nvdsinferserver/infer_ioptions.h:99
nvdsinferserver::OptionType::oUint
@ oUint
nvdsinferserver::IOptions
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:59
nvdsinferserver::IOptions::getObj
NvDsInferStatus getObj(const std::string &name, Obj *&obj) const
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:104
nvdsinferserver::IOptions::OTypeV::v
static constexpr OptionType v
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:77
nvdsinferserver::IOptions::IOptions
IOptions()=default
nvdsinferserver::IOptions::getInt
NvDsInferStatus getInt(const std::string &name, int64_t &v) const
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:87
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: sources/includes/nvdsinferserver/infer_ioptions.h:91
nvdsinferserver::OptionType
OptionType
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:33
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: sources/includes/nvdsinfer.h:231