docs/html/gstBufferManager_8h_source.html
| | 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
61 class gstBufferManager
62 {
63 public:
67gstBufferManager( videoOptions* options );
68
72~gstBufferManager();
73
77bool Enqueue( GstBuffer* buffer, GstCaps* caps );
78
82int Dequeue( void** output, imageFormat format, uint64_t timeout=UINT64_MAX );
83
87 uint64_t GetLastTimestamp() const { return mLastTimestamp; }
88
92inline imageFormat GetRawFormat() const { return mFormatYUV; }
93
97inline uint64_t GetFrameCount() const { return mFrameCount; }
98
99 protected:
100
105 uint64_t mLastTimestamp;
109 uint64_t mFrameCount;
112 #ifdef ENABLE_NVMM
113Mutex mNvmmMutex;
114int mNvmmFD;
115void* mNvmmEGL;
116void* mNvmmCUDA;
117size_t mNvmmSize;
118bool mNvmmReleaseFD;
119 #endif
120 };
121
122 #endif
Event mWaitEvent
Event that gets triggered when a new frame is recieved.
Definition: gstBufferManager.h:106
bool Enqueue(GstBuffer *buffer, GstCaps *caps)
Enqueue a GstBuffer from GStreamer.
imageFormat mFormatYUV
The YUV colorspace format coming from appsink (typically NV12 or YUY2)
Definition: gstBufferManager.h:101
RingBuffer mBufferYUV
Ringbuffer of CPU-based YUV frames (non-NVMM) that come from appsink.
Definition: gstBufferManager.h:102
Event object for signalling other threads.
Definition: Event.h:33
videoOptions * mOptions
Options of the gstDecoder / gstCamera object.
Definition: gstBufferManager.h:108
gstBufferManager::gstBufferManager
gstBufferManager(videoOptions *options)
Constructor.
A lightweight mutual exclusion lock.
Definition: Mutex.h:35
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
RingBuffer mBufferRGB
Ringbuffer of frames that have been converted to RGB colorspace.
Definition: gstBufferManager.h:104
uint64_t mFrameCount
Total number of frames that have been recieved.
Definition: gstBufferManager.h:109
gstBufferManager::~gstBufferManager
~gstBufferManager()
Destructor.
RingBuffer mTimestamps
Ringbuffer of timestamps that come from appsink.
Definition: gstBufferManager.h:103
gstBufferManager::GetFrameCount
uint64_t GetFrameCount() const
Get the total number of frames that have been recieved.
Definition: gstBufferManager.h:97
int Dequeue(void **output, imageFormat format, uint64_t timeout=UINT64_MAX)
Dequeue the next frame.
Thread-safe circular ring buffer queue.
Definition: RingBuffer.h:33
gstBufferManager::GetRawFormat
imageFormat GetRawFormat() const
Get raw image format.
Definition: gstBufferManager.h:92
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
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
bool mNvmmUsed
Is NVMM memory actually used by the stream?
Definition: gstBufferManager.h:110