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

#include <H264DecoderV4L2Helper.h>

Collaboration diagram for h264DecoderV4L2Helper:
Collaboration graph

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< BuffermBuffer
 
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
 

Constructor & Destructor Documentation

◆ h264DecoderV4L2Helper()

h264DecoderV4L2Helper::h264DecoderV4L2Helper ( )
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.

◆ ~h264DecoderV4L2Helper()

h264DecoderV4L2Helper::~h264DecoderV4L2Helper ( )
inline

Member Function Documentation

◆ capture_thread()

void * h264DecoderV4L2Helper::capture_thread ( void * arg)
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.

Parameters
[in]argA pointer to the application data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeAllThreads()

void h264DecoderV4L2Helper::closeAllThreads ( frame_sp eosFrame)
Here is the call graph for this function:

◆ decode_process()

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

Parameters
[in]ctxReference to the decoder context struct created.
Returns
If the application implementing this call returns TRUE, EOS is detected by the decoder and all the buffers are dequeued; else the decode process continues running.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deQueAllBuffers()

void h264DecoderV4L2Helper::deQueAllBuffers ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dq_buffer()

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

Parameters
[in]ctxPointer to the decoder context struct created.
[in]v4l2_bufA reference to the v4l2_buffer structure to use for dequeueing.
[in]bufferA double pointer to the Buffer object associated with the dequeued buffer. Can be NULL.
[in]buf_typeType of buffer, one of the enum v4l2_buf_type.
[in]mem_typeMemory type of the plane, one of the enum v4l2_memory mem_type
[in]num_retriesNumber of times to try dequeuing a buffer before a failure is returned.
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ dq_event()

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.

Parameters
[in]ctxPointer to the decoder context struct created.
[in,out]eventA reference to the v4l2_event structure to fill.
[in]max_wait_msSpecifies the max wait time for dequeuing an event, in milliseconds.
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ init()

bool h264DecoderV4L2Helper::init ( std::function< void(frame_sp &)> send,
std::function< frame_sp()> makeFrame )
Here is the call graph for this function:

◆ initializeDecoder()

bool h264DecoderV4L2Helper::initializeDecoder ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

int h264DecoderV4L2Helper::process ( void * inputFrameBuffer,
size_t inputFrameSize,
uint64_t inputFrameTS )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ q_buffer()

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.

Parameters
[in]ctxPointer to the decoder context struct created.
[in]v4l2_bufA reference to the v4l2_buffer structure to use for queueing.
[in]bufferA pointer to the Buffer object.
[in]buf_typeType of buffer, one of the enum v4l2_buf_type.
[in]mem_typeMemory type of the plane, one of the enum v4l2_memory mem_type
[in]num_planesNumber of planes in the buffer.
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ query_set_capture()

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.

Parameters
[in]ctxPointer to the decoder context struct created.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_input_chunk_frame_sp()

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

Parameters
[in]streamInput stream
[in]bufferBuffer class pointer
Here is the caller graph for this function:

◆ req_buffers_on_capture_plane()

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.

Parameters
[in]ctxPointer to the decoder context struct created.
[in]buf_typeType of buffer, one of the enum v4l2_buf_type.
[in]mem_typeMemory type of the plane, one of the enum v4l2_memory mem_type, here V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
[in]num_buffersNumber of buffers to be requested.
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ req_buffers_on_output_plane()

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.

Parameters
[in]ctxPointer to the decoder context struct created.
[in]buf_typeType of buffer, one of the enum v4l2_buf_type.
[in]mem_typeMemory type of the plane, one of the enum v4l2_memory mem_type, here V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
[in]num_buffersNumber of buffers to be requested.
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ sendFrames()

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.

Parameters
[in]dmabuf_fdDMABUF FD of buffer.
[in]planevideo frame plane.
[in]streamA pointer to the output file stream.
Returns
0 for success, -1 otherwise.

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.

Here is the caller graph for this function:

◆ set_capture_plane_format()

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.

Parameters
[in]ctxPointer to the decoder context struct created.
[in]pixfmtOne of the coded V4L2 pixel formats.
[in]widthWidth of the frame
[in]heightHeight of the frame
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ set_ext_controls()

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.

Parameters
[in]fdcontext FD
[in]idcontrol id
[in]valuecontrol value
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ set_output_plane_format()

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.

Parameters
[in]ctxReference to the decoder context struct created.
[in]pixfmtOne of the coded V4L2 pixel formats.
[in]sizeimageMaximum size of the buffers on the output plane. containing encoded data in bytes.
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

◆ subscribe_event()

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

Parameters
[in]fdcontext FD
[in]typeType of the event
[in]idID of the event source
[in]flagsEvent flags
Returns
0 for success, -1 otherwise.
Here is the caller graph for this function:

Member Data Documentation

◆ ctx

context_t h264DecoderV4L2Helper::ctx
protected

◆ framesTimestampEntry

std::queue<uint64_t> h264DecoderV4L2Helper::framesTimestampEntry
protected

◆ m

std::mutex h264DecoderV4L2Helper::m
protected

◆ makeFrame

std::function<frame_sp()> h264DecoderV4L2Helper::makeFrame
protected

◆ mBuffer

boost::shared_ptr<Buffer> h264DecoderV4L2Helper::mBuffer
protected

◆ ret

int h264DecoderV4L2Helper::ret = 0
protected

◆ send

std::function<void(frame_sp &)> h264DecoderV4L2Helper::send
protected

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