NVIDIA DeepStream SDK API Reference

9.0 Release
9.0/sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  */
5 
14 #ifndef __GST_NVDSVISIONENCODER_H__
15 #define __GST_NVDSVISIONENCODER_H__
16 
17 #include <gst/gst.h>
18 #include <gst/base/gstbasetransform.h>
19 #include <gst/video/video.h>
20 
21 #include "nvbufsurface.h"
22 #include "nvbufsurftransform.h"
23 #include "nvdsmeta.h"
24 #include "gstnvdsmeta.h"
25 #include "nvds_tracker_meta.h"
26 
27 #ifdef ENABLE_INSTRUMENTATION
28 #include <sys/time.h>
29 #endif
30 
31 G_BEGIN_DECLS
32 
33 #define GST_TYPE_NVDSVISIONENCODER (gst_nvdsvisionencoder_get_type())
34 #define GST_NVDSVISIONENCODER(obj) \
35  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NVDSVISIONENCODER,GstNvDsVisionEncoder))
36 #define GST_NVDSVISIONENCODER_CLASS(klass) \
37  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NVDSVISIONENCODER,GstNvDsVisionEncoderClass))
38 #define GST_IS_NVDSVISIONENCODER(obj) \
39  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NVDSVISIONENCODER))
40 #define GST_IS_NVDSVISIONENCODER_CLASS(klass) \
41  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NVDSVISIONENCODER))
42 
45 
49 typedef enum {
53 
57 struct _GstNvDsVisionEncoder {
58  GstBaseTransform base_trans;
59 
60  /* Configuration properties */
61  gboolean enable;
63  gchar *backend_str; // String version for property
64  gchar *triton_url;
65  gchar *triton_model;
66  gchar *model_variant; // For compatibility with Python plugin config
67  gchar *tensorrt_engine;
68  gchar *onnx_model; // Path to ONNX model for engine building
69  guint batch_size; // TensorRT batch size (for engine building/selection)
70  guint min_crop_size;
71  gboolean verbose;
72  guint gpu_id;
73  gchar *device; // For compatibility (cuda/cpu)
74  guint skip_interval; // Frame skip interval: 0=none, 1=every other, 2=every 3rd, etc.
75  gchar *embedding_classes; // Semicolon-separated list of classes to generate embeddings for (NULL = all classes)
76 
77  /* Runtime state */
78  guint frame_count;
79  gchar **allowed_classes; // Parsed array of allowed class names
80  guint num_allowed_classes; // Number of allowed classes
81  gboolean is_initialized;
82 
83  /* Triton client handle (C++ object wrapped as void*) */
84  void *triton_client;
85 
86  /* CUDA stream for async operations */
87  void *cuda_stream; // cudaStream_t
88 
89  /* Model info */
90  guint input_width;
91  guint input_height;
92  guint embedding_dim;
93 
94  /* Pre-allocated buffers for preprocessing (like nvinfer SGIE) */
95  guint max_batch_size; // Maximum number of objects per transform call
96  NvBufSurfaceParams *prealloc_surf_list; // Pre-allocated surface list for src_batch
97  NvBufSurfTransformRect *prealloc_src_rect; // Pre-allocated source rectangles
98  NvBufSurfTransformRect *prealloc_dst_rect; // Pre-allocated destination rectangles
99  NvBufSurface *prealloc_output_surface; // Pre-allocated output surface (reused across calls)
100  float *d_preprocessed_pool; // Pre-allocated device tensor (max_batch_size) for GPU path
101  size_t d_preprocessed_pool_bytes; // Allocated size in bytes
102  float *embeddings_buffer; // Pre-allocated host buffer for inference output (max_batch_size * embedding_dim)
103 
104 #ifdef ENABLE_INSTRUMENTATION
105  /* Performance counters */
106  GstClockTime total_process_time;
107  guint total_objects_processed;
108 
109  /* Periodic performance reporting (every PERF_WINDOW_SEC seconds) */
110  struct timeval perf_window_start;
111  guint perf_window_objects;
112  guint perf_window_batches;
113  gboolean perf_window_started;
114 
115  /* Per-phase cumulative microseconds within current window */
116  guint64 perf_phase_preproc_us; /* NvBufSurfTransform crop+resize */
117  guint64 perf_phase_tensor_us; /* RGB surface -> CHW float tensor */
118  guint64 perf_phase_infer_us; /* TRT inference + D2H memcpy */
119  guint64 perf_phase_post_us; /* Attach embedding metadata */
120 #endif
121 };
122 
127  GstBaseTransformClass parent_class;
128 };
129 
130 GType gst_nvdsvisionencoder_get_type (void);
131 
132 G_END_DECLS
133 
134 #endif /* __GST_NVDSVISIONENCODER_H__ */
_GstNvDsVisionEncoder::onnx_model
gchar * onnx_model
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:68
_GstNvDsVisionEncoder::backend_str
gchar * backend_str
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:63
_GstNvDsVisionEncoder::prealloc_surf_list
NvBufSurfaceParams * prealloc_surf_list
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:96
_GstNvDsVisionEncoder::model_variant
gchar * model_variant
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:66
NvBufSurface
Holds information about batched buffers.
Definition: sources/includes/nvbufsurface.h:597
NvDsVisionEncoderBackend
NvDsVisionEncoderBackend
Encoder backend type.
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:49
_GstNvDsVisionEncoder::triton_url
gchar * triton_url
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:64
_GstNvDsVisionEncoder::is_initialized
gboolean is_initialized
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:81
NvBufSurfTransformRect
Holds the coordinates of a rectangle.
Definition: sources/includes/nvbufsurftransform.h:158
_GstNvDsVisionEncoder::input_width
guint input_width
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:90
NVDS_VISION_ENCODER_BACKEND_TENSORRT
@ NVDS_VISION_ENCODER_BACKEND_TENSORRT
Definition: 9.0/sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:51
_GstNvDsVisionEncoder::backend
NvDsVisionEncoderBackend backend
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:62
_GstNvDsVisionEncoder
GstNvDsVisionEncoder structure.
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:57
_GstNvDsVisionEncoder::max_batch_size
guint max_batch_size
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:95
_GstNvDsVisionEncoder::enable
gboolean enable
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:61
_GstNvDsVisionEncoder::device
gchar * device
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:73
NvDsVisionEncoderBackend
NvDsVisionEncoderBackend
Encoder backend type.
Definition: 9.0/sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:49
gst_nvdsvisionencoder_get_type
GType gst_nvdsvisionencoder_get_type(void)
_GstNvDsVisionEncoder::d_preprocessed_pool_bytes
size_t d_preprocessed_pool_bytes
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:101
_GstNvDsVisionEncoder::allowed_classes
gchar ** allowed_classes
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:79
NvBufSurfaceParams
Hold the information of single buffer in the batch.
Definition: sources/includes/nvbufsurface.h:562
_GstNvDsVisionEncoder::triton_client
void * triton_client
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:84
_GstNvDsVisionEncoder::gpu_id
guint gpu_id
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:72
_GstNvDsVisionEncoder::input_height
guint input_height
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:91
_GstNvDsVisionEncoderClass::parent_class
GstBaseTransformClass parent_class
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:127
_GstNvDsVisionEncoder::batch_size
guint batch_size
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:69
_GstNvDsVisionEncoder::d_preprocessed_pool
float * d_preprocessed_pool
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:100
_GstNvDsVisionEncoder::num_allowed_classes
guint num_allowed_classes
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:80
_GstNvDsVisionEncoder::embeddings_buffer
float * embeddings_buffer
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:102
_GstNvDsVisionEncoder::verbose
gboolean verbose
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:71
NVDS_VISION_ENCODER_BACKEND_TRITON
@ NVDS_VISION_ENCODER_BACKEND_TRITON
Definition: 9.0/sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:50
_GstNvDsVisionEncoder::prealloc_output_surface
NvBufSurface * prealloc_output_surface
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:99
_GstNvDsVisionEncoder::skip_interval
guint skip_interval
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:74
_GstNvDsVisionEncoder::embedding_dim
guint embedding_dim
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:92
_GstNvDsVisionEncoder::cuda_stream
void * cuda_stream
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:87
_GstNvDsVisionEncoder::frame_count
guint frame_count
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:78
_GstNvDsVisionEncoder::base_trans
GstBaseTransform base_trans
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:58
_GstNvDsVisionEncoder::embedding_classes
gchar * embedding_classes
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:75
_GstNvDsVisionEncoder::prealloc_src_rect
NvBufSurfTransformRect * prealloc_src_rect
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:97
_GstNvDsVisionEncoder::triton_model
gchar * triton_model
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:65
_GstNvDsVisionEncoder::min_crop_size
guint min_crop_size
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:70
_GstNvDsVisionEncoderClass
GstNvDsVisionEncoderClass structure.
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:126
_GstNvDsVisionEncoder::prealloc_dst_rect
NvBufSurfTransformRect * prealloc_dst_rect
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:98
_GstNvDsVisionEncoder::tensorrt_engine
gchar * tensorrt_engine
Definition: sources/gst-plugins/gst-nvdsvisionencoder-c/gstnvdsvisionencoder.h:67