NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-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 __GST_NVINFERBASE_H__
19 #define __GST_NVINFERBASE_H__
20 
21 #include <gst/base/gstbasetransform.h>
22 #include <gst/video/video.h>
23 #include <gst/audio/audio.h>
24 
25 #include <set>
26 #include <unordered_map>
27 #include <vector>
28 #include <memory>
29 
30 #include "cuda_runtime_api.h"
31 #include "nvbufsurftransform.h"
32 #include <nvdsinfer_context.h>
33 
34 #include "gstnvdsinfer.h"
35 #include "gstnvinfer_impl.h"
36 #include "gstnvdsmeta.h"
37 
38 #include "nvtx3/nvToolsExt.h"
39 
40 G_BEGIN_DECLS
41 /* Standard GStreamer boilerplate */
44 typedef struct _GstNvInferImpl GstNvInferImpl;
45 
46 /* Standard GStreamer boilerplate */
47 #define GST_TYPE_NVINFERBASE (gst_nvinferbase_get_type())
48 #define GST_NVINFERBASE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NVINFERBASE,GstNvInferBase))
49 #define GST_NVINFERBASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NVINFERBASE,GstNvInferBaseClass))
50 #define GST_NVINFERBASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_NVINFERBASE, GstNvInferBaseClass))
51 #define GST_IS_NVINFERBASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NVINFERBASE))
52 #define GST_IS_NVINFERBASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NVINFERBASE))
53 #define GST_NVINFERBASE_CAST(obj) ((GstNvInferBase *)(obj))
54 
58 enum
59 {
80 };
81 
82 /* nvinfer signals */
83 enum {
84  /* Signal emitted to notify app about model update completion with
85  * success/error messages. */
88 };
89 
90 extern guint gst_nvinfer_signals[LAST_SIGNAL];
91 
95 struct _GstNvInferBase
96 {
98  GstBaseTransform base_trans;
99 
102 
104  guint max_batch_size;
105 
113  guint unique_id;
114 
115  const gchar *classifier_type;
116 
117  guint interval_counter;
118 
120  GQueue *process_queue;
121  GMutex process_lock;
122  GCond process_cond;
123  GQueue *input_queue;
124 
126  GThread *output_thread;
127  GThread *input_queue_thread;
128 
130  gboolean stop;
131 
133  gint network_width;
134  gint network_height;
135 
137  gchar *config_file_path;
138 
140  GstFlowReturn last_flow_ret;
141 
143  guint gpu_id;
144 
146  gulong current_batch_num;
147 
150 
152  std::vector<NvDsInferLayerInfo> *layers_info;
153 
155  std::vector<NvDsInferLayerInfo> *output_layers_info;
156 
158  gboolean write_raw_buffers_to_file;
159 
161  guint64 file_write_batch_num;
162 
166  gpointer output_generated_userdata;
167 
170  std::vector<gboolean> *is_prop_set;
171 
174  gboolean output_tensor_meta;
175 
177  nvtxDomainHandle_t nvtx_domain;
178 
180 };
181 
182 /* GStreamer boilerplate. */
183 struct _GstNvInferBaseClass {
184  GstBaseTransformClass parent_class;
185 
191  void (*model_updated) (GstNvInferBase *, gint err, const gchar *cfg_file);
192 
193  gboolean (*start) (GstNvInferBase *base, NvDsInferContextInitParams *init_params);
194  void (*stop) (GstNvInferBase *base);
195  gboolean (*set_caps) (GstNvInferBase *base, GstCaps * incaps, GstCaps * outcaps);
196  gboolean (*sink_event) (GstNvInferBase * base, GstEvent * event);
197  void (*finalize) (GObject * object);
198 
199  GstFlowReturn (*process_input) (GstNvInferBase *base, GstBuffer *inbuf);
200  gboolean (*process_output) (GstNvInferBase *base, GstNvInferBatch *batch, NvDsInferContextBatchOutput *batch_output, GstMiniObject * tensor_out_object);
202  void (*clear_history) (GstNvInferBase *base);
203 
204  gboolean (*parse_other_attributes) (GstNvInferBase * base, GKeyFile * key_file, const gchar * group_name, const gchar * key);
205  gboolean (*parse_other_groups) (GstNvInferBase * base, GKeyFile * key_file, NvDsInferContextInitParams *init_params);
206 
209  unsigned int (*get_input_pitch) (GstNvInferBase *base, GstNvInferBatch *batch);
210  unsigned int (*get_output_buffer_pool_size) (GstNvInferBase *base);
211  gboolean (*get_classifier_async_mode) (GstNvInferBase *base);
212 };
213 
215 
216 GType gst_nvinferbase_get_type (void);
217 
218 G_END_DECLS
219 
220 #endif /* __GST_NVINFERBASE_H__ */
PROP_INTERVAL
@ PROP_INTERVAL
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:69
PROP_LAST
@ PROP_LAST
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:79
_GstNvInferBaseClass::parse_other_groups
gboolean(* parse_other_groups)(GstNvInferBase *base, GKeyFile *key_file, NvDsInferContextInitParams *init_params)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:205
_GstNvInferBase::base_trans
GstBaseTransform base_trans
Should be the first member when extending from GstBaseTransform.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:98
PROP_OUTPUT_CALLBACK
@ PROP_OUTPUT_CALLBACK
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:72
_GstNvInferBase::output_generated_callback
gst_nvinfer_raw_output_generated_callback output_generated_callback
Pointer to the callback function and userdata for application access to the bound buffer contents.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:165
PROP_AUDIO_TRANSFORM
@ PROP_AUDIO_TRANSFORM
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:75
NvDsInferFormat
NvDsInferFormat
Defines color formats.
Definition: includes/nvdsinfer_context.h:163
_GstNvInferBase::config_file_path
gchar * config_file_path
Path to the configuration file for this instance of gst-nvinfer.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:137
PROP_AUDIO_FRAME_SIZE
@ PROP_AUDIO_FRAME_SIZE
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:76
_GstNvInferBase::impl
GstNvInferImpl * impl
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:179
_GstNvInferBaseClass::get_classifier_async_mode
gboolean(* get_classifier_async_mode)(GstNvInferBase *base)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:211
PROP_MODEL_ENGINEFILE
@ PROP_MODEL_ENGINEFILE
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:67
_GstNvInferBase::unique_id
guint unique_id
Unique ID of the element.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:113
PROP_PROCESS_MODE
@ PROP_PROCESS_MODE
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:62
_GstNvInferBase::process_cond
GCond process_cond
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:122
_GstNvInferBaseClass::process_input
GstFlowReturn(* process_input)(GstNvInferBase *base, GstBuffer *inbuf)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:199
_GstNvInferBaseClass::finalize
void(* finalize)(GObject *object)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:197
PROP_OPERATE_ON_CLASS_IDS
@ PROP_OPERATE_ON_CLASS_IDS
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:65
PROP_OUTPUT_TENSOR_META
@ PROP_OUTPUT_TENSOR_META
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:74
GstNvInferBase
typedefG_BEGIN_DECLS struct _GstNvInferBase GstNvInferBase
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:42
_GstNvInferBase::max_batch_size
guint max_batch_size
Maximum batch size.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:104
_GstNvInferBase
GstNvInferBase element structure.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:95
_GstNvInferBase::network_height
gint network_height
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:134
_GstNvInferBase::output_tensor_meta
gboolean output_tensor_meta
Boolean indicating if tensor outputs should be attached as meta on GstBuffers.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:174
_GstNvInferBase::output_layers_info
std::vector< NvDsInferLayerInfo > * output_layers_info
Vector of bound output layers information.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:155
_GstNvInferBase::stop
gboolean stop
Boolean to signal output thread to stop.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:130
PROP_UNIQUE_ID
@ PROP_UNIQUE_ID
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:61
PROP_OUTPUT_CALLBACK_USERDATA
@ PROP_OUTPUT_CALLBACK_USERDATA
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:73
_GstNvInferBaseClass
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:183
_GstNvInferBase::layers_info
std::vector< NvDsInferLayerInfo > * layers_info
Vector of bound layers information.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:152
GstBuffer
struct _GstBuffer GstBuffer
Definition: includes/ds3d/common/idatatype.h:24
_GstNvInferBaseClass::parse_other_attributes
gboolean(* parse_other_attributes)(GstNvInferBase *base, GKeyFile *key_file, const gchar *group_name, const gchar *key)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:204
PROP_FILTER_OUT_CLASS_IDS
@ PROP_FILTER_OUT_CLASS_IDS
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:66
_GstNvInferBase::file_write_batch_num
guint64 file_write_batch_num
Batch counter for writing buffer contents to file.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:161
_GstNvInferBaseClass::clear_history
void(* clear_history)(GstNvInferBase *base)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:202
_GstNvInferBaseClass::process_output
gboolean(* process_output)(GstNvInferBase *base, GstNvInferBatch *batch, NvDsInferContextBatchOutput *batch_output, GstMiniObject *tensor_out_object)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:200
PROP_0
@ PROP_0
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:60
_GstNvInferBaseClass::model_updated
void(* model_updated)(GstNvInferBase *, gint err, const gchar *cfg_file)
Signals.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:191
PROP_GPU_DEVICE_ID
@ PROP_GPU_DEVICE_ID
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:70
PROP_OPERATE_ON_GIE_ID
@ PROP_OPERATE_ON_GIE_ID
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:64
_GstNvInferBase::last_flow_ret
GstFlowReturn last_flow_ret
GstFlowReturn returned by the latest buffer pad push.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:140
LAST_SIGNAL
@ LAST_SIGNAL
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:87
NvDsInferNetworkInfo
Holds information about the model network.
Definition: includes/nvdsinfer.h:119
GstNvInferBatch
Holds information about the batch of frames to be inferred.
Definition: sources/gst-plugins/gst-nvinfer/gstnvinfer_impl.h:99
_GstNvInferBase::write_raw_buffers_to_file
gboolean write_raw_buffers_to_file
Boolean indicating if the bound buffer contents should be written to file.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:158
gst_nvinfer_signals
guint gst_nvinfer_signals[LAST_SIGNAL]
_GstNvInferBaseClass::get_input_format
NvDsInferFormat(* get_input_format)(GstNvInferBase *base, GstNvInferBatch *batch)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:208
_GstNvInferBase::process_lock
GMutex process_lock
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:121
PROP_BATCH_SIZE
@ PROP_BATCH_SIZE
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:68
_GstNvInferBase::output_thread
GThread * output_thread
Output thread.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:126
_GstNvInferBaseClass::get_default_infer_format
NvDsInferFormat(* get_default_infer_format)(GstNvInferBase *base)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:207
_GstNvInferBase::interval_counter
guint interval_counter
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:117
PROP_CLASSIFIER_TYPE
@ PROP_CLASSIFIER_TYPE
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:78
PROP_CONFIG_FILE_PATH
@ PROP_CONFIG_FILE_PATH
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:63
_GstNvInferBase::classifier_type
const gchar * classifier_type
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:115
_GstNvInferBase::nvtx_domain
nvtxDomainHandle_t nvtx_domain
NVTX Domain.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:177
_NvDsInferContextInitParams
Holds the initialization parameters required for the NvDsInferContext interface.
Definition: includes/nvdsinfer_context.h:246
_GstNvInferBase::process_queue
GQueue * process_queue
Processing Queue and related synchronization structures.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:120
_GstNvInferBaseClass::start
gboolean(* start)(GstNvInferBase *base, NvDsInferContextInitParams *init_params)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:193
_GstNvInferBase::config_file_parse_successful
gboolean config_file_parse_successful
Boolean indicating if the config parsing was successful.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:101
_GstNvInferBaseClass::attach_previous_metadata
void(* attach_previous_metadata)(GstNvInferBase *base, GstNvInferBatch *batch)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:201
gst_nvinferbase_get_type
GType gst_nvinferbase_get_type(void)
_GstNvInferBase::gpu_id
guint gpu_id
ID of the GPU this element uses for conversions / inference.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:143
_GstNvInferBase::is_prop_set
std::vector< gboolean > * is_prop_set
Vector of booleans indicating if properties have been set through GObject set method.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:170
_GstNvInferBase::network_width
gint network_width
Network input resolution.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:133
NvDsInferContextBatchOutput
Holds the output for all of the frames in a batch (an array of frame), and related buffer information...
Definition: includes/nvdsinfer_context.h:645
gst_nvinfer_raw_output_generated_callback
G_BEGIN_DECLS typedef void(* gst_nvinfer_raw_output_generated_callback)(GstBuffer *buf, NvDsInferNetworkInfo *network_info, NvDsInferLayerInfo *layers_info, guint num_layers, guint batch_size, gpointer user_data)
Function definition for the inference raw output generated callback of Gst-NvInfer plugin.
Definition: includes/gstnvdsinfer.h:63
_GstNvInferBaseClass::set_caps
gboolean(* set_caps)(GstNvInferBase *base, GstCaps *incaps, GstCaps *outcaps)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:195
_GstNvInferBaseClass::get_output_buffer_pool_size
unsigned int(* get_output_buffer_pool_size)(GstNvInferBase *base)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:210
_GstNvInferBase::current_batch_num
gulong current_batch_num
Current batch number of the input batch.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:146
_GstNvInferBase::output_generated_userdata
gpointer output_generated_userdata
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:166
_GstNvInferBaseClass::parent_class
GstBaseTransformClass parent_class
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:184
gst_nvinfer_push_to_input_queue
void gst_nvinfer_push_to_input_queue(GstNvInferBase *nvinfer, GstNvInferBatch *batch)
_GstNvInferBaseClass::sink_event
gboolean(* sink_event)(GstNvInferBase *base, GstEvent *event)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:196
_GstNvInferBase::network_info
NvDsInferNetworkInfo network_info
Network input information.
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:149
_GstNvInferBaseClass::get_input_pitch
unsigned int(* get_input_pitch)(GstNvInferBase *base, GstNvInferBatch *batch)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:209
_GstNvInferBaseClass::stop
void(* stop)(GstNvInferBase *base)
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:194
SIGNAL_MODEL_UPDATED
@ SIGNAL_MODEL_UPDATED
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:86
_GstNvInferBase::input_queue_thread
GThread * input_queue_thread
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:127
PROP_OUTPUT_WRITE_TO_FILE
@ PROP_OUTPUT_WRITE_TO_FILE
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:71
GstNvInferImpl
struct _GstNvInferImpl GstNvInferImpl
Definition: sources/gst-plugins/gst-nvinfer/gstnvinfer.h:52
_GstNvInferBase::input_queue
GQueue * input_queue
Definition: sources/libs/gst-nvdsinferbase/gstnvinferbase.h:123
PROP_AUDIO_HOP_SIZE
@ PROP_AUDIO_HOP_SIZE
Definition: 9.2/sources/libs/gst-nvdsinferbase/gstnvinferbase.h:77
gstnvinfer_impl.h