NVIDIA DeepStream SDK API Reference

9.1 Release
9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-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 __NVSTREAMMUX_PADS__H__
19 #define __NVSTREAMMUX_PADS__H__
20 
21 #include <condition_variable>
22 #include <mutex>
23 #include <vector>
24 #include <chrono>
25 #include "nvstreammux_debug.h"
26 
27 typedef std::chrono::duration<double, std::nano> NanoSecondsType;
28 
29 typedef enum
30 {
37 } SINK_EVENT;
38 
39 
40 typedef enum
41 {
46 } SOURCE_STATE;
47 
48 typedef enum
49 {
53 } ENTRY_TYPE;
54 
55 
56 typedef enum
57 {
61 
63 
64 typedef enum
65 {
70 
71 typedef enum
72 {
77 
78 /*
79  * @brief Wrapper class for queued events
80  */
81 class QueueEntry
82 {
83  public :
85  {
86  type = ENTRY_EVENT;
87  }
88  virtual ~QueueEntry() = default;
89  void * wrapped;
92 };
93 
94 /*
95  * @brief Wrapper class for queued source buffers
96  */
97 class BufferWrapper : public QueueEntry
98 {
99 
100  public :
101  BufferWrapper(void * buffer, ENTRY_TYPE et, BATCH_SEQUENCE_TYPE bt = BATCH_SEQUENCE_IN_BATCH, uint64_t ts = 0) : QueueEntry(buffer, et, bt)
102  {
103  type = ENTRY_BUFFER;
104  raw = buffer;
105  timestamp = 0;
106  }
107  virtual ~BufferWrapper() = default;
108  void * raw;
109  uint32_t rawSize;
110  //virtual void copy_meta(NvStreammuxMeta * dest);
111  //virtual void copy_buf(OutBufType * dest);
112  virtual void free() = 0;
113 
114  uint64_t timestamp;
115 
116 };
117 
118 
119 class NvDsBufferWrapper : public BufferWrapper
120 {
121  public :
122  //virtual void copy_meta(NvStreamMeta * dest);
123  //virtual void copy_to(NvDsBuffer * buffer);
124 
125 
126 
127 };
128 
129 /*
130  * @brief Wrapper class for queued events
131  */
132 class EventWrapper : public QueueEntry
133 {
134  public :
135  EventWrapper(void * event, ENTRY_TYPE et , BATCH_SEQUENCE_TYPE bt) : QueueEntry(event, et, bt)
136  {
137  type = ENTRY_EVENT;
138  }
140 };
141 
142 /*
143  * @brief SourcePad is abstraction of pad for outgoing data
144  */
145 class SourcePad
146 {
147 
148  public :
149  SourcePad(unsigned int id, void * pad) : wrapped(pad), id(id)
150  {
151 
152  }
153  /*
154  * @brief push a buffer on outgoing pad
155  */
156  //void push_buffer(BufferWrapper *);
157  /*
158  * @brief push a buffer on outgoing pad
159  */
160  //void push_event();
161 
163  //unsigned int num_bufs_in_queue; //derive from buf_queue size
164 
165  void * wrapped;
166  protected :
167  unsigned int id;
168 };
169 /*
170  * @brief SinkPad is abstraction of pad for incoming data
171  */
172 class SinkPad
173 {
174 
175  public:
176  SinkPad(unsigned int id, void * pad) : queue(), id(id), wrapped(pad), mutex(), mutex_buffer_count(), source_id(id)
177  {
178  //top_event_index = -1;
179  buffer_count = 0;
180  max_buffer_count = 0;
181  frame_count = 0;
183  switched_to_idle = false;
184  switched_to_active = false;
185  mime_type = PAD_MIME_TYPE_VIDEO;
186  eos = false;
187  }
188 
189  virtual ~SinkPad(){}
190  /*
191  * @brief release all resources of this pad
192  */
193  void release();
194  /*
195  * @brief wait till queue is empty
196  */
197  void wait_till_empty();
198  /*
199  * @brief check if queue is empty
200  */
201  bool check_queue_empty();
202  //boolean check_queued_events();
203  /*
204  * @brief queue a buffer or event entry to ordered queue
205  */
206  void queue_entry(std::shared_ptr<QueueEntry> );
207  //void add_buffer(BufferWrapper *);
208  //void add_event(EventWrapper *);
209  /*
210  * @brief wait till there is some activity on the pad
211  */
212  //virtual void wait();
213  /*
214  * @brief notify all waiting on the pad
215  */
216  //virtual void notify_all();
217 
218  void push_events(SourcePad * src_pad);
219 
220  virtual void push_event(SourcePad * src_pad, QueueEntry *){};
221 
222 
223  unsigned int get_available();
224 
225  void adjust_event_indices(unsigned int, bool is_event);
226 
227  void update_frame_count(unsigned int count);
228 
229  unsigned long get_frame_count();
230 
232 
233  void reset();
234 
235  void clear_frames();
236 
237  void set_switched_to_idle(bool val)
238  {
239  switched_to_idle = val;
240  }
241 
242  void set_switched_to_active(bool val)
243  {
244  switched_to_active = val;
245  }
246 
248  {
249  return switched_to_idle;
250  }
251 
253  {
254  return switched_to_active;
255  }
256 
257  void set_mime_type(PAD_MIME_TYPE n_mime_type)
258  {
259  mime_type = n_mime_type;
260  }
261 
263  {
264  return mime_type;
265  }
266 
267  void set_eos(bool aEos)
268  {
269  eos = aEos;
270  }
271 
272  bool get_eos()
273  {
274  return eos;
275  }
276 
278  {
279  std::unique_lock<std::mutex> lck(mutex_buffer_count);
280  buffer_count++;
281  }
282 
284  void wait_if_queue_full();
285 
287  {
288  std::unique_lock<std::mutex> lck(mutex_buffer_count);
289  buffer_count--;
291  cv_input_full.notify_all();
292  }
293 
294  void set_max_buffer_count(unsigned int max_buffer_c)
295  {
296  std::unique_lock<std::mutex> lck(mutex_buffer_count);
297  max_buffer_count = max_buffer_c;
298  }
299 
300  unsigned int get_max_buffer_count()
301  {
302  std::unique_lock<std::mutex> lck(mutex_buffer_count);
303  return max_buffer_count;
304  }
305 
307  {
308  debug_iface = a_debug_iface;
309  }
310 
312  //unsigned int num_bufs_in_queue; //derive from buf_queue size
313 
314  std::vector <std::shared_ptr<QueueEntry> > queue;
315  std::vector <unsigned int> event_indices;
316  //std::vector <EventWrapper *> event_queue;
317  unsigned int id;
318  void * wrapped;
319  std::mutex mutex;
320  std::mutex mutex_buffer_count;
321  unsigned int top_event_index;
322  unsigned int source_id;
323  private:
327  bool switched_to_idle;
331  bool switched_to_active;
332  PAD_MIME_TYPE mime_type;
333  bool eos;
334  INvStreammuxDebug* debug_iface;
335  protected :
336  friend class SourcePad;
338  std::condition_variable cv;
340  std::condition_variable cv_input_full;
341  unsigned long frame_count;
342  unsigned long buffer_count;
343  unsigned long max_buffer_count;
344 
345 };
346 
347 class ISynchronizeBuffer
348 {
349  public:
350 
351  virtual ~ISynchronizeBuffer() = default;
352  virtual BUFFER_TS_STATUS get_synch_info(BufferWrapper* buffer) = 0;
353  virtual void removing_old_buffer(BufferWrapper* buffer) = 0;
358  virtual uint64_t GetBufferRunningTime(uint64_t pts, unsigned int stream_id) = 0;
359  virtual uint64_t GetCurrentRunningTime() = 0;
360 };
361 
362 #endif
SinkPad::get_mime_type
PAD_MIME_TYPE get_mime_type()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:262
SinkPad::wrapped
void * wrapped
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:318
QueueEntry::QueueEntry
QueueEntry(void *entry, ENTRY_TYPE et, BATCH_SEQUENCE_TYPE bt=BATCH_SEQUENCE_IN_BATCH)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:84
SinkPad::release
void release()
BATCH_SEQUENCE_PRE_BATCH
@ BATCH_SEQUENCE_PRE_BATCH
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:59
SinkPad::top_event_index
unsigned int top_event_index
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:321
SinkPad::buffer_count
unsigned long buffer_count
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:342
BATCH_SEQUENCE_IN_BATCH
@ BATCH_SEQUENCE_IN_BATCH
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:58
SinkPad::~SinkPad
virtual ~SinkPad()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:189
SinkPad::set_eos
void set_eos(bool aEos)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:267
SinkPad::get_eos
bool get_eos()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:272
BufferWrapper::free
virtual void free()=0
SinkPad::set_mime_type
void set_mime_type(PAD_MIME_TYPE n_mime_type)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:257
PAD_MIME_TYPE_INVALID
@ PAD_MIME_TYPE_INVALID
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:66
ISynchronizeBuffer::removing_old_buffer
virtual void removing_old_buffer(BufferWrapper *buffer)=0
SinkPad::check_queue_empty
bool check_queue_empty()
EventWrapper
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:132
SinkPad::adjust_event_indices
void adjust_event_indices(unsigned int, bool is_event)
PAD_MIME_TYPE_VIDEO
@ PAD_MIME_TYPE_VIDEO
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:67
ENTRY_EVENT
@ ENTRY_EVENT
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:52
SinkPad::set_debug_interface
void set_debug_interface(INvStreammuxDebug *a_debug_iface)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:306
SinkPad
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:172
ENTRY_BUFFER
@ ENTRY_BUFFER
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:51
QueueEntry::batch_type
BATCH_SEQUENCE_TYPE batch_type
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:90
SinkPad::queue_entry
void queue_entry(std::shared_ptr< QueueEntry >)
BufferWrapper
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:97
BUFFER_TS_EARLY
@ BUFFER_TS_EARLY
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:73
SinkPad::set_switched_to_active
void set_switched_to_active(bool val)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:242
SourcePad::state
SOURCE_STATE state
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:162
SOURCE_STATE
SOURCE_STATE
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:40
BUFFER_TS_ONTIME
@ BUFFER_TS_ONTIME
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:74
nvstreammux_debug.h
EventWrapper::EventWrapper
EventWrapper(void *event, ENTRY_TYPE et, BATCH_SEQUENCE_TYPE bt)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:135
SinkPad::clear_frames
void clear_frames()
ENTRY_ALL
@ ENTRY_ALL
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:50
ISynchronizeBuffer::~ISynchronizeBuffer
virtual ~ISynchronizeBuffer()=default
SinkPad::update_frame_count
void update_frame_count(unsigned int count)
SourcePad
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:145
SinkPad::cv
std::condition_variable cv
cv which shall be notified when we have input buffer in queue
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:338
BUFFER_TS_STATUS
BUFFER_TS_STATUS
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:71
PAD_MIME_TYPE_AUDIO
@ PAD_MIME_TYPE_AUDIO
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:68
SinkPad::wait_if_queue_full
void wait_if_queue_full()
always call after queue_entry() for type=ENTRY_BUFFER
SinkPad::reset
void reset()
BATCH_SEQUENCE_TYPE
BATCH_SEQUENCE_TYPE
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:56
BufferWrapper::raw
void * raw
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:108
QueueEntry::type
ENTRY_TYPE type
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:91
PAD_MIME_TYPE
PAD_MIME_TYPE
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:64
BUFFER_TS_STATUS
BUFFER_TS_STATUS
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:71
ISynchronizeBuffer::get_buffer_earlyby_time
virtual NanoSecondsType get_buffer_earlyby_time()=0
Returns the time by which the latest early-buffer was early.
SinkPad::get_switched_to_active
bool get_switched_to_active()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:252
SOURCE_STATE_STOPPING
@ SOURCE_STATE_STOPPING
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:45
SinkPad::push_events
void push_events(SourcePad *src_pad)
SinkPad::mutex_buffer_count
std::mutex mutex_buffer_count
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:320
SinkPad::reset_frame_count
void reset_frame_count()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:231
ISynchronizeBuffer::GetBufferRunningTime
virtual uint64_t GetBufferRunningTime(uint64_t pts, unsigned int stream_id)=0
SourcePad::wrapped
void * wrapped
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:165
BATCH_SEQUENCE_TYPE
BATCH_SEQUENCE_TYPE
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:56
BufferWrapper::rawSize
uint32_t rawSize
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:109
BUFFER_TS_LATE
@ BUFFER_TS_LATE
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:75
BATCH_SEQUENCE_POST_BATCH
@ BATCH_SEQUENCE_POST_BATCH
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:60
SinkPad::get_switched_to_idle
bool get_switched_to_idle()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:247
ENTRY_TYPE
ENTRY_TYPE
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:48
EventWrapper::~EventWrapper
~EventWrapper()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:139
SinkPad::mutex
std::mutex mutex
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:319
SOURCE_STATE_IDLE
@ SOURCE_STATE_IDLE
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:42
SOURCE_STATE_PAUSED
@ SOURCE_STATE_PAUSED
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:43
BufferWrapper::timestamp
uint64_t timestamp
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:114
SinkPad::wait_till_empty
void wait_till_empty()
BufferWrapper::BufferWrapper
BufferWrapper(void *buffer, ENTRY_TYPE et, BATCH_SEQUENCE_TYPE bt=BATCH_SEQUENCE_IN_BATCH, uint64_t ts=0)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:101
SinkPad::get_available
unsigned int get_available()
SinkPad::queue
std::vector< std::shared_ptr< QueueEntry > > queue
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:314
NanoSecondsType
std::chrono::duration< double, std::nano > NanoSecondsType
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:27
SINK_EVENT_STREAM_RESET
@ SINK_EVENT_STREAM_RESET
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:36
SinkPad::id
unsigned int id
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:317
SinkPad::frame_count
unsigned long frame_count
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:341
ENTRY_TYPE
ENTRY_TYPE
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:48
SourcePad::SourcePad
SourcePad(unsigned int id, void *pad)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:149
SinkPad::max_buffer_count
unsigned long max_buffer_count
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:343
SinkPad::get_frame_count
unsigned long get_frame_count()
SourcePad::id
unsigned int id
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:167
QueueEntry::~QueueEntry
virtual ~QueueEntry()=default
BufferWrapper::~BufferWrapper
virtual ~BufferWrapper()=default
SinkPad::pop_buffer_done
void pop_buffer_done()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:286
SinkPad::event_indices
std::vector< unsigned int > event_indices
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:315
SinkPad::source_id
unsigned int source_id
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:322
SINK_EVENT_PLAY_START
@ SINK_EVENT_PLAY_START
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:32
NvDsBufferWrapper
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:119
ISynchronizeBuffer::GetCurrentRunningTime
virtual uint64_t GetCurrentRunningTime()=0
SinkPad::push_event
virtual void push_event(SourcePad *src_pad, QueueEntry *)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:220
PAD_MIME_TYPE
PAD_MIME_TYPE
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:64
SINK_EVENT_EOS
@ SINK_EVENT_EOS
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:31
SOURCE_STATE_PLAYING
@ SOURCE_STATE_PLAYING
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:44
SinkPad::SinkPad
SinkPad(unsigned int id, void *pad)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:176
QueueEntry
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:81
NanoSecondsType
std::chrono::duration< double, std::nano > NanoSecondsType
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:27
SinkPad::push_buffer_done
void push_buffer_done()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:277
SinkPad::set_switched_to_idle
void set_switched_to_idle(bool val)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:237
SINK_EVENT_SEGMENT
@ SINK_EVENT_SEGMENT
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:33
ISynchronizeBuffer
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:347
ISynchronizeBuffer::get_synch_info
virtual BUFFER_TS_STATUS get_synch_info(BufferWrapper *buffer)=0
SOURCE_STATE
SOURCE_STATE
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:40
SINK_EVENT_STREAM_START
@ SINK_EVENT_STREAM_START
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:35
SinkPad::state
SOURCE_STATE state
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:311
SinkPad::set_max_buffer_count
void set_max_buffer_count(unsigned int max_buffer_c)
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:294
QueueEntry::wrapped
void * wrapped
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:89
SINK_EVENT
SINK_EVENT
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:29
SinkPad::get_max_buffer_count
unsigned int get_max_buffer_count()
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:300
INvStreammuxDebug
Definition: sources/libs/nvstreammux/include/nvstreammux_debug.h:21
SINK_EVENT_FLUSH_STOP
@ SINK_EVENT_FLUSH_STOP
Definition: 9.1/sources/libs/nvstreammux/include/nvstreammux_pads.h:34
SinkPad::cv_input_full
std::condition_variable cv_input_full
cv which shall be notified when we have space left in queue
Definition: sources/libs/nvstreammux/include/nvstreammux_pads.h:340