NVIDIA DeepStream SDK API Reference

7.0 Release
gstnvinfer.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2020 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 __GST_NVINFER_H__
14 #define __GST_NVINFER_H__
15 
16 #include <gst/base/gstbasetransform.h>
17 #include <gst/video/video.h>
18 
19 #include <set>
20 #include <unordered_map>
21 #include <vector>
22 #include <memory>
23 
24 #include "cuda_runtime_api.h"
25 #include "nvbufsurftransform.h"
26 #include <nvdsinfer_context.h>
27 
28 #include "gstnvdsinfer.h"
29 
30 #include "gstnvdsmeta.h"
31 
32 #include "nvtx3/nvToolsExt.h"
33 
34 /* Package and library details required for plugin_init */
35 #define PACKAGE "nvinfer"
36 #define VERSION "1.0"
37 #define LICENSE "Proprietary"
38 #define DESCRIPTION "NVIDIA DeepStreamSDK TensorRT plugin"
39 #define BINARY_PACKAGE "NVIDIA DeepStreamSDK TensorRT plugin"
40 #define URL "http://nvidia.com/"
41 
42 
43 G_BEGIN_DECLS
44 /* Standard GStreamer boilerplate */
45 typedef struct _GstNvInfer GstNvInfer;
47 typedef struct _GstNvInferImpl GstNvInferImpl;
48 
49 /* Standard GStreamer boilerplate */
50 #define GST_TYPE_NVINFER (gst_nvinfer_get_type())
51 #define GST_NVINFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NVINFER,GstNvInfer))
52 #define GST_NVINFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NVINFER,GstNvInferClass))
53 #define GST_NVINFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_NVINFER, GstNvInferClass))
54 #define GST_IS_NVINFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NVINFER))
55 #define GST_IS_NVINFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NVINFER))
56 #define GST_NVINFER_CAST(obj) ((GstNvInfer *)(obj))
57 
61 enum
62 {
83 };
84 
85 /* nvinfer signals */
86 enum {
87  /* Signal emitted to notify app about model update completion with
88  * success/error messages. */
91 };
92 
93 extern guint gst_nvinfer_signals[LAST_SIGNAL];
94 
98 typedef struct
99 {
107 
111 typedef struct
112 {
115 
116  gboolean have_bg_color;
119 
123  std::vector<NvDsInferAttribute> attributes;
125  std::string label;
126 
128  GstNvInferObjectInfo() = default;
130  for (auto &attr : attributes) {
131  if (attr.attributeLabel)
132  free (attr.attributeLabel);
133  }
134  }
135 };
136 
142 {
144  gboolean under_inference;
156 
158 typedef std::unordered_map<guint64, std::shared_ptr<GstNvInferObjectHistory>> GstNvInferObjectHistoryMap;
159 
163 typedef struct
164 {
172 
177 {
179  GstBaseTransform base_trans;
180 
183 
186 
194  guint unique_id;
195 
199  GstBufferPool *pool;
200 
202  GQueue *process_queue;
203  GMutex process_lock;
205  GQueue *input_queue;
206 
208  GThread *output_thread;
210 
212  gboolean stop;
213 
217 
221 
224 
226  GstFlowReturn last_flow_ret;
227 
229  guint gpu_id;
230 
233 
235 
238 
242 
247 
249  std::vector<GstNvInferDetectionFilterParams> *perClassDetectionFilterParams;
250 
252  std::vector<GstNvInferColorParams> *perClassColorParams;
253 
255  guint interval;
257 
260 
266 
269  std::vector<gboolean> *operate_on_class_ids;
270  std::set<uint> *filter_out_class_ids;
271 
273  std::unordered_map<gint, GstNvInferSourceInfo> *source_info;
275 
278 
281 
284 
287 
289  std::vector<NvDsInferLayerInfo> *layers_info;
290 
292  std::vector<NvDsInferLayerInfo> *output_layers_info;
293 
296 
299 
304 
307  std::vector<gboolean> *is_prop_set;
308 
311 
314 
317 
321 
325 
329 
331  nvtxDomainHandle_t nvtx_domain;
332 
333  /*Clip the object bounding-box which lies outside the roi boundary. */
335 
337 };
338 
339 /* GStreamer boilerplate. */
341  GstBaseTransformClass parent_class;
342 
348  void (*model_updated) (GstNvInfer *, gint err, const gchar *cfg_file);
349 };
350 
351 GType gst_nvinfer_get_type (void);
352 
353 G_END_DECLS
354 
355 #endif /* __GST_INFER_H__ */
GstNvInferSourceInfo::last_cleanup_frame_num
gulong last_cleanup_frame_num
Frame number of the buffer when the history map was last cleaned up.
Definition: gstnvinfer.h:168
_GstNvInfer::min_input_object_width
guint min_input_object_width
Input object size-based filtering parameters for object processing mode.
Definition: gstnvinfer.h:262
GstNvInferColorParams::have_bg_color
gboolean have_bg_color
Definition: gstnvinfer.h:116
PROP_LAST
@ PROP_LAST
Definition: gstnvinfer.h:82
_NvOSD_RectParams
Holds the box parameters of the box to be overlayed.
Definition: nvll_osd_struct.h:140
_GstNvInfer::output_thread
GThread * output_thread
Output thread.
Definition: gstnvinfer.h:208
_GstNvInfer::process_full_frame
gboolean process_full_frame
Boolean indicating if entire frame should be inferred or crop objects based on metadata recieved from...
Definition: gstnvinfer.h:220
_GstNvInfer::output_instance_mask
gboolean output_instance_mask
Boolean indicating if instance masks are expected in output and has to be attached in metadata.
Definition: gstnvinfer.h:324
PROP_OUTPUT_WRITE_TO_FILE
@ PROP_OUTPUT_WRITE_TO_FILE
Definition: gstnvinfer.h:74
GstNvInferObjectInfo::attributes
std::vector< NvDsInferAttribute > attributes
Vector of cached classification attributes.
Definition: gstnvinfer.h:123
_GstNvInfer::process_cond
GCond process_cond
Definition: gstnvinfer.h:204
_GstNvInferObjectHistory
Holds the inference information/history for one object based on it's tracking id.
Definition: gstnvinfer.h:141
PROP_OPERATE_ON_GIE_ID
@ PROP_OPERATE_ON_GIE_ID
Definition: gstnvinfer.h:67
PROP_CLIP_OBJECT_OUTSIDE_ROI
@ PROP_CLIP_OBJECT_OUTSIDE_ROI
Definition: gstnvinfer.h:80
gst_nvinfer_get_type
GType gst_nvinfer_get_type(void)
PROP_PROCESS_MODE
@ PROP_PROCESS_MODE
Definition: gstnvinfer.h:65
GstNvInferDetectionFilterParams::detectionMaxHeight
guint detectionMaxHeight
Definition: gstnvinfer.h:105
GstNvInfer
typedefG_BEGIN_DECLS struct _GstNvInfer GstNvInfer
Definition: gstnvinfer.h:45
_NvBufSurfaceTransformParams
Holds transform parameters for a transform call.
Definition: nvbufsurftransform.h:190
PROP_FILTER_OUT_CLASS_IDS
@ PROP_FILTER_OUT_CLASS_IDS
Definition: gstnvinfer.h:69
_GstNvInfer::base_trans
GstBaseTransform base_trans
Should be the first member when extending from GstBaseTransform.
Definition: gstnvinfer.h:179
NvBufSurface
Holds information about batched buffers.
Definition: nvbufsurface.h:509
gstnvdsinfer.h
_GstNvInfer::transform_params
NvBufSurfTransformParams transform_params
Parameters to use for transforming buffers.
Definition: gstnvinfer.h:313
PROP_CONFIG_FILE_PATH
@ PROP_CONFIG_FILE_PATH
Definition: gstnvinfer.h:66
_GstNvInfer::network_info
NvDsInferNetworkInfo network_info
Network input information.
Definition: gstnvinfer.h:286
_GstNvInfer::convertStream
cudaStream_t convertStream
Cuda Stream to launch npp operations on.
Definition: gstnvinfer.h:232
GstNvInferColorParams
Holds the bounding box coloring information for one class;.
Definition: gstnvinfer.h:111
PROP_INTERVAL
@ PROP_INTERVAL
Definition: gstnvinfer.h:72
_GstNvInfer::max_input_object_width
guint max_input_object_width
Definition: gstnvinfer.h:264
PROP_OUTPUT_CALLBACK_USERDATA
@ PROP_OUTPUT_CALLBACK_USERDATA
Definition: gstnvinfer.h:76
_GstNvInfer::network_width
gint network_width
Network input resolution.
Definition: gstnvinfer.h:215
_GstNvInfer::output_layers_info
std::vector< NvDsInferLayerInfo > * output_layers_info
Vector of bound output layers information.
Definition: gstnvinfer.h:292
_GstNvInferObjectHistory::under_inference
gboolean under_inference
Boolean indicating if the object is already being inferred on.
Definition: gstnvinfer.h:144
_GstNvInfer::config_file_parse_successful
gboolean config_file_parse_successful
Boolean indicating if the config parsing was successful.
Definition: gstnvinfer.h:182
LAST_SIGNAL
@ LAST_SIGNAL
Definition: gstnvinfer.h:90
_GstNvInfer::process_queue
GQueue * process_queue
Processing Queue and related synchronization structures.
Definition: gstnvinfer.h:202
_GstNvInfer::process_lock
GMutex process_lock
Definition: gstnvinfer.h:203
GstNvInferObjectInfo::label
std::string label
Cached string label.
Definition: gstnvinfer.h:125
_GstNvInfer::write_raw_buffers_to_file
gboolean write_raw_buffers_to_file
Boolean indicating if the bound buffer contents should be written to file.
Definition: gstnvinfer.h:295
_GstNvInfer::transform_config_params
NvBufSurfTransformConfigParams transform_config_params
Config params required by NvBufSurfTransform API.
Definition: gstnvinfer.h:310
SIGNAL_MODEL_UPDATED
@ SIGNAL_MODEL_UPDATED
Definition: gstnvinfer.h:89
_GstNvInfer::current_batch_num
gulong current_batch_num
Current batch number of the input batch.
Definition: gstnvinfer.h:277
GstNvInferDetectionFilterParams::detectionMinHeight
guint detectionMinHeight
Definition: gstnvinfer.h:103
_GstNvInfer::input_tensor_from_meta
gboolean input_tensor_from_meta
Definition: gstnvinfer.h:234
PROP_OPERATE_ON_CLASS_IDS
@ PROP_OPERATE_ON_CLASS_IDS
Definition: gstnvinfer.h:68
_GstNvInfer::clip_object_outside_roi
gboolean clip_object_outside_roi
Clip the object bounding-box which lies outside the roi specified by nvdspreprosess plugin.
Definition: gstnvinfer.h:237
_NvBufSurfTransformConfigParams
Holds configuration parameters for a transform/composite session.
Definition: nvbufsurftransform.h:172
_GstNvInfer::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: gstnvinfer.h:302
GstNvInferColorParams::bg_color
NvOSD_ColorParams bg_color
Definition: gstnvinfer.h:117
_GstNvInferObjectHistory::last_inferred_coords
NvOSD_RectParams last_inferred_coords
Bounding box co-ordinates of the object when it was last inferred on.
Definition: gstnvinfer.h:146
_GstNvInfer::input_queue_thread
GThread * input_queue_thread
Definition: gstnvinfer.h:209
_GstNvInfer::config_file_path
gchar * config_file_path
Path to the configuration file for this instance of gst-nvinfer.
Definition: gstnvinfer.h:223
_GstNvInferClass
Definition: gstnvinfer.h:340
GstNvInferDetectionFilterParams::roiTopOffset
guint roiTopOffset
Definition: gstnvinfer.h:100
_GstNvInfer::operate_on_gie_id
gint operate_on_gie_id
Source GIE ID and class-id based filtering parameters for object processing mode.
Definition: gstnvinfer.h:268
cudaStream_t
struct CUstream_st * cudaStream_t
Forward declaration of cudaStream_t.
Definition: nvbufsurftransform.h:34
NvDsInferNetworkInfo
Holds information about the model network.
Definition: nvdsinfer.h:110
_GstNvInfer::classifier_async_mode
gboolean classifier_async_mode
Boolean indicating if the secondary classifier should run in asynchronous mode.
Definition: gstnvinfer.h:280
GstNvInferImpl
struct _GstNvInferImpl GstNvInferImpl
Definition: gstnvinfer.h:47
GstNvInferSourceInfo::last_seen_frame_num
gulong last_seen_frame_num
Frame number of the frame which .
Definition: gstnvinfer.h:170
_GstNvInferObjectHistory::last_accessed_frame_num
gulong last_accessed_frame_num
Number of the frame in the stream when the object was last accessed.
Definition: gstnvinfer.h:152
_GstNvInfer::max_batch_size
guint max_batch_size
Maximum batch size.
Definition: gstnvinfer.h:185
_GstNvInfer::interval_counter
guint interval_counter
Definition: gstnvinfer.h:256
_GstNvInfer::impl
GstNvInferImpl * impl
Definition: gstnvinfer.h:336
nvdsinfer_context.h
_GstNvInfer::perClassColorParams
std::vector< GstNvInferColorParams > * perClassColorParams
Vector for per-class color parameters.
Definition: gstnvinfer.h:252
gstnvdsmeta.h
_GstNvInfer::last_map_cleanup_frame_num
gulong last_map_cleanup_frame_num
Definition: gstnvinfer.h:274
_GstNvInfer::output_generated_userdata
gpointer output_generated_userdata
Definition: gstnvinfer.h:303
GstNvInferDetectionFilterParams::detectionMinWidth
guint detectionMinWidth
Definition: gstnvinfer.h:102
_GstNvInfer::classifier_type
gchar * classifier_type
String containing the type of classifier.
Definition: gstnvinfer.h:283
_GstNvInfer::untracked_object_warn_pts
GstClockTime untracked_object_warn_pts
PTS of input buffer when nvinfer last posted the warning about untracked object.
Definition: gstnvinfer.h:328
_GstNvInfer::unique_id
guint unique_id
Unique ID of the element.
Definition: gstnvinfer.h:194
_GstNvInfer::network_height
gint network_height
Definition: gstnvinfer.h:216
_GstNvInfer::file_write_batch_num
guint64 file_write_batch_num
Batch counter for writing buffer contents to file.
Definition: gstnvinfer.h:298
_GstNvInfer::filter_out_class_ids
std::set< uint > * filter_out_class_ids
Definition: gstnvinfer.h:270
_GstNvInfer::operate_on_class_ids
std::vector< gboolean > * operate_on_class_ids
Definition: gstnvinfer.h:269
_GstNvInfer::last_flow_ret
GstFlowReturn last_flow_ret
GstFlowReturn returned by the latest buffer pad push.
Definition: gstnvinfer.h:226
GstNvInferSourceInfo
Holds source-specific information.
Definition: gstnvinfer.h:163
gst_nvinfer_signals
guint gst_nvinfer_signals[LAST_SIGNAL]
PROP_GPU_DEVICE_ID
@ PROP_GPU_DEVICE_ID
Definition: gstnvinfer.h:73
GstNvInferObjectInfo::~GstNvInferObjectInfo
~GstNvInferObjectInfo()
Definition: gstnvinfer.h:129
GstNvInferDetectionFilterParams::detectionMaxWidth
guint detectionMaxWidth
Definition: gstnvinfer.h:104
PROP_CROP_OBJECTS_TO_ROI_BOUNDARY
@ PROP_CROP_OBJECTS_TO_ROI_BOUNDARY
Definition: gstnvinfer.h:81
_GstNvInfer::min_input_object_height
guint min_input_object_height
Definition: gstnvinfer.h:263
GstNvInferObjectHistory
struct _GstNvInferObjectHistory GstNvInferObjectHistory
Holds the inference information/history for one object based on it's tracking id.
GstNvInferColorParams::have_border_color
gboolean have_border_color
Definition: gstnvinfer.h:113
GstNvInferObjectInfo::GstNvInferObjectInfo
GstNvInferObjectInfo()=default
PROP_OUTPUT_TENSOR_META
@ PROP_OUTPUT_TENSOR_META
Definition: gstnvinfer.h:77
_NvOSD_ColorParams
Holds the color parameters of the box or text to be overlayed.
Definition: nvll_osd_struct.h:81
_GstNvInfer::pool
GstBufferPool * pool
Internal buffer pool for memory required for scaling input frames and cropping object.
Definition: gstnvinfer.h:199
_GstNvInfer::perClassDetectionFilterParams
std::vector< GstNvInferDetectionFilterParams > * perClassDetectionFilterParams
Vector for per-class detection filtering parameters.
Definition: gstnvinfer.h:249
GstNvInferObjectHistoryMap
std::unordered_map< guint64, std::shared_ptr< GstNvInferObjectHistory > > GstNvInferObjectHistoryMap
Map type for maintaing inference history for objects based on their tracking ids.
Definition: gstnvinfer.h:158
GstNvInferDetectionFilterParams::roiBottomOffset
guint roiBottomOffset
Definition: gstnvinfer.h:101
_GstNvInfer::tmp_surf
NvBufSurface tmp_surf
Temporary NvBufSurface for batched transformations.
Definition: gstnvinfer.h:316
_GstNvInferClass::model_updated
void(* model_updated)(GstNvInfer *, gint err, const gchar *cfg_file)
Signals.
Definition: gstnvinfer.h:348
_GstNvInfer::stop
gboolean stop
Boolean to signal output thread to stop.
Definition: gstnvinfer.h:212
_GstNvInfer::symmetric_padding
gboolean symmetric_padding
Boolean indicating which padding to be used when scaling to network resolution.
Definition: gstnvinfer.h:246
PROP_UNIQUE_ID
@ PROP_UNIQUE_ID
Definition: gstnvinfer.h:64
_GstNvInfer::max_input_object_height
guint max_input_object_height
Definition: gstnvinfer.h:265
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: gstnvdsinfer.h:58
_GstNvInferObjectHistory::cached_info
GstNvInferObjectInfo cached_info
Cached object information.
Definition: gstnvinfer.h:154
_GstNvInfer
GstNvInfer element structure.
Definition: gstnvinfer.h:176
GstNvInferSourceInfo::object_history_map
GstNvInferObjectHistoryMap object_history_map
Map of object tracking ID and the object infer history.
Definition: gstnvinfer.h:166
_GstNvInfer::secondary_reinfer_interval
guint secondary_reinfer_interval
Frame interval after which objects should be reinferred on.
Definition: gstnvinfer.h:259
_GstNvInfer::nvtx_domain
nvtxDomainHandle_t nvtx_domain
NVTX Domain.
Definition: gstnvinfer.h:331
PROP_OUTPUT_CALLBACK
@ PROP_OUTPUT_CALLBACK
Definition: gstnvinfer.h:75
nvbufsurftransform.h
_GstNvInfer::layers_info
std::vector< NvDsInferLayerInfo > * layers_info
Vector of bound layers information.
Definition: gstnvinfer.h:289
_GstNvInfer::is_prop_set
std::vector< gboolean > * is_prop_set
Vector of booleans indicating if properties have been set through GObject set method.
Definition: gstnvinfer.h:307
_GstNvInfer::source_info
std::unordered_map< gint, GstNvInferSourceInfo > * source_info
Per source information.
Definition: gstnvinfer.h:273
_GstNvInfer::interval
guint interval
Batch interval for full-frame processing.
Definition: gstnvinfer.h:255
_GstNvInferObjectHistory::last_inferred_frame_num
gulong last_inferred_frame_num
Number of the frame in the stream when the object was last inferred on.
Definition: gstnvinfer.h:148
GstNvInferObjectInfo
Holds the cached information of an object.
Definition: gstnvinfer.h:121
PROP_MODEL_ENGINEFILE
@ PROP_MODEL_ENGINEFILE
Definition: gstnvinfer.h:70
PROP_OUTPUT_INSTANCE_MASK
@ PROP_OUTPUT_INSTANCE_MASK
Definition: gstnvinfer.h:78
PROP_0
@ PROP_0
Definition: gstnvinfer.h:63
_GstNvInfer::output_tensor_meta
gboolean output_tensor_meta
Boolean indicating if tensor outputs should be attached as meta on GstBuffers.
Definition: gstnvinfer.h:320
_GstNvInfer::crop_objects_to_roi_boundary
gboolean crop_objects_to_roi_boundary
Definition: gstnvinfer.h:334
GstNvInferDetectionFilterParams
Holds the bounding box/object detection filtering parameters per class.
Definition: gstnvinfer.h:98
_GstNvInfer::input_queue
GQueue * input_queue
Definition: gstnvinfer.h:205
PROP_BATCH_SIZE
@ PROP_BATCH_SIZE
Definition: gstnvinfer.h:71
_GstNvInfer::maintain_aspect_ratio
gboolean maintain_aspect_ratio
Boolean indicating if aspect ratio should be maintained when scaling to network resolution.
Definition: gstnvinfer.h:241
GstNvInferColorParams::border_color
NvOSD_ColorParams border_color
Definition: gstnvinfer.h:114
PROP_INPUT_TENSOR_META
@ PROP_INPUT_TENSOR_META
Definition: gstnvinfer.h:79
_GstNvInfer::gpu_id
guint gpu_id
ID of the GPU this element uses for conversions / inference.
Definition: gstnvinfer.h:229
_GstNvInferClass::parent_class
GstBaseTransformClass parent_class
Definition: gstnvinfer.h:341