Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
Buffer Class Reference

Class representing a buffer. More...

#include <H264DecoderV4L2Helper.h>

Collaboration diagram for Buffer:
Collaboration graph

Classes

struct  BufferPlane
 
struct  BufferPlaneFormat
 

Public Member Functions

 Buffer ()
 
 Buffer (enum v4l2_buf_type buf_type, enum v4l2_memory memory_type, uint32_t index)
 
 Buffer (enum v4l2_buf_type buf_type, enum v4l2_memory memory_type, uint32_t n_planes, BufferPlaneFormat *fmt, uint32_t index)
 
 ~Buffer ()
 
int map ()
 
void unmap ()
 
int fill_buffer_plane_format (uint32_t *num_planes, Buffer::BufferPlaneFormat *planefmts, uint32_t width, uint32_t height, uint32_t raw_pixfmt)
 

Public Attributes

enum v4l2_buf_type buf_type
 
enum v4l2_memory memory_type
 
uint32_t index
 
uint32_t n_planes
 
BufferPlane planes [MAX_PLANES]
 

Private Attributes

bool mapped
 

Detailed Description

Class representing a buffer.

The Buffer 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 BufferPlane array similar to the array of v4l2_plane structures in v4l2_buffer.m.planes. It also contains a corresponding BufferPlaneFormat array that describes the format of each of the planes.

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.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

Buffer::Buffer ( )
inline

◆ Buffer() [2/3]

Buffer::Buffer ( enum v4l2_buf_type buf_type,
enum v4l2_memory memory_type,
uint32_t index )

Execution command: ./decode_sample elementary_h264file.264 output_raw_file.yuv V4L2 H264 Video Decoder Sample

The video decoder device node isls /dev/nvhost-nvdec

In this sample:

Pixel Formats

OUTPUT PLANE CAPTURE PLANE
V4L2_PIX_FMT_H264 V4L2_PIX_FMT_NV12M

Memory Type

| OUTPUT PLANE | CAPTURE PLANE :-----—: | :-------—: | :--------—: MEMORY | V4L2_MEMORY_MMAP | V4L2_MEMORY_DMABUF

Supported Controls

  • #V4L2_CID_MPEG_VIDEO_DISABLE_COMPLETE_FRAME_INPUT
  • V4L2_CID_MIN_BUFFERS_FOR_CAPTURE (Get the minimum buffers to be allocated on capture plane. Read-only. Valid after #V4L2_EVENT_RESOLUTION_CHANGE)

Supported Events

Event Purpose
#V4L2_EVENT_RESOLUTION_CHANGE Resolution of the stream has changed.

Opening the Decoder

The decoder device node is opened through the v4l2_open IOCTL call. After opening the device, the application calls VIDIOC_QUERYCAP to identify the driver capabilities.

Subscribing events and setting up the planes

The application subscribes to the V4L2_EVENT_RESOLUTION_CHANGE event, to detect the change in the resolution and handle the plane buffers accordingly. It calls VIDIOC_S_FMT to setup the formats required on OUTPUT PLANE and CAPTURE PLANE for the data negotiation between the former and the driver.

Setting Controls

The application gets/sets the properties of the decoder by setting the controls, calling VIDIOC_S_EXT_CTRLS, VIDIOC_G_CTRL.

Buffer Management

Buffers are requested on the OUTPUT PLANE by the application, calling VIDIOC_REQBUFS. The actual buffers allocated by the decoder are then queried and exported as FD for the DMA-mapped buffer while mapped for Mmaped buffer. Status STREAMON is called on both planes to signal the decoder for processing.

Application continuously queues the encoded stream in the allocated OUTPUT PLANE buffer and dequeues the next empty buffer fed into the decoder. The decoder decodes the buffer and triggers the resolution change event on the capture plane

Handling Resolution Change Events

When the decoder generates a V4L2_EVENT_RESOLUTION_CHANGE event, the application calls STREAMOFF on the capture plane to tell the decoder to deallocate the current buffers by calling REQBUF with count zero, get the new capture plane format calling VIDIOC_G_FMT, and then proceed with setting up the buffers for the capture plane.

The decoding thread blocks on the DQ buffer call, which returns either after a successful decoded raw buffer or after a specific timeout.

EOS Handling

For sending EOS and receiving EOS from the decoder, the application must

  • Send EOS to the decoder by queueing on the output plane a buffer with bytesused = 0 for the 0th plane (v4l2_buffer.m.planes[0].bytesused = 0).
  • Dequeues buffers on the output plane until it gets a buffer with bytesused = 0 for the 0th plane (v4l2_buffer.m.planes[0].bytesused == 0)
  • Dequeues buffers on the capture plane until it gets a buffer with bytesused = 0 for the 0th plane. After the last buffer on the capture plane is dequeued, set STREAMOFF on both planes and destroy the allocated buffers.

◆ Buffer() [3/3]

Buffer::Buffer ( enum v4l2_buf_type buf_type,
enum v4l2_memory memory_type,
uint32_t n_planes,
BufferPlaneFormat * fmt,
uint32_t index )

◆ ~Buffer()

Buffer::~Buffer ( )
Here is the call graph for this function:

Member Function Documentation

◆ fill_buffer_plane_format()

int Buffer::fill_buffer_plane_format ( uint32_t * num_planes,
Buffer::BufferPlaneFormat * planefmts,
uint32_t width,
uint32_t height,
uint32_t raw_pixfmt )

Fills the Buffer::BufferPlaneFormat array.

◆ map()

int Buffer::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.)

Here is the caller graph for this function:

◆ unmap()

void Buffer::unmap ( )

Unmaps the contents of the buffer from memory. (MMAP buffers only.)

Here is the caller graph for this function:

Member Data Documentation

◆ buf_type

enum v4l2_buf_type Buffer::buf_type

Type of the buffer.

◆ index

uint32_t Buffer::index

Holds the buffer index.

◆ mapped

bool Buffer::mapped
private

◆ memory_type

enum v4l2_memory Buffer::memory_type

Type of memory associated with the buffer.

◆ n_planes

uint32_t Buffer::n_planes

Holds the number of planes in the buffer.

◆ planes

BufferPlane Buffer::planes[MAX_PLANES]

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


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