NVIDIA DeepStream SDK API Reference

7.1 Release
gstdsexample_optimized.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2021 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_DSEXAMPLE_H__
14 #define __GST_DSEXAMPLE_H__
15 
16 #include <gst/base/gstbasetransform.h>
17 #include <gst/video/video.h>
18 
19 /* Open CV headers */
20 #ifdef WITH_OPENCV
21 #include "opencv2/imgproc/imgproc.hpp"
22 #include "opencv2/highgui/highgui.hpp"
23 #endif
24 
25 #include <cuda.h>
26 #include <cuda_runtime.h>
27 #include "nvbufsurface.h"
28 #include "nvbufsurftransform.h"
29 #include "gst-nvquery.h"
30 #include "gstnvdsmeta.h"
32 #include "nvtx3/nvToolsExt.h"
33 
34 #include <condition_variable>
35 #include <mutex>
36 #include <thread>
37 #include <vector>
38 
39 /* Package and library details required for plugin_init */
40 #define PACKAGE "dsexample"
41 #define VERSION "1.0"
42 #define LICENSE "Proprietary"
43 #define DESCRIPTION "NVIDIA example plugin for integration with DeepStream on DGPU/Jetson"
44 #define BINARY_PACKAGE "NVIDIA DeepStream 3rdparty IP integration example plugin"
45 #define URL "http://nvidia.com/"
46 
47 
48 G_BEGIN_DECLS
49 /* Standard boilerplate stuff */
50 typedef struct _GstDsExample GstDsExample;
52 
53 /* Standard boilerplate stuff */
54 #define GST_TYPE_DSEXAMPLE (gst_dsexample_get_type())
55 #define GST_DSEXAMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DSEXAMPLE,GstDsExample))
56 #define GST_DSEXAMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DSEXAMPLE,GstDsExampleClass))
57 #define GST_DSEXAMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_DSEXAMPLE, GstDsExampleClass))
58 #define GST_IS_DSEXAMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DSEXAMPLE))
59 #define GST_IS_DSEXAMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DSEXAMPLE))
60 #define GST_DSEXAMPLE_CAST(obj) ((GstDsExample *)(obj))
61 
63 #define NVDSEXAMPLE_MAX_BATCH_SIZE 1024
64 
65 struct _GstDsExample
66 {
67  GstBaseTransform base_trans;
68 
71 
75  GMutex process_lock;
76 
78  GQueue *process_queue;
79 
81  GCond process_cond;
82 
84  GQueue *buf_queue;
85 
87  GCond buf_cond;
88 
90  GThread *process_thread;
91 
93  gboolean stop;
94 
97  guint unique_id;
98 
100  guint64 frame_num;
101 
104 
107 
110 
112  GstVideoInfo video_info;
113 
115  gint processing_width;
116  gint processing_height;
117 
119  guint max_batch_size;
120 
122  guint gpu_id;
123 
125  gboolean process_full_frame;
126 
129 
131  GstFlowReturn last_flow_ret;
132 
135 
138 
140  nvtxDomainHandle_t nvtx_domain;
141 };
142 
143 typedef struct
144 {
148  gdouble scale_ratio_x = 0.0;
152  gdouble scale_ratio_y = 0.0;
154  NvDsObjectMeta *obj_meta = nullptr;
155  NvDsFrameMeta *frame_meta = nullptr;
158  guint batch_index = 0;
160  gulong frame_num = 0;
162  NvBufSurfaceParams *input_surf_params = nullptr;
164 
168 typedef struct
169 {
171  std::vector < GstDsExampleFrame > frames;
173  GstBuffer *inbuf = nullptr;
175  gulong inbuf_batch_num = 0;
180  gboolean push_buffer = FALSE;
184  gboolean event_marker = FALSE;
185 
186 #ifdef WITH_OPENCV
187 
188  cv::Mat * cvmat;
189 #else
191 #endif
192 
193  nvtxRangeId_t nvtx_complete_buf_range = 0;
195 
197 struct _GstDsExampleClass
198 {
199  GstBaseTransformClass parent_class;
200 };
201 
202 GType gst_dsexample_get_type (void);
203 
204 G_END_DECLS
205 #endif /* __GST_DSEXAMPLE_H__ */
_GstDsExample::transform_params
NvBufSurfTransformParams transform_params
Parameters to use for transforming buffers.
Definition: gstdsexample_optimized.h:137
GstDsExampleBatch
Holds information about the batch of frames to be inferred.
Definition: gstdsexample_optimized.h:168
DsExampleCtx
struct DsExampleCtx DsExampleCtx
Definition: dsexample_lib.h:21
_NvBufSurfaceTransformParams
Holds transform parameters for a transform call.
Definition: nvbufsurftransform.h:190
_GstDsExample::process_lock
GMutex process_lock
Processing Queue and related synchronization structures.
Definition: gstdsexample_optimized.h:75
_GstDsExample::process_full_frame
gboolean process_full_frame
Boolean indicating if entire frame or cropped objects should be processed.
Definition: gstdsexample.h:109
NvBufSurface
Holds information about batched buffers.
Definition: nvbufsurface.h:520
_GstDsExample::processing_width
gint processing_width
Resolution at which frames/objects should be processed.
Definition: gstdsexample.h:96
gst-nvquery.h
_GstDsExample::video_info
GstVideoInfo video_info
Input video info (resolution, color format, framerate, etc)
Definition: gstdsexample.h:93
GstDsExample
typedefG_BEGIN_DECLS struct _GstDsExample GstDsExample
Definition: gstdsexample.h:49
_GstDsExample::current_batch_num
gulong current_batch_num
Current batch number of the input batch.
Definition: gstdsexample_optimized.h:128
_GstDsExample::gpu_id
guint gpu_id
GPU ID on which we expect to execute the task.
Definition: gstdsexample.h:106
_GstDsExample::buf_cond
GCond buf_cond
Gcondition for buf queue.
Definition: gstdsexample_optimized.h:87
_GstDsExample::buf_queue
GQueue * buf_queue
Queue to receive processed data from output thread.
Definition: gstdsexample_optimized.h:84
_GstDsExample::cuda_stream
cudaStream_t cuda_stream
CUDA Stream used for allocating the CUDA task.
Definition: gstdsexample.h:79
_GstDsExampleClass
Boiler plate stuff.
Definition: gstdsexample.h:119
_GstDsExample::max_batch_size
guint max_batch_size
Maximum batch size.
Definition: gstdsexample.h:103
_GstDsExample::process_cond
GCond process_cond
Gcondition for process queue.
Definition: gstdsexample_optimized.h:81
_GstDsExample
Definition: gstdsexample.h:64
_NvBufSurfTransformConfigParams
Holds configuration parameters for a transform/composite session.
Definition: nvbufsurftransform.h:172
NvBufSurfaceParams
Hold the information of single buffer in the batch.
Definition: nvbufsurface.h:487
_GstDsExample::nvtx_domain
nvtxDomainHandle_t nvtx_domain
NVTX Domain.
Definition: gstdsexample_optimized.h:140
_GstDsExampleClass::parent_class
GstBaseTransformClass parent_class
Definition: gstdsexample.h:121
cudaStream_t
struct CUstream_st * cudaStream_t
Forward declaration of cudaStream_t.
Definition: nvbufsurftransform.h:34
_GstDsExample::frame_num
guint64 frame_num
Frame number of the current input buffer.
Definition: gstdsexample.h:76
gstnvdsmeta.h
_GstDsExample::transform_config_params
NvBufSurfTransformConfigParams transform_config_params
Config params required by NvBufSurfTransform API.
Definition: gstdsexample.h:115
_GstDsExample::process_thread
GThread * process_thread
Output thread.
Definition: gstdsexample_optimized.h:90
_GstDsExample::unique_id
guint unique_id
Unique ID of the element.
Definition: gstdsexample.h:73
dsexample_lib.h
_GstDsExample::stop
gboolean stop
Boolean to signal output thread to stop.
Definition: gstdsexample_optimized.h:93
gst_dsexample_get_type
GType gst_dsexample_get_type(void)
_GstDsExample::process_queue
GQueue * process_queue
Queue to send data to output thread for processing.
Definition: gstdsexample_optimized.h:78
GstDsExampleBatch::frames
std::vector< GstDsExampleFrame > frames
Vector of frames in the batch.
Definition: gstdsexample_optimized.h:171
GstDsExampleFrame
Definition: gstdsexample_optimized.h:143
_GstDsExample::inter_buf
NvBufSurface * inter_buf
the intermediate scratch buffer for conversions RGBA
Definition: gstdsexample.h:85
GstBuffer
struct _GstBuffer GstBuffer
Definition: idatatype.h:19
_GstDsExample::base_trans
GstBaseTransform base_trans
Definition: gstdsexample.h:66
_GstDsExample::dsexamplelib_ctx
DsExampleCtx * dsexamplelib_ctx
Context of the custom algorithm library.
Definition: gstdsexample.h:69
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: nvdsmeta.h:286
_GstDsExample::last_flow_ret
GstFlowReturn last_flow_ret
GstFlowReturn returned by the latest buffer pad push.
Definition: gstdsexample_optimized.h:131
nvbufsurftransform.h
_GstDsExample::batch_insurf
NvBufSurface batch_insurf
Temporary NvBufSurface for batched transformations.
Definition: gstdsexample_optimized.h:106
nvbufsurface.h
_GstDsExample::processing_height
gint processing_height
Definition: gstdsexample.h:97
GstDsExampleBatch::inter_buf
NvBufSurface * inter_buf
Definition: gstdsexample_optimized.h:190
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: nvdsmeta.h:344