NVIDIA DeepStream SDK API Reference

9.1 Release
sources/gst-plugins/gst-dsexample/gstdsexample_optimized.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_DSEXAMPLE_H__
19 #define __GST_DSEXAMPLE_H__
20 
21 #include <gst/base/gstbasetransform.h>
22 #include <gst/video/video.h>
23 
24 /* Open CV headers */
25 #ifdef WITH_OPENCV
26 #include "opencv2/imgproc/imgproc.hpp"
27 #include "opencv2/highgui/highgui.hpp"
28 #endif
29 
30 #include <cuda.h>
31 #include <cuda_runtime.h>
32 #include "nvbufsurface.h"
33 #include "nvbufsurftransform.h"
34 #include "gst-nvquery.h"
35 #include "gstnvdsmeta.h"
36 #include "dsexample_lib/dsexample_lib.h"
37 #include "nvtx3/nvToolsExt.h"
38 
39 #include <condition_variable>
40 #include <mutex>
41 #include <thread>
42 #include <vector>
43 
44 /* Package and library details required for plugin_init */
45 #define PACKAGE "dsexample"
46 #define VERSION "1.0"
47 #define LICENSE "Proprietary"
48 #define DESCRIPTION "NVIDIA example plugin for integration with DeepStream on DGPU/Jetson"
49 #define BINARY_PACKAGE "NVIDIA DeepStream 3rdparty IP integration example plugin"
50 #define URL "http://nvidia.com/"
51 
52 
53 G_BEGIN_DECLS
54 /* Standard boilerplate stuff */
55 typedef struct _GstDsExample GstDsExample;
57 
58 /* Standard boilerplate stuff */
59 #define GST_TYPE_DSEXAMPLE (gst_dsexample_get_type())
60 #define GST_DSEXAMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DSEXAMPLE,GstDsExample))
61 #define GST_DSEXAMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DSEXAMPLE,GstDsExampleClass))
62 #define GST_DSEXAMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_DSEXAMPLE, GstDsExampleClass))
63 #define GST_IS_DSEXAMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DSEXAMPLE))
64 #define GST_IS_DSEXAMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DSEXAMPLE))
65 #define GST_DSEXAMPLE_CAST(obj) ((GstDsExample *)(obj))
66 
68 #define NVDSEXAMPLE_MAX_BATCH_SIZE 1024
69 
70 struct _GstDsExample
71 {
72  GstBaseTransform base_trans;
73 
76 
80  GMutex process_lock;
81 
83  GQueue *process_queue;
84 
86  GCond process_cond;
87 
89  GQueue *buf_queue;
90 
92  GCond buf_cond;
93 
95  GThread *process_thread;
96 
98  gboolean stop;
99 
102  guint unique_id;
103 
105  guint64 frame_num;
106 
109 
112 
115 
117  GstVideoInfo video_info;
118 
120  gint processing_width;
121  gint processing_height;
122 
123  // Flag which defince igpu/dgpu
124  guint is_integrated;
125 
127  guint max_batch_size;
128 
130  guint gpu_id;
131 
133  gboolean process_full_frame;
134 
137 
139  GstFlowReturn last_flow_ret;
140 
143 
146 
148  nvtxDomainHandle_t nvtx_domain;
149 };
150 
151 typedef struct
152 {
156  gdouble scale_ratio_x = 0.0;
160  gdouble scale_ratio_y = 0.0;
162  NvDsObjectMeta *obj_meta = nullptr;
163  NvDsFrameMeta *frame_meta = nullptr;
166  guint batch_index = 0;
168  gulong frame_num = 0;
170  NvBufSurfaceParams *input_surf_params = nullptr;
172 
176 typedef struct
177 {
179  std::vector < GstDsExampleFrame > frames;
181  GstBuffer *inbuf = nullptr;
183  gulong inbuf_batch_num = 0;
188  gboolean push_buffer = FALSE;
192  gboolean event_marker = FALSE;
193 
194 #ifdef WITH_OPENCV
195 
196  cv::Mat * cvmat;
197 #else
199 #endif
200 
201  nvtxRangeId_t nvtx_complete_buf_range = 0;
203 
205 struct _GstDsExampleClass
206 {
207  GstBaseTransformClass parent_class;
208 };
209 
210 GType gst_dsexample_get_type (void);
211 
212 G_END_DECLS
213 #endif /* __GST_DSEXAMPLE_H__ */
cudaStream_t
struct CUstream_st * cudaStream_t
Forward declaration of cudaStream_t.
Definition: sources/includes/nvbufsurftransform.h:35
GstDsExample
typedefG_BEGIN_DECLS struct _GstDsExample GstDsExample
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:54
_GstDsExample::transform_params
NvBufSurfTransformParams transform_params
Parameters to use for transforming buffers.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:145
GstDsExampleBatch
Holds information about the batch of frames to be inferred.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:176
GstDsExampleBatch::inter_buf
NvBufSurface * inter_buf
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:198
_NvBufSurfaceTransformParams
Holds transform parameters for a transform call.
Definition: sources/includes/nvbufsurftransform.h:196
_GstDsExample::process_lock
GMutex process_lock
Processing Queue and related synchronization structures.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:80
_GstDsExample::process_full_frame
gboolean process_full_frame
Boolean indicating if entire frame or cropped objects should be processed.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:114
NvBufSurface
Holds information about batched buffers.
Definition: sources/includes/nvbufsurface.h:597
_GstDsExample::processing_width
gint processing_width
Resolution at which frames/objects should be processed.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:101
_GstDsExample::video_info
GstVideoInfo video_info
Input video info (resolution, color format, framerate, etc)
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:98
_GstDsExample::current_batch_num
gulong current_batch_num
Current batch number of the input batch.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:136
_GstDsExample::gpu_id
guint gpu_id
GPU ID on which we expect to execute the task.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:111
_GstDsExample::buf_cond
GCond buf_cond
Gcondition for buf queue.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:92
gst_dsexample_get_type
GType gst_dsexample_get_type(void)
_GstDsExample::cuda_stream
cudaStream_t cuda_stream
CUDA Stream used for allocating the CUDA task.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:84
_GstDsExample::buf_queue
GQueue * buf_queue
Queue to receive processed data from output thread.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:89
_GstDsExampleClass
Boiler plate stuff.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:124
_GstDsExample::max_batch_size
guint max_batch_size
Maximum batch size.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:108
_GstDsExample::process_cond
GCond process_cond
Gcondition for process queue.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:86
_GstDsExample
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:69
_NvBufSurfTransformConfigParams
Holds configuration parameters for a transform/composite session.
Definition: sources/includes/nvbufsurftransform.h:175
NvBufSurfaceParams
Hold the information of single buffer in the batch.
Definition: sources/includes/nvbufsurface.h:562
_GstDsExample::nvtx_domain
nvtxDomainHandle_t nvtx_domain
NVTX Domain.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:148
_GstDsExampleClass::parent_class
GstBaseTransformClass parent_class
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:126
_GstDsExample::frame_num
guint64 frame_num
Frame number of the current input buffer.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:81
DsExampleCtx
struct DsExampleCtx DsExampleCtx
Definition: sources/gst-plugins/gst-dsexample/dsexample_lib/dsexample_lib.h:26
_GstDsExample::transform_config_params
NvBufSurfTransformConfigParams transform_config_params
Config params required by NvBufSurfTransform API.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:120
_GstDsExample::unique_id
guint unique_id
Unique ID of the element.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:78
_GstDsExample::stop
gboolean stop
Boolean to signal output thread to stop.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:98
_GstDsExample::process_queue
GQueue * process_queue
Queue to send data to output thread for processing.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:83
GstDsExampleBatch::frames
std::vector< GstDsExampleFrame > frames
Vector of frames in the batch.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:179
GstDsExampleFrame
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:151
_GstDsExample::inter_buf
NvBufSurface * inter_buf
the intermediate scratch buffer for conversions RGBA
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:90
_GstDsExample::base_trans
GstBaseTransform base_trans
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:71
_GstDsExample::dsexamplelib_ctx
DsExampleCtx * dsexamplelib_ctx
Context of the custom algorithm library.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:74
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: sources/includes/nvdsmeta.h:306
_GstDsExample::last_flow_ret
GstFlowReturn last_flow_ret
GstFlowReturn returned by the latest buffer pad push.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:139
_GstDsExample::is_integrated
guint is_integrated
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:105
_GstDsExample::batch_insurf
NvBufSurface batch_insurf
Temporary NvBufSurface for batched transformations.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:111
_GstDsExample::process_thread
GThread * process_thread
Output thread.
Definition: sources/gst-plugins/gst-dsexample/gstdsexample_optimized.h:95
_GstDsExample::processing_height
gint processing_height
Definition: sources/gst-plugins/gst-dsexample/gstdsexample.h:102
GstBuffer
struct _GstBuffer GstBuffer
Definition: sources/includes/ds3d/common/idatatype.h:24
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: sources/includes/nvdsmeta.h:365