![]() |
ApraPipes 1.0
|
#include <H264DecoderV4L2Helper.h>
Classes | |
struct | context_t |
Public Member Functions | |
h264DecoderV4L2Helper () | |
Struct defining the decoder context. The video decoder device node is /dev/nvhost-nvdec . The category name for the decoder is "NVDEC" . | |
~h264DecoderV4L2Helper () | |
void | read_input_chunk_frame_sp (void *inputFrameBuffer, size_t inputFrameSize, Buffer *buffer) |
Reads the encoded data from a file to the buffer structure. | |
int | sendFrames (int dmaOutFrameFd, frame_sp outFrame) |
Writes a plane data of the buffer to a file. | |
int | set_capture_plane_format (context_t *ctx, uint32_t pixfmt, uint32_t width, uint32_t height) |
Sets the format on the decoder capture plane. | |
void | query_set_capture (context_t *ctx) |
Query and Set Capture plane. | |
bool | decode_process (context_t &ctx, void *inputFrameBuffer, size_t inputFrameSize) |
Decode processing function for blocking mode. | |
int | dq_event (context_t *ctx, struct v4l2_event &event, uint32_t max_wait_ms) |
Dequeues an event. | |
int | dq_buffer (context_t *ctx, struct v4l2_buffer &v4l2_buf, Buffer **buffer, enum v4l2_buf_type buf_type, enum v4l2_memory memory_type, uint32_t num_retries) |
Dequeues a buffer from the plane. | |
int | q_buffer (context_t *ctx, struct v4l2_buffer &v4l2_buf, Buffer *buffer, enum v4l2_buf_type buf_type, enum v4l2_memory memory_type, int num_planes) |
Queues a buffer on the plane. | |
int | req_buffers_on_capture_plane (context_t *ctx, enum v4l2_buf_type buf_type, enum v4l2_memory mem_type, int num_buffers) |
Requests for buffers on the decoder capture plane. | |
int | req_buffers_on_output_plane (context_t *ctx, enum v4l2_buf_type buf_type, enum v4l2_memory mem_type, int num_buffers) |
Requests for buffers on the decoder output plane. | |
int | set_output_plane_format (context_t &ctx, uint32_t pixfmt, uint32_t sizeimage) |
Sets the format on the decoder output plane. | |
int | set_ext_controls (int fd, uint32_t id, uint32_t value) |
Sets the value of controls. | |
int | subscribe_event (int fd, uint32_t type, uint32_t id, uint32_t flags) |
Subscribes to an V4L2 event. | |
int | process (void *inputFrameBuffer, size_t inputFrameSize, uint64_t inputFrameTS) |
bool | init (std::function< void(frame_sp &)> send, std::function< frame_sp()> makeFrame) |
bool | initializeDecoder () |
void | closeAllThreads (frame_sp eosFrame) |
void | deQueAllBuffers () |
Static Public Member Functions | |
static void * | capture_thread (void *arg) |
Callback function on capture thread. | |
Protected Attributes | |
boost::shared_ptr< Buffer > | mBuffer |
context_t | ctx |
std::function< frame_sp()> | makeFrame |
std::function< void(frame_sp &)> | send |
int | ret = 0 |
std::queue< uint64_t > | framesTimestampEntry |
std::mutex | m |
|
inline |
Struct defining the decoder context. The video decoder device node is /dev/nvhost-nvdec
. The category name for the decoder is "NVDEC"
.
The context stores the information for decoding. Refer to V4L2 Video Decoder for more information on the decoder.
|
inline |
|
static |
Callback function on capture thread.
This is a callback function of the capture loop thread created. the function runs infinitely until signaled to stop, or error is encountered.
Setting the stream to off automatically stops the thread.
[in] | arg | A pointer to the application data. |
void h264DecoderV4L2Helper::closeAllThreads | ( | frame_sp | eosFrame | ) |
bool h264DecoderV4L2Helper::decode_process | ( | context_t & | ctx, |
void * | inputFrameBuffer, | ||
size_t | inputFrameSize ) |
Decode processing function for blocking mode.
Function loop to DQ and EnQ buffers on output plane till eos is signalled
[in] | ctx | Reference to the decoder context struct created. |
void h264DecoderV4L2Helper::deQueAllBuffers | ( | ) |
int h264DecoderV4L2Helper::dq_buffer | ( | context_t * | ctx, |
struct v4l2_buffer & | v4l2_buf, | ||
Buffer ** | buffer, | ||
enum v4l2_buf_type | buf_type, | ||
enum v4l2_memory | memory_type, | ||
uint32_t | num_retries ) |
Dequeues a buffer from the plane.
This method calls VIDIOC_DQBUF
IOCTL internally. This is a blocking call. This call returns when a buffer is successfully dequeued or timeout is reached. If the buffer is not NULL, returns the Buffer object at the index returned by VIDIOC_DQBUF IOCTL
[in] | ctx | Pointer to the decoder context struct created. |
[in] | v4l2_buf | A reference to the v4l2_buffer structure to use for dequeueing. |
[in] | buffer | A double pointer to the Buffer object associated with the dequeued buffer. Can be NULL. |
[in] | buf_type | Type of buffer, one of the enum v4l2_buf_type. |
[in] | mem_type | Memory type of the plane, one of the enum v4l2_memory mem_type |
[in] | num_retries | Number of times to try dequeuing a buffer before a failure is returned. |
int h264DecoderV4L2Helper::dq_event | ( | context_t * | ctx, |
struct v4l2_event & | event, | ||
uint32_t | max_wait_ms ) |
Dequeues an event.
Calls VIDIOC_DQEVENT
IOCTL internally. This is a blocking call. The call returns when an event is successfully dequeued or timeout is reached.
[in] | ctx | Pointer to the decoder context struct created. |
[in,out] | event | A reference to the v4l2_event structure to fill. |
[in] | max_wait_ms | Specifies the max wait time for dequeuing an event, in milliseconds. |
bool h264DecoderV4L2Helper::init | ( | std::function< void(frame_sp &)> | send, |
std::function< frame_sp()> | makeFrame ) |
bool h264DecoderV4L2Helper::initializeDecoder | ( | ) |
int h264DecoderV4L2Helper::process | ( | void * | inputFrameBuffer, |
size_t | inputFrameSize, | ||
uint64_t | inputFrameTS ) |
int h264DecoderV4L2Helper::q_buffer | ( | context_t * | ctx, |
struct v4l2_buffer & | v4l2_buf, | ||
Buffer * | buffer, | ||
enum v4l2_buf_type | buf_type, | ||
enum v4l2_memory | memory_type, | ||
int | num_planes ) |
Queues a buffer on the plane.
This method calls VIDIOC_QBUF
IOCTL internally.
[in] | ctx | Pointer to the decoder context struct created. |
[in] | v4l2_buf | A reference to the v4l2_buffer structure to use for queueing. |
[in] | buffer | A pointer to the Buffer object. |
[in] | buf_type | Type of buffer, one of the enum v4l2_buf_type. |
[in] | mem_type | Memory type of the plane, one of the enum v4l2_memory mem_type |
[in] | num_planes | Number of planes in the buffer. |
void h264DecoderV4L2Helper::query_set_capture | ( | context_t * | ctx | ) |
Query and Set Capture plane.
On successful dqevent, this method sets capture plane properties, buffers and streaming status.
[in] | ctx | Pointer to the decoder context struct created. |
void h264DecoderV4L2Helper::read_input_chunk_frame_sp | ( | void * | inputFrameBuffer, |
size_t | inputFrameSize, | ||
Buffer * | buffer ) |
Reads the encoded data from a file to the buffer structure.
Helper function to read the filestream to mmaped buffer
[in] | stream | Input stream |
[in] | buffer | Buffer class pointer |
int h264DecoderV4L2Helper::req_buffers_on_capture_plane | ( | context_t * | ctx, |
enum v4l2_buf_type | buf_type, | ||
enum v4l2_memory | mem_type, | ||
int | num_buffers ) |
Requests for buffers on the decoder capture plane.
Calls the VIDIOC_REQBUFS
IOCTL internally on the capture plane.
[in] | ctx | Pointer to the decoder context struct created. |
[in] | buf_type | Type of buffer, one of the enum v4l2_buf_type. |
[in] | mem_type | Memory type of the plane, one of the enum v4l2_memory mem_type, here V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE |
[in] | num_buffers | Number of buffers to be requested. |
int h264DecoderV4L2Helper::req_buffers_on_output_plane | ( | context_t * | ctx, |
enum v4l2_buf_type | buf_type, | ||
enum v4l2_memory | mem_type, | ||
int | num_buffers ) |
Requests for buffers on the decoder output plane.
Calls the VIDIOC_REQBUFS
IOCTL internally on the output plane.
[in] | ctx | Pointer to the decoder context struct created. |
[in] | buf_type | Type of buffer, one of the enum v4l2_buf_type. |
[in] | mem_type | Memory type of the plane, one of the enum v4l2_memory mem_type, here V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE |
[in] | num_buffers | Number of buffers to be requested. |
int h264DecoderV4L2Helper::sendFrames | ( | int | dmaOutFrameFd, |
frame_sp | outputFrame ) |
Writes a plane data of the buffer to a file.
This function writes data into the file from a plane of the DMA buffer.
[in] | dmabuf_fd | DMABUF FD of buffer. |
[in] | plane | video frame plane. |
[in] | stream | A pointer to the output file stream. |
This function writes the video frame from the HW buffer exported as FD into the destination file. Using the FD, HW buffer parameters are filled by calling NvBufferGetParams. The parameters received from the buffer are then used to read the planar stream from the HW buffer into the output filestream.
For reading from the HW buffer: A void data-pointer is created which stores the memory-mapped virtual addresses of the planes. For each plane, NvBufferMemMap is called which gets the memory-mapped virtual address of the plane with the access pointed by the flag into the void data-pointer. Before the mapped memory is accessed, a call to NvBufferMemSyncForCpu() with the virtual address returned must be present before any access is made by the CPU to the buffer.
After reading the data, the memory-mapped virtual address of the plane is unmapped.
int h264DecoderV4L2Helper::set_capture_plane_format | ( | context_t * | ctx, |
uint32_t | pixfmt, | ||
uint32_t | width, | ||
uint32_t | height ) |
Sets the format on the decoder capture plane.
Calls the VIDIOC_S_FMT
IOCTL internally on the capture plane.
[in] | ctx | Pointer to the decoder context struct created. |
[in] | pixfmt | One of the coded V4L2 pixel formats. |
[in] | width | Width of the frame |
[in] | height | Height of the frame |
int h264DecoderV4L2Helper::set_ext_controls | ( | int | fd, |
uint32_t | id, | ||
uint32_t | value ) |
Sets the value of controls.
Calls the VIDIOC_S_EXT_CTRLS
IOCTL internally with Control ID as an input.
[in] | fd | context FD |
[in] | id | control id |
[in] | value | control value |
int h264DecoderV4L2Helper::set_output_plane_format | ( | context_t & | ctx, |
uint32_t | pixfmt, | ||
uint32_t | sizeimage ) |
Sets the format on the decoder output plane.
Calls the VIDIOC_S_FMT
IOCTL internally on the output plane.
[in] | ctx | Reference to the decoder context struct created. |
[in] | pixfmt | One of the coded V4L2 pixel formats. |
[in] | sizeimage | Maximum size of the buffers on the output plane. containing encoded data in bytes. |
int h264DecoderV4L2Helper::subscribe_event | ( | int | fd, |
uint32_t | type, | ||
uint32_t | id, | ||
uint32_t | flags ) |
Subscribes to an V4L2 event.
Calls the VIDIOC_SUBSCRIBE_EVENT
IOCTL internally
[in] | fd | context FD |
[in] | type | Type of the event |
[in] | id | ID of the event source |
[in] | flags | Event flags |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |