![]() |
ApraPipes 1.0
|
Class representing a buffer. More...
#include <H264DecoderV4L2Helper.h>
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 |
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.
|
inline |
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:
OUTPUT PLANE | CAPTURE PLANE |
---|---|
V4L2_PIX_FMT_H264 | V4L2_PIX_FMT_NV12M |
| OUTPUT PLANE | CAPTURE PLANE :-----—: | :-------—: | :--------—: MEMORY | V4L2_MEMORY_MMAP | V4L2_MEMORY_DMABUF
Event | Purpose |
---|---|
#V4L2_EVENT_RESOLUTION_CHANGE | Resolution of the stream has changed. |
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.
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.
The application gets/sets the properties of the decoder by setting the controls, calling VIDIOC_S_EXT_CTRLS, VIDIOC_G_CTRL.
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
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.
For sending EOS and receiving EOS from the decoder, the application must
v4l2_buffer.m.planes[0].bytesused = 0
).v4l2_buffer.m.planes[0].bytesused == 0
)Buffer::Buffer | ( | enum v4l2_buf_type | buf_type, |
enum v4l2_memory | memory_type, | ||
uint32_t | n_planes, | ||
BufferPlaneFormat * | fmt, | ||
uint32_t | index ) |
Buffer::~Buffer | ( | ) |
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.
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.)
void Buffer::unmap | ( | ) |
Unmaps the contents of the buffer from memory. (MMAP buffers only.)
enum v4l2_buf_type Buffer::buf_type |
Type of the buffer.
uint32_t Buffer::index |
Holds the buffer index.
|
private |
enum v4l2_memory Buffer::memory_type |
Type of memory associated with the buffer.
uint32_t Buffer::n_planes |
Holds the number of planes in the buffer.
BufferPlane Buffer::planes[MAX_PLANES] |
Holds the data pointer, plane file descriptor (FD), plane format, etc.