Jetson Inference
DNN Vision Library
gstBufferManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __GSTREAMER_BUFFER_MANAGER_H__
24 #define __GSTREAMER_BUFFER_MANAGER_H__
25 
26 #include "gstUtility.h"
27 #include "imageFormat.h"
28 #include "videoOptions.h"
29 #include "Event.h"
30 #include "Mutex.h"
31 #include "RingBuffer.h"
32 
33 
34 #ifdef ENABLE_NVMM
35 #if !GST_CHECK_VERSION(1,0,0)
36  #undef ENABLE_NVMM // NVMM is only enabled for GStreamer 1.0 and newer
37 #endif
38 
39 #include "NvInfer.h"
40 #if NV_TENSORRT_MAJOR > 8 || (NV_TENSORRT_MAJOR == 8 && NV_TENSORRT_MINOR >= 4)
41  #undef ENABLE_NVMM // debug NVMM under JetPack 5
42 #endif
43 #endif
44 
45 #define GST_CAPS_FEATURE_MEMORY_NVMM "memory:NVMM"
46 
47 
62 {
63 public:
67  gstBufferManager( videoOptions* options );
68 
73 
77  bool Enqueue( GstBuffer* buffer, GstCaps* caps );
78 
82  int Dequeue( void** output, imageFormat format, uint64_t timeout=UINT64_MAX );
83 
87  uint64_t GetLastTimestamp() const { return mLastTimestamp; }
88 
92  inline imageFormat GetRawFormat() const { return mFormatYUV; }
93 
97  inline uint64_t GetFrameCount() const { return mFrameCount; }
98 
99 protected:
100 
105  uint64_t mLastTimestamp;
109  uint64_t mFrameCount;
110  bool mNvmmUsed;
112 #ifdef ENABLE_NVMM
113  Mutex mNvmmMutex;
114  int mNvmmFD;
115  void* mNvmmEGL;
116  void* mNvmmCUDA;
117  size_t mNvmmSize;
118  bool mNvmmReleaseFD;
119 #endif
120 };
121 
122 #endif
gstBufferManager::mWaitEvent
Event mWaitEvent
Event that gets triggered when a new frame is recieved.
Definition: gstBufferManager.h:106
gstBufferManager::Enqueue
bool Enqueue(GstBuffer *buffer, GstCaps *caps)
Enqueue a GstBuffer from GStreamer.
gstBufferManager::mFormatYUV
imageFormat mFormatYUV
The YUV colorspace format coming from appsink (typically NV12 or YUY2)
Definition: gstBufferManager.h:101
gstBufferManager::mBufferYUV
RingBuffer mBufferYUV
Ringbuffer of CPU-based YUV frames (non-NVMM) that come from appsink.
Definition: gstBufferManager.h:102
Event
Event object for signalling other threads.
Definition: Event.h:33
gstBufferManager::mOptions
videoOptions * mOptions
Options of the gstDecoder / gstCamera object.
Definition: gstBufferManager.h:108
gstBufferManager::gstBufferManager
gstBufferManager(videoOptions *options)
Constructor.
Mutex
A lightweight mutual exclusion lock.
Definition: Mutex.h:35
gstBufferManager
gstBufferManager recieves GStreamer buffers from appsink elements and unpacks/maps them into CUDA add...
Definition: gstBufferManager.h:61
gstBufferManager::GetLastTimestamp
uint64_t GetLastTimestamp() const
Get timestamp of the latest dequeued frame.
Definition: gstBufferManager.h:87
gstUtility.h
gstBufferManager::mBufferRGB
RingBuffer mBufferRGB
Ringbuffer of frames that have been converted to RGB colorspace.
Definition: gstBufferManager.h:104
gstBufferManager::mFrameCount
uint64_t mFrameCount
Total number of frames that have been recieved.
Definition: gstBufferManager.h:109
Event.h
gstBufferManager::~gstBufferManager
~gstBufferManager()
Destructor.
gstBufferManager::mTimestamps
RingBuffer mTimestamps
Ringbuffer of timestamps that come from appsink.
Definition: gstBufferManager.h:103
Mutex.h
gstBufferManager::GetFrameCount
uint64_t GetFrameCount() const
Get the total number of frames that have been recieved.
Definition: gstBufferManager.h:97
RingBuffer.h
gstBufferManager::Dequeue
int Dequeue(void **output, imageFormat format, uint64_t timeout=UINT64_MAX)
Dequeue the next frame.
RingBuffer
Thread-safe circular ring buffer queue.
Definition: RingBuffer.h:33
gstBufferManager::GetRawFormat
imageFormat GetRawFormat() const
Get raw image format.
Definition: gstBufferManager.h:92
videoOptions
The videoOptions struct contains common settings that are used to configure and query videoSource and...
Definition: videoOptions.h:37
gstBufferManager::mLastTimestamp
uint64_t mLastTimestamp
Timestamp of the latest dequeued frame.
Definition: gstBufferManager.h:105
imageFormat.h
videoOptions.h
imageFormat
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
gstBufferManager::mNvmmUsed
bool mNvmmUsed
Is NVMM memory actually used by the stream?
Definition: gstBufferManager.h:110