Class representing a buffer.
The NvBuffer class is modeled on the basis of the v4l2_buffer
structure. The buffer has buf_type
v4l2_buf_type
, memory_type
v4l2_memory
, and an index. It contains an NvBufferPlane array similar to the array of v4l2_plane
structures in v4l2_buffer.m.planes
. It also contains a corresponding NvBufferPlaneFormat array that describes the format of each of the planes.
Even though NvBuffer
closely resembles v4l2 structures, it can be easily used with other non-v4l2 components. NvBuffer
contains data pointers, buffer length, file descriptor (FD) of buffer planes, buffer format (height, width, stride, etc.), and other members that are required by such components.
This class also provides buffer reference count functionality. This is useful when the same buffer is being used by multiple elements.
In the case of a V4L2 MMAP, this class provides convenience methods for mapping or unmapping the contents of the buffer to or from memory, allocating or deallocating software memory depending on its format.
Definition at line 85 of file NvBuffer.h.
Data Structures | |
struct | NvBufferPlane |
Holds the buffer plane parameters. More... | |
struct | NvBufferPlaneFormat |
Holds the buffer plane format. More... | |
Public Member Functions | |
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. More... | |
NvBuffer (uint32_t pixfmt, uint32_t width, uint32_t height, uint32_t index) | |
Creates a new NvBuffer for raw pixel formats. More... | |
NvBuffer (uint32_t size, uint32_t index) | |
Creates a new NvBuffer object for non-raw pixel formats. More... | |
~NvBuffer () | |
Destroys an NvBuffer object. More... | |
int | map () |
Maps the contents of the buffer to memory. More... | |
void | unmap () |
Unmaps the contents of the buffer from memory. More... | |
int | allocateMemory () |
Allocates software memory for the buffer. More... | |
void | deallocateMemory () |
Deallocates buffer memory. More... | |
int | ref () |
Increases the reference count of the buffer. More... | |
int | unref () |
Decreases the reference count of the buffer. More... | |
Static Public Member Functions | |
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. More... | |
Data Fields | |
enum v4l2_buf_type | buf_type |
Type of the buffer. More... | |
enum v4l2_memory | memory_type |
Type of memory associated with the buffer. More... | |
const uint32_t | index |
Holds the buffer index. More... | |
uint32_t | n_planes |
Holds the number of planes in the buffer. More... | |
NvBufferPlane | planes [MAX_PLANES] |
Holds the data pointer, plane file descriptor (FD), plane format, etc. More... | |
Friends | |
class | NvV4l2ElementPlane |
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.
This convenience method for V4L2 elements creates a new buffer with the planes array memset to zero and the refcount initialized to zero.
[in] | buf_type | Type of buffer, enumerated as v4l2_buf_type . |
[in] | memory_type | NvBuffer memory, enumerated as an v4l2_memory enum. |
[in] | n_planes | Number of planes in the buffer. |
[in] | fmt | Specifies a pointer to the array of buffer plane formats. Should contain at least n_planes elements. |
[in] | index | Index of the buffer in the plane. |
NvBuffer::NvBuffer | ( | uint32_t | pixfmt, |
uint32_t | width, | ||
uint32_t | height, | ||
uint32_t | index | ||
) |
Creates a new NvBuffer for raw pixel formats.
This convenience method for V4L2 elements is an NvBuffer
constructor for raw pixel formats only. It requires width, height, and pixel format to be specified.
The planes array is memset to zero and the refcount is initialized to zero.
[in] | pixfmt | Pixel format of the buffer. |
[in] | width | Width of the buffer in pixels. |
[in] | height | Height of the buffer in pixels. |
[in] | index | Index/ID of the buffer. |
NvBuffer::NvBuffer | ( | uint32_t | size, |
uint32_t | index | ||
) |
Creates a new NvBuffer object for non-raw pixel formats.
This convenience method for V4L2 elements is an NvBuffer
constructor for non raw pixel formats. It requires size of the buffer to be supplied.
The planes array is memset to zero and refcount initialized to zero.
[in] | size | Size of the buffer in bytes. |
[in] | index | Index/ID of the buffer. |
NvBuffer::~NvBuffer | ( | ) |
Destroys an NvBuffer object.
This method cleans up class instances, unmapping any mapped planes.
int NvBuffer::allocateMemory | ( | ) |
Allocates software memory for the buffer.
V4L2_MEMORY_USERPTR
memory.This method allocates memory on the basis of the buffer format: height, width, bytesperpixel, and sizeimage.
void NvBuffer::deallocateMemory | ( | ) |
Deallocates buffer memory.
V4L2_MEMORY_USERPTR
memory and if the memory was previously allocated using NvBuffer::allocateMemory.
|
static |
Fills the NvBuffer::NvBufferPlaneFormat array.
This convenience method populates the NvBuffer::NvBufferPlaneFormat
array on the basis of width, height and pixel format (raw_pixfmt). It also returns the number of planes required for the pixel format in num_planes.
[out] | num_planes | The number of planes. Must not be NULL. |
[in,out] | planefmts | Array of NvBuffer::NvBufferPlaneFormat to fill. Must be at least num_planes in length. For best results, pass an array of length MAX_PLANES. |
[in] | width | Width of the buffer in pixels. |
[in] | height | Height of the buffer in pixels. |
[in] | raw_pixfmt | Raw V4L2 pixel formats. |
int NvBuffer::map | ( | ) |
Maps the contents of the buffer to memory.
This method maps the file descriptor (FD) of the planes to a data pointer of planes
. (MMAP buffers only.)
int NvBuffer::ref | ( | ) |
Increases the reference count of the buffer.
This method is thread safe.
void NvBuffer::unmap | ( | ) |
Unmaps the contents of the buffer from memory.
(MMAP buffers only.)
int NvBuffer::unref | ( | ) |
Decreases the reference count of the buffer.
This thread-safe method decreases the buffer reference count if the buffer reference count is above 0.
|
friend |
Definition at line 290 of file NvBuffer.h.
enum v4l2_buf_type NvBuffer::buf_type |
Type of the buffer.
Definition at line 237 of file NvBuffer.h.
const uint32_t NvBuffer::index |
Holds the buffer index.
Definition at line 241 of file NvBuffer.h.
enum v4l2_memory NvBuffer::memory_type |
Type of memory associated with the buffer.
Definition at line 238 of file NvBuffer.h.
uint32_t NvBuffer::n_planes |
Holds the number of planes in the buffer.
Definition at line 243 of file NvBuffer.h.
NvBufferPlane NvBuffer::planes[MAX_PLANES] |
Holds the data pointer, plane file descriptor (FD), plane format, etc.
Definition at line 244 of file NvBuffer.h.