NVIDIA DeepStream SDK API Reference

6.4 Release
seq_process_common.h
Go to the documentation of this file.
1 
23 #ifndef __NVDS_SEQ_PREPROCESS_COMMON_H__
24 #define __NVDS_SEQ_PREPROCESS_COMMON_H__
25 
26 #include <inttypes.h>
27 #include <stdint.h>
28 #include <string.h>
29 
30 #include <atomic>
31 #include <cassert>
32 #include <condition_variable>
33 #include <fstream>
34 #include <functional>
35 #include <iostream>
36 #include <map>
37 #include <memory>
38 #include <mutex>
39 #include <numeric>
40 #include <queue>
41 #include <stdexcept>
42 #include <thread>
43 #include <tuple>
44 #include <unordered_map>
45 
46 #include "nvbufsurface.h"
47 #include "nvbufsurftransform.h"
48 #include "nvdspreprocess_interface.h"
49 
50 // custom settings in [user-config]
51 #define CUSTOM_CONFIG_SUBSAMPLE "subsample"
52 #define CUSTOM_CONFIG_STRIDE "stride"
53 #define CUSTOM_CONFIG_CHANNEL_SCALE_FACTORS "channel-scale-factors"
54 #define CUSTOM_CONFIG_CHANNEL_MEANS "channel-mean-offsets"
55 
56 // Misc macro definitions
57 #define DSASSERT assert
58 
59 #ifndef UNUSED
60 #define UNUSED(var) (void)(var)
61 #endif
62 
63 // log information definition for log print, debug, info, error.
64 
65 #define LOG_PRINT_(out, level, fmt, ...) \
66  fprintf(out, "%s:%d, [%s: CUSTOM_LIB] " fmt "\n", __FILE__, __LINE__, #level, ##__VA_ARGS__)
67 
68 #define LOG_DEBUG(fmt, ...) \
69  if (kEnableDebug) { \
70  LOG_PRINT_(stdout, DEBUG, fmt, ##__VA_ARGS__); \
71  }
72 
73 #define LOG_INFO(fmt, ...) LOG_PRINT_(stdout, INFO, fmt, ##__VA_ARGS__)
74 
75 #define LOG_ERROR(fmt, ...) LOG_PRINT_(stderr, ERROR, fmt, ##__VA_ARGS__)
76 
77 // check preprocess errors and return error no.
78 #define CHECK_PROCESS_ERROR(err, fmt, ...) \
79  do { \
80  NvDsPreProcessStatus _sno_ = (err); \
81  if (_sno_ != NVDSPREPROCESS_SUCCESS) { \
82  LOG_ERROR(fmt ", seq_process error: %d", ##__VA_ARGS__, (int)_sno_); \
83  return _sno_; \
84  } \
85  } while (0)
86 
87 // check CUDA errors errors and return process error
88 #define CHECK_CUDA_ERR(err, fmt, ...) \
89  do { \
90  cudaError_t _errnum_ = (err); \
91  if (_errnum_ != cudaSuccess) { \
92  LOG_ERROR( \
93  fmt ", cuda err_no: %d, err_str: %s", ##__VA_ARGS__, (int)_errnum_, \
94  cudaGetErrorName(_errnum_)); \
95  return NVDSPREPROCESS_CUDA_ERROR; \
96  } \
97  } while (0)
98 
99 // declare export APIs
100 #define PROCESS_EXPORT_API __attribute__((__visibility__("default")))
101 
102 // skip frame: extend values of NvDsPreProcessStatus
103 #define NVDSPREPROCESS_SKIP_FRAME (NvDsPreProcessStatus)255
104 
105 // default frame number value if not set
106 #define FRAME_NO_NOT_SET UINT64_MAX
107 
108 // tuple<stream_id, roi.xy0, roi.xy1>
109 using SourceKey = std::tuple<uint64_t, int64_t, int64_t>;
110 
111 // enable debug log
112 extern bool kEnableDebug;
113 
114 // Block descriptions to store multiple sequenced buffers
116  NvDsPreProcessCustomBuf* buf = nullptr; // allocated from NvDsPreProcessAcquirer
117  // parameters description of allocated `buf`
120  uint32_t maxBatchSize = 0; // parsed from param.network_input_shape[0]
121  uint32_t inUseBatchSize = 0;
122 };
123 
124 // ROI based sequence processing buffer
126  // pointer to batch buffer block
127  FullBatchBlock* block = nullptr;
128  // offsets in bytes for current sequence in batched block
129  uint64_t blockOffset = 0;
130 
131  // starting sequence index of this buffer.
132  // index loops between [0, seqence-size]
133  uint32_t startSeqIdx = 0;
134  // accumulation count of processed buffers.
135  // accumulation is sliding by stride in user-config
136  uint32_t processedSeq = 0;
137 
138  // ROI information of this sequence
140  // latest processed buffer information
142  // lastest updated frame number
144  // frame number to indicate next sequence is ready
145  uint64_t nextReadyFrameNo = 0;
146 };
147 
148 // results storing batches of sequence processed buffers
149 struct ReadyResult {
150  // allocated batches of processed sequence buffers
152  // ROI list of processed buffers
153  std::vector<NvDsRoiMeta> rois;
154  // updated parameter desciptions of `readyBuf`
157 };
158 
159 // mapping source/roi to specific sequence processing buffer
160 using SrcDestBufMap = std::map<SourceKey, std::unique_ptr<RoiProcessedBuf>>;
161 
162 // definition of smart pointer
163 template <class T>
164 using UniqPtr = std::unique_ptr<T, std::function<void(T*)>>;
165 
166 #endif // __NVDS_SEQ_PREPROCESS_COMMON_H__
RoiProcessedBuf
Definition: seq_process_common.h:125
ReadyResult
Definition: seq_process_common.h:149
NvDsPreProcessFormat_RGB
@ NvDsPreProcessFormat_RGB
Specifies 24-bit interleaved R-G-B format.
Definition: gst-plugins/gst-nvdspreprocess/include/nvdspreprocess_interface.h:107
FullBatchBlock::maxBatchSize
uint32_t maxBatchSize
Definition: seq_process_common.h:120
RoiProcessedBuf::roiInfo
NvDsRoiMeta roiInfo
Definition: seq_process_common.h:139
FRAME_NO_NOT_SET
#define FRAME_NO_NOT_SET
Definition: seq_process_common.h:106
UniqPtr
std::unique_ptr< T, std::function< void(T *)> > UniqPtr
Definition: seq_process_common.h:164
RoiProcessedBuf::latestFrameNo
uint64_t latestFrameNo
Definition: seq_process_common.h:143
ReadyResult::param
NvDsPreProcessTensorParams param
Definition: seq_process_common.h:155
FullBatchBlock
Definition: seq_process_common.h:115
RoiProcessedBuf::latestUnit
NvDsPreProcessUnit latestUnit
Definition: seq_process_common.h:141
NvDsPreProcessUnit
A preprocess unit for processing which can be Frame/ROI.
Definition: gst-plugins/gst-nvdspreprocess/include/nvdspreprocess_interface.h:231
FullBatchBlock::param
NvDsPreProcessTensorParams param
Definition: seq_process_common.h:118
RoiProcessedBuf::blockOffset
uint64_t blockOffset
Definition: seq_process_common.h:129
ReadyResult::readyBuf
NvDsPreProcessCustomBuf * readyBuf
Definition: seq_process_common.h:151
FullBatchBlock::buf
NvDsPreProcessCustomBuf * buf
Definition: seq_process_common.h:116
FullBatchBlock::inUseBatchSize
uint32_t inUseBatchSize
Definition: seq_process_common.h:121
NvDsPreProcessCustomBuf
Custom Buffer passed to the custom lib for preparing tensor.
Definition: gst-plugins/gst-nvdspreprocess/include/nvdspreprocess_interface.h:209
RoiProcessedBuf::nextReadyFrameNo
uint64_t nextReadyFrameNo
Definition: seq_process_common.h:145
NvDsPreProcessTensorParams
Holds model parameters for tensor preparation.
Definition: gst-plugins/gst-nvdspreprocess/include/nvdspreprocess_interface.h:139
kEnableDebug
bool kEnableDebug
SourceKey
std::tuple< uint64_t, int64_t, int64_t > SourceKey
Definition: seq_process_common.h:109
RoiProcessedBuf::startSeqIdx
uint32_t startSeqIdx
Definition: seq_process_common.h:133
SrcDestBufMap
std::map< SourceKey, std::unique_ptr< RoiProcessedBuf > > SrcDestBufMap
Definition: seq_process_common.h:160
RoiProcessedBuf::block
FullBatchBlock * block
Definition: seq_process_common.h:127
ReadyResult::rois
std::vector< NvDsRoiMeta > rois
Definition: seq_process_common.h:153
NvDsRoiMeta
Holds Information about ROI Metadata.
Definition: nvds_roi_meta.h:96
RoiProcessedBuf::processedSeq
uint32_t processedSeq
Definition: seq_process_common.h:136
NvDsPreProcessNetworkInputOrder_CUSTOM
@ NvDsPreProcessNetworkInputOrder_CUSTOM
Specifies any other custom input order handled by custom lib.
Definition: gst-plugins/gst-nvdspreprocess/include/nvdspreprocess_interface.h:98
nvbufsurftransform.h
nvbufsurface.h