Jetson Linux API Reference

32.7.5 Release
NvBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions, and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
36 #ifndef __NV_BUFFER_H__
37 #define __NV_BUFFER_H__
38 
39 #include <linux/videodev2.h>
40 #include <pthread.h>
41 #include <stdint.h>
42 
43 #include "v4l2_nv_extensions.h"
44 
58 #define MAX_PLANES 3
59 
85 class NvBuffer
86 {
87 public:
91  typedef struct
92  {
93  uint32_t width;
94  uint32_t height;
96  uint32_t bytesperpixel;
98  uint32_t stride;
99  uint32_t sizeimage;
101 
105  typedef struct
106  {
109  unsigned char *data;
110  uint32_t bytesused;
112  int fd;
114  uint32_t mem_offset;
116  uint32_t length;
117  } NvBufferPlane;
118 
136  NvBuffer(enum v4l2_buf_type buf_type, enum v4l2_memory memory_type,
137  uint32_t n_planes, NvBufferPlaneFormat *fmt, uint32_t index);
138 
157  NvBuffer(uint32_t pixfmt, uint32_t width, uint32_t height, uint32_t index);
158 
175  NvBuffer(uint32_t size, uint32_t index);
176 
183  ~NvBuffer();
184 
193  int map();
198  void unmap();
199 
210  int allocateMemory();
217  void deallocateMemory();
218 
226  int ref();
235  int unref();
236 
237  const enum v4l2_buf_type buf_type;
238  const enum v4l2_memory memory_type;
241  const uint32_t index;
243  uint32_t n_planes;
265  static int fill_buffer_plane_format(uint32_t *num_planes,
267  uint32_t width, uint32_t height, uint32_t raw_pixfmt);
268 private:
269  uint32_t ref_count;
270  pthread_mutex_t ref_lock;
273  bool mapped;
275  bool allocated;
277  NvBuffer *shared_buffer;
284  NvBuffer(const NvBuffer& that);
288  void operator=(NvBuffer const&);
289 
290  friend class NvV4l2ElementPlane;
291 };
293 #endif
NvBuffer::NvBufferPlane::mem_offset
uint32_t mem_offset
Holds the offset of the first valid byte from the data pointer.
Definition: NvBuffer.h:114
NvBuffer::index
const uint32_t index
Holds the buffer index.
Definition: NvBuffer.h:241
NvBuffer::NvBufferPlane::data
unsigned char * data
Holds a pointer to the plane memory.
Definition: NvBuffer.h:109
NvBuffer::NvBufferPlane
Holds the buffer plane parameters.
Definition: NvBuffer.h:105
NvBuffer::NvBufferPlane::fmt
NvBufferPlaneFormat fmt
Holds the format of the plane.
Definition: NvBuffer.h:107
NvBuffer::NvBufferPlaneFormat::width
uint32_t width
Holds the width of the plane in pixels.
Definition: NvBuffer.h:93
NvBuffer::fill_buffer_plane_format
static int fill_buffer_plane_format(uint32_t *num_planes, NvBuffer::NvBufferPlaneFormat *planefmts, uint32_t width, uint32_t height, uint32_t raw_pixfmt)
Fills the NvBuffer::NvBufferPlaneFormat array.
NvBuffer::deallocateMemory
void deallocateMemory()
Deallocates buffer memory.
MAX_PLANES
#define MAX_PLANES
Specifies the maximum number of planes a buffer can contain.
Definition: NvBuffer.h:58
NvBuffer::allocateMemory
int allocateMemory()
Allocates software memory for the buffer.
NvBuffer::~NvBuffer
~NvBuffer()
Destroys an NvBuffer object.
NvBuffer::unmap
void unmap()
Unmaps the contents of the buffer from memory.
NvBuffer::n_planes
uint32_t n_planes
Holds the number of planes in the buffer.
Definition: NvBuffer.h:243
NvBuffer::buf_type
enum v4l2_buf_type buf_type
Type of the buffer.
Definition: NvBuffer.h:237
NvBuffer::NvBufferPlane::fd
int fd
Holds the file descriptor (FD) of the plane of the exported buffer, in the case of V4L2 MMAP buffers.
Definition: NvBuffer.h:112
NvBuffer::planes
NvBufferPlane planes[MAX_PLANES]
Holds the data pointer, plane file descriptor (FD), plane format, etc.
Definition: NvBuffer.h:244
NvBuffer::NvBuffer
NvBuffer(enum v4l2_buf_type buf_type, enum v4l2_memory memory_type, uint32_t n_planes, NvBufferPlaneFormat *fmt, uint32_t index)
Creates a new NvBuffer object.
NvV4l2ElementPlane
Defines a helper class for operations performed on a V4L2 Element plane.
Definition: NvV4l2ElementPlane.h:104
NvBuffer::NvBufferPlaneFormat::bytesperpixel
uint32_t bytesperpixel
Holds the bytes used to represent one pixel in the plane.
Definition: NvBuffer.h:96
NvBuffer::ref
int ref()
Increases the reference count of the buffer.
NvBuffer::memory_type
enum v4l2_memory memory_type
Type of memory associated with the buffer.
Definition: NvBuffer.h:238
v4l2_nv_extensions.h
NvBuffer::NvBufferPlane::length
uint32_t length
Holds the size of the buffer in bytes.
Definition: NvBuffer.h:116
NvBuffer::NvBufferPlaneFormat::sizeimage
uint32_t sizeimage
Holds the size of the plane in bytes.
Definition: NvBuffer.h:99
NvBuffer::map
int map()
Maps the contents of the buffer to memory.
NvBuffer::NvBufferPlaneFormat
Holds the buffer plane format.
Definition: NvBuffer.h:91
NvBuffer
Class representing a buffer.
Definition: NvBuffer.h:85
NvBuffer::NvBufferPlaneFormat::stride
uint32_t stride
Holds the stride of the plane in bytes.
Definition: NvBuffer.h:98
NvBuffer::NvBufferPlaneFormat::height
uint32_t height
Holds the height of the plane in pixels.
Definition: NvBuffer.h:94
NvBuffer::unref
int unref()
Decreases the reference count of the buffer.
NvBuffer::NvBufferPlane::bytesused
uint32_t bytesused
Holds the number of valid bytes in the plane.
Definition: NvBuffer.h:110