NVIDIA DeepStream SDK API Reference

6.4 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: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __NVSTREAMMUX_PADS__H__
25 #define __NVSTREAMMUX_PADS__H__
26 
27 #include <condition_variable>
28 #include <mutex>
29 #include <vector>
30 #include <chrono>
31 #include "nvstreammux_debug.h"
32 
33 typedef std::chrono::duration<double, std::nano> NanoSecondsType;
34 
35 typedef enum
36 {
43 } SINK_EVENT;
44 
45 
46 typedef enum
47 {
52 } SOURCE_STATE;
53 
54 typedef enum
55 {
59 } ENTRY_TYPE;
60 
61 
62 typedef enum
63 {
67 
69 
70 typedef enum
71 {
76 
77 typedef enum
78 {
83 
84 /*
85  * @brief Wrapper class for queued events
86  */
88 {
89  public :
91  {
92  type = ENTRY_EVENT;
93  }
94  virtual ~QueueEntry() = default;
95  void * wrapped;
98 };
99 
100 /*
101  * @brief Wrapper class for queued source buffers
102  */
103 class BufferWrapper : public QueueEntry
104 {
105 
106  public :
107  BufferWrapper(void * buffer, ENTRY_TYPE et, BATCH_SEQUENCE_TYPE bt = BATCH_SEQUENCE_IN_BATCH, uint64_t ts = 0) : QueueEntry(buffer, et, bt)
108  {
109  type = ENTRY_BUFFER;
110  raw = buffer;
111  timestamp = 0;
112  }
113  virtual ~BufferWrapper() = default;
114  void * raw;
115  uint32_t rawSize;
116  //virtual void copy_meta(NvStreammuxMeta * dest);
117  //virtual void copy_buf(OutBufType * dest);
118  virtual void free() = 0;
119 
120  uint64_t timestamp;
121 
122 };
123 
124 
126 {
127  public :
128  //virtual void copy_meta(NvStreamMeta * dest);
129  //virtual void copy_to(NvDsBuffer * buffer);
130 
131 
132 
133 };
134 
135 /*
136  * @brief Wrapper class for queued events
137  */
138 class EventWrapper : public QueueEntry
139 {
140  public :
141  EventWrapper(void * event, ENTRY_TYPE et , BATCH_SEQUENCE_TYPE bt) : QueueEntry(event, et, bt)
142  {
143  type = ENTRY_EVENT;
144  }
146 };
147 
148 /*
149  * @brief SourcePad is abstraction of pad for outgoing data
150  */
152 {
153 
154  public :
155  SourcePad(unsigned int id, void * pad) : wrapped(pad), id(id)
156  {
157 
158  }
159  /*
160  * @brief push a buffer on outgoing pad
161  */
162  //void push_buffer(BufferWrapper *);
163  /*
164  * @brief push a buffer on outgoing pad
165  */
166  //void push_event();
167 
169  //unsigned int num_bufs_in_queue; //derive from buf_queue size
170 
171  void * wrapped;
172  protected :
173  unsigned int id;
174 };
175 /*
176  * @brief SinkPad is abstraction of pad for incoming data
177  */
178 class SinkPad
179 {
180 
181  public:
182  SinkPad(unsigned int id, void * pad) : queue(), id(id), wrapped(pad), mutex(), mutex_buffer_count(), source_id(id)
183  {
184  //top_event_index = -1;
185  buffer_count = 0;
186  max_buffer_count = 0;
187  frame_count = 0;
189  switched_to_idle = false;
190  switched_to_active = false;
191  mime_type = PAD_MIME_TYPE_VIDEO;
192  eos = false;
193  }
194 
195  virtual ~SinkPad(){}
196  /*
197  * @brief release all resources of this pad
198  */
199  void release();
200  /*
201  * @brief wait till queue is empty
202  */
203  void wait_till_empty();
204  /*
205  * @brief check if queue is empty
206  */
207  bool check_queue_empty();
208  //boolean check_queued_events();
209  /*
210  * @brief queue a buffer or event entry to ordered queue
211  */
212  void queue_entry(std::shared_ptr<QueueEntry> );
213  //void add_buffer(BufferWrapper *);
214  //void add_event(EventWrapper *);
215  /*
216  * @brief wait till there is some activity on the pad
217  */
218  //virtual void wait();
219  /*
220  * @brief notify all waiting on the pad
221  */
222  //virtual void notify_all();
223 
224  void push_events(SourcePad * src_pad);
225 
226  virtual void push_event(SourcePad * src_pad, QueueEntry *){};
227 
228 
229  unsigned int get_available();
230 
231  void adjust_event_indices(unsigned int, bool is_event);
232 
233  void update_frame_count(unsigned int count);
234 
235  unsigned long get_frame_count();
236 
238 
239  void reset();
240 
241  void clear_frames();
242 
243  void set_switched_to_idle(bool val)
244  {
245  switched_to_idle = val;
246  }
247 
248  void set_switched_to_active(bool val)
249  {
250  switched_to_active = val;
251  }
252 
254  {
255  return switched_to_idle;
256  }
257 
259  {
260  return switched_to_active;
261  }
262 
263  void set_mime_type(PAD_MIME_TYPE n_mime_type)
264  {
265  mime_type = n_mime_type;
266  }
267 
269  {
270  return mime_type;
271  }
272 
273  void set_eos(bool aEos)
274  {
275  eos = aEos;
276  }
277 
278  bool get_eos()
279  {
280  return eos;
281  }
282 
284  {
285  std::unique_lock<std::mutex> lck(mutex_buffer_count);
286  buffer_count++;
287  }
288 
290  void wait_if_queue_full();
291 
293  {
294  std::unique_lock<std::mutex> lck(mutex_buffer_count);
295  buffer_count--;
297  cv_input_full.notify_all();
298  }
299 
300  void set_max_buffer_count(unsigned int max_buffer_c)
301  {
302  std::unique_lock<std::mutex> lck(mutex_buffer_count);
303  max_buffer_count = max_buffer_c;
304  }
305 
306  unsigned int get_max_buffer_count()
307  {
308  std::unique_lock<std::mutex> lck(mutex_buffer_count);
309  return max_buffer_count;
310  }
311 
313  {
314  debug_iface = a_debug_iface;
315  }
316 
318  //unsigned int num_bufs_in_queue; //derive from buf_queue size
319 
320  std::vector <std::shared_ptr<QueueEntry> > queue;
321  std::vector <unsigned int> event_indices;
322  //std::vector <EventWrapper *> event_queue;
323  unsigned int id;
324  void * wrapped;
325  std::mutex mutex;
326  std::mutex mutex_buffer_count;
327  unsigned int top_event_index;
328  unsigned int source_id;
329  private:
333  bool switched_to_idle;
337  bool switched_to_active;
338  PAD_MIME_TYPE mime_type;
339  bool eos;
340  INvStreammuxDebug* debug_iface;
341  protected :
342  friend class SourcePad;
344  std::condition_variable cv;
346  std::condition_variable cv_input_full;
347  unsigned long frame_count;
348  unsigned long buffer_count;
349  unsigned long max_buffer_count;
350 
351 };
352 
354 {
355  public:
356 
357  virtual ~ISynchronizeBuffer() = default;
358  virtual BUFFER_TS_STATUS get_synch_info(BufferWrapper* buffer) = 0;
359  virtual void removing_old_buffer(BufferWrapper* buffer) = 0;
364  virtual uint64_t GetBufferRunningTime(uint64_t pts, unsigned int stream_id) = 0;
365  virtual uint64_t GetCurrentRunningTime() = 0;
366 };
367 
368 #endif
SinkPad::get_mime_type
PAD_MIME_TYPE get_mime_type()
Definition: nvstreammux_pads.h:268
BATCH_SEQUENCE_TYPE
BATCH_SEQUENCE_TYPE
Definition: nvstreammux_pads.h:62
QueueEntry::QueueEntry
QueueEntry(void *entry, ENTRY_TYPE et, BATCH_SEQUENCE_TYPE bt=BATCH_SEQUENCE_IN_BATCH)
Definition: nvstreammux_pads.h:90
SinkPad::release
void release()
SinkPad::top_event_index
unsigned int top_event_index
Definition: nvstreammux_pads.h:327
SinkPad::buffer_count
unsigned long buffer_count
Definition: nvstreammux_pads.h:348
SinkPad::~SinkPad
virtual ~SinkPad()
Definition: nvstreammux_pads.h:195
SinkPad::queue
std::vector< std::shared_ptr< QueueEntry > > queue
Definition: nvstreammux_pads.h:320
SINK_EVENT_STREAM_START
@ SINK_EVENT_STREAM_START
Definition: nvstreammux_pads.h:41
SinkPad::set_eos
void set_eos(bool aEos)
Definition: nvstreammux_pads.h:273
SinkPad::get_eos
bool get_eos()
Definition: nvstreammux_pads.h:278
SOURCE_STATE_PAUSED
@ SOURCE_STATE_PAUSED
Definition: nvstreammux_pads.h:49
SinkPad::wrapped
void * wrapped
Definition: nvstreammux_pads.h:324
ENTRY_ALL
@ ENTRY_ALL
Definition: nvstreammux_pads.h:56
SINK_EVENT_STREAM_RESET
@ SINK_EVENT_STREAM_RESET
Definition: nvstreammux_pads.h:42
ENTRY_BUFFER
@ ENTRY_BUFFER
Definition: nvstreammux_pads.h:57
SINK_EVENT_SEGMENT
@ SINK_EVENT_SEGMENT
Definition: nvstreammux_pads.h:39
BufferWrapper::free
virtual void free()=0
SinkPad::set_mime_type
void set_mime_type(PAD_MIME_TYPE n_mime_type)
Definition: nvstreammux_pads.h:263
ISynchronizeBuffer::removing_old_buffer
virtual void removing_old_buffer(BufferWrapper *buffer)=0
ENTRY_TYPE
ENTRY_TYPE
Definition: nvstreammux_pads.h:54
SinkPad::check_queue_empty
bool check_queue_empty()
EventWrapper
Definition: nvstreammux_pads.h:138
SinkPad::event_indices
std::vector< unsigned int > event_indices
Definition: nvstreammux_pads.h:321
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:312
SinkPad
Definition: nvstreammux_pads.h:178
QueueEntry::batch_type
BATCH_SEQUENCE_TYPE batch_type
Definition: nvstreammux_pads.h:96
SINK_EVENT
SINK_EVENT
Definition: nvstreammux_pads.h:35
SinkPad::queue_entry
void queue_entry(std::shared_ptr< QueueEntry >)
BufferWrapper
Definition: nvstreammux_pads.h:103
SOURCE_STATE
SOURCE_STATE
Definition: nvstreammux_pads.h:46
SinkPad::set_switched_to_active
void set_switched_to_active(bool val)
Definition: nvstreammux_pads.h:248
SourcePad::state
SOURCE_STATE state
Definition: nvstreammux_pads.h:168
EventWrapper::EventWrapper
EventWrapper(void *event, ENTRY_TYPE et, BATCH_SEQUENCE_TYPE bt)
Definition: nvstreammux_pads.h:141
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:151
SinkPad::cv
std::condition_variable cv
cv which shall be notified when we have input buffer in queue
Definition: nvstreammux_pads.h:344
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:97
BufferWrapper::raw
void * raw
Definition: nvstreammux_pads.h:114
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:258
SinkPad::push_events
void push_events(SourcePad *src_pad)
SinkPad::mutex_buffer_count
std::mutex mutex_buffer_count
Definition: nvstreammux_pads.h:326
SinkPad::reset_frame_count
void reset_frame_count()
Definition: nvstreammux_pads.h:237
ENTRY_EVENT
@ ENTRY_EVENT
Definition: nvstreammux_pads.h:58
ISynchronizeBuffer::GetBufferRunningTime
virtual uint64_t GetBufferRunningTime(uint64_t pts, unsigned int stream_id)=0
BufferWrapper::rawSize
uint32_t rawSize
Definition: nvstreammux_pads.h:115
BATCH_SEQUENCE_PRE_BATCH
@ BATCH_SEQUENCE_PRE_BATCH
Definition: nvstreammux_pads.h:65
BUFFER_TS_STATUS
BUFFER_TS_STATUS
Definition: nvstreammux_pads.h:77
SOURCE_STATE_PLAYING
@ SOURCE_STATE_PLAYING
Definition: nvstreammux_pads.h:50
nvstreammux_debug.h
BATCH_SEQUENCE_IN_BATCH
@ BATCH_SEQUENCE_IN_BATCH
Definition: nvstreammux_pads.h:64
SinkPad::get_switched_to_idle
bool get_switched_to_idle()
Definition: nvstreammux_pads.h:253
EventWrapper::~EventWrapper
~EventWrapper()
Definition: nvstreammux_pads.h:145
SinkPad::mutex
std::mutex mutex
Definition: nvstreammux_pads.h:325
SINK_EVENT_FLUSH_STOP
@ SINK_EVENT_FLUSH_STOP
Definition: nvstreammux_pads.h:40
BufferWrapper::timestamp
uint64_t timestamp
Definition: nvstreammux_pads.h:120
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:107
SinkPad::get_available
unsigned int get_available()
SINK_EVENT_PLAY_START
@ SINK_EVENT_PLAY_START
Definition: nvstreammux_pads.h:38
SinkPad::id
unsigned int id
Definition: nvstreammux_pads.h:323
SinkPad::frame_count
unsigned long frame_count
Definition: nvstreammux_pads.h:347
SourcePad::SourcePad
SourcePad(unsigned int id, void *pad)
Definition: nvstreammux_pads.h:155
SinkPad::max_buffer_count
unsigned long max_buffer_count
Definition: nvstreammux_pads.h:349
SinkPad::get_frame_count
unsigned long get_frame_count()
SourcePad::id
unsigned int id
Definition: nvstreammux_pads.h:173
QueueEntry::~QueueEntry
virtual ~QueueEntry()=default
BUFFER_TS_ONTIME
@ BUFFER_TS_ONTIME
Definition: nvstreammux_pads.h:80
BufferWrapper::~BufferWrapper
virtual ~BufferWrapper()=default
SinkPad::pop_buffer_done
void pop_buffer_done()
Definition: nvstreammux_pads.h:292
PAD_MIME_TYPE_INVALID
@ PAD_MIME_TYPE_INVALID
Definition: nvstreammux_pads.h:72
NanoSecondsType
std::chrono::duration< double, std::nano > NanoSecondsType
Definition: nvstreammux_pads.h:33
SinkPad::source_id
unsigned int source_id
Definition: nvstreammux_pads.h:328
NvDsBufferWrapper
Definition: nvstreammux_pads.h:125
ISynchronizeBuffer::GetCurrentRunningTime
virtual uint64_t GetCurrentRunningTime()=0
SinkPad::push_event
virtual void push_event(SourcePad *src_pad, QueueEntry *)
Definition: nvstreammux_pads.h:226
PAD_MIME_TYPE_AUDIO
@ PAD_MIME_TYPE_AUDIO
Definition: nvstreammux_pads.h:74
SinkPad::SinkPad
SinkPad(unsigned int id, void *pad)
Definition: nvstreammux_pads.h:182
QueueEntry
Definition: nvstreammux_pads.h:87
BUFFER_TS_LATE
@ BUFFER_TS_LATE
Definition: nvstreammux_pads.h:81
SINK_EVENT_EOS
@ SINK_EVENT_EOS
Definition: nvstreammux_pads.h:37
SinkPad::push_buffer_done
void push_buffer_done()
Definition: nvstreammux_pads.h:283
SinkPad::set_switched_to_idle
void set_switched_to_idle(bool val)
Definition: nvstreammux_pads.h:243
QueueEntry::wrapped
void * wrapped
Definition: nvstreammux_pads.h:95
ISynchronizeBuffer
Definition: nvstreammux_pads.h:353
BATCH_SEQUENCE_POST_BATCH
@ BATCH_SEQUENCE_POST_BATCH
Definition: nvstreammux_pads.h:66
PAD_MIME_TYPE_VIDEO
@ PAD_MIME_TYPE_VIDEO
Definition: nvstreammux_pads.h:73
ISynchronizeBuffer::get_synch_info
virtual BUFFER_TS_STATUS get_synch_info(BufferWrapper *buffer)=0
SOURCE_STATE_STOPPING
@ SOURCE_STATE_STOPPING
Definition: nvstreammux_pads.h:51
PAD_MIME_TYPE
PAD_MIME_TYPE
Definition: nvstreammux_pads.h:70
SinkPad::state
SOURCE_STATE state
Definition: nvstreammux_pads.h:317
SinkPad::set_max_buffer_count
void set_max_buffer_count(unsigned int max_buffer_c)
Definition: nvstreammux_pads.h:300
BUFFER_TS_EARLY
@ BUFFER_TS_EARLY
Definition: nvstreammux_pads.h:79
SOURCE_STATE_IDLE
@ SOURCE_STATE_IDLE
Definition: nvstreammux_pads.h:48
SinkPad::get_max_buffer_count
unsigned int get_max_buffer_count()
Definition: nvstreammux_pads.h:306
INvStreammuxDebug
Definition: nvstreammux_debug.h:27
SourcePad::wrapped
void * wrapped
Definition: nvstreammux_pads.h:171
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:346