NVIDIA DeepStream SDK API Reference

7.1 Release
buffer.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024 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 
21 #ifndef DEEPSTREAM_BUFFER_HPP
22 #define DEEPSTREAM_BUFFER_HPP
23 
24 #include <vector>
25 #include <functional>
26 
27 #include "object.hpp"
28 #include "metadata.hpp"
29 #include "nvbufsurface.h"
30 
31 typedef struct _GstBuffer OpaqueBuffer;
32 
33 namespace deepstream {
34 
35 class Tensor;
36 
46 class Buffer {
47  public:
49  typedef struct _Latency {
51  unsigned int source_id;
53  unsigned int frame_num;
55  double latency;
56  } Latency;
57 
59  using FreeFunction = void(*)(void*);
60 
62  Buffer();
63 
74  Buffer(size_t length, void* data=nullptr, FreeFunction=nullptr);
75 
84  Buffer(const std::vector<uint8_t>);
85 
94  Buffer(OpaqueBuffer* buffer);
95 
97  Buffer(const Buffer&);
98 
100  Buffer(Buffer&&);
101 
103  Buffer& operator=(const Buffer&);
104 
106  Buffer& operator=(Buffer&&);
107 
109  virtual ~Buffer();
110 
112  operator bool() const;
113 
115  size_t size() const;
116 
118  uint64_t timestamp() const;
119 
121  std::vector<Latency> measureLatency() const;
122 
129  virtual size_t read(std::function<size_t(const void* data, size_t len)> callable);
130 
137  virtual size_t write(std::function<size_t(void* data, size_t len)> callable);
138 
140  OpaqueBuffer* give();
141 
146  virtual size_t batchSize();
147 
152  virtual Tensor* extract(unsigned int batchId);
153 
157  static void wrap(Tensor* );
158 
159  protected:
162 };
163 
164 class VideoBuffer : public Buffer {
165  public:
166  // NvSurface Buffer
167  VideoBuffer(size_t width, size_t height, NvBufSurfaceColorFormat video_format,
168  NvBufSurfaceMemType memtype, void* mem=nullptr, int gpu_id=0);
169 
170  // cast from a Buffer Object
171  VideoBuffer(const Buffer&);
172 
173  virtual size_t read(std::function<size_t(const void* data, size_t len)>);
174 
175  virtual size_t write(std::function<size_t(void* data, size_t len)>);
176 
178 
179  size_t width() const { return width_; }
180  size_t height() const { return height_; }
181  const NvBufSurfaceColorFormat format() const { return format_; }
182 
183  VideoBuffer clone() const;
184 
185  protected:
186  size_t width_ = 0;
187  size_t height_ = 0;
189 };
190 
191 } // namespace deepstream
192 
193 #endif
deepstream::VideoBuffer::getBatchMetadata
BatchMetadata getBatchMetadata()
deepstream::VideoBuffer::read
virtual size_t read(std::function< size_t(const void *data, size_t len)>)
deepstream::Buffer::read
virtual size_t read(std::function< size_t(const void *data, size_t len)> callable)
Read data from the buffer.
deepstream::Buffer::Buffer
Buffer()
empty buffer constructor
deepstream::Buffer::operator=
Buffer & operator=(const Buffer &)
Copy assignment.
deepstream::VideoBuffer::width_
size_t width_
Definition: buffer.hpp:186
deepstream::Buffer::measureLatency
std::vector< Latency > measureLatency() const
Return latency data of the buffer.
deepstream::VideoBuffer::height
size_t height() const
Definition: buffer.hpp:180
deepstream::VideoBuffer::clone
VideoBuffer clone() const
deepstream::VideoBuffer::write
virtual size_t write(std::function< size_t(void *data, size_t len)>)
deepstream::Buffer::_Latency::source_id
unsigned int source_id
Indicating the source from which the buffer is generated.
Definition: buffer.hpp:51
deepstream
Definition: buffer.hpp:33
deepstream::Buffer::size
size_t size() const
Size of the buffer in bytes.
deepstream::Buffer::~Buffer
virtual ~Buffer()
Destructor.
deepstream::BatchMetadata
Holds information about a formed batch containingframes from different sources.
Definition: metadata.hpp:407
deepstream::VideoBuffer::height_
size_t height_
Definition: buffer.hpp:187
OpaqueBuffer
struct _GstBuffer OpaqueBuffer
Definition: buffer.hpp:31
NvBufSurfaceMemType
NvBufSurfaceMemType
Specifies memory types for NvBufSurface.
Definition: nvbufsurface.h:312
deepstream::Buffer
Base class of a buffer.
Definition: buffer.hpp:46
deepstream::Buffer::wrap
static void wrap(Tensor *)
wrap the tensor to a new buffer
deepstream::VideoBuffer::format_
NvBufSurfaceColorFormat format_
Definition: buffer.hpp:188
deepstream::Buffer::_Latency
Unified definition of latency for a buffer.
Definition: buffer.hpp:49
metadata.hpp
deepstream::Buffer::write
virtual size_t write(std::function< size_t(void *data, size_t len)> callable)
Write data to the buffer.
deepstream::Buffer::buffer_
OpaqueBuffer * buffer_
opaque buffer pointer
Definition: buffer.hpp:161
deepstream::Buffer::Latency
struct deepstream::Buffer::_Latency Latency
Unified definition of latency for a buffer.
deepstream::Buffer::extract
virtual Tensor * extract(unsigned int batchId)
create a tensor object with the buffer data
deepstream::Buffer::batchSize
virtual size_t batchSize()
get the batch size of the buffer, 1 for un-batched buffer
deepstream::Tensor
Definition: service-maker/includes/tensor.hpp:49
deepstream::Buffer::_Latency::frame_num
unsigned int frame_num
Indicating the frame to which the buffer belongs.
Definition: buffer.hpp:53
deepstream::Buffer::_Latency::latency
double latency
Latency data.
Definition: buffer.hpp:55
deepstream::VideoBuffer::format
const NvBufSurfaceColorFormat format() const
Definition: buffer.hpp:181
deepstream::VideoBuffer::VideoBuffer
VideoBuffer(size_t width, size_t height, NvBufSurfaceColorFormat video_format, NvBufSurfaceMemType memtype, void *mem=nullptr, int gpu_id=0)
deepstream::Buffer::FreeFunction
void(*)(void *) FreeFunction
Signature of customized function for freeing data in a buffer.
Definition: buffer.hpp:59
deepstream::VideoBuffer
Definition: buffer.hpp:164
object.hpp
nvbufsurface.h
deepstream::Buffer::give
OpaqueBuffer * give()
Give up the ownership of this buffer and return the opaque buffer pointer.
deepstream::VideoBuffer::width
size_t width() const
Definition: buffer.hpp:179
NvBufSurfaceColorFormat
NvBufSurfaceColorFormat
Defines color formats for NvBufSurface.
Definition: nvbufsurface.h:107
deepstream::Buffer::timestamp
uint64_t timestamp() const
Timestamp of the buffer.