Jetson Linux API Reference

32.7.5 Release
NvBuffer Class Reference

Detailed Description

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.

Collaboration diagram for NvBuffer:

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
 

Constructor & Destructor Documentation

◆ NvBuffer() [1/3]

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.

Parameters
[in]buf_typeType of buffer, enumerated as v4l2_buf_type.
[in]memory_typeNvBuffer memory, enumerated as an v4l2_memory enum.
[in]n_planesNumber of planes in the buffer.
[in]fmtSpecifies a pointer to the array of buffer plane formats. Should contain at least n_planes elements.
[in]indexIndex of the buffer in the plane.

◆ NvBuffer() [2/3]

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.

Attention
The memory must be allocated by the application by calling NvBuffer::allocateMemory.
Parameters
[in]pixfmtPixel format of the buffer.
[in]widthWidth of the buffer in pixels.
[in]heightHeight of the buffer in pixels.
[in]indexIndex/ID of the buffer.

◆ NvBuffer() [3/3]

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.

Attention
The memory needs to be allocated by the application by calling NvBuffer::allocateMemory.
Parameters
[in]sizeSize of the buffer in bytes.
[in]indexIndex/ID of the buffer.

◆ ~NvBuffer()

NvBuffer::~NvBuffer ( )

Destroys an NvBuffer object.

This method cleans up class instances, unmapping any mapped planes.

Member Function Documentation

◆ allocateMemory()

int NvBuffer::allocateMemory ( )

Allocates software memory for the buffer.

Warning
This method works only for V4L2_MEMORY_USERPTR memory.

This method allocates memory on the basis of the buffer format: height, width, bytesperpixel, and sizeimage.

Returns
0 for success, -1 otherwise.

◆ deallocateMemory()

void NvBuffer::deallocateMemory ( )

Deallocates buffer memory.

Warning
This method works only for V4L2_MEMORY_USERPTR memory and if the memory was previously allocated using NvBuffer::allocateMemory.

◆ fill_buffer_plane_format()

static int NvBuffer::fill_buffer_plane_format ( uint32_t *  num_planes,
NvBuffer::NvBufferPlaneFormat planefmts,
uint32_t  width,
uint32_t  height,
uint32_t  raw_pixfmt 
)
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.

Parameters
[out]num_planesThe number of planes. Must not be NULL.
[in,out]planefmtsArray of NvBuffer::NvBufferPlaneFormat to fill. Must be at least num_planes in length. For best results, pass an array of length MAX_PLANES.
[in]widthWidth of the buffer in pixels.
[in]heightHeight of the buffer in pixels.
[in]raw_pixfmtRaw V4L2 pixel formats.
Returns
0 for success, -1 for an unsupported pixel format.

◆ map()

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.)

Returns
0 on success, -1 otherwise.

◆ ref()

int NvBuffer::ref ( )

Increases the reference count of the buffer.

This method is thread safe.

Returns
Reference count of the buffer after the operation.

◆ unmap()

void NvBuffer::unmap ( )

Unmaps the contents of the buffer from memory.

(MMAP buffers only.)

◆ unref()

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.

Returns
Reference count of the buffer after the operation.

Friends And Related Function Documentation

◆ NvV4l2ElementPlane

friend class NvV4l2ElementPlane
friend

Definition at line 290 of file NvBuffer.h.

Field Documentation

◆ buf_type

enum v4l2_buf_type NvBuffer::buf_type

Type of the buffer.

Definition at line 237 of file NvBuffer.h.

◆ index

const uint32_t NvBuffer::index

Holds the buffer index.

Definition at line 241 of file NvBuffer.h.

◆ memory_type

enum v4l2_memory NvBuffer::memory_type

Type of memory associated with the buffer.

Definition at line 238 of file NvBuffer.h.

◆ n_planes

uint32_t NvBuffer::n_planes

Holds the number of planes in the buffer.

Definition at line 243 of file NvBuffer.h.

◆ planes

NvBufferPlane NvBuffer::planes[MAX_PLANES]

Holds the data pointer, plane file descriptor (FD), plane format, etc.

Definition at line 244 of file NvBuffer.h.


The documentation for this class was generated from the following file: