NVIDIA DeepStream SDK API Reference

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